xref: /aoo42x/main/unoxml/source/xpath/xpathapi.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef XPATH_XPATHAPI_HXX
29 #define XPATH_XPATHAPI_HXX
30 
31 #include <map>
32 #include <vector>
33 
34 #include <sal/types.h>
35 
36 #include <cppuhelper/implbase2.hxx>
37 
38 #include <com/sun/star/uno/Reference.h>
39 #include <com/sun/star/uno/Sequence.h>
40 
41 #include <com/sun/star/uno/XInterface.hpp>
42 #include <com/sun/star/uno/Exception.hpp>
43 #include <com/sun/star/xml/xpath/XXPathAPI.hpp>
44 #include <com/sun/star/xml/dom/XNode.hpp>
45 #include <com/sun/star/xml/dom/XNodeList.hpp>
46 #include <com/sun/star/xml/xpath/XXPathAPI.hpp>
47 #include <com/sun/star/xml/xpath/XXPathObject.hpp>
48 #include <com/sun/star/xml/xpath/XXPathExtension.hpp>
49 #include <com/sun/star/xml/xpath/Libxml2ExtensionHandle.hpp>
50 #include <com/sun/star/xml/xpath/XPathException.hpp>
51 #include <com/sun/star/lang/XServiceInfo.hpp>
52 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
53 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
54 
55 
56 using ::rtl::OUString;
57 using namespace com::sun::star::uno;
58 using namespace com::sun::star::xml::dom;
59 using namespace com::sun::star::xml::xpath;
60 
61 namespace XPath
62 {
63     typedef std::map<OUString, OUString> nsmap_t;
64     typedef std::vector< Reference<XXPathExtension> > extensions_t;
65 
66     typedef ::cppu::WeakImplHelper2
67         <   XXPathAPI
68         ,   ::com::sun::star::lang::XServiceInfo
69         > CXPathAPI_Base;
70 
71     class  CXPathAPI
72         : public CXPathAPI_Base
73     {
74 
75     private:
76         ::osl::Mutex m_Mutex;
77         nsmap_t m_nsmap;
78         const Reference< ::com::sun::star::lang::XMultiServiceFactory > m_aFactory;
79         extensions_t m_extensions;
80 
81     public:
82         // ctor
83         CXPathAPI(
84             const Reference< ::com::sun::star::lang::XMultiServiceFactory >&
85                 rSMgr);
86 
87         // call for factory
88         static Reference< XInterface > getInstance(
89             const Reference < ::com::sun::star::lang::XMultiServiceFactory >&
90                 xFactory);
91 
92         // static helpers for service info and component management
93         static const char* aImplementationName;
94 	    static const char* aSupportedServiceNames[];
95         static OUString _getImplementationName();
96         static Sequence< OUString > _getSupportedServiceNames();
97         static Reference< XInterface > _getInstance(
98             const Reference< ::com::sun::star::lang::XMultiServiceFactory >&
99                 rSMgr);
100 
101         // XServiceInfo
102         virtual OUString SAL_CALL getImplementationName()
103             throw (RuntimeException);
104         virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName)
105             throw (RuntimeException);
106         virtual Sequence< OUString > SAL_CALL getSupportedServiceNames ()
107             throw (RuntimeException);
108 
109 
110         // --- XXPathAPI ---
111 
112         virtual void SAL_CALL registerNS(const OUString& aPrefix, const OUString& aURI)
113             throw (RuntimeException);
114 
115         virtual void SAL_CALL unregisterNS(const OUString& aPrefix, const OUString& aURI)
116             throw (RuntimeException);
117 
118         /**
119         Use an XPath string to select a nodelist.
120         */
121         virtual Reference< XNodeList > SAL_CALL selectNodeList(const Reference< XNode >& contextNode, const OUString& str)
122             throw (RuntimeException, XPathException);
123 
124         /**
125         Use an XPath string to select a nodelist.
126         */
127         virtual Reference< XNodeList > SAL_CALL selectNodeListNS(const Reference< XNode >& contextNode, const OUString& str, const Reference< XNode >&  namespaceNode)
128             throw (RuntimeException, XPathException);
129 
130         /**
131         Use an XPath string to select a single node.
132         */
133         virtual Reference< XNode > SAL_CALL selectSingleNode(const Reference< XNode >& contextNode, const OUString& str)
134             throw (RuntimeException, XPathException);
135 
136         /**
137         Use an XPath string to select a single node.
138         */
139         virtual Reference< XNode > SAL_CALL selectSingleNodeNS(const Reference< XNode >& contextNode, const OUString& str, const Reference< XNode >&  namespaceNode)
140             throw (RuntimeException, XPathException);
141 
142         virtual Reference< XXPathObject > SAL_CALL eval(const Reference< XNode >& contextNode, const OUString& str)
143             throw (RuntimeException, XPathException);
144 
145         virtual Reference< XXPathObject > SAL_CALL evalNS(const Reference< XNode >& contextNode, const OUString& str, const Reference< XNode >&  namespaceNode)
146             throw (RuntimeException, XPathException);
147 
148         virtual void SAL_CALL registerExtension(const OUString& aName) throw (RuntimeException);
149         virtual void SAL_CALL registerExtensionInstance(const Reference< XXPathExtension>& aExtension) throw (RuntimeException);
150 
151     };
152 }
153 
154 #endif
155