Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_XMLOFF_SOURCE_TRANSFORM_TRANSFORMERBASE_HXX
21 : #define INCLUDED_XMLOFF_SOURCE_TRANSFORM_TRANSFORMERBASE_HXX
22 :
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>
30 :
31 : #include "Transformer.hxx"
32 :
33 : namespace com { namespace sun { namespace star {
34 : namespace i18n { class XCharacterClassification; }
35 : }}}
36 :
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;
45 :
46 : const sal_uInt16 INVALID_ACTIONS = 0xffff;
47 :
48 : class XMLTransformerBase : public XMLTransformer
49 : {
50 : friend class XMLTransformerContext;
51 :
52 : ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >
53 : m_xLocator;
54 :
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;
60 :
61 : OUString m_aExtPathPrefix;
62 : OUString m_aClass;
63 :
64 : SvXMLNamespaceMap *m_pNamespaceMap;
65 : SvXMLNamespaceMap *m_pReplaceNamespaceMap;
66 : XMLTransformerContextVector *m_pContexts;
67 : XMLTransformerActions *m_pElemActions;
68 : XMLTransformerTokenMap *m_pTokenMap;
69 :
70 : protected:
71 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > mxModel;
72 :
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 );
78 :
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; }
83 :
84 : public:
85 : XMLTransformerBase( XMLTransformerActionInit *pInit=0,
86 : ::xmloff::token::XMLTokenEnum *pTKMapInit=0 ) throw();
87 : virtual ~XMLTransformerBase() throw();
88 :
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;
108 :
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;
118 :
119 : // XInitialization
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;
121 :
122 : // C++
123 42200 : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > & GetDocHandler() { return m_xHandler; }
124 :
125 2 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & GetPropertySet() { return m_xPropSet; }
126 :
127 :
128 16404 : SvXMLNamespaceMap& GetNamespaceMap() { return *m_pNamespaceMap; }
129 87 : const SvXMLNamespaceMap& GetNamespaceMap() const { return *m_pNamespaceMap; }
130 2359 : SvXMLNamespaceMap& GetReplaceNamespaceMap() { return *m_pReplaceNamespaceMap; }
131 :
132 17788 : 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;
140 :
141 :
142 : XMLMutableAttributeList *ProcessAttrList( ::com::sun::star::uno::Reference<
143 : ::com::sun::star::xml::sax::XAttributeList >& rAttrList,
144 : sal_uInt16 nActionMap, bool bClone );
145 :
146 : static bool ReplaceSingleInchWithIn( OUString& rValue );
147 : static bool ReplaceSingleInWithInch( OUString& rValue );
148 : static bool ReplaceInchWithIn( OUString& rValue );
149 : static bool ReplaceInWithInch( OUString& rValue );
150 :
151 : bool EncodeStyleName( OUString& rName ) const;
152 : static bool DecodeStyleName( OUString& rName );
153 : static bool NegPercent( OUString& rValue );
154 :
155 : bool AddNamespacePrefix( OUString& rName,
156 : sal_uInt16 nPrefix ) const;
157 : bool RemoveNamespacePrefix( OUString& rName,
158 : sal_uInt16 nPrefixOnly=0xffffU ) const;
159 :
160 : bool ConvertURIToOASIS( OUString& rURI,
161 : bool bSupportPackage=false ) const;
162 : bool ConvertURIToOOo( OUString& rURI,
163 : bool bSupportPackage=false ) const;
164 :
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.
168 : */
169 : static bool RenameAttributeValue( OUString& rOutAttributeValue,
170 : sal_Int32 nParam1,
171 : sal_Int32 nParam2,
172 : sal_Int32 nParam3 );
173 :
174 : /** converts the '.' that separates fractions of seconds in a dateTime
175 : string into a ',' that was used in the OOo format
176 :
177 : @param rDateTime
178 : A dateTime string that will be parsed and changed in case a match
179 : was found.
180 : @return <TRUE/> if the given string was changed
181 : */
182 : static bool ConvertRNGDateTimeToISO( OUString& rDateTime );
183 :
184 : ::xmloff::token::XMLTokenEnum GetToken( const OUString& rStr ) const;
185 :
186 : const XMLTransformerContext *GetCurrentContext() const;
187 : const XMLTransformerContext *GetAncestorContext( sal_uInt32 i ) const;
188 :
189 : // C++
190 46 : inline void SetClass( const OUString& r ) { m_aClass = r; }
191 64 : inline const OUString& GetClass() const { return m_aClass; }
192 :
193 : bool isWriter() const;
194 :
195 : };
196 :
197 : #endif // INCLUDED_XMLOFF_SOURCE_TRANSFORM_TRANSFORMERBASE_HXX
198 :
199 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|