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 : #include <osl/diagnose.h>
29 :
30 : using namespace ::com::sun::star;
31 : using namespace ::xmloff::token;
32 :
33 : using ::com::sun::star::uno::Reference;
34 :
35 : class XMLAxisOASISContext : public XMLPersElemContentTContext
36 : {
37 : public:
38 : TYPEINFO_OVERRIDE();
39 :
40 : XMLAxisOASISContext( XMLTransformerBase& rTransformer,
41 : const OUString& rQName,
42 : ::rtl::Reference< XMLPersAttrListTContext > & rOutCategoriesContext );
43 : virtual ~XMLAxisOASISContext();
44 :
45 : virtual XMLTransformerContext *CreateChildContext(
46 : sal_uInt16 nPrefix,
47 : const OUString& rLocalName,
48 : const OUString& rQName,
49 : const Reference< xml::sax::XAttributeList >& xAttrList ) SAL_OVERRIDE;
50 :
51 : virtual void StartElement( const Reference< xml::sax::XAttributeList >& rAttrList ) SAL_OVERRIDE;
52 : virtual void EndElement() SAL_OVERRIDE;
53 :
54 0 : bool IsCategoryAxis() const { return m_bHasCategories;}
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 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 OUString& rLocalName,
78 : const 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 :
191 :
192 0 : TYPEINIT1( XMLChartPlotAreaOASISTContext, XMLProcAttrTransformerContext );
193 :
194 0 : XMLChartPlotAreaOASISTContext::XMLChartPlotAreaOASISTContext(
195 : XMLTransformerBase & rTransformer, const OUString & rQName ) :
196 0 : XMLProcAttrTransformerContext( rTransformer, rQName, OASIS_SHAPE_ACTIONS )
197 : {
198 0 : }
199 :
200 0 : XMLChartPlotAreaOASISTContext::~XMLChartPlotAreaOASISTContext()
201 0 : {}
202 :
203 0 : XMLTransformerContext * XMLChartPlotAreaOASISTContext::CreateChildContext(
204 : sal_uInt16 nPrefix,
205 : const OUString& rLocalName,
206 : const OUString& rQName,
207 : const uno::Reference< xml::sax::XAttributeList >& xAttrList )
208 : {
209 0 : XMLTransformerContext *pContext = 0;
210 :
211 0 : if( XML_NAMESPACE_CHART == nPrefix &&
212 0 : IsXMLToken( rLocalName, XML_AXIS ) )
213 : {
214 0 : pContext = new XMLAxisOASISContext( GetTransformer(), rQName, m_rCategoriesContext );
215 : }
216 : else
217 : {
218 : // export (and forget) categories if found in an axis-element
219 : // otherwise export regularly
220 0 : ExportCategories();
221 : pContext = XMLProcAttrTransformerContext::CreateChildContext(
222 0 : nPrefix, rLocalName, rQName, xAttrList );
223 : }
224 :
225 0 : return pContext;
226 : }
227 :
228 0 : void XMLChartPlotAreaOASISTContext::EndElement()
229 : {
230 0 : ExportCategories();
231 0 : XMLProcAttrTransformerContext::EndElement();
232 0 : }
233 :
234 0 : void XMLChartPlotAreaOASISTContext::ExportCategories()
235 : {
236 0 : if( m_rCategoriesContext.is())
237 : {
238 0 : m_rCategoriesContext->Export();
239 0 : m_rCategoriesContext.clear();
240 : }
241 0 : }
242 :
243 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|