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 _FRAMEWORK_SCRIPT_SCRIPTHANDLER_HXX
25 #define _FRAMEWORK_SCRIPT_SCRIPTHANDLER_HXX
26 
27 #include <com/sun/star/uno/RuntimeException.hpp>
28 #include <com/sun/star/frame/XDispatchProvider.hpp>
29 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
30 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <com/sun/star/lang/XInitialization.hpp>
32 #include <cppuhelper/implbase4.hxx>
33 #include <com/sun/star/script/provider/XScriptProvider.hpp>
34 
35 namespace rtl
36 {
37 class OUString;
38 }
39 
40 namespace com { namespace sun { namespace star {
41 
42     namespace document {
43         class XScriptInvocationContext;
44     }
45     namespace uno {
46         class Any;
47     }
48     namespace lang {
49         class XMultiServiceFactory;
50         class XSingleServiceFactory;
51     }
52     namespace frame {
53         class XFrame;
54         class XModel;
55         class XDispatch;
56         class XNotifyingDispatch;
57         class XDispatchResultListener;
58         struct DispatchDescriptor;
59     }
60     namespace beans {
61         struct PropertyValue;
62     }
63     namespace util {
64         struct URL;
65     }
66 } } }
67 
68 namespace scripting_protocolhandler
69 {
70 
71 namespace css = ::com::sun::star;
72 
73 class ScriptProtocolHandler :
74 public ::cppu::WeakImplHelper4< css::frame::XDispatchProvider,
75     css::frame::XNotifyingDispatch, css::lang::XServiceInfo, css::lang::XInitialization >
76 {
77 private:
78     bool m_bInitialised;
79     css::uno::Reference < css::lang::XMultiServiceFactory >         m_xFactory;
80     css::uno::Reference < css::frame::XFrame >                      m_xFrame;
81     css::uno::Reference < css::script::provider::XScriptProvider >  m_xScriptProvider;
82     css::uno::Reference< css::document::XScriptInvocationContext >  m_xScriptInvocation;
83 
84     void createScriptProvider();
85     bool getScriptInvocation();
86 
87 public:
88     ScriptProtocolHandler( const css::uno::Reference <
89         css::lang::XMultiServiceFactory >& xFactory );
90     virtual ~ScriptProtocolHandler();
91 
92     /* XServiceInfo */
93     virtual ::rtl::OUString SAL_CALL getImplementationName()
94         throw( css::uno::RuntimeException );
95     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& sServiceName )
96         throw( css::uno::RuntimeException );
97     virtual css::uno::Sequence < ::rtl::OUString > SAL_CALL getSupportedServiceNames()
98         throw( css::uno::RuntimeException );
99 
100     /* Helper for XServiceInfo */
101     static css::uno::Sequence < ::rtl::OUString > impl_getStaticSupportedServiceNames();
102     static ::rtl::OUString impl_getStaticImplementationName();
103 
104     /* Helper for registry */
105     static css::uno::Reference < css::uno::XInterface > SAL_CALL
106     impl_createInstance(
107         const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager )
108     throw( css::uno::RuntimeException );
109     static css::uno::Reference < css::lang::XSingleServiceFactory > impl_createFactory(
110         const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager );
111 
112     /* Implementation for XDispatchProvider */
113     virtual css::uno::Reference < css::frame::XDispatch > SAL_CALL
114     queryDispatch( const css::util::URL& aURL, const ::rtl::OUString& sTargetFrameName,
115                    sal_Int32 eSearchFlags ) throw( css::uno::RuntimeException ) ;
116     virtual css::uno::Sequence< css::uno::Reference < css::frame::XDispatch > > SAL_CALL
117     queryDispatches(
118         const css::uno::Sequence < css::frame::DispatchDescriptor >& seqDescriptor )
119     throw( css::uno::RuntimeException );
120 
121     /* Implementation for X(Notifying)Dispatch */
122     virtual void SAL_CALL dispatchWithNotification(
123     const css::util::URL& aURL,
124     const css::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArgs,
125     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& Listener )
126     throw ( css::uno::RuntimeException );
127     virtual void SAL_CALL dispatch(
128         const css::util::URL& aURL,
129         const css::uno::Sequence< css::beans::PropertyValue >& lArgs )
130         throw ( css::uno::RuntimeException );
131     virtual void SAL_CALL addStatusListener(
132         const css::uno::Reference< css::frame::XStatusListener >& xControl,
133         const css::util::URL& aURL )
134         throw ( css::uno::RuntimeException );
135     virtual void SAL_CALL removeStatusListener(
136         const css::uno::Reference< css::frame::XStatusListener >& xControl,
137         const css::util::URL& aURL )
138         throw ( css::uno::RuntimeException );
139 
140     /* Implementation for XInitialization */
141     virtual void SAL_CALL initialize(
142         const css::uno::Sequence < css::uno::Any >& aArguments )
143         throw ( css::uno::Exception );
144 };
145 
146 }
147 #endif
148