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 <com/sun/star/xml/sax/SAXParseException.hpp>
24 #include <com/sun/star/xml/sax/SAXException.hpp>
25 #include <com/sun/star/xml/sax/XAttributeList.hpp>
26 #include <com/sun/star/xml/sax/XLocator.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/frame/XModel.hpp>
29 #include <xmloff/xmltoken.hxx>
31 #include "Transformer.hxx"
33 namespace com
{ namespace sun
{ namespace star
{
34 namespace i18n
{ class XCharacterClassification
; }
37 class SvXMLNamespaceMap
;
38 class XMLTransformerContext
;
39 class XMLTransformerContextVector
;
40 class XMLTransformerActions
;
41 struct XMLTransformerActionInit
;
42 struct TransformerAction_Impl
;
43 class XMLMutableAttributeList
;
44 class XMLTransformerTokenMap
;
46 const sal_uInt16 INVALID_ACTIONS
= 0xffff;
48 class XMLTransformerBase
: public XMLTransformer
50 friend class XMLTransformerContext
;
52 ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XLocator
>
55 ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XDocumentHandler
> m_xHandler
; // the handlers
56 ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XExtendedDocumentHandler
> m_xExtHandler
;
57 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> m_xPropSet
;
58 ::com::sun::star::uno::Reference
<
59 ::com::sun::star::i18n::XCharacterClassification
> xCharClass
;
61 OUString m_aExtPathPrefix
;
64 SvXMLNamespaceMap
*m_pNamespaceMap
;
65 SvXMLNamespaceMap
*m_pReplaceNamespaceMap
;
66 XMLTransformerContextVector
*m_pContexts
;
67 XMLTransformerActions
*m_pElemActions
;
68 XMLTransformerTokenMap
*m_pTokenMap
;
71 ::com::sun::star::uno::Reference
< ::com::sun::star::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
);
79 // this method may return an empty reference when the transformer service
80 // was created outside the xmloff environment.
81 // It is strictly forbidden to use this as a write access to the model!
82 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& getModel() const { return mxModel
; }
85 XMLTransformerBase( XMLTransformerActionInit
*pInit
=0,
86 ::xmloff::token::XMLTokenEnum
*pTKMapInit
=0 ) throw();
87 virtual ~XMLTransformerBase() throw();
89 // ::com::sun::star::xml::sax::XDocumentHandler
90 virtual void SAL_CALL
startDocument()
91 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
92 virtual void SAL_CALL
endDocument()
93 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
94 virtual void SAL_CALL
startElement(const OUString
& aName
,
95 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
> & xAttribs
)
96 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
97 virtual void SAL_CALL
endElement(const OUString
& aName
)
98 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
99 virtual void SAL_CALL
characters(const OUString
& aChars
)
100 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
101 virtual void SAL_CALL
ignorableWhitespace(const OUString
& aWhitespaces
)
102 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
103 virtual void SAL_CALL
processingInstruction(const OUString
& aTarget
,
104 const OUString
& aData
)
105 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
106 virtual void SAL_CALL
setDocumentLocator(const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XLocator
> & xLocator
)
107 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
109 // ::com::sun::star::xml::sax::XExtendedDocumentHandler
110 virtual void SAL_CALL
startCDATA() throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
111 virtual void SAL_CALL
endCDATA() throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
112 virtual void SAL_CALL
comment(const OUString
& sComment
)
113 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
114 virtual void SAL_CALL
allowLineBreak()
115 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
116 virtual void SAL_CALL
unknown(const OUString
& sString
)
117 throw( ::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
120 virtual void SAL_CALL
initialize( const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& aArguments
) throw(::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
123 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XDocumentHandler
> & GetDocHandler() { return m_xHandler
; }
125 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> & GetPropertySet() { return m_xPropSet
; }
128 SvXMLNamespaceMap
& GetNamespaceMap() { return *m_pNamespaceMap
; }
129 const SvXMLNamespaceMap
& GetNamespaceMap() const { return *m_pNamespaceMap
; }
130 SvXMLNamespaceMap
& GetReplaceNamespaceMap() { return *m_pReplaceNamespaceMap
; }
132 XMLTransformerActions
& GetElemActions() { return *m_pElemActions
; }
133 virtual XMLTransformerActions
*GetUserDefinedActions( sal_uInt16 n
);
134 virtual XMLTransformerContext
*CreateUserDefinedContext(
135 const TransformerAction_Impl
& rAction
,
136 const OUString
& rQName
,
137 bool bPersistent
=false ) = 0;
138 virtual OUString
GetEventName( const OUString
& rName
,
139 bool bForm
= false ) = 0;
142 XMLMutableAttributeList
*ProcessAttrList( ::com::sun::star::uno::Reference
<
143 ::com::sun::star::xml::sax::XAttributeList
>& rAttrList
,
144 sal_uInt16 nActionMap
, bool bClone
);
146 static bool ReplaceSingleInchWithIn( OUString
& rValue
);
147 static bool ReplaceSingleInWithInch( OUString
& rValue
);
148 static bool ReplaceInchWithIn( OUString
& rValue
);
149 static bool ReplaceInWithInch( OUString
& rValue
);
151 bool EncodeStyleName( OUString
& rName
) const;
152 static bool DecodeStyleName( OUString
& rName
);
153 static bool NegPercent( OUString
& rValue
);
155 bool AddNamespacePrefix( OUString
& rName
,
156 sal_uInt16 nPrefix
) const;
157 bool RemoveNamespacePrefix( OUString
& rName
,
158 sal_uInt16 nPrefixOnly
=0xffffU
) const;
160 bool ConvertURIToOASIS( OUString
& rURI
,
161 bool bSupportPackage
=false ) const;
162 bool ConvertURIToOOo( OUString
& rURI
,
163 bool bSupportPackage
=false ) const;
165 /** renames the given rOutAttributeValue if one of the parameters contains a
166 matching token in its lower 16 bits. The value is converted to the
167 token that is given in the upper 16 bits of the matching parameter.
169 static bool RenameAttributeValue( OUString
& rOutAttributeValue
,
174 /** converts the '.' that separates fractions of seconds in a dateTime
175 string into a ',' that was used in the OOo format
178 A dateTime string that will be parsed and changed in case a match
180 @return <TRUE/> if the given string was changed
182 static bool ConvertRNGDateTimeToISO( OUString
& rDateTime
);
184 ::xmloff::token::XMLTokenEnum
GetToken( const OUString
& rStr
) const;
186 const XMLTransformerContext
*GetCurrentContext() const;
187 const XMLTransformerContext
*GetAncestorContext( sal_uInt32 i
) const;
190 inline void SetClass( const OUString
& r
) { m_aClass
= r
; }
191 inline const OUString
& GetClass() const { return m_aClass
; }
193 bool isWriter() const;
197 #endif // INCLUDED_XMLOFF_SOURCE_TRANSFORM_TRANSFORMERBASE_HXX
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */