1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ChartPlotAreaOASISTContext.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "ChartPlotAreaOASISTContext.hxx"
34 #include "TransformerBase.hxx"
35 #include <xmloff/nmspmap.hxx>
36 #include "xmlnmspe.hxx"
37 #include <xmloff/xmltoken.hxx>
38 #include "DeepTContext.hxx"
39 #include "ActionMapTypesOASIS.hxx"
40 #include "MutableAttrList.hxx"
42 using namespace ::com::sun::star
;
43 using namespace ::xmloff::token
;
45 using ::com::sun::star::uno::Reference
;
46 using ::rtl::OUString
;
48 class XMLAxisOASISContext
: public XMLPersElemContentTContext
53 XMLAxisOASISContext( XMLTransformerBase
& rTransformer
,
54 const ::rtl::OUString
& rQName
,
55 ::rtl::Reference
< XMLPersAttrListTContext
> & rOutCategoriesContext
);
56 ~XMLAxisOASISContext();
58 virtual XMLTransformerContext
*CreateChildContext(
60 const ::rtl::OUString
& rLocalName
,
61 const ::rtl::OUString
& rQName
,
62 const Reference
< xml::sax::XAttributeList
>& xAttrList
);
64 virtual void StartElement( const Reference
< xml::sax::XAttributeList
>& rAttrList
);
65 virtual void EndElement();
67 bool IsCategoryAxis() const;
70 ::rtl::Reference
< XMLPersAttrListTContext
> & m_rCategoriesContext
;
71 bool m_bHasCategories
;
74 TYPEINIT1( XMLAxisOASISContext
, XMLPersElemContentTContext
);
76 XMLAxisOASISContext::XMLAxisOASISContext(
77 XMLTransformerBase
& rTransformer
,
78 const ::rtl::OUString
& rQName
,
79 ::rtl::Reference
< XMLPersAttrListTContext
> & rOutCategoriesContext
) :
80 XMLPersElemContentTContext( rTransformer
, rQName
),
81 m_rCategoriesContext( rOutCategoriesContext
),
82 m_bHasCategories( false )
85 XMLAxisOASISContext::~XMLAxisOASISContext()
88 XMLTransformerContext
* XMLAxisOASISContext::CreateChildContext(
90 const ::rtl::OUString
& rLocalName
,
91 const ::rtl::OUString
& rQName
,
92 const Reference
< xml::sax::XAttributeList
>& xAttrList
)
94 XMLTransformerContext
* pContext
= 0;
96 if( XML_NAMESPACE_CHART
== nPrefix
&&
97 IsXMLToken( rLocalName
, XML_CATEGORIES
) )
99 // store categories element at parent
100 m_rCategoriesContext
.set( new XMLPersAttrListTContext( GetTransformer(), rQName
));
101 m_bHasCategories
= true;
102 pContext
= m_rCategoriesContext
.get();
106 pContext
= XMLPersElemContentTContext::CreateChildContext(
107 nPrefix
, rLocalName
, rQName
, xAttrList
);
113 void XMLAxisOASISContext::StartElement(
114 const Reference
< xml::sax::XAttributeList
>& rAttrList
)
116 OUString aLocation
, aMacroName
;
117 Reference
< xml::sax::XAttributeList
> xAttrList( rAttrList
);
118 XMLMutableAttributeList
*pMutableAttrList
= 0;
119 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
120 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
122 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
125 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
, &aLocalName
);
127 if( nPrefix
== XML_NAMESPACE_CHART
&&
128 IsXMLToken( aLocalName
, XML_DIMENSION
) )
130 if( !pMutableAttrList
)
132 pMutableAttrList
= new XMLMutableAttributeList( xAttrList
);
133 xAttrList
= pMutableAttrList
;
136 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
137 XMLTokenEnum eToken
= XML_TOKEN_INVALID
;
138 if( IsXMLToken( rAttrValue
, XML_X
))
141 // has to be XML_CATEGORY for axes with a categories
142 // sub-element. The attribute is changed later (when it is
143 // known that there is a categories sub-element) in this case.
145 else if( IsXMLToken( rAttrValue
, XML_Y
))
149 else if( IsXMLToken( rAttrValue
, XML_Z
))
155 OSL_ENSURE( false, "ChartAxis: Invalid attribute value" );
158 if( eToken
!= XML_TOKEN_INVALID
)
160 OUString
aNewAttrQName(
161 GetTransformer().GetNamespaceMap().GetQNameByKey(
162 XML_NAMESPACE_CHART
, GetXMLToken( XML_CLASS
)));
163 pMutableAttrList
->RenameAttributeByIndex( i
, aNewAttrQName
);
165 pMutableAttrList
->SetValueByIndex( i
, GetXMLToken( eToken
));
170 XMLPersElemContentTContext::StartElement( xAttrList
);
173 void XMLAxisOASISContext::EndElement()
175 // if we have categories, change the "class" attribute
176 if( IsCategoryAxis() &&
177 m_rCategoriesContext
.is() )
179 OSL_ENSURE( GetAttrList().is(), "Invalid attribute list" );
180 XMLMutableAttributeList
* pMutableAttrList
=
181 new XMLMutableAttributeList( GetAttrList());
182 OUString
aAttrQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
183 XML_NAMESPACE_CHART
, GetXMLToken( XML_CLASS
)));
184 sal_Int16 nIndex
= pMutableAttrList
->GetIndexByName( aAttrQName
);
187 OSL_ENSURE( IsXMLToken( pMutableAttrList
->getValueByIndex( nIndex
),
188 XML_DOMAIN
), "Axis Dimension: invalid former value" );
189 pMutableAttrList
->SetValueByIndex( nIndex
, GetXMLToken( XML_CATEGORY
));
190 OSL_ENSURE( IsXMLToken( pMutableAttrList
->getValueByIndex( nIndex
),
191 XML_CATEGORY
), "Axis Dimension: invalid new value" );
194 GetTransformer().GetDocHandler()->startElement(
196 Reference
< xml::sax::XAttributeList
>( pMutableAttrList
));
198 GetTransformer().GetDocHandler()->endElement( GetExportQName());
204 bool XMLAxisOASISContext::IsCategoryAxis() const
206 return m_bHasCategories
;
210 TYPEINIT1( XMLChartPlotAreaOASISTContext
, XMLProcAttrTransformerContext
);
212 XMLChartPlotAreaOASISTContext::XMLChartPlotAreaOASISTContext(
213 XMLTransformerBase
& rTransformer
, const ::rtl::OUString
& rQName
) :
214 XMLProcAttrTransformerContext( rTransformer
, rQName
, OASIS_SHAPE_ACTIONS
)
218 XMLChartPlotAreaOASISTContext::~XMLChartPlotAreaOASISTContext()
221 XMLTransformerContext
* XMLChartPlotAreaOASISTContext::CreateChildContext(
223 const ::rtl::OUString
& rLocalName
,
224 const ::rtl::OUString
& rQName
,
225 const uno::Reference
< xml::sax::XAttributeList
>& xAttrList
)
227 XMLTransformerContext
*pContext
= 0;
229 if( XML_NAMESPACE_CHART
== nPrefix
&&
230 IsXMLToken( rLocalName
, XML_AXIS
) )
232 pContext
= new XMLAxisOASISContext( GetTransformer(), rQName
, m_rCategoriesContext
);
236 // export (and forget) categories if found in an axis-element
237 // otherwise export regularly
239 pContext
= XMLProcAttrTransformerContext::CreateChildContext(
240 nPrefix
, rLocalName
, rQName
, xAttrList
);
246 void XMLChartPlotAreaOASISTContext::EndElement()
249 XMLProcAttrTransformerContext::EndElement();
252 void XMLChartPlotAreaOASISTContext::ExportCategories()
254 if( m_rCategoriesContext
.is())
256 m_rCategoriesContext
->Export();
257 m_rCategoriesContext
.clear();