1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include <com/sun/star/util/XCloneable.hpp>
27 #include "IgnoreTContext.hxx"
28 #ifndef _XMLOFF_TRANSFORMERBASE_HXX
29 #include "TransformerBase.hxx"
30 #endif
31 #include "MutableAttrList.hxx"
32 #include <xmloff/nmspmap.hxx>
33 #include "PersAttrListTContext.hxx"
34 
35 using ::rtl::OUString;
36 
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::util;
39 using namespace ::com::sun::star::xml::sax;
40 
41 TYPEINIT1( XMLPersAttrListTContext, XMLTransformerContext );
42 
AddAttribute(sal_uInt16 nAPrefix,::xmloff::token::XMLTokenEnum eAToken,::xmloff::token::XMLTokenEnum eVToken)43 void XMLPersAttrListTContext::AddAttribute(
44 		sal_uInt16 nAPrefix,
45 	   	::xmloff::token::XMLTokenEnum eAToken,
46 	   	::xmloff::token::XMLTokenEnum eVToken )
47 {
48 	OUString aAttrValue( ::xmloff::token::GetXMLToken( eVToken ) );
49     AddAttribute( nAPrefix, eAToken, aAttrValue );
50 }
51 
AddAttribute(sal_uInt16 nAPrefix,::xmloff::token::XMLTokenEnum eAToken,const::rtl::OUString & rValue)52 void XMLPersAttrListTContext::AddAttribute(
53     sal_uInt16 nAPrefix,
54     ::xmloff::token::XMLTokenEnum eAToken,
55     const ::rtl::OUString & rValue )
56 {
57 	OUString aAttrQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
58 				nAPrefix, ::xmloff::token::GetXMLToken( eAToken ) ) );
59 	OUString aAttrValue( rValue );
60 
61 	XMLMutableAttributeList *pMutableAttrList;
62 	if( m_xAttrList.is() )
63 	{
64 		pMutableAttrList =
65 			static_cast< XMLMutableAttributeList * >( m_xAttrList.get() );
66 	}
67 	else
68 	{
69 		pMutableAttrList = new XMLMutableAttributeList ;
70 		m_xAttrList = pMutableAttrList;
71 	}
72 
73 	pMutableAttrList->AddAttribute( aAttrQName, aAttrValue );
74 }
75 
XMLPersAttrListTContext(XMLTransformerBase & rImp,const OUString & rQName)76 XMLPersAttrListTContext::XMLPersAttrListTContext(
77 		XMLTransformerBase& rImp,
78 		const OUString& rQName ) :
79 	XMLTransformerContext( rImp, rQName ),
80 	m_aElemQName( rQName ),
81 	m_nActionMap( INVALID_ACTIONS )
82 {
83 }
84 
XMLPersAttrListTContext(XMLTransformerBase & rImp,const OUString & rQName,sal_uInt16 nActionMap)85 XMLPersAttrListTContext::XMLPersAttrListTContext(
86 		XMLTransformerBase& rImp,
87 		const OUString& rQName,
88 	   sal_uInt16 nActionMap ) :
89 	XMLTransformerContext( rImp, rQName ),
90 	m_aElemQName( rQName ),
91 	m_nActionMap( nActionMap )
92 {
93 }
94 
XMLPersAttrListTContext(XMLTransformerBase & rImp,const OUString & rQName,sal_uInt16 nPrefix,::xmloff::token::XMLTokenEnum eToken)95 XMLPersAttrListTContext::XMLPersAttrListTContext(
96 		XMLTransformerBase& rImp,
97 		const OUString& rQName,
98 	    sal_uInt16 nPrefix,
99 		::xmloff::token::XMLTokenEnum eToken ) :
100 	XMLTransformerContext( rImp, rQName ),
101 	m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( nPrefix,
102 							::xmloff::token::GetXMLToken( eToken ) ) ),
103 	m_nActionMap( INVALID_ACTIONS )
104 {
105 }
106 
XMLPersAttrListTContext(XMLTransformerBase & rImp,const OUString & rQName,sal_uInt16 nPrefix,::xmloff::token::XMLTokenEnum eToken,sal_uInt16 nActionMap)107 XMLPersAttrListTContext::XMLPersAttrListTContext(
108 		XMLTransformerBase& rImp,
109 		const OUString& rQName,
110 	    sal_uInt16 nPrefix,
111 		::xmloff::token::XMLTokenEnum eToken,
112 	   sal_uInt16 nActionMap ) :
113 	XMLTransformerContext( rImp, rQName ),
114 	m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( nPrefix,
115 							::xmloff::token::GetXMLToken( eToken ) ) ),
116 	m_nActionMap( nActionMap )
117 {
118 }
119 
~XMLPersAttrListTContext()120 XMLPersAttrListTContext::~XMLPersAttrListTContext()
121 {
122 }
123 
CreateChildContext(sal_uInt16,const OUString &,const OUString & rQName,const Reference<XAttributeList> &)124 XMLTransformerContext *XMLPersAttrListTContext::CreateChildContext(
125 		sal_uInt16 /*nPrefix*/,
126 		const OUString& /*rLocalName*/,
127 		const OUString& rQName,
128 		const Reference< XAttributeList >& )
129 {
130 	// ignore all child elements
131 	return  new XMLIgnoreTransformerContext( GetTransformer(),
132 											 rQName, sal_True, sal_True );
133 }
134 
StartElement(const Reference<XAttributeList> & rAttrList)135 void XMLPersAttrListTContext::StartElement(
136 	const Reference< XAttributeList >& rAttrList )
137 {
138 	XMLMutableAttributeList *pMutableAttrList = 0;
139 
140 	Reference< XAttributeList > xAttrList( rAttrList );
141 	if( m_nActionMap != INVALID_ACTIONS )
142 	{
143 		pMutableAttrList =
144 			GetTransformer().ProcessAttrList( xAttrList, m_nActionMap,
145 				   							  sal_True );
146 	}
147 
148 	if( m_xAttrList.is() )
149 	{
150 		static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
151 				->AppendAttributeList( xAttrList );
152 	}
153 	else if( pMutableAttrList )
154 	{
155 		m_xAttrList = xAttrList;
156 	}
157 	else
158 	{
159 		m_xAttrList = new XMLMutableAttributeList( rAttrList, sal_True );
160 	}
161 }
162 
EndElement()163 void XMLPersAttrListTContext::EndElement()
164 {
165 	// ignore for now
166 }
167 
Characters(const OUString &)168 void XMLPersAttrListTContext::Characters( const OUString& )
169 {
170 }
171 
IsPersistent() const172 sal_Bool XMLPersAttrListTContext::IsPersistent() const
173 {
174 	return sal_True;
175 }
176 
Export()177 void XMLPersAttrListTContext::Export()
178 {
179 	GetTransformer().GetDocHandler()->startElement( m_aElemQName, m_xAttrList );
180 	ExportContent();
181 	GetTransformer().GetDocHandler()->endElement( m_aElemQName );
182 }
183 
ExportContent()184 void XMLPersAttrListTContext::ExportContent()
185 {
186 	// nothing to export
187 }
188 
GetAttrList() const189 Reference< XAttributeList > XMLPersAttrListTContext::GetAttrList() const
190 {
191     return m_xAttrList;
192 }
193