xref: /AOO41X/main/xmloff/source/chart/XMLChartStyleContext.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include "XMLChartStyleContext.hxx"
27 #include <xmloff/xmltoken.hxx>
28 #include "xmloff/xmlnmspe.hxx"
29 #include <xmloff/xmlnumfi.hxx>
30 #include <xmloff/families.hxx>
31 
32 #include "XMLChartPropertyContext.hxx"
33 
34 using namespace com::sun::star;
35 using ::xmloff::token::IsXMLToken;
36 using ::xmloff::token::XML_DATA_STYLE_NAME;
37 using ::xmloff::token::XML_PERCENTAGE_DATA_STYLE_NAME;
38 using ::xmloff::token::XML_TEXT_PROPERTIES;
39 using ::xmloff::token::XML_PARAGRAPH_PROPERTIES;
40 using ::xmloff::token::XML_GRAPHIC_PROPERTIES;
41 using ::xmloff::token::XML_CHART_PROPERTIES;
42 
43 
44 TYPEINIT1( XMLChartStyleContext, XMLPropStyleContext );
45 
46 // protected
47 
SetAttribute(sal_uInt16 nPrefixKey,const::rtl::OUString & rLocalName,const::rtl::OUString & rValue)48 void XMLChartStyleContext::SetAttribute(
49     sal_uInt16 nPrefixKey,
50     const ::rtl::OUString& rLocalName,
51     const ::rtl::OUString& rValue )
52 {
53     if( IsXMLToken( rLocalName, XML_DATA_STYLE_NAME ) )
54     {
55         msDataStyleName =rValue;
56     }
57     else if( IsXMLToken( rLocalName, XML_PERCENTAGE_DATA_STYLE_NAME ) )
58     {
59         msPercentageDataStyleName =rValue;
60     }
61     else
62     {
63         XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
64     }
65 }
66 
67 //public
68 
69 // CTOR
XMLChartStyleContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const::rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,SvXMLStylesContext & rStyles,sal_uInt16 nFamily)70 XMLChartStyleContext::XMLChartStyleContext(
71     SvXMLImport& rImport, sal_uInt16 nPrfx,
72     const ::rtl::OUString& rLName,
73     const uno::Reference< xml::sax::XAttributeList > & xAttrList,
74     SvXMLStylesContext& rStyles, sal_uInt16 nFamily ) :
75 
76         XMLShapeStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily ),
77         mrStyles( rStyles )
78 {}
79 
80 // DTOR
~XMLChartStyleContext()81 XMLChartStyleContext::~XMLChartStyleContext()
82 {}
83 
84 namespace
85 {
86 
lcl_NumberFormatStyleToProperty(const::rtl::OUString & rStyleName,const::rtl::OUString & rPropertyName,const SvXMLStylesContext & rStylesContext,const uno::Reference<beans::XPropertySet> & rPropSet)87     void lcl_NumberFormatStyleToProperty( const ::rtl::OUString& rStyleName, const ::rtl::OUString& rPropertyName,
88                                       const SvXMLStylesContext& rStylesContext,
89                                       const uno::Reference< beans::XPropertySet >& rPropSet )
90 {
91     if( rStyleName.getLength())
92     {
93         SvXMLNumFormatContext* pStyle = (SvXMLNumFormatContext *)rStylesContext.FindStyleChildContext(
94             XML_STYLE_FAMILY_DATA_STYLE, rStyleName, sal_True );
95         if( pStyle )
96         {
97             uno::Any aNumberFormat;
98             sal_Int32 nNumberFormat = pStyle->GetKey();
99             aNumberFormat <<= nNumberFormat;
100             rPropSet->setPropertyValue( rPropertyName, aNumberFormat );
101         }
102     }
103 }
104 
105 }// anonymous namespace
106 
FillPropertySet(const uno::Reference<beans::XPropertySet> & rPropSet)107 void XMLChartStyleContext::FillPropertySet(
108     const uno::Reference< beans::XPropertySet > & rPropSet )
109 {
110     try
111     {
112         XMLShapeStyleContext::FillPropertySet( rPropSet );
113     }
114     catch( beans::UnknownPropertyException&  )
115     {
116         DBG_ASSERT( false, "unknown property exception -> shape style not completly imported for chart style" );
117     }
118 
119     lcl_NumberFormatStyleToProperty( msDataStyleName, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NumberFormat" )), mrStyles, rPropSet );
120     lcl_NumberFormatStyleToProperty( msPercentageDataStyleName, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PercentageNumberFormat" )), mrStyles, rPropSet );
121 }
122 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)123 SvXMLImportContext *XMLChartStyleContext::CreateChildContext(
124     sal_uInt16 nPrefix,
125     const ::rtl::OUString& rLocalName,
126     const uno::Reference< xml::sax::XAttributeList > & xAttrList )
127 {
128     SvXMLImportContext* pContext = NULL;
129 
130     if( XML_NAMESPACE_STYLE == nPrefix )
131     {
132         sal_uInt32 nFamily = 0;
133         if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
134             nFamily = XML_TYPE_PROP_TEXT;
135         else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
136             nFamily = XML_TYPE_PROP_PARAGRAPH;
137         else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
138             nFamily = XML_TYPE_PROP_GRAPHIC;
139         else if( IsXMLToken( rLocalName, XML_CHART_PROPERTIES ) )
140             nFamily = XML_TYPE_PROP_CHART;
141         if( nFamily )
142         {
143             UniReference < SvXMLImportPropertyMapper > xImpPrMap =
144                 GetStyles()->GetImportPropertyMapper( GetFamily() );
145             if( xImpPrMap.is() )
146                 pContext = new XMLChartPropertyContext(
147                     GetImport(), nPrefix, rLocalName, xAttrList, nFamily,
148                     GetProperties(), xImpPrMap );
149         }
150     }
151 
152     if( !pContext )
153         pContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName,
154                                                              xAttrList );
155 
156     return pContext;
157 }
158