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