xref: /AOO41X/main/xmloff/source/transform/ChartPlotAreaOASISTContext.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include "ChartPlotAreaOASISTContext.hxx"
27cdf0e10cSrcweir #include "TransformerBase.hxx"
28cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
29cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
30cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
31cdf0e10cSrcweir #include "DeepTContext.hxx"
32cdf0e10cSrcweir #include "ActionMapTypesOASIS.hxx"
33cdf0e10cSrcweir #include "MutableAttrList.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace ::com::sun::star;
36cdf0e10cSrcweir using namespace ::xmloff::token;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
39cdf0e10cSrcweir using ::rtl::OUString;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir class XMLAxisOASISContext : public XMLPersElemContentTContext
42cdf0e10cSrcweir {
43cdf0e10cSrcweir public:
44cdf0e10cSrcweir 	TYPEINFO();
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 	XMLAxisOASISContext( XMLTransformerBase& rTransformer,
47cdf0e10cSrcweir                          const ::rtl::OUString& rQName,
48cdf0e10cSrcweir                          ::rtl::Reference< XMLPersAttrListTContext > & rOutCategoriesContext );
49cdf0e10cSrcweir     ~XMLAxisOASISContext();
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 	virtual XMLTransformerContext *CreateChildContext(
52cdf0e10cSrcweir         sal_uInt16 nPrefix,
53cdf0e10cSrcweir         const ::rtl::OUString& rLocalName,
54cdf0e10cSrcweir         const ::rtl::OUString& rQName,
55cdf0e10cSrcweir         const Reference< xml::sax::XAttributeList >& xAttrList );
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     virtual void StartElement( const Reference< xml::sax::XAttributeList >& rAttrList );
58cdf0e10cSrcweir 	virtual void EndElement();
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     bool IsCategoryAxis() const;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir private:
63cdf0e10cSrcweir     ::rtl::Reference< XMLPersAttrListTContext > &   m_rCategoriesContext;
64cdf0e10cSrcweir     bool                                            m_bHasCategories;
65cdf0e10cSrcweir };
66cdf0e10cSrcweir 
67cdf0e10cSrcweir TYPEINIT1( XMLAxisOASISContext, XMLPersElemContentTContext );
68cdf0e10cSrcweir 
XMLAxisOASISContext(XMLTransformerBase & rTransformer,const::rtl::OUString & rQName,::rtl::Reference<XMLPersAttrListTContext> & rOutCategoriesContext)69cdf0e10cSrcweir XMLAxisOASISContext::XMLAxisOASISContext(
70cdf0e10cSrcweir     XMLTransformerBase& rTransformer,
71cdf0e10cSrcweir     const ::rtl::OUString& rQName,
72cdf0e10cSrcweir     ::rtl::Reference< XMLPersAttrListTContext > & rOutCategoriesContext ) :
73cdf0e10cSrcweir         XMLPersElemContentTContext( rTransformer, rQName ),
74cdf0e10cSrcweir         m_rCategoriesContext( rOutCategoriesContext ),
75cdf0e10cSrcweir         m_bHasCategories( false )
76cdf0e10cSrcweir {}
77cdf0e10cSrcweir 
~XMLAxisOASISContext()78cdf0e10cSrcweir XMLAxisOASISContext::~XMLAxisOASISContext()
79cdf0e10cSrcweir {}
80cdf0e10cSrcweir 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::rtl::OUString & rQName,const Reference<xml::sax::XAttributeList> & xAttrList)81cdf0e10cSrcweir XMLTransformerContext * XMLAxisOASISContext::CreateChildContext(
82cdf0e10cSrcweir     sal_uInt16 nPrefix,
83cdf0e10cSrcweir     const ::rtl::OUString& rLocalName,
84cdf0e10cSrcweir     const ::rtl::OUString& rQName,
85cdf0e10cSrcweir     const Reference< xml::sax::XAttributeList >& xAttrList )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	XMLTransformerContext * pContext = 0;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	if( XML_NAMESPACE_CHART == nPrefix &&
90cdf0e10cSrcweir         IsXMLToken( rLocalName, XML_CATEGORIES ) )
91cdf0e10cSrcweir     {
92cdf0e10cSrcweir         // store categories element at parent
93cdf0e10cSrcweir         m_rCategoriesContext.set( new XMLPersAttrListTContext( GetTransformer(), rQName ));
94cdf0e10cSrcweir         m_bHasCategories = true;
95cdf0e10cSrcweir         pContext = m_rCategoriesContext.get();
96cdf0e10cSrcweir     }
97cdf0e10cSrcweir     else
98cdf0e10cSrcweir     {
99cdf0e10cSrcweir         pContext =  XMLPersElemContentTContext::CreateChildContext(
100cdf0e10cSrcweir             nPrefix, rLocalName, rQName, xAttrList );
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     return pContext;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
StartElement(const Reference<xml::sax::XAttributeList> & rAttrList)106cdf0e10cSrcweir void XMLAxisOASISContext::StartElement(
107cdf0e10cSrcweir     const Reference< xml::sax::XAttributeList >& rAttrList )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir 	OUString aLocation, aMacroName;
110cdf0e10cSrcweir 	Reference< xml::sax::XAttributeList > xAttrList( rAttrList );
111cdf0e10cSrcweir 	XMLMutableAttributeList *pMutableAttrList = 0;
112cdf0e10cSrcweir 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
113cdf0e10cSrcweir 	for( sal_Int16 i=0; i < nAttrCount; i++ )
114cdf0e10cSrcweir 	{
115cdf0e10cSrcweir 		const OUString& rAttrName = xAttrList->getNameByIndex( i );
116cdf0e10cSrcweir 		OUString aLocalName;
117cdf0e10cSrcweir 		sal_uInt16 nPrefix =
118cdf0e10cSrcweir 			GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         if( nPrefix == XML_NAMESPACE_CHART &&
121cdf0e10cSrcweir             IsXMLToken( aLocalName, XML_DIMENSION ) )
122cdf0e10cSrcweir         {
123cdf0e10cSrcweir 			if( !pMutableAttrList )
124cdf0e10cSrcweir 			{
125cdf0e10cSrcweir 				pMutableAttrList = new XMLMutableAttributeList( xAttrList );
126cdf0e10cSrcweir 				xAttrList = pMutableAttrList;
127cdf0e10cSrcweir 			}
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 			const OUString& rAttrValue = xAttrList->getValueByIndex( i );
130cdf0e10cSrcweir             XMLTokenEnum eToken = XML_TOKEN_INVALID;
131cdf0e10cSrcweir             if( IsXMLToken( rAttrValue, XML_X ))
132cdf0e10cSrcweir             {
133cdf0e10cSrcweir                 eToken = XML_DOMAIN;
134cdf0e10cSrcweir                 // has to be XML_CATEGORY for axes with a categories
135cdf0e10cSrcweir                 // sub-element.  The attribute is changed later (when it is
136cdf0e10cSrcweir                 // known that there is a categories sub-element) in this case.
137cdf0e10cSrcweir             }
138cdf0e10cSrcweir             else if( IsXMLToken( rAttrValue, XML_Y ))
139cdf0e10cSrcweir             {
140cdf0e10cSrcweir                 eToken = XML_VALUE;
141cdf0e10cSrcweir             }
142cdf0e10cSrcweir             else if( IsXMLToken( rAttrValue, XML_Z ))
143cdf0e10cSrcweir             {
144cdf0e10cSrcweir                 eToken = XML_SERIES;
145cdf0e10cSrcweir             }
146cdf0e10cSrcweir             else
147cdf0e10cSrcweir             {
148cdf0e10cSrcweir                 OSL_ENSURE( false, "ChartAxis: Invalid attribute value" );
149cdf0e10cSrcweir             }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir             if( eToken != XML_TOKEN_INVALID )
152cdf0e10cSrcweir             {
153cdf0e10cSrcweir                 OUString aNewAttrQName(
154cdf0e10cSrcweir                     GetTransformer().GetNamespaceMap().GetQNameByKey(
155cdf0e10cSrcweir                         XML_NAMESPACE_CHART, GetXMLToken( XML_CLASS )));
156cdf0e10cSrcweir                 pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 				pMutableAttrList->SetValueByIndex( i, GetXMLToken( eToken ));
159cdf0e10cSrcweir             }
160cdf0e10cSrcweir         }
161cdf0e10cSrcweir     }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir     XMLPersElemContentTContext::StartElement( xAttrList );
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
EndElement()166cdf0e10cSrcweir void XMLAxisOASISContext::EndElement()
167cdf0e10cSrcweir {
168cdf0e10cSrcweir     // if we have categories, change the "class" attribute
169cdf0e10cSrcweir     if( IsCategoryAxis() &&
170cdf0e10cSrcweir         m_rCategoriesContext.is() )
171cdf0e10cSrcweir     {
172cdf0e10cSrcweir         OSL_ENSURE( GetAttrList().is(), "Invalid attribute list" );
173cdf0e10cSrcweir         XMLMutableAttributeList * pMutableAttrList =
174cdf0e10cSrcweir             new XMLMutableAttributeList( GetAttrList());
175cdf0e10cSrcweir         OUString aAttrQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
176cdf0e10cSrcweir                                  XML_NAMESPACE_CHART, GetXMLToken( XML_CLASS )));
177cdf0e10cSrcweir         sal_Int16 nIndex = pMutableAttrList->GetIndexByName( aAttrQName );
178cdf0e10cSrcweir         if( nIndex != -1 )
179cdf0e10cSrcweir         {
180cdf0e10cSrcweir             OSL_ENSURE( IsXMLToken( pMutableAttrList->getValueByIndex( nIndex ),
181cdf0e10cSrcweir                                     XML_DOMAIN ), "Axis Dimension: invalid former value" );
182cdf0e10cSrcweir             pMutableAttrList->SetValueByIndex( nIndex, GetXMLToken( XML_CATEGORY ));
183cdf0e10cSrcweir             OSL_ENSURE( IsXMLToken( pMutableAttrList->getValueByIndex( nIndex ),
184cdf0e10cSrcweir                                     XML_CATEGORY ), "Axis Dimension: invalid new value" );
185cdf0e10cSrcweir         }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir         GetTransformer().GetDocHandler()->startElement(
188cdf0e10cSrcweir             GetExportQName(),
189cdf0e10cSrcweir             Reference< xml::sax::XAttributeList >( pMutableAttrList ));
190cdf0e10cSrcweir         ExportContent();
191cdf0e10cSrcweir         GetTransformer().GetDocHandler()->endElement( GetExportQName());
192cdf0e10cSrcweir     }
193cdf0e10cSrcweir     else
194cdf0e10cSrcweir         Export();
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
IsCategoryAxis() const197cdf0e10cSrcweir bool XMLAxisOASISContext::IsCategoryAxis() const
198cdf0e10cSrcweir {
199cdf0e10cSrcweir     return m_bHasCategories;
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 
203cdf0e10cSrcweir TYPEINIT1( XMLChartPlotAreaOASISTContext, XMLProcAttrTransformerContext );
204cdf0e10cSrcweir 
XMLChartPlotAreaOASISTContext(XMLTransformerBase & rTransformer,const::rtl::OUString & rQName)205cdf0e10cSrcweir XMLChartPlotAreaOASISTContext::XMLChartPlotAreaOASISTContext(
206cdf0e10cSrcweir     XMLTransformerBase & rTransformer, const ::rtl::OUString & rQName ) :
207cdf0e10cSrcweir         XMLProcAttrTransformerContext( rTransformer, rQName, OASIS_SHAPE_ACTIONS )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
~XMLChartPlotAreaOASISTContext()211cdf0e10cSrcweir XMLChartPlotAreaOASISTContext::~XMLChartPlotAreaOASISTContext()
212cdf0e10cSrcweir {}
213cdf0e10cSrcweir 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::rtl::OUString & rQName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)214cdf0e10cSrcweir XMLTransformerContext * XMLChartPlotAreaOASISTContext::CreateChildContext(
215cdf0e10cSrcweir     sal_uInt16 nPrefix,
216cdf0e10cSrcweir     const ::rtl::OUString& rLocalName,
217cdf0e10cSrcweir     const ::rtl::OUString& rQName,
218cdf0e10cSrcweir     const uno::Reference< xml::sax::XAttributeList >& xAttrList )
219cdf0e10cSrcweir {
220cdf0e10cSrcweir 	XMLTransformerContext *pContext = 0;
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 	if( XML_NAMESPACE_CHART == nPrefix &&
223cdf0e10cSrcweir 		IsXMLToken( rLocalName, XML_AXIS ) )
224cdf0e10cSrcweir 	{
225cdf0e10cSrcweir         pContext = new XMLAxisOASISContext( GetTransformer(), rQName, m_rCategoriesContext );
226cdf0e10cSrcweir     }
227cdf0e10cSrcweir     else
228cdf0e10cSrcweir 	{
229cdf0e10cSrcweir         // export (and forget) categories if found in an axis-element
230cdf0e10cSrcweir         // otherwise export regularly
231cdf0e10cSrcweir         ExportCategories();
232cdf0e10cSrcweir         pContext =  XMLProcAttrTransformerContext::CreateChildContext(
233cdf0e10cSrcweir                 nPrefix, rLocalName, rQName, xAttrList );
234cdf0e10cSrcweir 	}
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 	return pContext;
237cdf0e10cSrcweir }
238cdf0e10cSrcweir 
EndElement()239cdf0e10cSrcweir void XMLChartPlotAreaOASISTContext::EndElement()
240cdf0e10cSrcweir {
241cdf0e10cSrcweir     ExportCategories();
242cdf0e10cSrcweir     XMLProcAttrTransformerContext::EndElement();
243cdf0e10cSrcweir }
244cdf0e10cSrcweir 
ExportCategories()245cdf0e10cSrcweir void XMLChartPlotAreaOASISTContext::ExportCategories()
246cdf0e10cSrcweir {
247cdf0e10cSrcweir     if( m_rCategoriesContext.is())
248cdf0e10cSrcweir     {
249cdf0e10cSrcweir         m_rCategoriesContext->Export();
250cdf0e10cSrcweir         m_rCategoriesContext.clear();
251cdf0e10cSrcweir     }
252cdf0e10cSrcweir }
253