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_SCRIPTNAMERESOLVERIMPL_HXX_
25 #define  _FRAMEWORK_SCRIPT_SCRIPTNAMERESOLVERIMPL_HXX_
26 
27 #include <cppuhelper/implbase1.hxx> // helper for XInterface, XTypeProvider etc.
28 
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/lang/IllegalArgumentException.hpp>
31 #include <com/sun/star/uno/RuntimeException.hpp>
32 #include <com/sun/star/script/CannotConvertException.hpp>
33 #include <com/sun/star/reflection/InvocationTargetException.hpp>
34 
35 #include <drafts/com/sun/star/script/framework/runtime/XScriptNameResolver.hpp>
36 #include <drafts/com/sun/star/script/framework/storage/XScriptInfoAccess.hpp>
37 #include <drafts/com/sun/star/script/framework/storage/XScriptInfo.hpp>
38 
39 namespace scripting_runtimemgr
40 {
41 // for simplification
42 #define css ::com::sun::star
43 #define dcsssf ::drafts::com::sun::star::script::framework
44 
45 class ScriptNameResolverImpl : public
46     ::cppu::WeakImplHelper1 < dcsssf::runtime::XScriptNameResolver >
47 {
48 public:
49     /**********************************************
50      ScriptNameResolverImpl Constructor
51      @param  the current context
52     */
53     ScriptNameResolverImpl(
54         const css::uno::Reference< css::uno::XComponentContext > & xContext );
55     ~ScriptNameResolverImpl();
56 
57     // XServiceInfo implementation
58     virtual ::rtl::OUString SAL_CALL getImplementationName()
59         throw( css::uno::RuntimeException );
60     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
61         throw( css::uno::RuntimeException );
62     virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
63         throw( css::uno::RuntimeException );
64 
65     /**********************************************
66      resolve method
67      @param  scriptURI this is the given ScriptURI
68      @param invocationCtx  the invocation context contains the
69       documentStorageID and document reference for use in script name
70       resolving. On full name resolution it sets the resolvedScriptStorageID to
71       the actual storage location of the fully resolved script. May or may not * be the
72       same as the documentStorageID.
73      @exception CannotResolveScriptNameException
74      @exception IllegalArgumentException
75      @exception NullPointerException
76      @return  the resolved XScriptURI
77     */
78     css::uno::Reference < dcsssf::storage::XScriptInfo > SAL_CALL resolve(
79         const ::rtl::OUString & scriptURI,
80         css::uno::Any& invocationCtx )
81         throw( css::script::CannotConvertException, css::lang::IllegalArgumentException,
82            css::uno::RuntimeException );
83 private:
84     css::uno::Reference < dcsssf::storage::XScriptInfo >
85     resolveURIFromStorageID( sal_Int32 sid, const rtl::OUString & docURI,
86         const ::rtl::OUString & nameToResolve )
87         SAL_THROW ( ( css::lang::IllegalArgumentException, css::uno::RuntimeException ) );
88     css::uno::Reference< dcsssf::storage::XScriptInfoAccess >
89     getStorageInstance( sal_Int32 sid, const rtl::OUString & permissionURI)
90         SAL_THROW ( ( css::uno::RuntimeException ) );
91     ::rtl::OUString
92     ScriptNameResolverImpl::getFilesysURL( const ::rtl::OUString & scriptURI )
93         throw( css::lang::IllegalArgumentException );
94 
95     /**********************************************
96      Reference< XComponentContext > m_xContext
97         to obtain other services if needed
98     */
99     css::uno::Reference< css::uno::XComponentContext > m_xContext;
100     css::uno::Reference< css::lang::XMultiComponentFactory > m_xMultiComFac;
101     ::osl::Mutex m_mutex;
102 
103 };
104 } // scripting_runtimemgr
105 
106 #endif //_FRAMEWORK_SCRIPT_SCRIPTNAMERESOLVERIMPL_HXX_
107