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