1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include "XMLChartStyleContext.hxx"
31 #include <xmloff/xmltoken.hxx>
32 #include "xmloff/xmlnmspe.hxx"
33 #include <xmloff/xmlnumfi.hxx>
34 #include <xmloff/families.hxx>
35 
36 #include "XMLChartPropertyContext.hxx"
37 
38 using namespace com::sun::star;
39 using ::xmloff::token::IsXMLToken;
40 using ::xmloff::token::XML_DATA_STYLE_NAME;
41 using ::xmloff::token::XML_PERCENTAGE_DATA_STYLE_NAME;
42 using ::xmloff::token::XML_TEXT_PROPERTIES;
43 using ::xmloff::token::XML_PARAGRAPH_PROPERTIES;
44 using ::xmloff::token::XML_GRAPHIC_PROPERTIES;
45 using ::xmloff::token::XML_CHART_PROPERTIES;
46 
47 
48 TYPEINIT1( XMLChartStyleContext, XMLPropStyleContext );
49 
50 // protected
51 
52 void XMLChartStyleContext::SetAttribute(
53 	sal_uInt16 nPrefixKey,
54 	const ::rtl::OUString& rLocalName,
55 	const ::rtl::OUString& rValue )
56 {
57 	if( IsXMLToken( rLocalName, XML_DATA_STYLE_NAME ) )
58 	{
59 		msDataStyleName =rValue;
60 	}
61     else if( IsXMLToken( rLocalName, XML_PERCENTAGE_DATA_STYLE_NAME ) )
62 	{
63         msPercentageDataStyleName =rValue;
64     }
65 	else
66 	{
67 		XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
68 	}
69 }
70 
71 //public
72 
73 // CTOR
74 XMLChartStyleContext::XMLChartStyleContext(
75 	SvXMLImport& rImport, sal_uInt16 nPrfx,
76 	const ::rtl::OUString& rLName,
77 	const uno::Reference< xml::sax::XAttributeList > & xAttrList,
78 	SvXMLStylesContext& rStyles, sal_uInt16 nFamily ) :
79 
80         XMLShapeStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily ),
81 		mrStyles( rStyles )
82 {}
83 
84 // DTOR
85 XMLChartStyleContext::~XMLChartStyleContext()
86 {}
87 
88 namespace
89 {
90 
91     void lcl_NumberFormatStyleToProperty( const ::rtl::OUString& rStyleName, const ::rtl::OUString& rPropertyName,
92                                       const SvXMLStylesContext& rStylesContext,
93                                       const uno::Reference< beans::XPropertySet >& rPropSet )
94 {
95     if( rStyleName.getLength())
96 	{
97 		SvXMLNumFormatContext* pStyle = (SvXMLNumFormatContext *)rStylesContext.FindStyleChildContext(
98 			XML_STYLE_FAMILY_DATA_STYLE, rStyleName, sal_True );
99 		if( pStyle )
100 		{
101 			uno::Any aNumberFormat;
102 			sal_Int32 nNumberFormat = pStyle->GetKey();
103 			aNumberFormat <<= nNumberFormat;
104 			rPropSet->setPropertyValue( rPropertyName, aNumberFormat );
105 		}
106 	}
107 }
108 
109 }// anonymous namespace
110 
111 void XMLChartStyleContext::FillPropertySet(
112 	const uno::Reference< beans::XPropertySet > & rPropSet )
113 {
114     try
115     {
116 	    XMLShapeStyleContext::FillPropertySet( rPropSet );
117     }
118     catch( beans::UnknownPropertyException&  )
119     {
120         DBG_ASSERT( false, "unknown property exception -> shape style not completly imported for chart style" );
121     }
122 
123     lcl_NumberFormatStyleToProperty( msDataStyleName, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NumberFormat" )), mrStyles, rPropSet );
124     lcl_NumberFormatStyleToProperty( msPercentageDataStyleName, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PercentageNumberFormat" )), mrStyles, rPropSet );
125 }
126 
127 SvXMLImportContext *XMLChartStyleContext::CreateChildContext(
128     sal_uInt16 nPrefix,
129     const ::rtl::OUString& rLocalName,
130     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
131 {
132 	SvXMLImportContext* pContext = NULL;
133 
134 	if( XML_NAMESPACE_STYLE == nPrefix )
135 	{
136 		sal_uInt32 nFamily = 0;
137 		if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
138 			nFamily = XML_TYPE_PROP_TEXT;
139 		else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
140 			nFamily = XML_TYPE_PROP_PARAGRAPH;
141 		else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
142 			nFamily = XML_TYPE_PROP_GRAPHIC;
143 		else if( IsXMLToken( rLocalName, XML_CHART_PROPERTIES ) )
144 			nFamily = XML_TYPE_PROP_CHART;
145 		if( nFamily )
146 		{
147 			UniReference < SvXMLImportPropertyMapper > xImpPrMap =
148 				GetStyles()->GetImportPropertyMapper( GetFamily() );
149 			if( xImpPrMap.is() )
150 				pContext = new XMLChartPropertyContext(
151 					GetImport(), nPrefix, rLocalName, xAttrList, nFamily,
152 					GetProperties(), xImpPrMap );
153 		}
154 	}
155 
156 	if( !pContext )
157 		pContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName,
158                                                              xAttrList );
159 
160 	return pContext;
161 }
162