xref: /trunk/main/unoxml/source/dom/saxbuilder.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 DOM_SAXBUILDER_HXX
25 #define DOM_SAXBUILDER_HXX
26 
27 #include <stack>
28 #include <map>
29 
30 #include <sal/types.h>
31 #include <osl/mutex.hxx>
32 #include <cppuhelper/implbase3.hxx>
33 #include <com/sun/star/uno/Reference.h>
34 #include <com/sun/star/uno/Sequence.h>
35 
36 #include <com/sun/star/uno/XInterface.hpp>
37 #include <com/sun/star/uno/Exception.hpp>
38 #include <com/sun/star/xml/dom/XSAXDocumentBuilder.hpp>
39 #include <com/sun/star/xml/dom/SAXDocumentBuilderState.hpp>
40 #include <com/sun/star/xml/dom/XDocument.hpp>
41 #include <com/sun/star/xml/dom/XDocumentFragment.hpp>
42 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
43 #include <com/sun/star/xml/sax/XLocator.hpp>
44 #include <com/sun/star/xml/sax/XAttributeList.hpp>
45 #include <com/sun/star/lang/XServiceInfo.hpp>
46 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
47 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
48 
49 using ::rtl::OUString;
50 using namespace com::sun::star::uno;
51 using namespace com::sun::star::xml::dom;
52 using namespace com::sun::star::xml::sax;
53 
54 using com::sun::star::lang::XServiceInfo;
55 using com::sun::star::lang::XSingleServiceFactory;
56 using com::sun::star::lang::XMultiServiceFactory;
57 
58 namespace DOM
59 {
60 
61     typedef std::stack< Reference< XNode > > NodeStack;
62     typedef std::map< OUString, OUString > NSMap;
63     typedef std::map< OUString, OUString > AttrMap;
64     typedef std::stack< NSMap > NSStack;
65 
66     class  CSAXDocumentBuilder
67         : public ::cppu::WeakImplHelper3< XDocumentHandler, XSAXDocumentBuilder, XServiceInfo >
68     {
69 
70     private:
71         ::osl::Mutex m_Mutex;
72         const Reference< XMultiServiceFactory > m_aServiceManager;
73 
74         SAXDocumentBuilderState m_aState;
75         NodeStack m_aNodeStack;
76         NSStack m_aNSStack;
77 
78         OUString resolvePrefix(const OUString& aPrefix);
79 
80         Reference< XDocument > m_aDocument;
81         Reference< XDocumentFragment > m_aFragment;
82         Reference< XLocator > m_aLocator;
83 
84 
85     public:
86 
87         // call for factory
88         static Reference< XInterface > getInstance(const Reference < XMultiServiceFactory >& xFactory);
89 
90         // static helpers for service info and component management
91         static const char* aImplementationName;
92     static const char* aSupportedServiceNames[];
93         static OUString _getImplementationName();
94         static Sequence< OUString > _getSupportedServiceNames();
95         static Reference< XInterface > _getInstance(const Reference< XMultiServiceFactory >& rSMgr);
96 
97         CSAXDocumentBuilder(const Reference< XMultiServiceFactory >& mgr);
98 
99         // XServiceInfo
100         virtual OUString SAL_CALL getImplementationName();
101         virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName);
102         virtual Sequence< OUString > SAL_CALL getSupportedServiceNames ();
103 
104         // XDocumentHandler
105         virtual void SAL_CALL startDocument();
106         virtual void SAL_CALL endDocument();
107         virtual void SAL_CALL startElement( const OUString& aName,
108              const Reference< XAttributeList >& xAttribs );
109         virtual void SAL_CALL endElement( const OUString& aName );
110         virtual void SAL_CALL characters( const OUString& aChars );
111         virtual void SAL_CALL ignorableWhitespace( const OUString& aWhitespaces );
112         virtual void SAL_CALL processingInstruction( const OUString& aTarget,
113              const OUString& aData );
114         virtual void SAL_CALL setDocumentLocator( const Reference< XLocator >& xLocator );
115 
116 
117         // XSAXDocumentBuilder
118         virtual SAXDocumentBuilderState SAL_CALL getState();
119         virtual void SAL_CALL reset();
120         virtual Reference< XDocument > SAL_CALL getDocument();
121         virtual Reference< XDocumentFragment > SAL_CALL getDocumentFragment();
122         virtual void SAL_CALL startDocumentFragment(const Reference< XDocument >& ownerDoc);
123         virtual void SAL_CALL endDocumentFragment();
124 
125 
126     };
127 }
128 
129 #endif
130