xref: /trunk/main/unoxml/source/xpath/xpathapi.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 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         virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName);
100         virtual Sequence< OUString > SAL_CALL getSupportedServiceNames ();
101 
102 
103         // --- XXPathAPI ---
104 
105         virtual void SAL_CALL registerNS(const OUString& aPrefix, const OUString& aURI);
106 
107         virtual void SAL_CALL unregisterNS(const OUString& aPrefix, const OUString& aURI);
108 
109         /**
110         Use an XPath string to select a nodelist.
111         */
112         virtual Reference< XNodeList > SAL_CALL selectNodeList(const Reference< XNode >& contextNode, const OUString& str);
113 
114         /**
115         Use an XPath string to select a nodelist.
116         */
117         virtual Reference< XNodeList > SAL_CALL selectNodeListNS(const Reference< XNode >& contextNode, const OUString& str, const Reference< XNode >&  namespaceNode);
118 
119         /**
120         Use an XPath string to select a single node.
121         */
122         virtual Reference< XNode > SAL_CALL selectSingleNode(const Reference< XNode >& contextNode, const OUString& str);
123 
124         /**
125         Use an XPath string to select a single node.
126         */
127         virtual Reference< XNode > SAL_CALL selectSingleNodeNS(const Reference< XNode >& contextNode, const OUString& str, const Reference< XNode >&  namespaceNode);
128 
129         virtual Reference< XXPathObject > SAL_CALL eval(const Reference< XNode >& contextNode, const OUString& str);
130 
131         virtual Reference< XXPathObject > SAL_CALL evalNS(const Reference< XNode >& contextNode, const OUString& str, const Reference< XNode >&  namespaceNode);
132 
133         virtual void SAL_CALL registerExtension(const OUString& aName);
134         virtual void SAL_CALL registerExtensionInstance(const Reference< XXPathExtension>& aExtension);
135 
136     };
137 }
138 
139 #endif
140