1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PersAttrListTContext.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <com/sun/star/util/XCloneable.hpp>
34 #include "IgnoreTContext.hxx"
35 #ifndef _XMLOFF_TRANSFORMERBASE_HXX
36 #include "TransformerBase.hxx"
38 #include "MutableAttrList.hxx"
39 #include <xmloff/nmspmap.hxx>
40 #include "PersAttrListTContext.hxx"
42 using ::rtl::OUString
;
44 using namespace ::com::sun::star::uno
;
45 using namespace ::com::sun::star::util
;
46 using namespace ::com::sun::star::xml::sax
;
48 TYPEINIT1( XMLPersAttrListTContext
, XMLTransformerContext
);
50 void XMLPersAttrListTContext::AddAttribute(
52 ::xmloff::token::XMLTokenEnum eAToken
,
53 ::xmloff::token::XMLTokenEnum eVToken
)
55 OUString
aAttrValue( ::xmloff::token::GetXMLToken( eVToken
) );
56 AddAttribute( nAPrefix
, eAToken
, aAttrValue
);
59 void XMLPersAttrListTContext::AddAttribute(
61 ::xmloff::token::XMLTokenEnum eAToken
,
62 const ::rtl::OUString
& rValue
)
64 OUString
aAttrQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
65 nAPrefix
, ::xmloff::token::GetXMLToken( eAToken
) ) );
66 OUString
aAttrValue( rValue
);
68 XMLMutableAttributeList
*pMutableAttrList
;
69 if( m_xAttrList
.is() )
72 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() );
76 pMutableAttrList
= new XMLMutableAttributeList
;
77 m_xAttrList
= pMutableAttrList
;
80 pMutableAttrList
->AddAttribute( aAttrQName
, aAttrValue
);
83 XMLPersAttrListTContext::XMLPersAttrListTContext(
84 XMLTransformerBase
& rImp
,
85 const OUString
& rQName
) :
86 XMLTransformerContext( rImp
, rQName
),
87 m_aElemQName( rQName
),
88 m_nActionMap( INVALID_ACTIONS
)
92 XMLPersAttrListTContext::XMLPersAttrListTContext(
93 XMLTransformerBase
& rImp
,
94 const OUString
& rQName
,
95 sal_uInt16 nActionMap
) :
96 XMLTransformerContext( rImp
, rQName
),
97 m_aElemQName( rQName
),
98 m_nActionMap( nActionMap
)
102 XMLPersAttrListTContext::XMLPersAttrListTContext(
103 XMLTransformerBase
& rImp
,
104 const OUString
& rQName
,
106 ::xmloff::token::XMLTokenEnum eToken
) :
107 XMLTransformerContext( rImp
, rQName
),
108 m_aElemQName( rImp
.GetNamespaceMap().GetQNameByKey( nPrefix
,
109 ::xmloff::token::GetXMLToken( eToken
) ) ),
110 m_nActionMap( INVALID_ACTIONS
)
114 XMLPersAttrListTContext::XMLPersAttrListTContext(
115 XMLTransformerBase
& rImp
,
116 const OUString
& rQName
,
118 ::xmloff::token::XMLTokenEnum eToken
,
119 sal_uInt16 nActionMap
) :
120 XMLTransformerContext( rImp
, rQName
),
121 m_aElemQName( rImp
.GetNamespaceMap().GetQNameByKey( nPrefix
,
122 ::xmloff::token::GetXMLToken( eToken
) ) ),
123 m_nActionMap( nActionMap
)
127 XMLPersAttrListTContext::~XMLPersAttrListTContext()
131 XMLTransformerContext
*XMLPersAttrListTContext::CreateChildContext(
132 sal_uInt16
/*nPrefix*/,
133 const OUString
& /*rLocalName*/,
134 const OUString
& rQName
,
135 const Reference
< XAttributeList
>& )
137 // ignore all child elements
138 return new XMLIgnoreTransformerContext( GetTransformer(),
139 rQName
, sal_True
, sal_True
);
142 void XMLPersAttrListTContext::StartElement(
143 const Reference
< XAttributeList
>& rAttrList
)
145 XMLMutableAttributeList
*pMutableAttrList
= 0;
147 Reference
< XAttributeList
> xAttrList( rAttrList
);
148 if( m_nActionMap
!= INVALID_ACTIONS
)
151 GetTransformer().ProcessAttrList( xAttrList
, m_nActionMap
,
155 if( m_xAttrList
.is() )
157 static_cast< XMLMutableAttributeList
* >( m_xAttrList
.get() )
158 ->AppendAttributeList( xAttrList
);
160 else if( pMutableAttrList
)
162 m_xAttrList
= xAttrList
;
166 m_xAttrList
= new XMLMutableAttributeList( rAttrList
, sal_True
);
170 void XMLPersAttrListTContext::EndElement()
175 void XMLPersAttrListTContext::Characters( const OUString
& )
179 sal_Bool
XMLPersAttrListTContext::IsPersistent() const
184 void XMLPersAttrListTContext::Export()
186 GetTransformer().GetDocHandler()->startElement( m_aElemQName
, m_xAttrList
);
188 GetTransformer().GetDocHandler()->endElement( m_aElemQName
);
191 void XMLPersAttrListTContext::ExportContent()
196 Reference
< XAttributeList
> XMLPersAttrListTContext::GetAttrList() const