xref: /aoo4110/main/unoxml/source/xpath/xpathapi.hxx (revision b1cdbd2c)
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 XPATH_XPATHAPI_HXX
25 #define XPATH_XPATHAPI_HXX
26 
27 #include <map>
28 #include <vector>
29 
30 #include <sal/types.h>
31 
32 #include <cppuhelper/implbase2.hxx>
33 
34 #include <com/sun/star/uno/Reference.h>
35 #include <com/sun/star/uno/Sequence.h>
36 
37 #include <com/sun/star/uno/XInterface.hpp>
38 #include <com/sun/star/uno/Exception.hpp>
39 #include <com/sun/star/xml/xpath/XXPathAPI.hpp>
40 #include <com/sun/star/xml/dom/XNode.hpp>
41 #include <com/sun/star/xml/dom/XNodeList.hpp>
42 #include <com/sun/star/xml/xpath/XXPathAPI.hpp>
43 #include <com/sun/star/xml/xpath/XXPathObject.hpp>
44 #include <com/sun/star/xml/xpath/XXPathExtension.hpp>
45 #include <com/sun/star/xml/xpath/Libxml2ExtensionHandle.hpp>
46 #include <com/sun/star/xml/xpath/XPathException.hpp>
47 #include <com/sun/star/lang/XServiceInfo.hpp>
48 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
49 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
50 
51 
52 using ::rtl::OUString;
53 using namespace com::sun::star::uno;
54 using namespace com::sun::star::xml::dom;
55 using namespace com::sun::star::xml::xpath;
56 
57 namespace XPath
58 {
59     typedef std::map<OUString, OUString> nsmap_t;
60     typedef std::vector< Reference<XXPathExtension> > extensions_t;
61 
62     typedef ::cppu::WeakImplHelper2
63         <   XXPathAPI
64         ,   ::com::sun::star::lang::XServiceInfo
65         > CXPathAPI_Base;
66 
67     class  CXPathAPI
68         : public CXPathAPI_Base
69     {
70 
71     private:
72         ::osl::Mutex m_Mutex;
73         nsmap_t m_nsmap;
74         const Reference< ::com::sun::star::lang::XMultiServiceFactory > m_aFactory;
75         extensions_t m_extensions;
76 
77     public:
78         // ctor
79         CXPathAPI(
80             const Reference< ::com::sun::star::lang::XMultiServiceFactory >&
81                 rSMgr);
82 
83         // call for factory
84         static Reference< XInterface > getInstance(
85             const Reference < ::com::sun::star::lang::XMultiServiceFactory >&
86                 xFactory);
87 
88         // static helpers for service info and component management
89         static const char* aImplementationName;
90 	    static const char* aSupportedServiceNames[];
91         static OUString _getImplementationName();
92         static Sequence< OUString > _getSupportedServiceNames();
93         static Reference< XInterface > _getInstance(
94             const Reference< ::com::sun::star::lang::XMultiServiceFactory >&
95                 rSMgr);
96 
97         // XServiceInfo
98         virtual OUString SAL_CALL getImplementationName()
99             throw (RuntimeException);
100         virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName)
101             throw (RuntimeException);
102         virtual Sequence< OUString > SAL_CALL getSupportedServiceNames ()
103             throw (RuntimeException);
104 
105 
106         // --- XXPathAPI ---
107 
108         virtual void SAL_CALL registerNS(const OUString& aPrefix, const OUString& aURI)
109             throw (RuntimeException);
110 
111         virtual void SAL_CALL unregisterNS(const OUString& aPrefix, const OUString& aURI)
112             throw (RuntimeException);
113 
114         /**
115         Use an XPath string to select a nodelist.
116         */
117         virtual Reference< XNodeList > SAL_CALL selectNodeList(const Reference< XNode >& contextNode, const OUString& str)
118             throw (RuntimeException, XPathException);
119 
120         /**
121         Use an XPath string to select a nodelist.
122         */
123         virtual Reference< XNodeList > SAL_CALL selectNodeListNS(const Reference< XNode >& contextNode, const OUString& str, const Reference< XNode >&  namespaceNode)
124             throw (RuntimeException, XPathException);
125 
126         /**
127         Use an XPath string to select a single node.
128         */
129         virtual Reference< XNode > SAL_CALL selectSingleNode(const Reference< XNode >& contextNode, const OUString& str)
130             throw (RuntimeException, XPathException);
131 
132         /**
133         Use an XPath string to select a single node.
134         */
135         virtual Reference< XNode > SAL_CALL selectSingleNodeNS(const Reference< XNode >& contextNode, const OUString& str, const Reference< XNode >&  namespaceNode)
136             throw (RuntimeException, XPathException);
137 
138         virtual Reference< XXPathObject > SAL_CALL eval(const Reference< XNode >& contextNode, const OUString& str)
139             throw (RuntimeException, XPathException);
140 
141         virtual Reference< XXPathObject > SAL_CALL evalNS(const Reference< XNode >& contextNode, const OUString& str, const Reference< XNode >&  namespaceNode)
142             throw (RuntimeException, XPathException);
143 
144         virtual void SAL_CALL registerExtension(const OUString& aName) throw (RuntimeException);
145         virtual void SAL_CALL registerExtensionInstance(const Reference< XXPathExtension>& aExtension) throw (RuntimeException);
146 
147     };
148 }
149 
150 #endif
151