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 "RenameElemTContext.hxx"
27 #include "MutableAttrList.hxx"
28 #ifndef _XMLOFF_TRANSFORMERBASE_HXX
29 #include "TransformerBase.hxx"
30 #endif
31 #include <xmloff/nmspmap.hxx>
32 
33 using ::rtl::OUString;
34 
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::xml::sax;
37 
38 TYPEINIT1( XMLRenameElemTransformerContext, XMLTransformerContext );
39 
XMLRenameElemTransformerContext(XMLTransformerBase & rImp,const OUString & rQName,sal_uInt16 nPrefix,::xmloff::token::XMLTokenEnum eToken)40 XMLRenameElemTransformerContext::XMLRenameElemTransformerContext(
41 		XMLTransformerBase& rImp,
42 		const OUString& rQName,
43 	    sal_uInt16 nPrefix,
44 		::xmloff::token::XMLTokenEnum eToken ) :
45 	XMLTransformerContext( rImp, rQName ),
46 	m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( nPrefix,
47 							::xmloff::token::GetXMLToken( eToken ) ) )
48 {
49 }
50 
XMLRenameElemTransformerContext(XMLTransformerBase & rImp,const OUString & rQName,sal_uInt16 nPrefix,::xmloff::token::XMLTokenEnum eToken,sal_uInt16 nAPrefix,::xmloff::token::XMLTokenEnum eAToken,::xmloff::token::XMLTokenEnum eVToken)51 XMLRenameElemTransformerContext::XMLRenameElemTransformerContext(
52 		XMLTransformerBase& rImp,
53 		const OUString& rQName,
54 	    sal_uInt16 nPrefix,
55 		::xmloff::token::XMLTokenEnum eToken,
56 		sal_uInt16 nAPrefix,
57 		::xmloff::token::XMLTokenEnum eAToken,
58 		::xmloff::token::XMLTokenEnum eVToken ) :
59 	XMLTransformerContext( rImp, rQName ),
60 	m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( nPrefix,
61 							::xmloff::token::GetXMLToken( eToken ) ) ),
62 	m_aAttrQName( rImp.GetNamespaceMap().GetQNameByKey( nAPrefix,
63 									::xmloff::token::GetXMLToken( eAToken ) ) ),
64 	m_aAttrValue( ::xmloff::token::GetXMLToken( eVToken ) )
65 {
66 }
67 
~XMLRenameElemTransformerContext()68 XMLRenameElemTransformerContext::~XMLRenameElemTransformerContext()
69 {
70 }
71 
StartElement(const Reference<XAttributeList> & rAttrList)72 void XMLRenameElemTransformerContext::StartElement(
73 		const Reference< XAttributeList >& rAttrList )
74 {
75 	Reference< XAttributeList > xAttrList( rAttrList );
76 	if( m_aAttrQName.getLength() )
77 	{
78 		XMLMutableAttributeList *pMutableAttrList =
79 			new XMLMutableAttributeList( xAttrList );
80 		xAttrList = pMutableAttrList;
81 		pMutableAttrList->AddAttribute( m_aAttrQName, m_aAttrValue );
82 	}
83 	GetTransformer().GetDocHandler()->startElement( m_aElemQName, xAttrList );
84 }
85 
EndElement()86 void XMLRenameElemTransformerContext::EndElement()
87 {
88 	GetTransformer().GetDocHandler()->endElement( m_aElemQName );
89 }
90