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 _XMLOFF_TRANSFORMER_BASE_HXX
21 : #define _XMLOFF_TRANSFORMER_BASE_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 rtl { class OUString; }
34 : namespace com { namespace sun { namespace star {
35 : namespace i18n { class XCharacterClassification; }
36 : }}}
37 :
38 : class SvXMLNamespaceMap;
39 : class XMLTransformerContext;
40 : class XMLTransformerContextVector;
41 : class XMLTransformerActions;
42 : struct XMLTransformerActionInit;
43 : struct TransformerAction_Impl;
44 : class XMLMutableAttributeList;
45 : class XMLTransformerTokenMap;
46 :
47 : const sal_uInt16 INVALID_ACTIONS = 0xffff;
48 :
49 : class XMLTransformerBase : public XMLTransformer
50 : {
51 : friend class XMLTransformerContext;
52 :
53 : ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >
54 : m_xLocator;
55 :
56 : ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > m_xHandler; // the handlers
57 : ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler > m_xExtHandler;
58 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xPropSet;
59 : ::com::sun::star::uno::Reference<
60 : ::com::sun::star::i18n::XCharacterClassification > xCharClass;
61 :
62 : ::rtl::OUString m_aExtPathPrefix;
63 : ::rtl::OUString m_aClass;
64 :
65 : SvXMLNamespaceMap *m_pNamespaceMap;
66 : SvXMLNamespaceMap *m_pReplaceNamespaceMap;
67 : XMLTransformerContextVector *m_pContexts;
68 : XMLTransformerActions *m_pElemActions;
69 : XMLTransformerTokenMap *m_pTokenMap;
70 :
71 : protected:
72 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > mxModel;
73 :
74 : // This method is called after the namespace map has been updated, but
75 : // before a context for the current element has been pushed.
76 : XMLTransformerContext *CreateContext( sal_uInt16 nPrefix,
77 : const ::rtl::OUString& rLocalName,
78 : const ::rtl::OUString& rQName );
79 :
80 : // this method may return an empty reference when the transformer service
81 : // was created outside the xmloff environment.
82 : // It is strictly forbiden to use this as a write access to the model!
83 : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& getModel() const { return mxModel; }
84 :
85 : public:
86 : XMLTransformerBase( XMLTransformerActionInit *pInit=0,
87 : ::xmloff::token::XMLTokenEnum *pTKMapInit=0 ) throw();
88 : virtual ~XMLTransformerBase() throw();
89 :
90 : // ::com::sun::star::xml::sax::XDocumentHandler
91 : virtual void SAL_CALL startDocument(void)
92 : throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
93 : virtual void SAL_CALL endDocument(void)
94 : throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
95 : virtual void SAL_CALL startElement(const ::rtl::OUString& aName,
96 : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttribs)
97 : throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
98 : virtual void SAL_CALL endElement(const ::rtl::OUString& aName)
99 : throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
100 : virtual void SAL_CALL characters(const ::rtl::OUString& aChars)
101 : throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
102 : virtual void SAL_CALL ignorableWhitespace(const ::rtl::OUString& aWhitespaces)
103 : throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
104 : virtual void SAL_CALL processingInstruction(const ::rtl::OUString& aTarget,
105 : const ::rtl::OUString& aData)
106 : throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
107 : virtual void SAL_CALL setDocumentLocator(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > & xLocator)
108 : throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
109 :
110 : // ::com::sun::star::xml::sax::XExtendedDocumentHandler
111 : virtual void SAL_CALL startCDATA(void) throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
112 : virtual void SAL_CALL endCDATA(void) throw( ::com::sun::star::uno::RuntimeException );
113 : virtual void SAL_CALL comment(const ::rtl::OUString& sComment)
114 : throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
115 : virtual void SAL_CALL allowLineBreak(void)
116 : throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
117 : virtual void SAL_CALL unknown(const ::rtl::OUString& sString)
118 : throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
119 :
120 : // XInitialization
121 : 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);
122 :
123 : // C++
124 263 : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > & GetDocHandler() { return m_xHandler; }
125 :
126 0 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & GetPropertySet() { return m_xPropSet; }
127 :
128 :
129 84 : SvXMLNamespaceMap& GetNamespaceMap() { return *m_pNamespaceMap; }
130 4 : const SvXMLNamespaceMap& GetNamespaceMap() const { return *m_pNamespaceMap; }
131 45 : SvXMLNamespaceMap& GetReplaceNamespaceMap() { return *m_pReplaceNamespaceMap; }
132 :
133 186 : XMLTransformerActions& GetElemActions() { return *m_pElemActions; }
134 : virtual XMLTransformerActions *GetUserDefinedActions( sal_uInt16 n );
135 : virtual XMLTransformerContext *CreateUserDefinedContext(
136 : const TransformerAction_Impl& rAction,
137 : const ::rtl::OUString& rQName,
138 : sal_Bool bPersistent=sal_False ) = 0;
139 : virtual ::rtl::OUString GetEventName( const ::rtl::OUString& rName,
140 : sal_Bool bForm = sal_False ) = 0;
141 :
142 :
143 : XMLMutableAttributeList *ProcessAttrList( ::com::sun::star::uno::Reference<
144 : ::com::sun::star::xml::sax::XAttributeList >& rAttrList,
145 : sal_uInt16 nActionMap, sal_Bool bClone );
146 :
147 : static sal_Bool ReplaceSingleInchWithIn( ::rtl::OUString& rValue );
148 : static sal_Bool ReplaceSingleInWithInch( ::rtl::OUString& rValue );
149 : static sal_Bool ReplaceInchWithIn( ::rtl::OUString& rValue );
150 : static sal_Bool ReplaceInWithInch( ::rtl::OUString& rValue );
151 :
152 : sal_Bool EncodeStyleName( ::rtl::OUString& rName ) const;
153 : static sal_Bool DecodeStyleName( ::rtl::OUString& rName );
154 : static sal_Bool NegPercent( ::rtl::OUString& rValue );
155 :
156 : sal_Bool AddNamespacePrefix( ::rtl::OUString& rName,
157 : sal_uInt16 nPrefix ) const;
158 : sal_Bool RemoveNamespacePrefix( ::rtl::OUString& rName,
159 : sal_uInt16 nPrefixOnly=0xffffU ) const;
160 :
161 : sal_Bool ConvertURIToOASIS( ::rtl::OUString& rURI,
162 : sal_Bool bSupportPackage=sal_False ) const;
163 : sal_Bool ConvertURIToOOo( ::rtl::OUString& rURI,
164 : sal_Bool bSupportPackage=sal_False ) const;
165 :
166 : /** renames the given rOutAttributeValue if one of the parameters contains a
167 : matching token in its lower 16 bits. The value is converted to the
168 : token that is given in the upper 16 bits of the matching parameter.
169 : */
170 : sal_Bool RenameAttributeValue( ::rtl::OUString& rOutAttributeValue,
171 : sal_Int32 nParam1,
172 : sal_Int32 nParam2,
173 : sal_Int32 nParam3 );
174 :
175 : /** converts the '.' that separates fractions of seconds in a dateTime
176 : string into a ',' that was used in the OOo format
177 :
178 : @param rDateTime
179 : A dateTime string that will be parsed and changed in case a match
180 : was found.
181 : @return <TRUE/> if the given string was changed
182 : */
183 : static bool ConvertRNGDateTimeToISO( ::rtl::OUString& rDateTime );
184 :
185 : ::xmloff::token::XMLTokenEnum GetToken( const ::rtl::OUString& rStr ) const;
186 :
187 : const XMLTransformerContext *GetCurrentContext() const;
188 : const XMLTransformerContext *GetAncestorContext( sal_uInt32 i ) const;
189 :
190 : // C++
191 1 : inline void SetClass( const ::rtl::OUString& r ) { m_aClass = r; }
192 1 : inline const ::rtl::OUString& GetClass() const { return m_aClass; }
193 :
194 : bool isWriter() const;
195 :
196 : };
197 :
198 : #endif // _XMLOFF_TRANSFORMER_BASE_HXX
199 :
200 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|