xref: /trunk/main/filter/source/xsltdialog/typedetectionimport.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 _TYPEDETECTION_IMPORT_HXX
25 #define _TYPEDETECTION_IMPORT_HXX
26 
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/io/XInputStream.hpp>
29 #include <cppuhelper/implbase1.hxx> // helper for implementations
30 #ifndef _COM_SUN_STAR_XML_SAX_XDUCUMENTHANDLER_HPP_
31 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
32 #endif
33 #include <comphelper/stl_types.hxx>
34 
35 #include "xmlfilterjar.hxx"
36 
37 #include <vector>
38 #include <stack>
39 
40 namespace com { namespace sun { namespace star {
41     namespace xml { namespace sax { class XAttributeList; } }
42     namespace beans { struct PropertyValue; }
43 } } }
44 
45 enum ImportState
46 {
47     e_Root,
48     e_Filters,
49     e_Types,
50     e_Filter,
51     e_Type,
52     e_Property,
53     e_Value,
54     e_Unknown
55 };
56 
57 DECLARE_STL_USTRINGACCESS_MAP( ::rtl::OUString, PropertyMap );
58 
59 struct Node
60 {
61     ::rtl::OUString maName;
62     PropertyMap maPropertyMap;
63 };
64 
65 typedef std::vector< Node* > NodeVector;
66 
67 class TypeDetectionImporter : public cppu::WeakImplHelper1 < com::sun::star::xml::sax::XDocumentHandler >
68 {
69 public:
70     TypeDetectionImporter( com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMSF );
71     virtual ~TypeDetectionImporter( void );
72 
73     static void doImport( com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMSF, com::sun::star::uno::Reference < com::sun::star::io::XInputStream > xOS, XMLFilterVector& rFilters );
74 
75     virtual void SAL_CALL startDocument(  );
76     virtual void SAL_CALL endDocument(  );
77     virtual void SAL_CALL startElement( const ::rtl::OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs );
78     virtual void SAL_CALL endElement( const ::rtl::OUString& aName );
79     virtual void SAL_CALL characters( const ::rtl::OUString& aChars );
80     virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces );
81     virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData );
82     virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator );
83 
84 private:
85     void fillFilterVector(  XMLFilterVector& rFilters );
86     filter_info_impl* createFilterForNode( Node * pNode );
87     Node* findTypeNode( const ::rtl::OUString& rType );
88 
89     com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > mxMSF;
90 
91     std::stack< ImportState > maStack;
92     PropertyMap maPropertyMap;
93 
94     NodeVector maFilterNodes;
95     NodeVector maTypeNodes;
96 
97     ::rtl::OUString maValue;
98     ::rtl::OUString maNodeName;
99     ::rtl::OUString maPropertyName;
100 
101     const ::rtl::OUString sRootNode;
102     const ::rtl::OUString sNode;
103     const ::rtl::OUString sName;
104     const ::rtl::OUString sProp;
105     const ::rtl::OUString sValue;
106     const ::rtl::OUString sUIName;
107     const ::rtl::OUString sData;
108     const ::rtl::OUString sFilters;
109     const ::rtl::OUString sTypes;
110     const ::rtl::OUString sFilterAdaptorService;
111     const ::rtl::OUString sXSLTFilterService;
112 
113     const ::rtl::OUString sCdataAttribute;
114     const ::rtl::OUString sWhiteSpace;
115 
116 };
117 #endif
118