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 "ChartOOoTContext.hxx"
21 : #include "MutableAttrList.hxx"
22 : #include <xmloff/xmlnmspe.hxx>
23 : #include "ActionMapTypesOOo.hxx"
24 : #include "AttrTransformerAction.hxx"
25 : #include "TransformerActions.hxx"
26 : #include "TransformerBase.hxx"
27 :
28 : using namespace ::com::sun::star::uno;
29 : using namespace ::com::sun::star::xml::sax;
30 : using namespace ::xmloff::token;
31 :
32 0 : TYPEINIT1( XMLChartOOoTransformerContext, XMLTransformerContext );
33 :
34 0 : XMLChartOOoTransformerContext::XMLChartOOoTransformerContext(
35 : XMLTransformerBase& rImp,
36 : const OUString& rQName ) :
37 0 : XMLTransformerContext( rImp, rQName )
38 : {
39 0 : }
40 :
41 0 : XMLChartOOoTransformerContext::~XMLChartOOoTransformerContext()
42 : {
43 0 : }
44 :
45 0 : void XMLChartOOoTransformerContext::StartElement(
46 : const Reference< XAttributeList >& rAttrList )
47 : {
48 : XMLTransformerActions *pActions =
49 0 : GetTransformer().GetUserDefinedActions( OOO_CHART_ACTIONS );
50 : OSL_ENSURE( pActions, "go no actions" );
51 :
52 0 : sal_Int16 nClassName = -1;
53 0 : OUString aAddInName;
54 0 : Reference< XAttributeList > xAttrList( rAttrList );
55 0 : XMLMutableAttributeList *pMutableAttrList = 0;
56 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
57 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
58 : {
59 0 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
60 0 : OUString aLocalName;
61 : sal_uInt16 nPrefix =
62 0 : GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
63 0 : &aLocalName );
64 0 : XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
65 : XMLTransformerActions::const_iterator aIter =
66 0 : pActions->find( aKey );
67 0 : if( !(aIter == pActions->end() ) )
68 : {
69 0 : if( !pMutableAttrList )
70 : {
71 : pMutableAttrList =
72 0 : new XMLMutableAttributeList( xAttrList );
73 0 : xAttrList = pMutableAttrList;
74 : }
75 0 : const OUString& rAttrValue = xAttrList->getValueByIndex( i );
76 0 : switch( (*aIter).second.m_nActionType )
77 : {
78 : case XML_ATACTION_INCH2IN:
79 : {
80 0 : OUString aAttrValue( rAttrValue );
81 0 : if( XMLTransformerBase::ReplaceSingleInchWithIn(
82 0 : aAttrValue ) )
83 0 : pMutableAttrList->SetValueByIndex( i, aAttrValue );
84 : }
85 0 : break;
86 : case XML_ATACTION_ENCODE_STYLE_NAME_REF:
87 : {
88 0 : OUString aAttrValue( rAttrValue );
89 0 : if( GetTransformer().EncodeStyleName(aAttrValue) )
90 0 : pMutableAttrList->SetValueByIndex( i, aAttrValue );
91 : }
92 0 : break;
93 : case XML_ATACTION_ADD_NAMESPACE_PREFIX:
94 : OSL_ENSURE( ::xmloff::token::IsXMLToken( aLocalName, XML_CLASS ),
95 : "unexpected class token" );
96 0 : if( ::xmloff::token::IsXMLToken( rAttrValue, XML_ADD_IN ) )
97 : {
98 0 : nClassName = i;
99 : }
100 : else
101 : {
102 0 : OUString aAttrValue( rAttrValue );
103 : sal_uInt16 nValPrefix =
104 0 : static_cast<sal_uInt16>((*aIter).second.m_nParam1);
105 0 : if( GetTransformer().AddNamespacePrefix( aAttrValue,
106 0 : nValPrefix ) )
107 0 : pMutableAttrList->SetValueByIndex( i, aAttrValue );
108 : }
109 0 : break;
110 : case XML_ATACTION_REMOVE:
111 : OSL_ENSURE( ::xmloff::token::IsXMLToken( aLocalName, XML_ADD_IN_NAME ),
112 : "unexpected class token" );
113 0 : aAddInName = rAttrValue;
114 0 : pMutableAttrList->RemoveAttributeByIndex( i );
115 0 : --i;
116 0 : --nAttrCount;
117 0 : break;
118 : default:
119 : OSL_ENSURE( !this, "unknown action" );
120 0 : break;
121 0 : }
122 : }
123 0 : }
124 :
125 0 : if( nClassName != -1 && !aAddInName.isEmpty() )
126 : {
127 0 : GetTransformer().AddNamespacePrefix( aAddInName, XML_NAMESPACE_OOO );
128 0 : pMutableAttrList->SetValueByIndex( nClassName, aAddInName );
129 : }
130 :
131 0 : XMLTransformerContext::StartElement( xAttrList );
132 0 : }
133 :
134 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|