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