xref: /AOO41X/main/xmloff/source/transform/TransformerBase.hxx (revision ecfe53c5d1886e1e0d215b0d140d05282ab1c477)
1*ecfe53c5SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ecfe53c5SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ecfe53c5SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ecfe53c5SAndrew Rist  * distributed with this work for additional information
6*ecfe53c5SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ecfe53c5SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ecfe53c5SAndrew Rist  * "License"); you may not use this file except in compliance
9*ecfe53c5SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*ecfe53c5SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*ecfe53c5SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ecfe53c5SAndrew Rist  * software distributed under the License is distributed on an
15*ecfe53c5SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ecfe53c5SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ecfe53c5SAndrew Rist  * specific language governing permissions and limitations
18*ecfe53c5SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*ecfe53c5SAndrew Rist  *************************************************************/
21*ecfe53c5SAndrew Rist 
22*ecfe53c5SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _XMLOFF_TRANSFORMER_BASE_HXX
25cdf0e10cSrcweir #define _XMLOFF_TRANSFORMER_BASE_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/xml/sax/SAXParseException.hpp>
28cdf0e10cSrcweir #include <com/sun/star/xml/sax/SAXException.hpp>
29cdf0e10cSrcweir #include <com/sun/star/xml/sax/XAttributeList.hpp>
30cdf0e10cSrcweir #include <com/sun/star/xml/sax/XLocator.hpp>
31cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
32cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
33cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #ifndef _XMLOFF_TRANSFORMER_HXX_
36cdf0e10cSrcweir #include "Transformer.hxx"
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace rtl { class OUString; }
40cdf0e10cSrcweir namespace com { namespace sun { namespace star {
41cdf0e10cSrcweir 	namespace i18n { class XCharacterClassification; }
42cdf0e10cSrcweir }}}
43cdf0e10cSrcweir 
44cdf0e10cSrcweir class SvXMLNamespaceMap;
45cdf0e10cSrcweir class XMLTransformerContext;
46cdf0e10cSrcweir class XMLTransformerContextVector;
47cdf0e10cSrcweir class XMLTransformerActions;
48cdf0e10cSrcweir struct XMLTransformerActionInit;
49cdf0e10cSrcweir struct TransformerAction_Impl;
50cdf0e10cSrcweir class XMLMutableAttributeList;
51cdf0e10cSrcweir class XMLTransformerTokenMap;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir const sal_uInt16 INVALID_ACTIONS = 0xffff;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir class XMLTransformerBase : public XMLTransformer
56cdf0e10cSrcweir {
57cdf0e10cSrcweir 	friend class XMLTransformerContext;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >
60cdf0e10cSrcweir 		m_xLocator;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > 			m_xHandler;		// the handlers
63cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler > 	m_xExtHandler;
64cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xPropSet;
65cdf0e10cSrcweir 	::com::sun::star::uno::Reference<
66cdf0e10cSrcweir 		::com::sun::star::i18n::XCharacterClassification > xCharClass;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	::rtl::OUString m_aExtPathPrefix;
69cdf0e10cSrcweir 	::rtl::OUString m_aClass;
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	SvXMLNamespaceMap 			*m_pNamespaceMap;
72cdf0e10cSrcweir 	SvXMLNamespaceMap 			*m_pReplaceNamespaceMap;
73cdf0e10cSrcweir 	XMLTransformerContextVector *m_pContexts;
74cdf0e10cSrcweir 	XMLTransformerActions		*m_pElemActions;
75cdf0e10cSrcweir 	XMLTransformerTokenMap		*m_pTokenMap;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir protected:
78cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >		mxModel;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	// This method is called after the namespace map has been updated, but
81cdf0e10cSrcweir 	// before a context for the current element has been pushed.
82cdf0e10cSrcweir 	XMLTransformerContext *CreateContext( sal_uInt16 nPrefix,
83cdf0e10cSrcweir 									  const ::rtl::OUString& rLocalName,
84cdf0e10cSrcweir 									  const ::rtl::OUString& rQName );
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	// this method may return an empty reference when the transformer service
87cdf0e10cSrcweir 	// was created outside the xmloff environment.
88cdf0e10cSrcweir 	// It is strictly forbiden to use this as a write access to the model!
getModel() const89cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& getModel() const { return mxModel; }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir public:
92cdf0e10cSrcweir 	XMLTransformerBase( XMLTransformerActionInit *pInit=0,
93cdf0e10cSrcweir 		   				::xmloff::token::XMLTokenEnum *pTKMapInit=0 ) throw();
94cdf0e10cSrcweir 	virtual ~XMLTransformerBase() throw();
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	// ::com::sun::star::xml::sax::XDocumentHandler
97cdf0e10cSrcweir 	virtual void SAL_CALL startDocument(void)
98cdf0e10cSrcweir 		throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
99cdf0e10cSrcweir 	virtual void SAL_CALL endDocument(void)
100cdf0e10cSrcweir 		throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
101cdf0e10cSrcweir 	virtual void SAL_CALL startElement(const ::rtl::OUString& aName,
102cdf0e10cSrcweir 							  const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttribs)
103cdf0e10cSrcweir 		throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
104cdf0e10cSrcweir 	virtual void SAL_CALL endElement(const ::rtl::OUString& aName)
105cdf0e10cSrcweir 		throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
106cdf0e10cSrcweir 	virtual void SAL_CALL characters(const ::rtl::OUString& aChars)
107cdf0e10cSrcweir 		throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
108cdf0e10cSrcweir 	virtual void SAL_CALL ignorableWhitespace(const ::rtl::OUString& aWhitespaces)
109cdf0e10cSrcweir 		throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
110cdf0e10cSrcweir 	virtual void SAL_CALL processingInstruction(const ::rtl::OUString& aTarget,
111cdf0e10cSrcweir 									   const ::rtl::OUString& aData)
112cdf0e10cSrcweir 		throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
113cdf0e10cSrcweir 	virtual void SAL_CALL setDocumentLocator(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > & xLocator)
114cdf0e10cSrcweir 		throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	// ::com::sun::star::xml::sax::XExtendedDocumentHandler
117cdf0e10cSrcweir 	virtual void SAL_CALL startCDATA(void) throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
118cdf0e10cSrcweir 	virtual void SAL_CALL endCDATA(void) throw( ::com::sun::star::uno::RuntimeException );
119cdf0e10cSrcweir 	virtual void SAL_CALL comment(const ::rtl::OUString& sComment)
120cdf0e10cSrcweir 		throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
121cdf0e10cSrcweir 	virtual void SAL_CALL allowLineBreak(void)
122cdf0e10cSrcweir 		throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
123cdf0e10cSrcweir 	virtual void SAL_CALL unknown(const ::rtl::OUString& sString)
124cdf0e10cSrcweir 		throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	// XInitialization
127cdf0e10cSrcweir     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);
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	// C++
GetDocHandler()130cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > & GetDocHandler() { return m_xHandler; }
131cdf0e10cSrcweir 
GetPropertySet()132cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & GetPropertySet() { return m_xPropSet; }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 
GetNamespaceMap()135cdf0e10cSrcweir 	SvXMLNamespaceMap& GetNamespaceMap() { return *m_pNamespaceMap; }
GetNamespaceMap() const136cdf0e10cSrcweir 	const SvXMLNamespaceMap& GetNamespaceMap() const { return *m_pNamespaceMap; }
GetReplaceNamespaceMap()137cdf0e10cSrcweir 	SvXMLNamespaceMap& GetReplaceNamespaceMap() { return *m_pReplaceNamespaceMap; }
138cdf0e10cSrcweir 
GetElemActions()139cdf0e10cSrcweir 	XMLTransformerActions& GetElemActions() { return *m_pElemActions; }
140cdf0e10cSrcweir 	virtual XMLTransformerActions *GetUserDefinedActions( sal_uInt16 n );
141cdf0e10cSrcweir 	virtual XMLTransformerContext *CreateUserDefinedContext(
142cdf0e10cSrcweir 									  const TransformerAction_Impl& rAction,
143cdf0e10cSrcweir 									  const ::rtl::OUString& rQName,
144cdf0e10cSrcweir 		   							  sal_Bool bPersistent=sal_False ) = 0;
145cdf0e10cSrcweir 	virtual ::rtl::OUString GetEventName( const ::rtl::OUString& rName,
146cdf0e10cSrcweir 		   								  sal_Bool bForm = sal_False ) = 0;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	XMLMutableAttributeList *ProcessAttrList( ::com::sun::star::uno::Reference<
150cdf0e10cSrcweir 				::com::sun::star::xml::sax::XAttributeList >& rAttrList,
151cdf0e10cSrcweir 						 sal_uInt16 nActionMap, sal_Bool bClone );
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	static sal_Bool ReplaceSingleInchWithIn( ::rtl::OUString& rValue );
154cdf0e10cSrcweir 	static sal_Bool ReplaceSingleInWithInch( ::rtl::OUString& rValue );
155cdf0e10cSrcweir 	static sal_Bool ReplaceInchWithIn( ::rtl::OUString& rValue );
156cdf0e10cSrcweir 	static sal_Bool ReplaceInWithInch( ::rtl::OUString& rValue );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 	sal_Bool EncodeStyleName( ::rtl::OUString& rName ) const;
159cdf0e10cSrcweir 	static sal_Bool DecodeStyleName( ::rtl::OUString& rName );
160cdf0e10cSrcweir 	static sal_Bool NegPercent( ::rtl::OUString& rValue );
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 	sal_Bool AddNamespacePrefix( ::rtl::OUString& rName,
163cdf0e10cSrcweir 								 sal_uInt16 nPrefix ) const;
164cdf0e10cSrcweir 	sal_Bool RemoveNamespacePrefix( ::rtl::OUString& rName,
165cdf0e10cSrcweir 									sal_uInt16 nPrefixOnly=0xffffU ) const;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 	sal_Bool ConvertURIToOASIS( ::rtl::OUString& rURI,
168cdf0e10cSrcweir 								sal_Bool bSupportPackage=sal_False ) const;
169cdf0e10cSrcweir 	sal_Bool ConvertURIToOOo( ::rtl::OUString& rURI,
170cdf0e10cSrcweir 								sal_Bool bSupportPackage=sal_False ) const;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     /** renames the given rOutAttributeValue if one of the parameters contains a
173cdf0e10cSrcweir         matching token in its lower 16 bits.  The value is converted to the
174cdf0e10cSrcweir         token that is given in the upper 16 bits of the matching parameter.
175cdf0e10cSrcweir      */
176cdf0e10cSrcweir     sal_Bool RenameAttributeValue( ::rtl::OUString& rOutAttributeValue,
177cdf0e10cSrcweir                                    sal_Int32 nParam1,
178cdf0e10cSrcweir                                    sal_Int32 nParam2,
179cdf0e10cSrcweir                                    sal_Int32 nParam3 );
180cdf0e10cSrcweir 
181cdf0e10cSrcweir     /** converts the '.' that separates fractions of seconds in a dateTime
182cdf0e10cSrcweir         string into a ',' that was used in the OOo format
183cdf0e10cSrcweir 
184cdf0e10cSrcweir         @param rDateTime
185cdf0e10cSrcweir             A dateTime string that will be parsed and changed in case a match
186cdf0e10cSrcweir             was found.
187cdf0e10cSrcweir         @return <TRUE/> if the given string was changed
188cdf0e10cSrcweir      */
189cdf0e10cSrcweir     static bool ConvertRNGDateTimeToISO( ::rtl::OUString& rDateTime );
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     ::xmloff::token::XMLTokenEnum GetToken( const ::rtl::OUString& rStr ) const;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 	const XMLTransformerContext *GetCurrentContext() const;
194cdf0e10cSrcweir 	const XMLTransformerContext *GetAncestorContext( sal_uInt32 i ) const;
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 	// C++
SetClass(const::rtl::OUString & r)197cdf0e10cSrcweir 	inline void SetClass( const ::rtl::OUString& r ) { m_aClass = r; }
GetClass() const198cdf0e10cSrcweir 	inline const ::rtl::OUString& GetClass() const { return m_aClass; }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 	bool isWriter() const;
201cdf0e10cSrcweir 
202cdf0e10cSrcweir };
203cdf0e10cSrcweir 
204cdf0e10cSrcweir #endif	//  _XMLOFF_TRANSFORMER_BASE_HXX
205