1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <sal/config.h>
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>
35 #include "Transformer.hxx"
36 #include "TransformerActions.hxx"
37 #include "TransformerTokenMap.hxx"
39 namespace com::sun::star
{
40 namespace i18n
{ class XCharacterClassification
; }
43 class SvXMLNamespaceMap
;
44 class XMLTransformerContext
;
45 class XMLTransformerActions
;
46 struct XMLTransformerActionInit
;
47 struct TransformerAction_Impl
;
48 class XMLMutableAttributeList
;
50 const sal_uInt16 INVALID_ACTIONS
= 0xffff;
52 class XMLTransformerBase
: public XMLTransformer
54 friend class XMLTransformerContext
;
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
;
60 OUString m_aExtPathPrefix
;
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
;
70 css::uno::Reference
< css::frame::XModel
> mxModel
;
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
);
79 XMLTransformerBase( XMLTransformerActionInit
const *pInit
,
80 ::xmloff::token::XMLTokenEnum
const *pTKMapInit
) noexcept
;
81 virtual ~XMLTransformerBase() noexcept override
;
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
;
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
;
103 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
106 const css::uno::Reference
< css::xml::sax::XDocumentHandler
> & GetDocHandler() const { return m_xHandler
; }
108 const css::uno::Reference
< css::beans::XPropertySet
> & GetPropertySet() const { return m_xPropSet
; }
111 SvXMLNamespaceMap
& GetNamespaceMap() { return *m_pNamespaceMap
; }
112 const SvXMLNamespaceMap
& GetNamespaceMap() const { return *m_pNamespaceMap
; }
113 SvXMLNamespaceMap
& GetReplaceNamespaceMap() { return m_vReplaceNamespaceMap
; }
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;
125 XMLMutableAttributeList
*ProcessAttrList( css::uno::Reference
< css::xml::sax::XAttributeList
>& rAttrList
,
126 sal_uInt16 nActionMap
, bool bClone
);
128 static bool ReplaceSingleInchWithIn( OUString
& rValue
);
129 static bool ReplaceSingleInWithInch( OUString
& rValue
);
130 static bool ReplaceInchWithIn( OUString
& rValue
);
131 static bool ReplaceInWithInch( OUString
& rValue
);
133 bool EncodeStyleName( OUString
& rName
) const;
134 static bool DecodeStyleName( OUString
& rName
);
135 static bool NegPercent( OUString
& rValue
);
137 void AddNamespacePrefix( OUString
& rName
,
138 sal_uInt16 nPrefix
) const;
139 bool RemoveNamespacePrefix( OUString
& rName
,
140 sal_uInt16 nPrefixOnly
=0xffffU
) const;
142 bool ConvertURIToOASIS( OUString
& rURI
,
143 bool bSupportPackage
) const;
144 bool ConvertURIToOOo( OUString
& rURI
,
145 bool bSupportPackage
) const;
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.
151 static bool RenameAttributeValue( OUString
& rOutAttributeValue
,
156 /** converts the '.' that separates fractions of seconds in a dateTime
157 string into a ',' that was used in the OOo format
160 A dateTime string that will be parsed and changed in case a match
162 @return <TRUE/> if the given string was changed
164 static bool ConvertRNGDateTimeToISO( OUString
& rDateTime
);
166 ::xmloff::token::XMLTokenEnum
GetToken( const OUString
& rStr
) const;
168 const XMLTransformerContext
*GetCurrentContext() const;
169 const XMLTransformerContext
*GetAncestorContext( sal_uInt32 i
) const;
172 void SetClass( const OUString
& r
) { m_aClass
= r
; }
173 const OUString
& GetClass() const { return m_aClass
; }
175 bool isWriter() const;
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */