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 <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 TYPEINIT1( XMLNotesTransformerContext
, XMLPersElemContentTContext
);
44 XMLNotesTransformerContext::XMLNotesTransformerContext(
45 XMLTransformerBase
& rImp
,
46 const OUString
& rQName
,
47 XMLTokenEnum eToken
, sal_Bool bPersistent
) :
48 XMLPersElemContentTContext( rImp
, rQName
),
49 m_bEndNote( sal_False
),
50 m_bPersistent( bPersistent
),
51 m_eTypeToken( eToken
)
55 XMLNotesTransformerContext::~XMLNotesTransformerContext()
59 void XMLNotesTransformerContext::StartElement(
60 const Reference
< XAttributeList
>& rAttrList
)
62 XMLTransformerActions
*pActions
=
63 GetTransformer().GetUserDefinedActions( OASIS_NOTES_ACTIONS
);
64 OSL_ENSURE( pActions
, "go no actions" );
66 Reference
< XAttributeList
> xAttrList( rAttrList
);
67 XMLMutableAttributeList
*pMutableAttrList
= 0;
68 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
69 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
71 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
74 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
76 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
77 XMLTransformerActions::const_iterator aIter
=
78 pActions
->find( aKey
);
79 if( !(aIter
== pActions
->end() ) )
81 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
83 if( !pMutableAttrList
)
86 new XMLMutableAttributeList( xAttrList
);
87 xAttrList
= pMutableAttrList
;
89 switch( (*aIter
).second
.m_nActionType
)
91 case XML_ATACTION_STYLE_FAMILY
:
93 if( IsXMLToken( rAttrValue
, XML_FOOTNOTE
) )
96 else if( IsXMLToken( rAttrValue
, XML_ENDNOTE
) )
98 m_bEndNote
= sal_True
;
100 pMutableAttrList
->RemoveAttributeByIndex( i
);
105 case XML_ATACTION_DECODE_STYLE_NAME
:
106 case XML_ATACTION_DECODE_STYLE_NAME_REF
:
108 OUString
aAttrValue( rAttrValue
);
109 if( GetTransformer().DecodeStyleName(aAttrValue
) )
110 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
117 XMLTokenEnum eToken
= XML_FOOTNOTE
;
118 switch( m_eTypeToken
)
121 eToken
= (m_bEndNote
? XML_ENDNOTE
: XML_FOOTNOTE
);
123 case XML_NOTES_CONFIGURATION
:
124 eToken
= (m_bEndNote
? XML_ENDNOTES_CONFIGURATION
125 : XML_FOOTNOTES_CONFIGURATION
);
128 eToken
= (m_bEndNote
? XML_ENDNOTE_REF
: XML_FOOTNOTE_REF
);
131 OSL_ENSURE( XML_NOTE
==m_eTypeToken
, "invalid note type" );
135 SetExportQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
137 ::xmloff::token::GetXMLToken( eToken
) ) );
139 XMLPersElemContentTContext::StartElement( xAttrList
);
141 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
145 void XMLNotesTransformerContext::EndElement()
149 XMLPersElemContentTContext::EndElement();
153 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
157 XMLTransformerContext
*XMLNotesTransformerContext::CreateChildContext(
159 const OUString
& rLocalName
,
160 const OUString
& rQName
,
161 const Reference
< XAttributeList
>& rAttrList
)
163 XMLTransformerContext
*pContext
= 0;
164 if( XML_NOTE
== m_eTypeToken
)
166 if( XML_NAMESPACE_TEXT
== nPrefix
)
168 XMLTokenEnum
eToken ( XML_TOKEN_INVALID
);
169 if( IsXMLToken( rLocalName
, XML_NOTE_CITATION
) )
171 eToken
= m_bEndNote
? XML_ENDNOTE_CITATION
172 : XML_FOOTNOTE_CITATION
;
174 else if( IsXMLToken( rLocalName
, XML_NOTE_BODY
) )
176 eToken
= m_bEndNote
? XML_ENDNOTE_BODY
180 if( XML_TOKEN_INVALID
!= eToken
)
184 pContext
= new XMLPersTextContentTContext(
185 GetTransformer(), rQName
,
188 AddContent( pContext
);
193 pContext
= new XMLRenameElemTransformerContext(
194 GetTransformer(), rQName
,
204 pContext
= m_bPersistent
205 ? XMLPersElemContentTContext::CreateChildContext(
206 nPrefix
, rLocalName
, rQName
, rAttrList
)
207 : XMLTransformerContext::CreateChildContext(
208 nPrefix
, rLocalName
, rQName
, rAttrList
);
214 sal_Bool
XMLNotesTransformerContext::IsPersistent() const
216 return m_bPersistent
;
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */