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