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>
24 #include <xmloff/namespacemap.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmlnamespace.hxx>
27 
28 #include "TransformerBase.hxx"
29 #include "TransformerActions.hxx"
31 #include "ActionMapTypesOASIS.hxx"
32 #include "MutableAttrList.hxx"
33 #include "RenameElemTContext.hxx"
34 #include "FlatTContext.hxx"
35 
36 #include "NotesTContext.hxx"
37 
38 using namespace ::xmloff::token;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::xml::sax;
41 
43  XMLTransformerBase& rImp,
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 );
65  XMLMutableAttributeList *pMutableAttrList = nullptr;
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 );
107  if( XMLTransformerBase::DecodeStyleName(aAttrValue) )
108  pMutableAttrList->SetValueByIndex( i, aAttrValue );
109  }
110  break;
111  }
112  }
113  }
114 
116  switch( m_eTypeToken )
117  {
118  case XML_NOTE:
119  eToken = (m_bEndNote ? XML_ENDNOTE : XML_FOOTNOTE);
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(
135  ::xmloff::token::GetXMLToken( eToken ) ) );
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  {
174  eToken = m_bEndNote ? XML_ENDNOTE_BODY
176  }
177 
178  if( XML_TOKEN_INVALID != eToken )
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: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3434
void SetExportQName(const OUString &r)
virtual ~XMLNotesTransformerContext() override
virtual void EndElement() override
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
XMLNotesTransformerContext(XMLTransformerBase &rTransformer, const OUString &rQName,::xmloff::token::XMLTokenEnum m_eToken, bool bPersistent)
SvXMLNamespaceMap & GetNamespaceMap()
virtual sal_Int16 SAL_CALL getLength() override
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:49
virtual rtl::Reference< XMLTransformerContext > CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const OUString &rQName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
int i
void SetValueByIndex(sal_Int16 i, const OUString &rValue)
constexpr sal_uInt16 XML_NAMESPACE_TEXT
void RemoveAttributeByIndex(sal_Int16 i)
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
void AddContent(rtl::Reference< XMLTransformerContext > const &pContent)
const OUString & GetExportQName() const
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)
XMLTransformerBase & GetTransformer()
virtual bool IsPersistent() const override
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3378
Handling of tokens in XML:
static bool DecodeStyleName(OUString &rName)
XMLTokenEnum eToken
Definition: xmltoken.cxx:40
virtual void EndElement() override
::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)