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