Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / transform / NotesTContext.cxx
blobbef8abcd8e40cef44e899afeaf57085f7a7969f9
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 XMLNotesTransformerContext::XMLNotesTransformerContext(
44 XMLTransformerBase& rImp,
45 const OUString& rQName,
46 XMLTokenEnum eToken, bool bPersistent ) :
47 XMLPersElemContentTContext( rImp, rQName ),
48 m_bEndNote( false ),
49 m_bPersistent( bPersistent ),
50 m_eTypeToken( eToken )
54 XMLNotesTransformerContext::~XMLNotesTransformerContext()
58 void XMLNotesTransformerContext::StartElement(
59 const Reference< XAttributeList >& rAttrList )
61 XMLTransformerActions *pActions =
62 GetTransformer().GetUserDefinedActions( OASIS_NOTES_ACTIONS );
63 OSL_ENSURE( pActions, "go no actions" );
65 Reference< XAttributeList > xAttrList( rAttrList );
66 XMLMutableAttributeList *pMutableAttrList = nullptr;
67 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
68 for( sal_Int16 i=0; i < nAttrCount; i++ )
70 const OUString& rAttrName = xAttrList->getNameByIndex( i );
71 OUString aLocalName;
72 sal_uInt16 nPrefix =
73 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
74 &aLocalName );
75 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
76 XMLTransformerActions::const_iterator aIter =
77 pActions->find( aKey );
78 if( !(aIter == pActions->end() ) )
80 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
82 if( !pMutableAttrList )
84 pMutableAttrList =
85 new XMLMutableAttributeList( xAttrList );
86 xAttrList = pMutableAttrList;
88 switch( (*aIter).second.m_nActionType )
90 case XML_ATACTION_STYLE_FAMILY:
92 if( IsXMLToken( rAttrValue, XML_FOOTNOTE ) )
95 else if( IsXMLToken( rAttrValue, XML_ENDNOTE ) )
97 m_bEndNote = true;
99 pMutableAttrList->RemoveAttributeByIndex( i );
100 --i;
101 --nAttrCount;
103 break;
104 case XML_ATACTION_DECODE_STYLE_NAME:
105 case XML_ATACTION_DECODE_STYLE_NAME_REF:
107 OUString aAttrValue( rAttrValue );
108 if( XMLTransformerBase::DecodeStyleName(aAttrValue) )
109 pMutableAttrList->SetValueByIndex( i, aAttrValue );
111 break;
116 XMLTokenEnum eToken = XML_FOOTNOTE;
117 switch( m_eTypeToken )
119 case XML_NOTE:
120 eToken = (m_bEndNote ? XML_ENDNOTE : XML_FOOTNOTE);
121 break;
122 case XML_NOTES_CONFIGURATION:
123 eToken = (m_bEndNote ? XML_ENDNOTES_CONFIGURATION
124 : XML_FOOTNOTES_CONFIGURATION);
125 break;
126 case XML_NOTE_REF:
127 eToken = (m_bEndNote ? XML_ENDNOTE_REF : XML_FOOTNOTE_REF);
128 break;
129 default:
130 OSL_ENSURE( XML_NOTE==m_eTypeToken, "invalid note type" );
131 break;
134 SetExportQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
135 XML_NAMESPACE_TEXT,
136 ::xmloff::token::GetXMLToken( eToken ) ) );
137 if( m_bPersistent )
138 XMLPersElemContentTContext::StartElement( xAttrList );
139 else
140 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
141 xAttrList );
144 void XMLNotesTransformerContext::EndElement()
146 if( m_bPersistent )
148 XMLPersElemContentTContext::EndElement();
150 else
152 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
156 rtl::Reference<XMLTransformerContext> XMLNotesTransformerContext::CreateChildContext(
157 sal_uInt16 nPrefix,
158 const OUString& rLocalName,
159 const OUString& rQName,
160 const Reference< XAttributeList >& rAttrList )
162 rtl::Reference<XMLTransformerContext> pContext;
163 if( XML_NOTE == m_eTypeToken )
165 if( XML_NAMESPACE_TEXT == nPrefix )
167 XMLTokenEnum eToken ( XML_TOKEN_INVALID );
168 if( IsXMLToken( rLocalName, XML_NOTE_CITATION ) )
170 eToken = m_bEndNote ? XML_ENDNOTE_CITATION
171 : XML_FOOTNOTE_CITATION;
173 else if( IsXMLToken( rLocalName, XML_NOTE_BODY ) )
175 eToken = m_bEndNote ? XML_ENDNOTE_BODY
176 : XML_FOOTNOTE_BODY;
179 if( XML_TOKEN_INVALID != eToken )
181 if( m_bPersistent )
183 pContext.set(new XMLPersTextContentTContext(
184 GetTransformer(), rQName,
185 XML_NAMESPACE_TEXT,
186 eToken ));
187 AddContent( pContext );
190 else
192 pContext.set(new XMLRenameElemTransformerContext(
193 GetTransformer(), rQName,
194 XML_NAMESPACE_TEXT,
195 eToken ));
201 if( !pContext.is() )
203 pContext = m_bPersistent
204 ? XMLPersElemContentTContext::CreateChildContext(
205 nPrefix, rLocalName, rQName, rAttrList )
206 : XMLTransformerContext::CreateChildContext(
207 nPrefix, rLocalName, rQName, rAttrList );
210 return pContext;
213 bool XMLNotesTransformerContext::IsPersistent() const
215 return m_bPersistent;
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */