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