ScriptForge (SF_Calc new Intersect() method
[LibreOffice.git] / xmloff / source / transform / TransformerBase.hxx
bloba5e6261883f816bb8d8d1079ee69533460a546af
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 #pragma once
22 #include <sal/config.h>
24 #include <vector>
25 #include <memory>
27 #include <com/sun/star/lang/XInitialization.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/xml/sax/XAttributeList.hpp>
30 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
31 #include <com/sun/star/xml/sax/XLocator.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/frame/XModel.hpp>
35 #include <cppuhelper/implbase.hxx>
36 #include <rtl/ref.hxx>
37 #include <xmloff/xmltoken.hxx>
38 #include <xmloff/namespacemap.hxx>
40 #include "TransformerActions.hxx"
41 #include "TransformerTokenMap.hxx"
43 namespace com::sun::star {
44 namespace i18n { class XCharacterClassification; }
47 class SvXMLNamespaceMap;
48 class XMLTransformerContext;
49 class XMLTransformerActions;
50 struct XMLTransformerActionInit;
51 struct TransformerAction_Impl;
52 class XMLMutableAttributeList;
54 const sal_uInt16 INVALID_ACTIONS = 0xffff;
56 class XMLTransformerBase : public cppu::WeakImplHelper<css::xml::sax::XExtendedDocumentHandler,
57 css::lang::XServiceInfo,
58 css::lang::XInitialization>
60 friend class XMLTransformerContext;
62 css::uno::Reference< css::xml::sax::XDocumentHandler > m_xHandler; // the handlers
63 css::uno::Reference< css::beans::XPropertySet > m_xPropSet;
64 css::uno::Reference< css::i18n::XCharacterClassification > xCharClass;
66 OUString m_aExtPathPrefix;
67 OUString m_aClass;
69 std::unique_ptr<SvXMLNamespaceMap> m_pNamespaceMap;
70 SvXMLNamespaceMap m_vReplaceNamespaceMap;
71 std::vector<rtl::Reference<XMLTransformerContext>> m_vContexts;
72 XMLTransformerActions m_ElemActions;
73 XMLTransformerTokenMap const m_TokenMap;
75 protected:
76 css::uno::Reference< css::frame::XModel > mxModel;
78 // This method is called after the namespace map has been updated, but
79 // before a context for the current element has been pushed.
80 XMLTransformerContext *CreateContext( sal_uInt16 nPrefix,
81 const OUString& rLocalName,
82 const OUString& rQName );
84 public:
85 XMLTransformerBase( XMLTransformerActionInit const *pInit,
86 ::xmloff::token::XMLTokenEnum const *pTKMapInit ) noexcept;
87 virtual ~XMLTransformerBase() noexcept override;
89 // css::xml::sax::XDocumentHandler
90 virtual void SAL_CALL startDocument() override;
91 virtual void SAL_CALL endDocument() override;
92 virtual void SAL_CALL startElement(const OUString& aName,
93 const css::uno::Reference< css::xml::sax::XAttributeList > & xAttribs) override;
94 virtual void SAL_CALL endElement(const OUString& aName) override;
95 virtual void SAL_CALL characters(const OUString& aChars) override;
96 virtual void SAL_CALL ignorableWhitespace(const OUString& aWhitespaces) override;
97 virtual void SAL_CALL processingInstruction(const OUString& aTarget,
98 const OUString& aData) override;
99 virtual void SAL_CALL setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator > & xLocator) override;
101 // css::xml::sax::XExtendedDocumentHandler
102 virtual void SAL_CALL startCDATA() override;
103 virtual void SAL_CALL endCDATA() override;
104 virtual void SAL_CALL comment(const OUString& sComment) override;
105 virtual void SAL_CALL allowLineBreak() override;
106 virtual void SAL_CALL unknown(const OUString& sString) override;
108 // XInitialization
109 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
111 // C++
112 const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const { return m_xHandler; }
114 const css::uno::Reference< css::beans::XPropertySet > & GetPropertySet() const { return m_xPropSet; }
117 SvXMLNamespaceMap& GetNamespaceMap() { return *m_pNamespaceMap; }
118 const SvXMLNamespaceMap& GetNamespaceMap() const { return *m_pNamespaceMap; }
119 SvXMLNamespaceMap& GetReplaceNamespaceMap() { return m_vReplaceNamespaceMap; }
121 XMLTransformerActions& GetElemActions() { return m_ElemActions; }
122 virtual XMLTransformerActions *GetUserDefinedActions( sal_uInt16 n );
123 virtual XMLTransformerContext *CreateUserDefinedContext(
124 const TransformerAction_Impl& rAction,
125 const OUString& rQName,
126 bool bPersistent=false ) = 0;
127 virtual OUString GetEventName( const OUString& rName,
128 bool bForm = false ) = 0;
131 XMLMutableAttributeList *ProcessAttrList( css::uno::Reference< css::xml::sax::XAttributeList >& rAttrList,
132 sal_uInt16 nActionMap, bool bClone );
134 static bool ReplaceSingleInchWithIn( OUString& rValue );
135 static bool ReplaceSingleInWithInch( OUString& rValue );
136 static bool ReplaceInchWithIn( OUString& rValue );
137 static bool ReplaceInWithInch( OUString& rValue );
139 bool EncodeStyleName( OUString& rName ) const;
140 static bool DecodeStyleName( OUString& rName );
141 static bool NegPercent( OUString& rValue );
143 void AddNamespacePrefix( OUString& rName,
144 sal_uInt16 nPrefix ) const;
145 bool RemoveNamespacePrefix( OUString& rName,
146 sal_uInt16 nPrefixOnly=0xffffU ) const;
148 bool ConvertURIToOASIS( OUString& rURI,
149 bool bSupportPackage ) const;
150 bool ConvertURIToOOo( OUString& rURI,
151 bool bSupportPackage ) const;
153 /** renames the given rOutAttributeValue if one of the parameters contains a
154 matching token in its lower 16 bits. The value is converted to the
155 token that is given in the upper 16 bits of the matching parameter.
157 static bool RenameAttributeValue( OUString& rOutAttributeValue,
158 sal_Int32 nParam1,
159 sal_Int32 nParam2,
160 sal_Int32 nParam3 );
162 /** converts the '.' that separates fractions of seconds in a dateTime
163 string into a ',' that was used in the OOo format
165 @param rDateTime
166 A dateTime string that will be parsed and changed in case a match
167 was found.
168 @return <TRUE/> if the given string was changed
170 static bool ConvertRNGDateTimeToISO( OUString& rDateTime );
172 ::xmloff::token::XMLTokenEnum GetToken( const OUString& rStr ) const;
174 const XMLTransformerContext *GetCurrentContext() const;
175 const XMLTransformerContext *GetAncestorContext( sal_uInt32 i ) const;
177 // C++
178 void SetClass( const OUString& r ) { m_aClass = r; }
179 const OUString& GetClass() const { return m_aClass; }
181 bool isWriter() const;
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */