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