LibreOffice Module xmloff (master) 1
NotesTContext.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <com/sun/star/xml/sax/SAXException.hpp>
21#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
22#include <com/sun/star/xml/sax/XAttributeList.hpp>
23#include <osl/diagnose.h>
25#include <xmloff/xmltoken.hxx>
27
28#include "TransformerBase.hxx"
32#include "MutableAttrList.hxx"
34#include "FlatTContext.hxx"
35
36#include "NotesTContext.hxx"
37
38using namespace ::xmloff::token;
39using namespace ::com::sun::star::uno;
40using namespace ::com::sun::star::xml::sax;
41
44 const OUString& rQName,
45 XMLTokenEnum eToken, bool bPersistent ) :
46 XMLPersElemContentTContext( rImp, rQName ),
47 m_bEndNote( false ),
48 m_bPersistent( bPersistent ),
49 m_eTypeToken( eToken )
50{
51}
52
54{
55}
56
58 const Reference< XAttributeList >& rAttrList )
59{
60 XMLTransformerActions *pActions =
62 OSL_ENSURE( pActions, "go no actions" );
63
64 Reference< XAttributeList > xAttrList( rAttrList );
66 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
67 for( sal_Int16 i=0; i < nAttrCount; i++ )
68 {
69 const OUString& rAttrName = xAttrList->getNameByIndex( i );
70 OUString aLocalName;
71 sal_uInt16 nPrefix =
73 &aLocalName );
74 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
75 XMLTransformerActions::const_iterator aIter =
76 pActions->find( aKey );
77 if( aIter != pActions->end() )
78 {
79 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
80
81 if( !pMutableAttrList )
82 {
83 pMutableAttrList =
84 new XMLMutableAttributeList( xAttrList );
85 xAttrList = pMutableAttrList;
86 }
87 switch( (*aIter).second.m_nActionType )
88 {
90 {
91 if( IsXMLToken( rAttrValue, XML_FOOTNOTE ) )
92 {
93 }
94 else if( IsXMLToken( rAttrValue, XML_ENDNOTE ) )
95 {
96 m_bEndNote = true;
97 }
98 pMutableAttrList->RemoveAttributeByIndex( i );
99 --i;
100 --nAttrCount;
101 }
102 break;
105 {
106 OUString aAttrValue( rAttrValue );
108 pMutableAttrList->SetValueByIndex( i, aAttrValue );
109 }
110 break;
111 }
112 }
113 }
114
116 switch( m_eTypeToken )
117 {
118 case XML_NOTE:
120 break;
124 break;
125 case XML_NOTE_REF:
127 break;
128 default:
129 OSL_ENSURE( XML_NOTE==m_eTypeToken, "invalid note type" );
130 break;
131 }
132
133 SetExportQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
136 if( m_bPersistent )
138 else
139 GetTransformer().GetDocHandler()->startElement( GetExportQName(),
140 xAttrList );
141}
142
144{
145 if( m_bPersistent )
146 {
148 }
149 else
150 {
151 GetTransformer().GetDocHandler()->endElement( GetExportQName() );
152 }
153}
154
156 sal_uInt16 nPrefix,
157 const OUString& rLocalName,
158 const OUString& rQName,
159 const Reference< XAttributeList >& rAttrList )
160{
162 if( XML_NOTE == m_eTypeToken )
163 {
164 if( XML_NAMESPACE_TEXT == nPrefix )
165 {
167 if( IsXMLToken( rLocalName, XML_NOTE_CITATION ) )
168 {
171 }
172 else if( IsXMLToken( rLocalName, XML_NOTE_BODY ) )
173 {
176 }
177
179 {
180 if( m_bPersistent )
181 {
182 pContext.set(new XMLPersTextContentTContext(
183 GetTransformer(), rQName,
185 eToken ));
186 AddContent( pContext );
187
188 }
189 else
190 {
191 pContext.set(new XMLRenameElemTransformerContext(
192 GetTransformer(), rQName,
194 eToken ));
195 }
196 }
197 }
198 }
199
200 if( !pContext.is() )
201 {
202 pContext = m_bPersistent
204 nPrefix, rLocalName, rQName, rAttrList )
206 nPrefix, rLocalName, rQName, rAttrList );
207 }
208
209 return pContext;
210}
211
213{
214 return m_bPersistent;
215}
216
217/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ OASIS_NOTES_ACTIONS
@ XML_ATACTION_DECODE_STYLE_NAME_REF
@ XML_ATACTION_DECODE_STYLE_NAME
@ XML_ATACTION_STYLE_FAMILY
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
::xmloff::token::XMLTokenEnum m_eTypeToken
virtual rtl::Reference< XMLTransformerContext > CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const OUString &rQName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
virtual ~XMLNotesTransformerContext() override
XMLNotesTransformerContext(XMLTransformerBase &rTransformer, const OUString &rQName, ::xmloff::token::XMLTokenEnum m_eToken, bool bPersistent)
virtual bool IsPersistent() const override
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
virtual void EndElement() override
const OUString & GetExportQName() const
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
void SetExportQName(const OUString &r)
virtual void EndElement() override
void AddContent(rtl::Reference< XMLTransformerContext > const &pContent)
virtual rtl::Reference< XMLTransformerContext > CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const OUString &rQName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
virtual XMLTransformerActions * GetUserDefinedActions(sal_uInt16 n)
static bool DecodeStyleName(OUString &rName)
SvXMLNamespaceMap & GetNamespaceMap()
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
virtual rtl::Reference< XMLTransformerContext > CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const OUString &rQName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
XMLTransformerBase & GetTransformer()
int i
Handling of tokens in XML:
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:50
@ XML_ENDNOTE_CITATION
Definition: xmltoken.hxx:766
@ XML_ENDNOTES_CONFIGURATION
Definition: xmltoken.hxx:768
@ XML_NOTES_CONFIGURATION
Definition: xmltoken.hxx:2624
@ XML_FOOTNOTE_CITATION
Definition: xmltoken.hxx:918
@ XML_FOOTNOTES_CONFIGURATION
Definition: xmltoken.hxx:924
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3597
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3541
constexpr sal_uInt16 XML_NAMESPACE_TEXT
XMLTokenEnum eToken
Definition: xmltoken.cxx:40