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; 44 class XMLTransformerContext; 45 class XMLTransformerActions; 46 struct XMLTransformerActionInit; 47 struct TransformerAction_Impl; 48 class XMLMutableAttributeList; 49 50 const sal_uInt16 INVALID_ACTIONS = 0xffff; 51 52 class XMLTransformerBase : public XMLTransformer 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; 64 SvXMLNamespaceMap m_vReplaceNamespaceMap; 65 std::vector<rtl::Reference<XMLTransformerContext>> m_vContexts; 66 XMLTransformerActions m_ElemActions; 67 XMLTransformerTokenMap const m_TokenMap; 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: 79 XMLTransformerBase( XMLTransformerActionInit const *pInit, 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++ GetDocHandler() const106 const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const { return m_xHandler; } 107 GetPropertySet() const108 const css::uno::Reference< css::beans::XPropertySet > & GetPropertySet() const { return m_xPropSet; } 109 110 GetNamespaceMap()111 SvXMLNamespaceMap& GetNamespaceMap() { return *m_pNamespaceMap; } GetNamespaceMap() const112 const SvXMLNamespaceMap& GetNamespaceMap() const { return *m_pNamespaceMap; } GetReplaceNamespaceMap()113 SvXMLNamespaceMap& GetReplaceNamespaceMap() { return m_vReplaceNamespaceMap; } 114 GetElemActions()115 XMLTransformerActions& GetElemActions() { return m_ElemActions; } 116 virtual XMLTransformerActions *GetUserDefinedActions( sal_uInt16 n ); 117 virtual XMLTransformerContext *CreateUserDefinedContext( 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 147 /** renames the given rOutAttributeValue if one of the parameters contains a 148 matching token in its lower 16 bits. The value is converted to the 149 token that is given in the upper 16 bits of the matching parameter. 150 */ 151 static bool RenameAttributeValue( OUString& rOutAttributeValue, 152 sal_Int32 nParam1, 153 sal_Int32 nParam2, 154 sal_Int32 nParam3 ); 155 156 /** converts the '.' that separates fractions of seconds in a dateTime 157 string into a ',' that was used in the OOo format 158 159 @param rDateTime 160 A dateTime string that will be parsed and changed in case a match 161 was found. 162 @return <TRUE/> if the given string was changed 163 */ 164 static bool ConvertRNGDateTimeToISO( OUString& rDateTime ); 165 166 ::xmloff::token::XMLTokenEnum GetToken( const OUString& rStr ) const; 167 168 const XMLTransformerContext *GetCurrentContext() const; 169 const XMLTransformerContext *GetAncestorContext( sal_uInt32 i ) const; 170 171 // C++ SetClass(const OUString & r)172 void SetClass( const OUString& r ) { m_aClass = r; } GetClass() const173 const OUString& GetClass() const { return m_aClass; } 174 175 bool isWriter() const; 176 177 }; 178 179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 180