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/SAXException.hpp>
21 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
22 #include <com/sun/star/xml/sax/XAttributeList.hpp>
23 #include <osl/diagnose.h>
24 #include <xmloff/nmspmap.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmlnmspe.hxx>
28 #include "TransformerBase.hxx"
29 #include "TransformerActions.hxx"
30 #include "AttrTransformerAction.hxx"
31 #include "ActionMapTypesOASIS.hxx"
32 #include "MutableAttrList.hxx"
33 #include "RenameElemTContext.hxx"
34 #include "FlatTContext.hxx"
36 #include "NotesTContext.hxx"
38 using namespace ::xmloff::token
;
39 using namespace ::com::sun::star::uno
;
40 using namespace ::com::sun::star::xml::sax
;
42 XMLNotesTransformerContext::XMLNotesTransformerContext(
43 XMLTransformerBase
& rImp
,
44 const OUString
& rQName
,
45 XMLTokenEnum eToken
, bool bPersistent
) :
46 XMLPersElemContentTContext( rImp
, rQName
),
48 m_bPersistent( bPersistent
),
49 m_eTypeToken( eToken
)
53 XMLNotesTransformerContext::~XMLNotesTransformerContext()
57 void XMLNotesTransformerContext::StartElement(
58 const Reference
< XAttributeList
>& rAttrList
)
60 XMLTransformerActions
*pActions
=
61 GetTransformer().GetUserDefinedActions( OASIS_NOTES_ACTIONS
);
62 OSL_ENSURE( pActions
, "go no actions" );
64 Reference
< XAttributeList
> xAttrList( rAttrList
);
65 XMLMutableAttributeList
*pMutableAttrList
= nullptr;
66 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
67 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
69 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
72 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
74 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
75 XMLTransformerActions::const_iterator aIter
=
76 pActions
->find( aKey
);
77 if( aIter
!= pActions
->end() )
79 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
81 if( !pMutableAttrList
)
84 new XMLMutableAttributeList( xAttrList
);
85 xAttrList
= pMutableAttrList
;
87 switch( (*aIter
).second
.m_nActionType
)
89 case XML_ATACTION_STYLE_FAMILY
:
91 if( IsXMLToken( rAttrValue
, XML_FOOTNOTE
) )
94 else if( IsXMLToken( rAttrValue
, XML_ENDNOTE
) )
98 pMutableAttrList
->RemoveAttributeByIndex( i
);
103 case XML_ATACTION_DECODE_STYLE_NAME
:
104 case XML_ATACTION_DECODE_STYLE_NAME_REF
:
106 OUString
aAttrValue( rAttrValue
);
107 if( XMLTransformerBase::DecodeStyleName(aAttrValue
) )
108 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
115 XMLTokenEnum eToken
= XML_FOOTNOTE
;
116 switch( m_eTypeToken
)
119 eToken
= (m_bEndNote
? XML_ENDNOTE
: XML_FOOTNOTE
);
121 case XML_NOTES_CONFIGURATION
:
122 eToken
= (m_bEndNote
? XML_ENDNOTES_CONFIGURATION
123 : XML_FOOTNOTES_CONFIGURATION
);
126 eToken
= (m_bEndNote
? XML_ENDNOTE_REF
: XML_FOOTNOTE_REF
);
129 OSL_ENSURE( XML_NOTE
==m_eTypeToken
, "invalid note type" );
133 SetExportQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
135 ::xmloff::token::GetXMLToken( eToken
) ) );
137 XMLPersElemContentTContext::StartElement( xAttrList
);
139 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
143 void XMLNotesTransformerContext::EndElement()
147 XMLPersElemContentTContext::EndElement();
151 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
155 rtl::Reference
<XMLTransformerContext
> XMLNotesTransformerContext::CreateChildContext(
157 const OUString
& rLocalName
,
158 const OUString
& rQName
,
159 const Reference
< XAttributeList
>& rAttrList
)
161 rtl::Reference
<XMLTransformerContext
> pContext
;
162 if( XML_NOTE
== m_eTypeToken
)
164 if( XML_NAMESPACE_TEXT
== nPrefix
)
166 XMLTokenEnum
eToken ( XML_TOKEN_INVALID
);
167 if( IsXMLToken( rLocalName
, XML_NOTE_CITATION
) )
169 eToken
= m_bEndNote
? XML_ENDNOTE_CITATION
170 : XML_FOOTNOTE_CITATION
;
172 else if( IsXMLToken( rLocalName
, XML_NOTE_BODY
) )
174 eToken
= m_bEndNote
? XML_ENDNOTE_BODY
178 if( XML_TOKEN_INVALID
!= eToken
)
182 pContext
.set(new XMLPersTextContentTContext(
183 GetTransformer(), rQName
,
186 AddContent( pContext
);
191 pContext
.set(new XMLRenameElemTransformerContext(
192 GetTransformer(), rQName
,
202 pContext
= m_bPersistent
203 ? XMLPersElemContentTContext::CreateChildContext(
204 nPrefix
, rLocalName
, rQName
, rAttrList
)
205 : XMLTransformerContext::CreateChildContext(
206 nPrefix
, rLocalName
, rQName
, rAttrList
);
212 bool XMLNotesTransformerContext::IsPersistent() const
214 return m_bPersistent
;
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */