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 :
34 : class XMLAxisOASISContext : public XMLPersElemContentTContext
35 : {
36 : public:
37 : TYPEINFO_OVERRIDE();
38 :
39 : XMLAxisOASISContext( XMLTransformerBase& rTransformer,
40 : const OUString& rQName,
41 : ::rtl::Reference< XMLPersAttrListTContext > & rOutCategoriesContext );
42 : virtual ~XMLAxisOASISContext();
43 :
44 : virtual XMLTransformerContext *CreateChildContext(
45 : sal_uInt16 nPrefix,
46 : const OUString& rLocalName,
47 : const OUString& rQName,
48 : const Reference< xml::sax::XAttributeList >& xAttrList ) SAL_OVERRIDE;
49 :
50 : virtual void StartElement( const Reference< xml::sax::XAttributeList >& rAttrList ) SAL_OVERRIDE;
51 : virtual void EndElement() SAL_OVERRIDE;
52 :
53 : bool IsCategoryAxis() const;
54 :
55 : private:
56 : ::rtl::Reference< XMLPersAttrListTContext > & m_rCategoriesContext;
57 : bool m_bHasCategories;
58 : };
59 :
60 0 : TYPEINIT1( XMLAxisOASISContext, XMLPersElemContentTContext );
61 :
62 0 : XMLAxisOASISContext::XMLAxisOASISContext(
63 : XMLTransformerBase& rTransformer,
64 : const OUString& rQName,
65 : ::rtl::Reference< XMLPersAttrListTContext > & rOutCategoriesContext ) :
66 : XMLPersElemContentTContext( rTransformer, rQName ),
67 : m_rCategoriesContext( rOutCategoriesContext ),
68 0 : m_bHasCategories( false )
69 0 : {}
70 :
71 0 : XMLAxisOASISContext::~XMLAxisOASISContext()
72 0 : {}
73 :
74 0 : XMLTransformerContext * XMLAxisOASISContext::CreateChildContext(
75 : sal_uInt16 nPrefix,
76 : const OUString& rLocalName,
77 : const OUString& rQName,
78 : const Reference< xml::sax::XAttributeList >& xAttrList )
79 : {
80 0 : XMLTransformerContext * pContext = 0;
81 :
82 0 : if( XML_NAMESPACE_CHART == nPrefix &&
83 0 : IsXMLToken( rLocalName, XML_CATEGORIES ) )
84 : {
85 : // store categories element at parent
86 0 : m_rCategoriesContext.set( new XMLPersAttrListTContext( GetTransformer(), rQName ));
87 0 : m_bHasCategories = true;
88 0 : pContext = m_rCategoriesContext.get();
89 : }
90 : else
91 : {
92 : pContext = XMLPersElemContentTContext::CreateChildContext(
93 0 : nPrefix, rLocalName, rQName, xAttrList );
94 : }
95 :
96 0 : return pContext;
97 : }
98 :
99 0 : void XMLAxisOASISContext::StartElement(
100 : const Reference< xml::sax::XAttributeList >& rAttrList )
101 : {
102 0 : Reference< xml::sax::XAttributeList > xAttrList( rAttrList );
103 0 : XMLMutableAttributeList *pMutableAttrList = 0;
104 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
105 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
106 : {
107 0 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
108 0 : OUString aLocalName;
109 : sal_uInt16 nPrefix =
110 0 : GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
111 :
112 0 : if( nPrefix == XML_NAMESPACE_CHART &&
113 0 : IsXMLToken( aLocalName, XML_DIMENSION ) )
114 : {
115 0 : if( !pMutableAttrList )
116 : {
117 0 : pMutableAttrList = new XMLMutableAttributeList( xAttrList );
118 0 : xAttrList = pMutableAttrList;
119 : }
120 :
121 0 : const OUString& rAttrValue = xAttrList->getValueByIndex( i );
122 0 : XMLTokenEnum eToken = XML_TOKEN_INVALID;
123 0 : if( IsXMLToken( rAttrValue, XML_X ))
124 : {
125 0 : eToken = XML_DOMAIN;
126 : // has to be XML_CATEGORY for axes with a categories
127 : // sub-element. The attribute is changed later (when it is
128 : // known that there is a categories sub-element) in this case.
129 : }
130 0 : else if( IsXMLToken( rAttrValue, XML_Y ))
131 : {
132 0 : eToken = XML_VALUE;
133 : }
134 0 : else if( IsXMLToken( rAttrValue, XML_Z ))
135 : {
136 0 : eToken = XML_SERIES;
137 : }
138 : else
139 : {
140 : OSL_FAIL( "ChartAxis: Invalid attribute value" );
141 : }
142 :
143 0 : if( eToken != XML_TOKEN_INVALID )
144 : {
145 : OUString aNewAttrQName(
146 0 : GetTransformer().GetNamespaceMap().GetQNameByKey(
147 0 : XML_NAMESPACE_CHART, GetXMLToken( XML_CLASS )));
148 0 : pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
149 :
150 0 : pMutableAttrList->SetValueByIndex( i, GetXMLToken( eToken ));
151 0 : }
152 : }
153 0 : }
154 :
155 0 : XMLPersElemContentTContext::StartElement( xAttrList );
156 0 : }
157 :
158 0 : void XMLAxisOASISContext::EndElement()
159 : {
160 : // if we have categories, change the "class" attribute
161 0 : if( IsCategoryAxis() &&
162 0 : m_rCategoriesContext.is() )
163 : {
164 : OSL_ENSURE( GetAttrList().is(), "Invalid attribute list" );
165 : XMLMutableAttributeList * pMutableAttrList =
166 0 : new XMLMutableAttributeList( GetAttrList());
167 0 : OUString aAttrQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
168 0 : XML_NAMESPACE_CHART, GetXMLToken( XML_CLASS )));
169 0 : sal_Int16 nIndex = pMutableAttrList->GetIndexByName( aAttrQName );
170 0 : if( nIndex != -1 )
171 : {
172 : OSL_ENSURE( IsXMLToken( pMutableAttrList->getValueByIndex( nIndex ),
173 : XML_DOMAIN ), "Axis Dimension: invalid former value" );
174 0 : pMutableAttrList->SetValueByIndex( nIndex, GetXMLToken( XML_CATEGORY ));
175 : OSL_ENSURE( IsXMLToken( pMutableAttrList->getValueByIndex( nIndex ),
176 : XML_CATEGORY ), "Axis Dimension: invalid new value" );
177 : }
178 :
179 0 : GetTransformer().GetDocHandler()->startElement(
180 0 : GetExportQName(),
181 0 : Reference< xml::sax::XAttributeList >( pMutableAttrList ));
182 0 : ExportContent();
183 0 : GetTransformer().GetDocHandler()->endElement( GetExportQName());
184 : }
185 : else
186 0 : Export();
187 0 : }
188 :
189 0 : bool XMLAxisOASISContext::IsCategoryAxis() const
190 : {
191 0 : return m_bHasCategories;
192 : }
193 :
194 :
195 0 : TYPEINIT1( XMLChartPlotAreaOASISTContext, XMLProcAttrTransformerContext );
196 :
197 0 : XMLChartPlotAreaOASISTContext::XMLChartPlotAreaOASISTContext(
198 : XMLTransformerBase & rTransformer, const OUString & rQName ) :
199 0 : XMLProcAttrTransformerContext( rTransformer, rQName, OASIS_SHAPE_ACTIONS )
200 : {
201 0 : }
202 :
203 0 : XMLChartPlotAreaOASISTContext::~XMLChartPlotAreaOASISTContext()
204 0 : {}
205 :
206 0 : XMLTransformerContext * XMLChartPlotAreaOASISTContext::CreateChildContext(
207 : sal_uInt16 nPrefix,
208 : const OUString& rLocalName,
209 : const OUString& rQName,
210 : const uno::Reference< xml::sax::XAttributeList >& xAttrList )
211 : {
212 0 : XMLTransformerContext *pContext = 0;
213 :
214 0 : if( XML_NAMESPACE_CHART == nPrefix &&
215 0 : IsXMLToken( rLocalName, XML_AXIS ) )
216 : {
217 0 : pContext = new XMLAxisOASISContext( GetTransformer(), rQName, m_rCategoriesContext );
218 : }
219 : else
220 : {
221 : // export (and forget) categories if found in an axis-element
222 : // otherwise export regularly
223 0 : ExportCategories();
224 : pContext = XMLProcAttrTransformerContext::CreateChildContext(
225 0 : nPrefix, rLocalName, rQName, xAttrList );
226 : }
227 :
228 0 : return pContext;
229 : }
230 :
231 0 : void XMLChartPlotAreaOASISTContext::EndElement()
232 : {
233 0 : ExportCategories();
234 0 : XMLProcAttrTransformerContext::EndElement();
235 0 : }
236 :
237 0 : void XMLChartPlotAreaOASISTContext::ExportCategories()
238 : {
239 0 : if( m_rCategoriesContext.is())
240 : {
241 0 : m_rCategoriesContext->Export();
242 0 : m_rCategoriesContext.clear();
243 : }
244 0 : }
245 :
246 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|