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 #ifndef _FRAMEWORK_SCRIPT_PROVIDER_OPENDOCUMENTLIST_HXX_
24 #define _FRAMEWORK_SCRIPT_PROVIDER_OPENDOCUMENTLIST_HXX_
25 
26 #include <hash_map>
27 #include <map>
28 
29 #include <osl/mutex.hxx>
30 #include <rtl/ustring.hxx>
31 #include <cppuhelper/implbase1.hxx>
32 #include <com/sun/star/uno/RuntimeException.hpp>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 
35 #include <com/sun/star/lang/XEventListener.hpp>
36 
37 #include <com/sun/star/script/provider/XScriptProvider.hpp>
38 #include <com/sun/star/script/browse/XBrowseNode.hpp>
39 #include <com/sun/star/document/XScriptInvocationContext.hpp>
40 
41 #include <comphelper/stl_types.hxx>
42 
43 namespace func_provider
44 {
45 // for simplification
46 #define css ::com::sun::star
47 
48 //Typedefs
49 //=============================================================================
50 
51 
52 typedef ::std::map  <   css::uno::Reference< css::uno::XInterface >
53                     ,   css::uno::Reference< css::script::provider::XScriptProvider >
54                     ,   ::comphelper::OInterfaceCompare< css::uno::XInterface >
55                     >   ScriptComponent_map;
56 
57 typedef ::std::hash_map< ::rtl::OUString,
58     css::uno::Reference< css::script::provider::XScriptProvider >,
59     ::rtl::OUStringHash,
60             ::std::equal_to< ::rtl::OUString > > Msp_hash;
61 
62 class ActiveMSPList : public ::cppu::WeakImplHelper1< css::lang::XEventListener  >
63 {
64 
65 public:
66 
67     ActiveMSPList(  const css::uno::Reference<
68         css::uno::XComponentContext > & xContext  );
69     ~ActiveMSPList();
70 
71     css::uno::Reference< css::script::provider::XScriptProvider >
72         getMSPFromStringContext( const ::rtl::OUString& context )
73             SAL_THROW(( css::lang::IllegalArgumentException, css::uno::RuntimeException ));
74 
75     css::uno::Reference< css::script::provider::XScriptProvider >
76         getMSPFromAnyContext( const css::uno::Any& context )
77             SAL_THROW(( css::lang::IllegalArgumentException, css::uno::RuntimeException ));
78 
79     css::uno::Reference< css::script::provider::XScriptProvider >
80         getMSPFromInvocationContext( const css::uno::Reference< css::document::XScriptInvocationContext >& context )
81             SAL_THROW(( css::lang::IllegalArgumentException, css::uno::RuntimeException ));
82 
83     //XEventListener
84     //======================================================================
85 
86     virtual void SAL_CALL disposing( const css::lang::EventObject& Source )
87         throw ( css::uno::RuntimeException );
88 
89 private:
90     void addActiveMSP( const css::uno::Reference< css::uno::XInterface >& xComponent,
91                        const css::uno::Reference< css::script::provider::XScriptProvider >& msp );
92     css::uno::Reference< css::script::provider::XScriptProvider >
93         createNewMSP( const css::uno::Any& context );
94     css::uno::Reference< css::script::provider::XScriptProvider >
createNewMSP(const::rtl::OUString & context)95         createNewMSP( const ::rtl::OUString& context )
96     {
97         return createNewMSP( css::uno::makeAny( context ) );
98     }
99 
100     void createNonDocMSPs();
101     Msp_hash m_hMsps;
102     ScriptComponent_map m_mScriptComponents;
103     osl::Mutex m_mutex;
104     ::rtl::OUString userDirString;
105     ::rtl::OUString shareDirString;
106     ::rtl::OUString bundledDirString;
107     css::uno::Reference< css::uno::XComponentContext > m_xContext;
108 };
109 } // func_provider
110 #endif
111