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 .
20 #ifndef INCLUDED_XMLOFF_SOURCE_TRANSFORM_TRANSFORMERBASE_HXX
21 #define INCLUDED_XMLOFF_SOURCE_TRANSFORM_TRANSFORMERBASE_HXX
23 #include <sal/config.h>
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/nmspmap.hxx>
36 #include "Transformer.hxx"
37 #include "TransformerActions.hxx"
38 #include "TransformerTokenMap.hxx"
40 namespace com
{ namespace sun
{ namespace star
{
41 namespace i18n
{ class XCharacterClassification
; }
44 class SvXMLNamespaceMap
;
45 class XMLTransformerContext
;
46 class XMLTransformerActions
;
47 struct XMLTransformerActionInit
;
48 struct TransformerAction_Impl
;
49 class XMLMutableAttributeList
;
51 const sal_uInt16 INVALID_ACTIONS
= 0xffff;
53 class XMLTransformerBase
: public XMLTransformer
55 friend class XMLTransformerContext
;
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
;
61 OUString m_aExtPathPrefix
;
64 std::unique_ptr
<SvXMLNamespaceMap
> m_pNamespaceMap
;
65 SvXMLNamespaceMap m_vReplaceNamespaceMap
;
66 std::vector
<rtl::Reference
<XMLTransformerContext
>> m_vContexts
;
67 XMLTransformerActions m_ElemActions
;
68 XMLTransformerTokenMap
const m_TokenMap
;
71 css::uno::Reference
< css::frame::XModel
> mxModel
;
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
);
80 XMLTransformerBase( XMLTransformerActionInit
const *pInit
,
81 ::xmloff::token::XMLTokenEnum
const *pTKMapInit
) throw();
82 virtual ~XMLTransformerBase() throw() override
;
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
;
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
;
104 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
107 const css::uno::Reference
< css::xml::sax::XDocumentHandler
> & GetDocHandler() const { return m_xHandler
; }
109 const css::uno::Reference
< css::beans::XPropertySet
> & GetPropertySet() const { return m_xPropSet
; }
112 SvXMLNamespaceMap
& GetNamespaceMap() { return *m_pNamespaceMap
; }
113 const SvXMLNamespaceMap
& GetNamespaceMap() const { return *m_pNamespaceMap
; }
114 SvXMLNamespaceMap
& GetReplaceNamespaceMap() { return m_vReplaceNamespaceMap
; }
116 XMLTransformerActions
& GetElemActions() { return m_ElemActions
; }
117 virtual XMLTransformerActions
*GetUserDefinedActions( sal_uInt16 n
);
118 virtual XMLTransformerContext
*CreateUserDefinedContext(
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;
126 XMLMutableAttributeList
*ProcessAttrList( css::uno::Reference
< css::xml::sax::XAttributeList
>& rAttrList
,
127 sal_uInt16 nActionMap
, bool bClone
);
129 static bool ReplaceSingleInchWithIn( OUString
& rValue
);
130 static bool ReplaceSingleInWithInch( OUString
& rValue
);
131 static bool ReplaceInchWithIn( OUString
& rValue
);
132 static bool ReplaceInWithInch( OUString
& rValue
);
134 bool EncodeStyleName( OUString
& rName
) const;
135 static bool DecodeStyleName( OUString
& rName
);
136 static bool NegPercent( OUString
& rValue
);
138 void AddNamespacePrefix( OUString
& rName
,
139 sal_uInt16 nPrefix
) const;
140 bool RemoveNamespacePrefix( OUString
& rName
,
141 sal_uInt16 nPrefixOnly
=0xffffU
) const;
143 bool ConvertURIToOASIS( OUString
& rURI
,
144 bool bSupportPackage
) const;
145 bool ConvertURIToOOo( OUString
& rURI
,
146 bool bSupportPackage
) const;
148 /** renames the given rOutAttributeValue if one of the parameters contains a
149 matching token in its lower 16 bits. The value is converted to the
150 token that is given in the upper 16 bits of the matching parameter.
152 static bool RenameAttributeValue( OUString
& rOutAttributeValue
,
157 /** converts the '.' that separates fractions of seconds in a dateTime
158 string into a ',' that was used in the OOo format
161 A dateTime string that will be parsed and changed in case a match
163 @return <TRUE/> if the given string was changed
165 static bool ConvertRNGDateTimeToISO( OUString
& rDateTime
);
167 ::xmloff::token::XMLTokenEnum
GetToken( const OUString
& rStr
) const;
169 const XMLTransformerContext
*GetCurrentContext() const;
170 const XMLTransformerContext
*GetAncestorContext( sal_uInt32 i
) const;
173 void SetClass( const OUString
& r
) { m_aClass
= r
; }
174 const OUString
& GetClass() const { return m_aClass
; }
176 bool isWriter() const;
180 #endif // INCLUDED_XMLOFF_SOURCE_TRANSFORM_TRANSFORMERBASE_HXX
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */