1*6998d047SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*6998d047SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6998d047SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6998d047SAndrew Rist  * distributed with this work for additional information
6*6998d047SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6998d047SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6998d047SAndrew Rist  * "License"); you may not use this file except in compliance
9*6998d047SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*6998d047SAndrew Rist  *
11*6998d047SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*6998d047SAndrew Rist  *
13*6998d047SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6998d047SAndrew Rist  * software distributed under the License is distributed on an
15*6998d047SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6998d047SAndrew Rist  * KIND, either express or implied.  See the License for the
17*6998d047SAndrew Rist  * specific language governing permissions and limitations
18*6998d047SAndrew Rist  * under the License.
19*6998d047SAndrew Rist  *
20*6998d047SAndrew Rist  *************************************************************/
21*6998d047SAndrew Rist 
22*6998d047SAndrew Rist 
23cdf0e10cSrcweir #ifndef _FRAMEWORK_SCRIPT_PROVIDER_OPENDOCUMENTLIST_HXX_
24cdf0e10cSrcweir #define _FRAMEWORK_SCRIPT_PROVIDER_OPENDOCUMENTLIST_HXX_
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <hash_map>
27cdf0e10cSrcweir #include <map>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <osl/mutex.hxx>
30cdf0e10cSrcweir #include <rtl/ustring.hxx>
31cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
32cdf0e10cSrcweir #include <com/sun/star/uno/RuntimeException.hpp>
33cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <com/sun/star/script/provider/XScriptProvider.hpp>
38cdf0e10cSrcweir #include <com/sun/star/script/browse/XBrowseNode.hpp>
39cdf0e10cSrcweir #include <com/sun/star/document/XScriptInvocationContext.hpp>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir namespace func_provider
44cdf0e10cSrcweir {
45cdf0e10cSrcweir // for simplification
46cdf0e10cSrcweir #define css ::com::sun::star
47cdf0e10cSrcweir 
48cdf0e10cSrcweir //Typedefs
49cdf0e10cSrcweir //=============================================================================
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 
52cdf0e10cSrcweir typedef ::std::map  <   css::uno::Reference< css::uno::XInterface >
53cdf0e10cSrcweir                     ,   css::uno::Reference< css::script::provider::XScriptProvider >
54cdf0e10cSrcweir                     ,   ::comphelper::OInterfaceCompare< css::uno::XInterface >
55cdf0e10cSrcweir                     >   ScriptComponent_map;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir typedef ::std::hash_map< ::rtl::OUString,
58cdf0e10cSrcweir     css::uno::Reference< css::script::provider::XScriptProvider >,
59cdf0e10cSrcweir     ::rtl::OUStringHash,
60cdf0e10cSrcweir             ::std::equal_to< ::rtl::OUString > > Msp_hash;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir class ActiveMSPList : public ::cppu::WeakImplHelper1< css::lang::XEventListener  >
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 
65cdf0e10cSrcweir public:
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     ActiveMSPList(  const css::uno::Reference<
68cdf0e10cSrcweir         css::uno::XComponentContext > & xContext  );
69cdf0e10cSrcweir     ~ActiveMSPList();
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     css::uno::Reference< css::script::provider::XScriptProvider >
72cdf0e10cSrcweir         getMSPFromStringContext( const ::rtl::OUString& context )
73cdf0e10cSrcweir             SAL_THROW(( css::lang::IllegalArgumentException, css::uno::RuntimeException ));
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     css::uno::Reference< css::script::provider::XScriptProvider >
76cdf0e10cSrcweir         getMSPFromAnyContext( const css::uno::Any& context )
77cdf0e10cSrcweir             SAL_THROW(( css::lang::IllegalArgumentException, css::uno::RuntimeException ));
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     css::uno::Reference< css::script::provider::XScriptProvider >
80cdf0e10cSrcweir         getMSPFromInvocationContext( const css::uno::Reference< css::document::XScriptInvocationContext >& context )
81cdf0e10cSrcweir             SAL_THROW(( css::lang::IllegalArgumentException, css::uno::RuntimeException ));
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     //XEventListener
84cdf0e10cSrcweir     //======================================================================
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     virtual void SAL_CALL disposing( const css::lang::EventObject& Source )
87cdf0e10cSrcweir         throw ( css::uno::RuntimeException );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir private:
90cdf0e10cSrcweir     void addActiveMSP( const css::uno::Reference< css::uno::XInterface >& xComponent,
91cdf0e10cSrcweir                        const css::uno::Reference< css::script::provider::XScriptProvider >& msp );
92cdf0e10cSrcweir     css::uno::Reference< css::script::provider::XScriptProvider >
93cdf0e10cSrcweir         createNewMSP( const css::uno::Any& context );
94cdf0e10cSrcweir     css::uno::Reference< css::script::provider::XScriptProvider >
createNewMSP(const::rtl::OUString & context)95cdf0e10cSrcweir         createNewMSP( const ::rtl::OUString& context )
96cdf0e10cSrcweir     {
97cdf0e10cSrcweir         return createNewMSP( css::uno::makeAny( context ) );
98cdf0e10cSrcweir     }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     void createNonDocMSPs();
101cdf0e10cSrcweir     Msp_hash m_hMsps;
102cdf0e10cSrcweir     ScriptComponent_map m_mScriptComponents;
103cdf0e10cSrcweir     osl::Mutex m_mutex;
104cdf0e10cSrcweir     ::rtl::OUString userDirString;
105cdf0e10cSrcweir     ::rtl::OUString shareDirString;
106cdf0e10cSrcweir     ::rtl::OUString bundledDirString;
107cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > m_xContext;
108cdf0e10cSrcweir };
109cdf0e10cSrcweir } // func_provider
110cdf0e10cSrcweir #endif
111