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