merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / transform / NotesTContext.cxx
blob3106703967abb82a1d64c0b2bb0f1efa29d944be
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: NotesTContext.cxx,v $
10 * $Revision: 1.9 $
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"
43 #endif
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"
53 #endif
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 );
90 OUString aLocalName;
91 sal_uInt16 nPrefix =
92 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
93 &aLocalName );
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 )
103 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 );
119 --i;
120 --nAttrCount;
122 break;
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 );
130 break;
135 XMLTokenEnum eToken = XML_FOOTNOTE;
136 switch( m_eTypeToken )
138 case XML_NOTE:
139 eToken = (m_bEndNote ? XML_ENDNOTE : XML_FOOTNOTE);
140 break;
141 case XML_NOTES_CONFIGURATION:
142 eToken = (m_bEndNote ? XML_ENDNOTES_CONFIGURATION
143 : XML_FOOTNOTES_CONFIGURATION);
144 break;
145 case XML_NOTE_REF:
146 eToken = (m_bEndNote ? XML_ENDNOTE_REF : XML_FOOTNOTE_REF);
147 break;
148 default:
149 OSL_ENSURE( XML_NOTE==m_eTypeToken, "invalid note type" );
150 break;
153 SetExportQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
154 XML_NAMESPACE_TEXT,
155 ::xmloff::token::GetXMLToken( eToken ) ) );
156 if( m_bPersistent )
157 XMLPersElemContentTContext::StartElement( xAttrList );
158 else
159 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
160 xAttrList );
163 void XMLNotesTransformerContext::EndElement()
165 if( m_bPersistent )
167 XMLPersElemContentTContext::EndElement();
169 else
171 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
175 XMLTransformerContext *XMLNotesTransformerContext::CreateChildContext(
176 sal_uInt16 nPrefix,
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
195 : XML_FOOTNOTE_BODY;
198 if( XML_TOKEN_INVALID != eToken )
200 if( m_bPersistent )
202 pContext = new XMLPersTextContentTContext(
203 GetTransformer(), rQName,
204 XML_NAMESPACE_TEXT,
205 eToken );
206 AddContent( pContext );
209 else
211 pContext = new XMLRenameElemTransformerContext(
212 GetTransformer(), rQName,
213 XML_NAMESPACE_TEXT,
214 eToken );
220 if( !pContext )
222 pContext = m_bPersistent
223 ? XMLPersElemContentTContext::CreateChildContext(
224 nPrefix, rLocalName, rQName, rAttrList )
225 : XMLTransformerContext::CreateChildContext(
226 nPrefix, rLocalName, rQName, rAttrList );
229 return pContext;
232 sal_Bool XMLNotesTransformerContext::IsPersistent() const
234 return m_bPersistent;