bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / transform / NotesTContext.cxx
blob19b52c6c562873b4df6ac96b221e7d3310621c07
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 <xmloff/nmspmap.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include "xmloff/xmlnmspe.hxx"
28 #include "TransformerBase.hxx"
29 #include "TransformerActions.hxx"
30 #include "AttrTransformerAction.hxx"
31 #include "ActionMapTypesOASIS.hxx"
32 #include "MutableAttrList.hxx"
33 #include "RenameElemTContext.hxx"
34 #include "FlatTContext.hxx"
36 #include "NotesTContext.hxx"
38 using namespace ::xmloff::token;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::xml::sax;
42 TYPEINIT1( XMLNotesTransformerContext, XMLPersElemContentTContext );
44 XMLNotesTransformerContext::XMLNotesTransformerContext(
45 XMLTransformerBase& rImp,
46 const OUString& rQName,
47 XMLTokenEnum eToken, sal_Bool bPersistent ) :
48 XMLPersElemContentTContext( rImp, rQName ),
49 m_bEndNote( sal_False ),
50 m_bPersistent( bPersistent ),
51 m_eTypeToken( eToken )
55 XMLNotesTransformerContext::~XMLNotesTransformerContext()
59 void XMLNotesTransformerContext::StartElement(
60 const Reference< XAttributeList >& rAttrList )
62 XMLTransformerActions *pActions =
63 GetTransformer().GetUserDefinedActions( OASIS_NOTES_ACTIONS );
64 OSL_ENSURE( pActions, "go no actions" );
66 Reference< XAttributeList > xAttrList( rAttrList );
67 XMLMutableAttributeList *pMutableAttrList = 0;
68 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
69 for( sal_Int16 i=0; i < nAttrCount; i++ )
71 const OUString& rAttrName = xAttrList->getNameByIndex( i );
72 OUString aLocalName;
73 sal_uInt16 nPrefix =
74 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
75 &aLocalName );
76 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
77 XMLTransformerActions::const_iterator aIter =
78 pActions->find( aKey );
79 if( !(aIter == pActions->end() ) )
81 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
83 if( !pMutableAttrList )
85 pMutableAttrList =
86 new XMLMutableAttributeList( xAttrList );
87 xAttrList = pMutableAttrList;
89 switch( (*aIter).second.m_nActionType )
91 case XML_ATACTION_STYLE_FAMILY:
93 if( IsXMLToken( rAttrValue, XML_FOOTNOTE ) )
96 else if( IsXMLToken( rAttrValue, XML_ENDNOTE ) )
98 m_bEndNote = sal_True;
100 pMutableAttrList->RemoveAttributeByIndex( i );
101 --i;
102 --nAttrCount;
104 break;
105 case XML_ATACTION_DECODE_STYLE_NAME:
106 case XML_ATACTION_DECODE_STYLE_NAME_REF:
108 OUString aAttrValue( rAttrValue );
109 if( GetTransformer().DecodeStyleName(aAttrValue) )
110 pMutableAttrList->SetValueByIndex( i, aAttrValue );
112 break;
117 XMLTokenEnum eToken = XML_FOOTNOTE;
118 switch( m_eTypeToken )
120 case XML_NOTE:
121 eToken = (m_bEndNote ? XML_ENDNOTE : XML_FOOTNOTE);
122 break;
123 case XML_NOTES_CONFIGURATION:
124 eToken = (m_bEndNote ? XML_ENDNOTES_CONFIGURATION
125 : XML_FOOTNOTES_CONFIGURATION);
126 break;
127 case XML_NOTE_REF:
128 eToken = (m_bEndNote ? XML_ENDNOTE_REF : XML_FOOTNOTE_REF);
129 break;
130 default:
131 OSL_ENSURE( XML_NOTE==m_eTypeToken, "invalid note type" );
132 break;
135 SetExportQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
136 XML_NAMESPACE_TEXT,
137 ::xmloff::token::GetXMLToken( eToken ) ) );
138 if( m_bPersistent )
139 XMLPersElemContentTContext::StartElement( xAttrList );
140 else
141 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
142 xAttrList );
145 void XMLNotesTransformerContext::EndElement()
147 if( m_bPersistent )
149 XMLPersElemContentTContext::EndElement();
151 else
153 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
157 XMLTransformerContext *XMLNotesTransformerContext::CreateChildContext(
158 sal_uInt16 nPrefix,
159 const OUString& rLocalName,
160 const OUString& rQName,
161 const Reference< XAttributeList >& rAttrList )
163 XMLTransformerContext *pContext = 0;
164 if( XML_NOTE == m_eTypeToken )
166 if( XML_NAMESPACE_TEXT == nPrefix )
168 XMLTokenEnum eToken ( XML_TOKEN_INVALID );
169 if( IsXMLToken( rLocalName, XML_NOTE_CITATION ) )
171 eToken = m_bEndNote ? XML_ENDNOTE_CITATION
172 : XML_FOOTNOTE_CITATION;
174 else if( IsXMLToken( rLocalName, XML_NOTE_BODY ) )
176 eToken = m_bEndNote ? XML_ENDNOTE_BODY
177 : XML_FOOTNOTE_BODY;
180 if( XML_TOKEN_INVALID != eToken )
182 if( m_bPersistent )
184 pContext = new XMLPersTextContentTContext(
185 GetTransformer(), rQName,
186 XML_NAMESPACE_TEXT,
187 eToken );
188 AddContent( pContext );
191 else
193 pContext = new XMLRenameElemTransformerContext(
194 GetTransformer(), rQName,
195 XML_NAMESPACE_TEXT,
196 eToken );
202 if( !pContext )
204 pContext = m_bPersistent
205 ? XMLPersElemContentTContext::CreateChildContext(
206 nPrefix, rLocalName, rQName, rAttrList )
207 : XMLTransformerContext::CreateChildContext(
208 nPrefix, rLocalName, rQName, rAttrList );
211 return pContext;
214 sal_Bool XMLNotesTransformerContext::IsPersistent() const
216 return m_bPersistent;
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */