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