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 _MATHMLIMPORT_HXX_
25 #define _MATHMLIMPORT_HXX_
26 
27 #include <xmloff/xmlimp.hxx>
28 #include <xmloff/xmlexp.hxx>
29 #include <xmloff/DocumentSettingsContext.hxx>
30 #include <xmloff/xmltoken.hxx>
31 
32 #include <node.hxx>
33 
34 class SfxMedium;
35 namespace com { namespace sun { namespace star {
36     namespace io {
37         class XInputStream;
38         class XOutputStream; }
39     namespace beans {
40         class XPropertySet; }
41 } } }
42 
43 ////////////////////////////////////////////////////////////
44 
45 class SmXMLImportWrapper
46 {
47     com::sun::star::uno::Reference<com::sun::star::frame::XModel> xModel;
48 
49 public:
50     SmXMLImportWrapper(com::sun::star::uno::Reference<com::sun::star::frame::XModel> &rRef)
51         : xModel(rRef) {}
52 
53     sal_uLong Import(SfxMedium &rMedium);
54 
55     sal_uLong ReadThroughComponent(
56         ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInputStream,
57         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xModelComponent,
58         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rFactory,
59         ::com::sun::star::uno::Reference<
60             ::com::sun::star::beans::XPropertySet > & rPropSet,
61         const sal_Char* pFilterName,
62         sal_Bool bEncrypted );
63 
64     sal_uLong ReadThroughComponent(
65          const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
66                 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xModelComponent,
67         const sal_Char* pStreamName,
68         const sal_Char* pCompatibilityStreamName,
69         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rFactory,
70         ::com::sun::star::uno::Reference<
71             ::com::sun::star::beans::XPropertySet > & rPropSet,
72         const sal_Char* pFilterName );
73 };
74 
75 ////////////////////////////////////////////////////////////
76 
77 class SmXMLImport : public SvXMLImport
78 {
79         SvXMLTokenMap *pPresLayoutElemTokenMap;
80         SvXMLTokenMap *pPresLayoutAttrTokenMap;
81         SvXMLTokenMap *pFencedAttrTokenMap;
82         SvXMLTokenMap *pOperatorAttrTokenMap;
83         SvXMLTokenMap *pAnnotationAttrTokenMap;
84         SvXMLTokenMap *pPresElemTokenMap;
85         SvXMLTokenMap *pPresScriptEmptyElemTokenMap;
86         SvXMLTokenMap *pPresTableElemTokenMap;
87         SvXMLTokenMap *pColorTokenMap;
88 
89         SmNodeStack aNodeStack;
90         sal_Bool bSuccess;
91         String aText;
92 
93 public:
94     // #110680#
95     SmXMLImport(
96         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
97         sal_uInt16 nImportFlags=IMPORT_ALL);
98     virtual ~SmXMLImport() throw ();
99 
100     // XServiceInfo (override parent method)
101     ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException );
102 
103     // XUnoTunnel
104     sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw(::com::sun::star::uno::RuntimeException);
105     static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId() throw();
106 
107     void SAL_CALL endDocument(void)
108         throw( ::com::sun::star::xml::sax::SAXException,
109         ::com::sun::star::uno::RuntimeException );
110 
111     SvXMLImportContext *CreateContext(sal_uInt16 nPrefix,
112         const rtl::OUString &rLocalName,
113         const com::sun::star::uno::Reference <
114         com::sun::star::xml::sax::XAttributeList> &xAttrList);
115     SvXMLImportContext *CreateMathContext(sal_uInt16 nPrefix,
116         const rtl::OUString &rLocalName,
117         const com::sun::star::uno::Reference <
118         com::sun::star::xml::sax::XAttributeList> &xAttrList);
119     SvXMLImportContext *CreateRowContext(sal_uInt16 nPrefix,
120         const rtl::OUString &rLocalName,
121         const com::sun::star::uno::Reference <
122         com::sun::star::xml::sax::XAttributeList> &xAttrList);
123     SvXMLImportContext *CreateFracContext(sal_uInt16 nPrefix,
124         const rtl::OUString &rLocalName,
125         const com::sun::star::uno::Reference <
126         com::sun::star::xml::sax::XAttributeList> &xAttrList);
127     SvXMLImportContext *CreateNumberContext(sal_uInt16 nPrefix,
128         const rtl::OUString &rLocalName,
129         const com::sun::star::uno::Reference <
130         com::sun::star::xml::sax::XAttributeList> &xAttrList);
131     SvXMLImportContext *CreateTextContext(sal_uInt16 nPrefix,
132         const rtl::OUString &rLocalName,
133         const com::sun::star::uno::Reference <
134         com::sun::star::xml::sax::XAttributeList> &xAttrList);
135     SvXMLImportContext *CreateAnnotationContext(sal_uInt16 nPrefix,
136         const rtl::OUString &rLocalName,
137         const com::sun::star::uno::Reference <
138         com::sun::star::xml::sax::XAttributeList> &xAttrList);
139     SvXMLImportContext *CreateStringContext(sal_uInt16 nPrefix,
140         const rtl::OUString &rLocalName,
141         const com::sun::star::uno::Reference <
142         com::sun::star::xml::sax::XAttributeList> &xAttrList);
143     SvXMLImportContext *CreateIdentifierContext(sal_uInt16 nPrefix,
144         const rtl::OUString &rLocalName,
145         const com::sun::star::uno::Reference <
146         com::sun::star::xml::sax::XAttributeList> &xAttrList);
147     SvXMLImportContext *CreateOperatorContext(sal_uInt16 nPrefix,
148         const rtl::OUString &rLocalName,
149         const com::sun::star::uno::Reference <
150         com::sun::star::xml::sax::XAttributeList> &xAttrList);
151     SvXMLImportContext *CreateSpaceContext(sal_uInt16 nPrefix,
152         const rtl::OUString &rLocalName,
153         const com::sun::star::uno::Reference <
154         com::sun::star::xml::sax::XAttributeList> &xAttrList);
155     SvXMLImportContext *CreateSqrtContext(sal_uInt16 nPrefix,
156         const rtl::OUString &rLocalName,
157         const com::sun::star::uno::Reference <
158         com::sun::star::xml::sax::XAttributeList> &xAttrList);
159     SvXMLImportContext *CreateRootContext(sal_uInt16 nPrefix,
160         const rtl::OUString &rLocalName,
161         const com::sun::star::uno::Reference <
162         com::sun::star::xml::sax::XAttributeList> &xAttrList);
163     SvXMLImportContext *CreateStyleContext(sal_uInt16 nPrefix,
164         const rtl::OUString &rLocalName,
165         const com::sun::star::uno::Reference <
166         com::sun::star::xml::sax::XAttributeList> &xAttrList);
167     SvXMLImportContext *CreatePaddedContext(sal_uInt16 nPrefix,
168         const rtl::OUString &rLocalName,
169         const com::sun::star::uno::Reference <
170         com::sun::star::xml::sax::XAttributeList> &xAttrList);
171     SvXMLImportContext *CreatePhantomContext(sal_uInt16 nPrefix,
172         const rtl::OUString &rLocalName,
173         const com::sun::star::uno::Reference <
174         com::sun::star::xml::sax::XAttributeList> &xAttrList);
175     SvXMLImportContext *CreateFencedContext(sal_uInt16 nPrefix,
176         const rtl::OUString &rLocalName,
177         const com::sun::star::uno::Reference <
178         com::sun::star::xml::sax::XAttributeList> &xAttrList);
179     SvXMLImportContext *CreateErrorContext(sal_uInt16 nPrefix,
180         const rtl::OUString &rLocalName,
181         const com::sun::star::uno::Reference <
182         com::sun::star::xml::sax::XAttributeList> &xAttrList);
183     SvXMLImportContext *CreateSubContext(sal_uInt16 nPrefix,
184         const rtl::OUString &rLocalName,
185         const com::sun::star::uno::Reference <
186         com::sun::star::xml::sax::XAttributeList> &xAttrList);
187     SvXMLImportContext *CreateSupContext(sal_uInt16 nPrefix,
188         const rtl::OUString &rLocalName,
189         const com::sun::star::uno::Reference <
190         com::sun::star::xml::sax::XAttributeList> &xAttrList);
191     SvXMLImportContext *CreateSubSupContext(sal_uInt16 nPrefix,
192         const rtl::OUString &rLocalName,
193         const com::sun::star::uno::Reference <
194         com::sun::star::xml::sax::XAttributeList> &xAttrList);
195     SvXMLImportContext *CreateUnderContext(sal_uInt16 nPrefix,
196         const rtl::OUString &rLocalName,
197         const com::sun::star::uno::Reference <
198         com::sun::star::xml::sax::XAttributeList> &xAttrList);
199     SvXMLImportContext *CreateOverContext(sal_uInt16 nPrefix,
200         const rtl::OUString &rLocalName,
201         const com::sun::star::uno::Reference <
202         com::sun::star::xml::sax::XAttributeList> &xAttrList);
203     SvXMLImportContext *CreateUnderOverContext(sal_uInt16 nPrefix,
204         const rtl::OUString &rLocalName,
205         const com::sun::star::uno::Reference <
206         com::sun::star::xml::sax::XAttributeList> &xAttrList);
207     SvXMLImportContext *CreateMultiScriptsContext(sal_uInt16 nPrefix,
208         const rtl::OUString &rLocalName,
209         const com::sun::star::uno::Reference <
210         com::sun::star::xml::sax::XAttributeList> &xAttrList);
211     SvXMLImportContext *CreateNoneContext(sal_uInt16 nPrefix,
212         const rtl::OUString &rLocalName,
213         const com::sun::star::uno::Reference <
214         com::sun::star::xml::sax::XAttributeList> &xAttrList);
215     SvXMLImportContext *CreatePrescriptsContext(sal_uInt16 nPrefix,
216         const rtl::OUString &rLocalName,
217         const com::sun::star::uno::Reference <
218         com::sun::star::xml::sax::XAttributeList> &xAttrList);
219     SvXMLImportContext *CreateTableContext(sal_uInt16 nPrefix,
220         const rtl::OUString &rLocalName,
221         const com::sun::star::uno::Reference <
222         com::sun::star::xml::sax::XAttributeList> &xAttrList);
223     SvXMLImportContext *CreateTableRowContext(sal_uInt16 nPrefix,
224         const rtl::OUString &rLocalName,
225         const com::sun::star::uno::Reference <
226         com::sun::star::xml::sax::XAttributeList> &xAttrList);
227     SvXMLImportContext *CreateTableCellContext(sal_uInt16 nPrefix,
228         const rtl::OUString &rLocalName,
229         const com::sun::star::uno::Reference <
230         com::sun::star::xml::sax::XAttributeList> &xAttrList);
231     SvXMLImportContext *CreateAlignGroupContext(sal_uInt16 nPrefix,
232         const rtl::OUString &rLocalName,
233         const com::sun::star::uno::Reference <
234         com::sun::star::xml::sax::XAttributeList> &xAttrList);
235     SvXMLImportContext *CreateActionContext(sal_uInt16 nPrefix,
236         const rtl::OUString &rLocalName,
237         const com::sun::star::uno::Reference <
238         com::sun::star::xml::sax::XAttributeList> &xAttrList);
239 
240     const SvXMLTokenMap &GetPresLayoutElemTokenMap();
241     const SvXMLTokenMap &GetPresLayoutAttrTokenMap();
242     const SvXMLTokenMap &GetFencedAttrTokenMap();
243     const SvXMLTokenMap &GetOperatorAttrTokenMap();
244     const SvXMLTokenMap &GetAnnotationAttrTokenMap();
245     const SvXMLTokenMap &GetPresElemTokenMap();
246     const SvXMLTokenMap &GetPresScriptEmptyElemTokenMap();
247     const SvXMLTokenMap &GetPresTableElemTokenMap();
248     const SvXMLTokenMap &GetColorTokenMap();
249 
250     SmNodeStack & GetNodeStack()    { return aNodeStack; }
251     SmNode *GetTree()               { return aNodeStack.Pop(); }
252     sal_Bool GetSuccess()           { return bSuccess; }
253     String &GetText()               { return aText; }
254 
255     virtual void SetViewSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aViewProps);
256     virtual void SetConfigurationSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aViewProps);
257 };
258 
259 ////////////////////////////////////////////////////////////
260 
261 enum SmXMLMathElemTokenMap
262 {
263     XML_TOK_MATH
264 };
265 
266 enum SmXMLPresLayoutElemTokenMap
267 {
268     XML_TOK_SEMANTICS,
269     XML_TOK_MSTYLE,
270     XML_TOK_MERROR,
271     XML_TOK_MPHANTOM,
272     XML_TOK_MROW,
273     XML_TOK_MFRAC,
274     XML_TOK_MSQRT,
275     XML_TOK_MROOT,
276     XML_TOK_MSUB,
277     XML_TOK_MSUP,
278     XML_TOK_MSUBSUP,
279     XML_TOK_MMULTISCRIPTS,
280     XML_TOK_MUNDER,
281     XML_TOK_MOVER,
282     XML_TOK_MUNDEROVER,
283     XML_TOK_MTABLE,
284     XML_TOK_MACTION,
285     XML_TOK_MFENCED,
286     XML_TOK_MPADDED
287 };
288 
289 enum SmXMLPresLayoutAttrTokenMap
290 {
291     XML_TOK_FONTWEIGHT,
292     XML_TOK_FONTSTYLE,
293     XML_TOK_FONTSIZE,
294     XML_TOK_FONTFAMILY,
295     XML_TOK_COLOR
296 };
297 
298 
299 enum SmXMLFencedAttrTokenMap
300 {
301     XML_TOK_OPEN,
302     XML_TOK_CLOSE
303 };
304 
305 
306 enum SmXMLPresTableElemTokenMap
307 {
308     XML_TOK_MTR,
309     XML_TOK_MTD
310 };
311 
312 enum SmXMLPresElemTokenMap
313 {
314     XML_TOK_ANNOTATION,
315     XML_TOK_MI,
316     XML_TOK_MN,
317     XML_TOK_MO,
318     XML_TOK_MTEXT,
319     XML_TOK_MSPACE,
320     XML_TOK_MS,
321     XML_TOK_MALIGNGROUP
322 };
323 
324 enum SmXMLPresScriptEmptyElemTokenMap
325 {
326     XML_TOK_MPRESCRIPTS,
327     XML_TOK_NONE
328 };
329 
330 enum SmXMLOperatorAttrTokenMap
331 {
332     XML_TOK_STRETCHY
333 };
334 
335 enum SmXMLAnnotationAttrTokenMap
336 {
337     XML_TOK_ENCODING
338 };
339 
340 ////////////////////////////////////////////////////////////
341 
342 #endif
343 
344