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