1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <com/sun/star/util/XCloneable.hpp>
21 #include "IgnoreTContext.hxx"
22 #include "TransformerBase.hxx"
23 #include "MutableAttrList.hxx"
24 #include <xmloff/namespacemap.hxx>
25 #include "PersAttrListTContext.hxx"
26 
27 
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::util;
30 using namespace ::com::sun::star::xml::sax;
31 
AddAttribute(sal_uInt16 nAPrefix,::xmloff::token::XMLTokenEnum eAToken,::xmloff::token::XMLTokenEnum eVToken)32 void XMLPersAttrListTContext::AddAttribute(
33         sal_uInt16 nAPrefix,
34            ::xmloff::token::XMLTokenEnum eAToken,
35            ::xmloff::token::XMLTokenEnum eVToken )
36 {
37     const OUString& aAttrValue( ::xmloff::token::GetXMLToken( eVToken ) );
38     AddAttribute( nAPrefix, eAToken, aAttrValue );
39 }
40 
AddAttribute(sal_uInt16 nAPrefix,::xmloff::token::XMLTokenEnum eAToken,const OUString & rValue)41 void XMLPersAttrListTContext::AddAttribute(
42     sal_uInt16 nAPrefix,
43     ::xmloff::token::XMLTokenEnum eAToken,
44     const OUString & rValue )
45 {
46     OUString aAttrQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
47                 nAPrefix, ::xmloff::token::GetXMLToken( eAToken ) ) );
48     const OUString& aAttrValue( rValue );
49 
50     rtl::Reference<XMLMutableAttributeList> pMutableAttrList;
51     if( m_xAttrList.is() )
52     {
53         pMutableAttrList =
54             static_cast< XMLMutableAttributeList * >( m_xAttrList.get() );
55     }
56     else
57     {
58         pMutableAttrList = new XMLMutableAttributeList ;
59         m_xAttrList = pMutableAttrList;
60     }
61 
62     pMutableAttrList->AddAttribute( aAttrQName, aAttrValue );
63 }
64 
XMLPersAttrListTContext(XMLTransformerBase & rImp,const OUString & rQName)65 XMLPersAttrListTContext::XMLPersAttrListTContext(
66         XMLTransformerBase& rImp,
67         const OUString& rQName ) :
68     XMLTransformerContext( rImp, rQName ),
69     m_aElemQName( rQName ),
70     m_nActionMap( INVALID_ACTIONS )
71 {
72 }
73 
XMLPersAttrListTContext(XMLTransformerBase & rImp,const OUString & rQName,sal_uInt16 nActionMap)74 XMLPersAttrListTContext::XMLPersAttrListTContext(
75         XMLTransformerBase& rImp,
76         const OUString& rQName,
77        sal_uInt16 nActionMap ) :
78     XMLTransformerContext( rImp, rQName ),
79     m_aElemQName( rQName ),
80     m_nActionMap( nActionMap )
81 {
82 }
83 
XMLPersAttrListTContext(XMLTransformerBase & rImp,const OUString & rQName,sal_uInt16 nPrefix,::xmloff::token::XMLTokenEnum eToken)84 XMLPersAttrListTContext::XMLPersAttrListTContext(
85         XMLTransformerBase& rImp,
86         const OUString& rQName,
87         sal_uInt16 nPrefix,
88         ::xmloff::token::XMLTokenEnum eToken ) :
89     XMLTransformerContext( rImp, rQName ),
90     m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( nPrefix,
91                             ::xmloff::token::GetXMLToken( eToken ) ) ),
92     m_nActionMap( INVALID_ACTIONS )
93 {
94 }
95 
XMLPersAttrListTContext(XMLTransformerBase & rImp,const OUString & rQName,sal_uInt16 nPrefix,::xmloff::token::XMLTokenEnum eToken,sal_uInt16 nActionMap)96 XMLPersAttrListTContext::XMLPersAttrListTContext(
97         XMLTransformerBase& rImp,
98         const OUString& rQName,
99         sal_uInt16 nPrefix,
100         ::xmloff::token::XMLTokenEnum eToken,
101        sal_uInt16 nActionMap ) :
102     XMLTransformerContext( rImp, rQName ),
103     m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( nPrefix,
104                             ::xmloff::token::GetXMLToken( eToken ) ) ),
105     m_nActionMap( nActionMap )
106 {
107 }
108 
CreateChildContext(sal_uInt16,const OUString &,const OUString & rQName,const Reference<XAttributeList> &)109 rtl::Reference<XMLTransformerContext> XMLPersAttrListTContext::CreateChildContext(
110         sal_uInt16 /*nPrefix*/,
111         const OUString& /*rLocalName*/,
112         const OUString& rQName,
113         const Reference< XAttributeList >& )
114 {
115     // ignore all child elements
116     return  new XMLIgnoreTransformerContext( GetTransformer(),
117                                              rQName, true, true );
118 }
119 
StartElement(const Reference<XAttributeList> & rAttrList)120 void XMLPersAttrListTContext::StartElement(
121     const Reference< XAttributeList >& rAttrList )
122 {
123     XMLMutableAttributeList *pMutableAttrList = nullptr;
124 
125     Reference< XAttributeList > xAttrList( rAttrList );
126     if( m_nActionMap != INVALID_ACTIONS )
127     {
128         pMutableAttrList =
129             GetTransformer().ProcessAttrList( xAttrList, m_nActionMap,
130                                                  true );
131     }
132 
133     if( m_xAttrList.is() )
134     {
135         static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
136                 ->AppendAttributeList( xAttrList );
137     }
138     else if( pMutableAttrList )
139     {
140         m_xAttrList = xAttrList;
141     }
142     else
143     {
144         m_xAttrList = new XMLMutableAttributeList( rAttrList, true );
145     }
146 }
147 
EndElement()148 void XMLPersAttrListTContext::EndElement()
149 {
150     // ignore for now
151 }
152 
Characters(const OUString &)153 void XMLPersAttrListTContext::Characters( const OUString& )
154 {
155 }
156 
IsPersistent() const157 bool XMLPersAttrListTContext::IsPersistent() const
158 {
159     return true;
160 }
161 
Export()162 void XMLPersAttrListTContext::Export()
163 {
164     GetTransformer().GetDocHandler()->startElement( m_aElemQName, m_xAttrList );
165     ExportContent();
166     GetTransformer().GetDocHandler()->endElement( m_aElemQName );
167 }
168 
ExportContent()169 void XMLPersAttrListTContext::ExportContent()
170 {
171     // nothing to export
172 }
173 
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
175