bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / transform / NotesTContext.cxx
blob437f8343f2752cc3cf698bf589343eb2b589d8ee
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 TYPEINIT1( XMLNotesTransformerContext, XMLPersElemContentTContext );
45 XMLNotesTransformerContext::XMLNotesTransformerContext(
46 XMLTransformerBase& rImp,
47 const OUString& rQName,
48 XMLTokenEnum eToken, bool bPersistent ) :
49 XMLPersElemContentTContext( rImp, rQName ),
50 m_bEndNote( false ),
51 m_bPersistent( bPersistent ),
52 m_eTypeToken( eToken )
56 XMLNotesTransformerContext::~XMLNotesTransformerContext()
60 void XMLNotesTransformerContext::StartElement(
61 const Reference< XAttributeList >& rAttrList )
63 XMLTransformerActions *pActions =
64 GetTransformer().GetUserDefinedActions( OASIS_NOTES_ACTIONS );
65 OSL_ENSURE( pActions, "go no actions" );
67 Reference< XAttributeList > xAttrList( rAttrList );
68 XMLMutableAttributeList *pMutableAttrList = 0;
69 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
70 for( sal_Int16 i=0; i < nAttrCount; i++ )
72 const OUString& rAttrName = xAttrList->getNameByIndex( i );
73 OUString aLocalName;
74 sal_uInt16 nPrefix =
75 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
76 &aLocalName );
77 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
78 XMLTransformerActions::const_iterator aIter =
79 pActions->find( aKey );
80 if( !(aIter == pActions->end() ) )
82 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
84 if( !pMutableAttrList )
86 pMutableAttrList =
87 new XMLMutableAttributeList( xAttrList );
88 xAttrList = pMutableAttrList;
90 switch( (*aIter).second.m_nActionType )
92 case XML_ATACTION_STYLE_FAMILY:
94 if( IsXMLToken( rAttrValue, XML_FOOTNOTE ) )
97 else if( IsXMLToken( rAttrValue, XML_ENDNOTE ) )
99 m_bEndNote = true;
101 pMutableAttrList->RemoveAttributeByIndex( i );
102 --i;
103 --nAttrCount;
105 break;
106 case XML_ATACTION_DECODE_STYLE_NAME:
107 case XML_ATACTION_DECODE_STYLE_NAME_REF:
109 OUString aAttrValue( rAttrValue );
110 if( XMLTransformerBase::DecodeStyleName(aAttrValue) )
111 pMutableAttrList->SetValueByIndex( i, aAttrValue );
113 break;
118 XMLTokenEnum eToken = XML_FOOTNOTE;
119 switch( m_eTypeToken )
121 case XML_NOTE:
122 eToken = (m_bEndNote ? XML_ENDNOTE : XML_FOOTNOTE);
123 break;
124 case XML_NOTES_CONFIGURATION:
125 eToken = (m_bEndNote ? XML_ENDNOTES_CONFIGURATION
126 : XML_FOOTNOTES_CONFIGURATION);
127 break;
128 case XML_NOTE_REF:
129 eToken = (m_bEndNote ? XML_ENDNOTE_REF : XML_FOOTNOTE_REF);
130 break;
131 default:
132 OSL_ENSURE( XML_NOTE==m_eTypeToken, "invalid note type" );
133 break;
136 SetExportQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
137 XML_NAMESPACE_TEXT,
138 ::xmloff::token::GetXMLToken( eToken ) ) );
139 if( m_bPersistent )
140 XMLPersElemContentTContext::StartElement( xAttrList );
141 else
142 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
143 xAttrList );
146 void XMLNotesTransformerContext::EndElement()
148 if( m_bPersistent )
150 XMLPersElemContentTContext::EndElement();
152 else
154 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
158 XMLTransformerContext *XMLNotesTransformerContext::CreateChildContext(
159 sal_uInt16 nPrefix,
160 const OUString& rLocalName,
161 const OUString& rQName,
162 const Reference< XAttributeList >& rAttrList )
164 XMLTransformerContext *pContext = 0;
165 if( XML_NOTE == m_eTypeToken )
167 if( XML_NAMESPACE_TEXT == nPrefix )
169 XMLTokenEnum eToken ( XML_TOKEN_INVALID );
170 if( IsXMLToken( rLocalName, XML_NOTE_CITATION ) )
172 eToken = m_bEndNote ? XML_ENDNOTE_CITATION
173 : XML_FOOTNOTE_CITATION;
175 else if( IsXMLToken( rLocalName, XML_NOTE_BODY ) )
177 eToken = m_bEndNote ? XML_ENDNOTE_BODY
178 : XML_FOOTNOTE_BODY;
181 if( XML_TOKEN_INVALID != eToken )
183 if( m_bPersistent )
185 pContext = new XMLPersTextContentTContext(
186 GetTransformer(), rQName,
187 XML_NAMESPACE_TEXT,
188 eToken );
189 AddContent( pContext );
192 else
194 pContext = new XMLRenameElemTransformerContext(
195 GetTransformer(), rQName,
196 XML_NAMESPACE_TEXT,
197 eToken );
203 if( !pContext )
205 pContext = m_bPersistent
206 ? XMLPersElemContentTContext::CreateChildContext(
207 nPrefix, rLocalName, rQName, rAttrList )
208 : XMLTransformerContext::CreateChildContext(
209 nPrefix, rLocalName, rQName, rAttrList );
212 return pContext;
215 bool XMLNotesTransformerContext::IsPersistent() const
217 return m_bPersistent;
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */