LibreOffice Module xmloff (master)  1
TransformerBase.hxx
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 #pragma once
21 
22 #include <sal/config.h>
23 
24 #include <vector>
25 #include <memory>
26 
27 #include <com/sun/star/xml/sax/XAttributeList.hpp>
28 #include <com/sun/star/xml/sax/XLocator.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/frame/XModel.hpp>
31 #include <rtl/ref.hxx>
32 #include <xmloff/xmltoken.hxx>
33 #include <xmloff/namespacemap.hxx>
34 
35 #include "Transformer.hxx"
36 #include "TransformerActions.hxx"
37 #include "TransformerTokenMap.hxx"
38 
39 namespace com::sun::star {
40  namespace i18n { class XCharacterClassification; }
41 }
42 
43 class SvXMLNamespaceMap;
49 
50 const sal_uInt16 INVALID_ACTIONS = 0xffff;
51 
53 {
54  friend class XMLTransformerContext;
55 
56  css::uno::Reference< css::xml::sax::XDocumentHandler > m_xHandler; // the handlers
57  css::uno::Reference< css::beans::XPropertySet > m_xPropSet;
58  css::uno::Reference< css::i18n::XCharacterClassification > xCharClass;
59 
60  OUString m_aExtPathPrefix;
61  OUString m_aClass;
62 
63  std::unique_ptr<SvXMLNamespaceMap> m_pNamespaceMap;
65  std::vector<rtl::Reference<XMLTransformerContext>> m_vContexts;
68 
69 protected:
70  css::uno::Reference< css::frame::XModel > mxModel;
71 
72  // This method is called after the namespace map has been updated, but
73  // before a context for the current element has been pushed.
74  XMLTransformerContext *CreateContext( sal_uInt16 nPrefix,
75  const OUString& rLocalName,
76  const OUString& rQName );
77 
78 public:
80  ::xmloff::token::XMLTokenEnum const *pTKMapInit ) noexcept;
81  virtual ~XMLTransformerBase() noexcept override;
82 
83  // css::xml::sax::XDocumentHandler
84  virtual void SAL_CALL startDocument() override;
85  virtual void SAL_CALL endDocument() override;
86  virtual void SAL_CALL startElement(const OUString& aName,
87  const css::uno::Reference< css::xml::sax::XAttributeList > & xAttribs) override;
88  virtual void SAL_CALL endElement(const OUString& aName) override;
89  virtual void SAL_CALL characters(const OUString& aChars) override;
90  virtual void SAL_CALL ignorableWhitespace(const OUString& aWhitespaces) override;
91  virtual void SAL_CALL processingInstruction(const OUString& aTarget,
92  const OUString& aData) override;
93  virtual void SAL_CALL setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator > & xLocator) override;
94 
95  // css::xml::sax::XExtendedDocumentHandler
96  virtual void SAL_CALL startCDATA() override;
97  virtual void SAL_CALL endCDATA() override;
98  virtual void SAL_CALL comment(const OUString& sComment) override;
99  virtual void SAL_CALL allowLineBreak() override;
100  virtual void SAL_CALL unknown(const OUString& sString) override;
101 
102  // XInitialization
103  virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
104 
105  // C++
106  const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const { return m_xHandler; }
107 
108  const css::uno::Reference< css::beans::XPropertySet > & GetPropertySet() const { return m_xPropSet; }
109 
110 
114 
116  virtual XMLTransformerActions *GetUserDefinedActions( sal_uInt16 n );
118  const TransformerAction_Impl& rAction,
119  const OUString& rQName,
120  bool bPersistent=false ) = 0;
121  virtual OUString GetEventName( const OUString& rName,
122  bool bForm = false ) = 0;
123 
124 
125  XMLMutableAttributeList *ProcessAttrList( css::uno::Reference< css::xml::sax::XAttributeList >& rAttrList,
126  sal_uInt16 nActionMap, bool bClone );
127 
128  static bool ReplaceSingleInchWithIn( OUString& rValue );
129  static bool ReplaceSingleInWithInch( OUString& rValue );
130  static bool ReplaceInchWithIn( OUString& rValue );
131  static bool ReplaceInWithInch( OUString& rValue );
132 
133  bool EncodeStyleName( OUString& rName ) const;
134  static bool DecodeStyleName( OUString& rName );
135  static bool NegPercent( OUString& rValue );
136 
137  void AddNamespacePrefix( OUString& rName,
138  sal_uInt16 nPrefix ) const;
139  bool RemoveNamespacePrefix( OUString& rName,
140  sal_uInt16 nPrefixOnly=0xffffU ) const;
141 
142  bool ConvertURIToOASIS( OUString& rURI,
143  bool bSupportPackage ) const;
144  bool ConvertURIToOOo( OUString& rURI,
145  bool bSupportPackage ) const;
146 
151  static bool RenameAttributeValue( OUString& rOutAttributeValue,
152  sal_Int32 nParam1,
153  sal_Int32 nParam2,
154  sal_Int32 nParam3 );
155 
164  static bool ConvertRNGDateTimeToISO( OUString& rDateTime );
165 
166  ::xmloff::token::XMLTokenEnum GetToken( const OUString& rStr ) const;
167 
169  const XMLTransformerContext *GetAncestorContext( sal_uInt32 i ) const;
170 
171  // C++
172  void SetClass( const OUString& r ) { m_aClass = r; }
173  const OUString& GetClass() const { return m_aClass; }
174 
175  bool isWriter() const;
176 
177 };
178 
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString & GetClass() const
virtual XMLTransformerContext * CreateUserDefinedContext(const TransformerAction_Impl &rAction, const OUString &rQName, bool bPersistent=false)=0
const css::uno::Reference< css::beans::XPropertySet > & GetPropertySet() const
css::uno::Reference< css::frame::XModel > mxModel
virtual void SAL_CALL startDocument() override
std::unique_ptr< SvXMLNamespaceMap > m_pNamespaceMap
static bool ReplaceInchWithIn(OUString &rValue)
virtual void SAL_CALL ignorableWhitespace(const OUString &aWhitespaces) override
XMLTransformerBase(XMLTransformerActionInit const *pInit,::xmloff::token::XMLTokenEnum const *pTKMapInit) noexcept
virtual void SAL_CALL endDocument() override
virtual void SAL_CALL startElement(const OUString &aName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttribs) override
const SvXMLNamespaceMap & GetNamespaceMap() const
virtual void SAL_CALL endElement(const OUString &aName) override
virtual void SAL_CALL startCDATA() override
bool ConvertURIToOOo(OUString &rURI, bool bSupportPackage) const
void SetClass(const OUString &r)
static bool RenameAttributeValue(OUString &rOutAttributeValue, sal_Int32 nParam1, sal_Int32 nParam2, sal_Int32 nParam3)
renames the given rOutAttributeValue if one of the parameters contains a matching token in its lower ...
SvXMLNamespaceMap & GetNamespaceMap()
css::uno::Reference< css::xml::sax::XDocumentHandler > m_xHandler
bool RemoveNamespacePrefix(OUString &rName, sal_uInt16 nPrefixOnly=0xffffU) const
static bool ConvertRNGDateTimeToISO(OUString &rDateTime)
converts the '.
virtual void SAL_CALL unknown(const OUString &sString) override
virtual void SAL_CALL setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator > &xLocator) override
const sal_uInt16 INVALID_ACTIONS
const XMLTransformerContext * GetAncestorContext(sal_uInt32 i) const
static bool ReplaceInWithInch(OUString &rValue)
virtual void SAL_CALL characters(const OUString &aChars) override
virtual void SAL_CALL processingInstruction(const OUString &aTarget, const OUString &aData) override
css::uno::Reference< css::beans::XPropertySet > m_xPropSet
exports com.sun.star. i18n
virtual void SAL_CALL allowLineBreak() override
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
static bool ReplaceSingleInWithInch(OUString &rValue)
void AddNamespacePrefix(OUString &rName, sal_uInt16 nPrefix) const
XMLTransformerTokenMap const m_TokenMap
virtual ~XMLTransformerBase() noexcept override
virtual void SAL_CALL comment(const OUString &sComment) override
css::uno::Reference< css::i18n::XCharacterClassification > xCharClass
virtual XMLTransformerActions * GetUserDefinedActions(sal_uInt16 n)
static bool ReplaceSingleInchWithIn(OUString &rValue)
static bool NegPercent(OUString &rValue)
XMLTransformerContext * CreateContext(sal_uInt16 nPrefix, const OUString &rLocalName, const OUString &rQName)
::xmloff::token::XMLTokenEnum GetToken(const OUString &rStr) const
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:49
virtual void SAL_CALL endCDATA() override
const XMLTransformerContext * GetCurrentContext() const
XMLMutableAttributeList * ProcessAttrList(css::uno::Reference< css::xml::sax::XAttributeList > &rAttrList, sal_uInt16 nActionMap, bool bClone)
bool EncodeStyleName(OUString &rName) const
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
XMLTransformerActions & GetElemActions()
XMLTransformerActions m_ElemActions
static bool DecodeStyleName(OUString &rName)
bool ConvertURIToOASIS(OUString &rURI, bool bSupportPackage) const
SvXMLNamespaceMap m_vReplaceNamespaceMap
virtual OUString GetEventName(const OUString &rName, bool bForm=false)=0
std::vector< rtl::Reference< XMLTransformerContext > > m_vContexts
SvXMLNamespaceMap & GetReplaceNamespaceMap()