xref: /trunk/main/xmloff/source/transform/PersAttrListTContext.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include <com/sun/star/util/XCloneable.hpp>
31 #include "IgnoreTContext.hxx"
32 #ifndef _XMLOFF_TRANSFORMERBASE_HXX
33 #include "TransformerBase.hxx"
34 #endif
35 #include "MutableAttrList.hxx"
36 #include <xmloff/nmspmap.hxx>
37 #include "PersAttrListTContext.hxx"
38 
39 using ::rtl::OUString;
40 
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::util;
43 using namespace ::com::sun::star::xml::sax;
44 
45 TYPEINIT1( XMLPersAttrListTContext, XMLTransformerContext );
46 
47 void XMLPersAttrListTContext::AddAttribute(
48         sal_uInt16 nAPrefix,
49         ::xmloff::token::XMLTokenEnum eAToken,
50         ::xmloff::token::XMLTokenEnum eVToken )
51 {
52     OUString aAttrValue( ::xmloff::token::GetXMLToken( eVToken ) );
53     AddAttribute( nAPrefix, eAToken, aAttrValue );
54 }
55 
56 void XMLPersAttrListTContext::AddAttribute(
57     sal_uInt16 nAPrefix,
58     ::xmloff::token::XMLTokenEnum eAToken,
59     const ::rtl::OUString & rValue )
60 {
61     OUString aAttrQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
62                 nAPrefix, ::xmloff::token::GetXMLToken( eAToken ) ) );
63     OUString aAttrValue( rValue );
64 
65     XMLMutableAttributeList *pMutableAttrList;
66     if( m_xAttrList.is() )
67     {
68         pMutableAttrList =
69             static_cast< XMLMutableAttributeList * >( m_xAttrList.get() );
70     }
71     else
72     {
73         pMutableAttrList = new XMLMutableAttributeList ;
74         m_xAttrList = pMutableAttrList;
75     }
76 
77     pMutableAttrList->AddAttribute( aAttrQName, aAttrValue );
78 }
79 
80 XMLPersAttrListTContext::XMLPersAttrListTContext(
81         XMLTransformerBase& rImp,
82         const OUString& rQName ) :
83     XMLTransformerContext( rImp, rQName ),
84     m_aElemQName( rQName ),
85     m_nActionMap( INVALID_ACTIONS )
86 {
87 }
88 
89 XMLPersAttrListTContext::XMLPersAttrListTContext(
90         XMLTransformerBase& rImp,
91         const OUString& rQName,
92        sal_uInt16 nActionMap ) :
93     XMLTransformerContext( rImp, rQName ),
94     m_aElemQName( rQName ),
95     m_nActionMap( nActionMap )
96 {
97 }
98 
99 XMLPersAttrListTContext::XMLPersAttrListTContext(
100         XMLTransformerBase& rImp,
101         const OUString& rQName,
102         sal_uInt16 nPrefix,
103         ::xmloff::token::XMLTokenEnum eToken ) :
104     XMLTransformerContext( rImp, rQName ),
105     m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( nPrefix,
106                             ::xmloff::token::GetXMLToken( eToken ) ) ),
107     m_nActionMap( INVALID_ACTIONS )
108 {
109 }
110 
111 XMLPersAttrListTContext::XMLPersAttrListTContext(
112         XMLTransformerBase& rImp,
113         const OUString& rQName,
114         sal_uInt16 nPrefix,
115         ::xmloff::token::XMLTokenEnum eToken,
116        sal_uInt16 nActionMap ) :
117     XMLTransformerContext( rImp, rQName ),
118     m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( nPrefix,
119                             ::xmloff::token::GetXMLToken( eToken ) ) ),
120     m_nActionMap( nActionMap )
121 {
122 }
123 
124 XMLPersAttrListTContext::~XMLPersAttrListTContext()
125 {
126 }
127 
128 XMLTransformerContext *XMLPersAttrListTContext::CreateChildContext(
129         sal_uInt16 /*nPrefix*/,
130         const OUString& /*rLocalName*/,
131         const OUString& rQName,
132         const Reference< XAttributeList >& )
133 {
134     // ignore all child elements
135     return  new XMLIgnoreTransformerContext( GetTransformer(),
136                                              rQName, sal_True, sal_True );
137 }
138 
139 void XMLPersAttrListTContext::StartElement(
140     const Reference< XAttributeList >& rAttrList )
141 {
142     XMLMutableAttributeList *pMutableAttrList = 0;
143 
144     Reference< XAttributeList > xAttrList( rAttrList );
145     if( m_nActionMap != INVALID_ACTIONS )
146     {
147         pMutableAttrList =
148             GetTransformer().ProcessAttrList( xAttrList, m_nActionMap,
149                                               sal_True );
150     }
151 
152     if( m_xAttrList.is() )
153     {
154         static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
155                 ->AppendAttributeList( xAttrList );
156     }
157     else if( pMutableAttrList )
158     {
159         m_xAttrList = xAttrList;
160     }
161     else
162     {
163         m_xAttrList = new XMLMutableAttributeList( rAttrList, sal_True );
164     }
165 }
166 
167 void XMLPersAttrListTContext::EndElement()
168 {
169     // ignore for now
170 }
171 
172 void XMLPersAttrListTContext::Characters( const OUString& )
173 {
174 }
175 
176 sal_Bool XMLPersAttrListTContext::IsPersistent() const
177 {
178     return sal_True;
179 }
180 
181 void XMLPersAttrListTContext::Export()
182 {
183     GetTransformer().GetDocHandler()->startElement( m_aElemQName, m_xAttrList );
184     ExportContent();
185     GetTransformer().GetDocHandler()->endElement( m_aElemQName );
186 }
187 
188 void XMLPersAttrListTContext::ExportContent()
189 {
190     // nothing to export
191 }
192 
193 Reference< XAttributeList > XMLPersAttrListTContext::GetAttrList() const
194 {
195     return m_xAttrList;
196 }
197