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 "ChartPlotAreaOOoTContext.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 "ActionMapTypesOOo.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 XMLAxisOOoContext : public XMLPersElemContentTContext
35 : {
36 : public:
37 : TYPEINFO_OVERRIDE();
38 :
39 : XMLAxisOOoContext( XMLTransformerBase& rTransformer,
40 : const OUString& rQName );
41 : virtual ~XMLAxisOOoContext();
42 :
43 : virtual void StartElement( const Reference< xml::sax::XAttributeList >& rAttrList ) SAL_OVERRIDE;
44 :
45 : bool IsCategoryAxis() const;
46 :
47 : private:
48 : bool m_bIsCategoryAxis;
49 : };
50 :
51 0 : TYPEINIT1( XMLAxisOOoContext, XMLPersElemContentTContext );
52 :
53 6 : XMLAxisOOoContext::XMLAxisOOoContext(
54 : XMLTransformerBase& rTransformer,
55 : const OUString& rQName ) :
56 : XMLPersElemContentTContext( rTransformer, rQName ),
57 6 : m_bIsCategoryAxis( false )
58 6 : {}
59 :
60 12 : XMLAxisOOoContext::~XMLAxisOOoContext()
61 12 : {}
62 :
63 6 : void XMLAxisOOoContext::StartElement(
64 : const Reference< xml::sax::XAttributeList >& rAttrList )
65 : {
66 6 : Reference< xml::sax::XAttributeList > xAttrList( rAttrList );
67 6 : XMLMutableAttributeList *pMutableAttrList = 0;
68 6 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
69 24 : for( sal_Int16 i=0; i < nAttrCount; i++ )
70 : {
71 18 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
72 36 : OUString aLocalName;
73 : sal_uInt16 nPrefix =
74 18 : GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
75 :
76 36 : if( nPrefix == XML_NAMESPACE_CHART &&
77 18 : IsXMLToken( aLocalName, XML_CLASS ) )
78 : {
79 6 : if( !pMutableAttrList )
80 : {
81 6 : pMutableAttrList = new XMLMutableAttributeList( xAttrList );
82 6 : xAttrList = pMutableAttrList;
83 : }
84 :
85 6 : const OUString& rAttrValue = xAttrList->getValueByIndex( i );
86 6 : XMLTokenEnum eToken = XML_TOKEN_INVALID;
87 12 : if( IsXMLToken( rAttrValue, XML_DOMAIN ) ||
88 6 : IsXMLToken( rAttrValue, XML_CATEGORY ))
89 : {
90 3 : eToken = XML_X;
91 3 : if( IsXMLToken( rAttrValue, XML_CATEGORY ) )
92 3 : m_bIsCategoryAxis = true;
93 : }
94 3 : else if( IsXMLToken( rAttrValue, XML_VALUE ))
95 : {
96 3 : eToken = XML_Y;
97 : }
98 0 : else if( IsXMLToken( rAttrValue, XML_SERIES ))
99 : {
100 0 : eToken = XML_Z;
101 : }
102 : else
103 : {
104 : OSL_FAIL( "ChartAxis: Invalid attribute value" );
105 : }
106 :
107 6 : if( eToken != XML_TOKEN_INVALID )
108 : {
109 : OUString aNewAttrQName(
110 6 : GetTransformer().GetNamespaceMap().GetQNameByKey(
111 12 : XML_NAMESPACE_CHART, GetXMLToken( XML_DIMENSION )));
112 6 : pMutableAttrList->RenameAttributeByIndex( i, aNewAttrQName );
113 6 : pMutableAttrList->SetValueByIndex( i, GetXMLToken( eToken ));
114 6 : }
115 : }
116 18 : }
117 :
118 6 : XMLPersElemContentTContext::StartElement( xAttrList );
119 6 : }
120 :
121 3 : bool XMLAxisOOoContext::IsCategoryAxis() const
122 : {
123 3 : return m_bIsCategoryAxis;
124 : }
125 :
126 :
127 0 : TYPEINIT1( XMLChartPlotAreaOOoTContext, XMLProcAttrTransformerContext )
128 :
129 3 : XMLChartPlotAreaOOoTContext::XMLChartPlotAreaOOoTContext(
130 : XMLTransformerBase & rTransformer, const OUString & rQName ) :
131 3 : XMLProcAttrTransformerContext( rTransformer, rQName, OOO_SHAPE_ACTIONS )
132 : {
133 3 : }
134 :
135 6 : XMLChartPlotAreaOOoTContext::~XMLChartPlotAreaOOoTContext()
136 6 : {}
137 :
138 24 : XMLTransformerContext * XMLChartPlotAreaOOoTContext::CreateChildContext(
139 : sal_uInt16 nPrefix,
140 : const OUString& rLocalName,
141 : const OUString& rQName,
142 : const uno::Reference< xml::sax::XAttributeList >& xAttrList )
143 : {
144 24 : XMLTransformerContext *pContext = 0;
145 :
146 48 : if( XML_NAMESPACE_CHART == nPrefix &&
147 24 : IsXMLToken( rLocalName, XML_AXIS ) )
148 : {
149 6 : XMLAxisOOoContext * pAxisContext( new XMLAxisOOoContext( GetTransformer(), rQName ));
150 6 : AddContent( pAxisContext );
151 6 : pContext = pAxisContext;
152 : }
153 36 : else if( XML_NAMESPACE_CHART == nPrefix &&
154 18 : IsXMLToken( rLocalName, XML_CATEGORIES ) )
155 : {
156 3 : pContext = new XMLPersAttrListTContext( GetTransformer(), rQName );
157 :
158 : // put categories at correct axis
159 3 : XMLAxisContextVector::iterator aIter = m_aChildContexts.begin();
160 3 : bool bFound =false;
161 :
162 : // iterate over axis elements
163 6 : for( ; ! bFound && aIter != m_aChildContexts.end(); ++aIter )
164 : {
165 3 : XMLAxisOOoContext * pAxisContext = (*aIter).get();
166 3 : if( pAxisContext != 0 )
167 : {
168 : // iterate over attributes to find category axis
169 3 : Reference< xml::sax::XAttributeList > xNewAttrList( pAxisContext->GetAttrList());
170 3 : sal_Int16 nAttrCount = xNewAttrList.is() ? xNewAttrList->getLength() : 0;
171 :
172 3 : for( sal_Int16 i=0; i < nAttrCount; i++ )
173 : {
174 3 : const OUString & rAttrName = xNewAttrList->getNameByIndex( i );
175 3 : OUString aLocalName;
176 : sal_uInt16 nNewPrefix =
177 3 : GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
178 3 : &aLocalName );
179 6 : if( nNewPrefix == XML_NAMESPACE_CHART &&
180 6 : pAxisContext->IsCategoryAxis() &&
181 3 : IsXMLToken( aLocalName, XML_DIMENSION ) )
182 : {
183 : // category axis found
184 3 : pAxisContext->AddContent( pContext );
185 3 : bFound = true;
186 3 : break;
187 : }
188 3 : }
189 : }
190 : }
191 : OSL_ENSURE( bFound, "No suitable axis for categories found." );
192 : }
193 : else
194 : {
195 15 : ExportContent();
196 : pContext = XMLProcAttrTransformerContext::CreateChildContext(
197 15 : nPrefix, rLocalName, rQName, xAttrList );
198 : }
199 :
200 24 : return pContext;
201 : }
202 :
203 3 : void XMLChartPlotAreaOOoTContext::EndElement()
204 : {
205 3 : ExportContent();
206 3 : XMLProcAttrTransformerContext::EndElement();
207 3 : }
208 :
209 6 : void XMLChartPlotAreaOOoTContext::AddContent( XMLAxisOOoContext *pContext )
210 : {
211 : OSL_ENSURE( pContext && pContext->IsPersistent(),
212 : "non-persistent context" );
213 6 : XMLAxisContextVector::value_type aVal( pContext );
214 6 : m_aChildContexts.push_back( aVal );
215 6 : }
216 :
217 :
218 18 : void XMLChartPlotAreaOOoTContext::ExportContent()
219 : {
220 18 : XMLAxisContextVector::iterator aIter = m_aChildContexts.begin();
221 :
222 24 : for( ; aIter != m_aChildContexts.end(); ++aIter )
223 : {
224 6 : (*aIter)->Export();
225 : }
226 :
227 18 : m_aChildContexts.clear();
228 18 : }
229 :
230 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|