1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/xml/sax/SAXParseException.hpp>
21 #include <com/sun/star/xml/sax/SAXException.hpp>
22 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
23 #include <com/sun/star/xml/sax/XAttributeList.hpp>
24 #include <osl/diagnose.h>
25 #include <xmloff/nmspmap.hxx>
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/xmlnmspe.hxx>
29 #include "TransformerBase.hxx"
30 #include "TransformerActions.hxx"
31 #include "AttrTransformerAction.hxx"
32 #include "ActionMapTypesOASIS.hxx"
33 #include "MutableAttrList.hxx"
34 #include "RenameElemTContext.hxx"
35 #include "FlatTContext.hxx"
37 #include "NotesTContext.hxx"
39 using namespace ::xmloff::token
;
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::xml::sax
;
43 XMLNotesTransformerContext::XMLNotesTransformerContext(
44 XMLTransformerBase
& rImp
,
45 const OUString
& rQName
,
46 XMLTokenEnum eToken
, bool bPersistent
) :
47 XMLPersElemContentTContext( rImp
, rQName
),
49 m_bPersistent( bPersistent
),
50 m_eTypeToken( eToken
)
54 XMLNotesTransformerContext::~XMLNotesTransformerContext()
58 void XMLNotesTransformerContext::StartElement(
59 const Reference
< XAttributeList
>& rAttrList
)
61 XMLTransformerActions
*pActions
=
62 GetTransformer().GetUserDefinedActions( OASIS_NOTES_ACTIONS
);
63 OSL_ENSURE( pActions
, "go no actions" );
65 Reference
< XAttributeList
> xAttrList( rAttrList
);
66 XMLMutableAttributeList
*pMutableAttrList
= nullptr;
67 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
68 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
70 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
73 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
75 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
76 XMLTransformerActions::const_iterator aIter
=
77 pActions
->find( aKey
);
78 if( !(aIter
== pActions
->end() ) )
80 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
82 if( !pMutableAttrList
)
85 new XMLMutableAttributeList( xAttrList
);
86 xAttrList
= pMutableAttrList
;
88 switch( (*aIter
).second
.m_nActionType
)
90 case XML_ATACTION_STYLE_FAMILY
:
92 if( IsXMLToken( rAttrValue
, XML_FOOTNOTE
) )
95 else if( IsXMLToken( rAttrValue
, XML_ENDNOTE
) )
99 pMutableAttrList
->RemoveAttributeByIndex( i
);
104 case XML_ATACTION_DECODE_STYLE_NAME
:
105 case XML_ATACTION_DECODE_STYLE_NAME_REF
:
107 OUString
aAttrValue( rAttrValue
);
108 if( XMLTransformerBase::DecodeStyleName(aAttrValue
) )
109 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
116 XMLTokenEnum eToken
= XML_FOOTNOTE
;
117 switch( m_eTypeToken
)
120 eToken
= (m_bEndNote
? XML_ENDNOTE
: XML_FOOTNOTE
);
122 case XML_NOTES_CONFIGURATION
:
123 eToken
= (m_bEndNote
? XML_ENDNOTES_CONFIGURATION
124 : XML_FOOTNOTES_CONFIGURATION
);
127 eToken
= (m_bEndNote
? XML_ENDNOTE_REF
: XML_FOOTNOTE_REF
);
130 OSL_ENSURE( XML_NOTE
==m_eTypeToken
, "invalid note type" );
134 SetExportQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
136 ::xmloff::token::GetXMLToken( eToken
) ) );
138 XMLPersElemContentTContext::StartElement( xAttrList
);
140 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
144 void XMLNotesTransformerContext::EndElement()
148 XMLPersElemContentTContext::EndElement();
152 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
156 rtl::Reference
<XMLTransformerContext
> XMLNotesTransformerContext::CreateChildContext(
158 const OUString
& rLocalName
,
159 const OUString
& rQName
,
160 const Reference
< XAttributeList
>& rAttrList
)
162 rtl::Reference
<XMLTransformerContext
> pContext
;
163 if( XML_NOTE
== m_eTypeToken
)
165 if( XML_NAMESPACE_TEXT
== nPrefix
)
167 XMLTokenEnum
eToken ( XML_TOKEN_INVALID
);
168 if( IsXMLToken( rLocalName
, XML_NOTE_CITATION
) )
170 eToken
= m_bEndNote
? XML_ENDNOTE_CITATION
171 : XML_FOOTNOTE_CITATION
;
173 else if( IsXMLToken( rLocalName
, XML_NOTE_BODY
) )
175 eToken
= m_bEndNote
? XML_ENDNOTE_BODY
179 if( XML_TOKEN_INVALID
!= eToken
)
183 pContext
.set(new XMLPersTextContentTContext(
184 GetTransformer(), rQName
,
187 AddContent( pContext
);
192 pContext
.set(new XMLRenameElemTransformerContext(
193 GetTransformer(), rQName
,
203 pContext
= m_bPersistent
204 ? XMLPersElemContentTContext::CreateChildContext(
205 nPrefix
, rLocalName
, rQName
, rAttrList
)
206 : XMLTransformerContext::CreateChildContext(
207 nPrefix
, rLocalName
, rQName
, rAttrList
);
213 bool XMLNotesTransformerContext::IsPersistent() const
215 return m_bPersistent
;
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */