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: NotesTContext.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/xml/sax/SAXParseException.hpp>
34 #include <com/sun/star/xml/sax/SAXException.hpp>
35 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
36 #include <com/sun/star/xml/sax/XAttributeList.hpp>
37 #include <xmloff/nmspmap.hxx>
38 #include <xmloff/xmltoken.hxx>
39 #include "xmlnmspe.hxx"
41 #ifndef _XMLOFF_TRANSFOERMERBASE_HXX
42 #include "TransformerBase.hxx"
44 #include "TransformerActions.hxx"
45 #include "AttrTransformerAction.hxx"
46 #include "ActionMapTypesOASIS.hxx"
47 #include "MutableAttrList.hxx"
48 #include "RenameElemTContext.hxx"
49 #include "FlatTContext.hxx"
51 #ifndef _XMLOFF_NOTESCONTEXT_HXX
52 #include "NotesTContext.hxx"
55 using ::rtl::OUString
;
56 using namespace ::xmloff::token
;
57 using namespace ::com::sun::star::uno
;
58 using namespace ::com::sun::star::xml::sax
;
60 TYPEINIT1( XMLNotesTransformerContext
, XMLPersElemContentTContext
);
62 XMLNotesTransformerContext::XMLNotesTransformerContext(
63 XMLTransformerBase
& rImp
,
64 const OUString
& rQName
,
65 XMLTokenEnum eToken
, sal_Bool bPersistent
) :
66 XMLPersElemContentTContext( rImp
, rQName
),
67 m_bEndNote( sal_False
),
68 m_bPersistent( bPersistent
),
69 m_eTypeToken( eToken
)
73 XMLNotesTransformerContext::~XMLNotesTransformerContext()
77 void XMLNotesTransformerContext::StartElement(
78 const Reference
< XAttributeList
>& rAttrList
)
80 XMLTransformerActions
*pActions
=
81 GetTransformer().GetUserDefinedActions( OASIS_NOTES_ACTIONS
);
82 OSL_ENSURE( pActions
, "go no actions" );
84 Reference
< XAttributeList
> xAttrList( rAttrList
);
85 XMLMutableAttributeList
*pMutableAttrList
= 0;
86 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
87 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
89 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
92 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
94 XMLTransformerActions::key_type
aKey( nPrefix
, aLocalName
);
95 XMLTransformerActions::const_iterator aIter
=
96 pActions
->find( aKey
);
97 if( !(aIter
== pActions
->end() ) )
99 const OUString
& rAttrValue
= xAttrList
->getValueByIndex( i
);
101 if( !pMutableAttrList
)
104 new XMLMutableAttributeList( xAttrList
);
105 xAttrList
= pMutableAttrList
;
107 switch( (*aIter
).second
.m_nActionType
)
109 case XML_ATACTION_STYLE_FAMILY
:
111 if( IsXMLToken( rAttrValue
, XML_FOOTNOTE
) )
114 else if( IsXMLToken( rAttrValue
, XML_ENDNOTE
) )
116 m_bEndNote
= sal_True
;
118 pMutableAttrList
->RemoveAttributeByIndex( i
);
123 case XML_ATACTION_DECODE_STYLE_NAME
:
124 case XML_ATACTION_DECODE_STYLE_NAME_REF
:
126 OUString
aAttrValue( rAttrValue
);
127 if( GetTransformer().DecodeStyleName(aAttrValue
) )
128 pMutableAttrList
->SetValueByIndex( i
, aAttrValue
);
135 XMLTokenEnum eToken
= XML_FOOTNOTE
;
136 switch( m_eTypeToken
)
139 eToken
= (m_bEndNote
? XML_ENDNOTE
: XML_FOOTNOTE
);
141 case XML_NOTES_CONFIGURATION
:
142 eToken
= (m_bEndNote
? XML_ENDNOTES_CONFIGURATION
143 : XML_FOOTNOTES_CONFIGURATION
);
146 eToken
= (m_bEndNote
? XML_ENDNOTE_REF
: XML_FOOTNOTE_REF
);
149 OSL_ENSURE( XML_NOTE
==m_eTypeToken
, "invalid note type" );
153 SetExportQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
155 ::xmloff::token::GetXMLToken( eToken
) ) );
157 XMLPersElemContentTContext::StartElement( xAttrList
);
159 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
163 void XMLNotesTransformerContext::EndElement()
167 XMLPersElemContentTContext::EndElement();
171 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
175 XMLTransformerContext
*XMLNotesTransformerContext::CreateChildContext(
177 const OUString
& rLocalName
,
178 const OUString
& rQName
,
179 const Reference
< XAttributeList
>& rAttrList
)
181 XMLTransformerContext
*pContext
= 0;
182 if( XML_NOTE
== m_eTypeToken
)
184 if( XML_NAMESPACE_TEXT
== nPrefix
)
186 XMLTokenEnum
eToken ( XML_TOKEN_INVALID
);
187 if( IsXMLToken( rLocalName
, XML_NOTE_CITATION
) )
189 eToken
= m_bEndNote
? XML_ENDNOTE_CITATION
190 : XML_FOOTNOTE_CITATION
;
192 else if( IsXMLToken( rLocalName
, XML_NOTE_BODY
) )
194 eToken
= m_bEndNote
? XML_ENDNOTE_BODY
198 if( XML_TOKEN_INVALID
!= eToken
)
202 pContext
= new XMLPersTextContentTContext(
203 GetTransformer(), rQName
,
206 AddContent( pContext
);
211 pContext
= new XMLRenameElemTransformerContext(
212 GetTransformer(), rQName
,
222 pContext
= m_bPersistent
223 ? XMLPersElemContentTContext::CreateChildContext(
224 nPrefix
, rLocalName
, rQName
, rAttrList
)
225 : XMLTransformerContext::CreateChildContext(
226 nPrefix
, rLocalName
, rQName
, rAttrList
);
232 sal_Bool
XMLNotesTransformerContext::IsPersistent() const
234 return m_bPersistent
;