Update git submodules
[LibreOffice.git] / xmloff / source / transform / NotesTContext.cxx
blob8208f3dd50c656ce78cd6433d84d87de834aa1ba
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/XDocumentHandler.hpp>
21 #include <osl/diagnose.h>
22 #include <xmloff/namespacemap.hxx>
23 #include <xmloff/xmltoken.hxx>
24 #include <xmloff/xmlnamespace.hxx>
26 #include "TransformerBase.hxx"
27 #include "TransformerActions.hxx"
28 #include "AttrTransformerAction.hxx"
29 #include "ActionMapTypesOASIS.hxx"
30 #include "MutableAttrList.hxx"
31 #include "RenameElemTContext.hxx"
32 #include "FlatTContext.hxx"
34 #include "NotesTContext.hxx"
36 using namespace ::xmloff::token;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::xml::sax;
40 XMLNotesTransformerContext::XMLNotesTransformerContext(
41 XMLTransformerBase& rImp,
42 const OUString& rQName,
43 XMLTokenEnum eToken, bool bPersistent ) :
44 XMLPersElemContentTContext( rImp, rQName ),
45 m_bEndNote( false ),
46 m_bPersistent( bPersistent ),
47 m_eTypeToken( eToken )
51 XMLNotesTransformerContext::~XMLNotesTransformerContext()
55 void XMLNotesTransformerContext::StartElement(
56 const Reference< XAttributeList >& rAttrList )
58 XMLTransformerActions *pActions =
59 GetTransformer().GetUserDefinedActions( OASIS_NOTES_ACTIONS );
60 OSL_ENSURE( pActions, "go no actions" );
62 Reference< XAttributeList > xAttrList( rAttrList );
63 rtl::Reference<XMLMutableAttributeList> pMutableAttrList;
64 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
65 for( sal_Int16 i=0; i < nAttrCount; i++ )
67 const OUString aAttrName = xAttrList->getNameByIndex( i );
68 OUString aLocalName;
69 sal_uInt16 nPrefix =
70 GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName,
71 &aLocalName );
72 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
73 XMLTransformerActions::const_iterator aIter =
74 pActions->find( aKey );
75 if( aIter != pActions->end() )
77 const OUString aAttrValue = xAttrList->getValueByIndex( i );
79 if( !pMutableAttrList )
81 pMutableAttrList =
82 new XMLMutableAttributeList( xAttrList );
83 xAttrList = pMutableAttrList;
85 switch( (*aIter).second.m_nActionType )
87 case XML_ATACTION_STYLE_FAMILY:
89 if( IsXMLToken( aAttrValue, XML_FOOTNOTE ) )
92 else if( IsXMLToken( aAttrValue, XML_ENDNOTE ) )
94 m_bEndNote = true;
96 pMutableAttrList->RemoveAttributeByIndex( i );
97 --i;
98 --nAttrCount;
100 break;
101 case XML_ATACTION_DECODE_STYLE_NAME:
102 case XML_ATACTION_DECODE_STYLE_NAME_REF:
104 OUString aAttrValue2( aAttrValue );
105 if( XMLTransformerBase::DecodeStyleName(aAttrValue2) )
106 pMutableAttrList->SetValueByIndex( i, aAttrValue2 );
108 break;
113 XMLTokenEnum eToken = XML_FOOTNOTE;
114 switch( m_eTypeToken )
116 case XML_NOTE:
117 eToken = (m_bEndNote ? XML_ENDNOTE : XML_FOOTNOTE);
118 break;
119 case XML_NOTES_CONFIGURATION:
120 eToken = (m_bEndNote ? XML_ENDNOTES_CONFIGURATION
121 : XML_FOOTNOTES_CONFIGURATION);
122 break;
123 case XML_NOTE_REF:
124 eToken = (m_bEndNote ? XML_ENDNOTE_REF : XML_FOOTNOTE_REF);
125 break;
126 default:
127 OSL_ENSURE( XML_NOTE==m_eTypeToken, "invalid note type" );
128 break;
131 SetExportQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
132 XML_NAMESPACE_TEXT,
133 ::xmloff::token::GetXMLToken( eToken ) ) );
134 if( m_bPersistent )
135 XMLPersElemContentTContext::StartElement( xAttrList );
136 else
137 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
138 xAttrList );
141 void XMLNotesTransformerContext::EndElement()
143 if( m_bPersistent )
145 XMLPersElemContentTContext::EndElement();
147 else
149 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
153 rtl::Reference<XMLTransformerContext> XMLNotesTransformerContext::CreateChildContext(
154 sal_uInt16 nPrefix,
155 const OUString& rLocalName,
156 const OUString& rQName,
157 const Reference< XAttributeList >& rAttrList )
159 rtl::Reference<XMLTransformerContext> pContext;
160 if( XML_NOTE == m_eTypeToken )
162 if( XML_NAMESPACE_TEXT == nPrefix )
164 XMLTokenEnum eToken ( XML_TOKEN_INVALID );
165 if( IsXMLToken( rLocalName, XML_NOTE_CITATION ) )
167 eToken = m_bEndNote ? XML_ENDNOTE_CITATION
168 : XML_FOOTNOTE_CITATION;
170 else if( IsXMLToken( rLocalName, XML_NOTE_BODY ) )
172 eToken = m_bEndNote ? XML_ENDNOTE_BODY
173 : XML_FOOTNOTE_BODY;
176 if( XML_TOKEN_INVALID != eToken )
178 if( m_bPersistent )
180 pContext.set(new XMLPersTextContentTContext(
181 GetTransformer(), rQName,
182 XML_NAMESPACE_TEXT,
183 eToken ));
184 AddContent( pContext );
187 else
189 pContext.set(new XMLRenameElemTransformerContext(
190 GetTransformer(), rQName,
191 XML_NAMESPACE_TEXT,
192 eToken ));
198 if( !pContext.is() )
200 pContext = m_bPersistent
201 ? XMLPersElemContentTContext::CreateChildContext(
202 nPrefix, rLocalName, rQName, rAttrList )
203 : XMLTransformerContext::CreateChildContext(
204 nPrefix, rLocalName, rQName, rAttrList );
207 return pContext;
210 bool XMLNotesTransformerContext::IsPersistent() const
212 return m_bPersistent;
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */