1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _FRAMEWORK_SCRIPT_PROVIDER_OPENDOCUMENTLIST_HXX_
28 #define _FRAMEWORK_SCRIPT_PROVIDER_OPENDOCUMENTLIST_HXX_
29 
30 #include <hash_map>
31 #include <map>
32 
33 #include <osl/mutex.hxx>
34 #include <rtl/ustring.hxx>
35 #include <cppuhelper/implbase1.hxx>
36 #include <com/sun/star/uno/RuntimeException.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 
39 #include <com/sun/star/lang/XEventListener.hpp>
40 
41 #include <com/sun/star/script/provider/XScriptProvider.hpp>
42 #include <com/sun/star/script/browse/XBrowseNode.hpp>
43 #include <com/sun/star/document/XScriptInvocationContext.hpp>
44 
45 #include <comphelper/stl_types.hxx>
46 
47 namespace func_provider
48 {
49 // for simplification
50 #define css ::com::sun::star
51 
52 //Typedefs
53 //=============================================================================
54 
55 
56 typedef ::std::map  <   css::uno::Reference< css::uno::XInterface >
57                     ,   css::uno::Reference< css::script::provider::XScriptProvider >
58                     ,   ::comphelper::OInterfaceCompare< css::uno::XInterface >
59                     >   ScriptComponent_map;
60 
61 typedef ::std::hash_map< ::rtl::OUString,
62     css::uno::Reference< css::script::provider::XScriptProvider >,
63     ::rtl::OUStringHash,
64             ::std::equal_to< ::rtl::OUString > > Msp_hash;
65 
66 class ActiveMSPList : public ::cppu::WeakImplHelper1< css::lang::XEventListener  >
67 {
68 
69 public:
70 
71     ActiveMSPList(  const css::uno::Reference<
72         css::uno::XComponentContext > & xContext  );
73     ~ActiveMSPList();
74 
75     css::uno::Reference< css::script::provider::XScriptProvider >
76         getMSPFromStringContext( const ::rtl::OUString& context )
77             SAL_THROW(( css::lang::IllegalArgumentException, css::uno::RuntimeException ));
78 
79     css::uno::Reference< css::script::provider::XScriptProvider >
80         getMSPFromAnyContext( const css::uno::Any& context )
81             SAL_THROW(( css::lang::IllegalArgumentException, css::uno::RuntimeException ));
82 
83     css::uno::Reference< css::script::provider::XScriptProvider >
84         getMSPFromInvocationContext( const css::uno::Reference< css::document::XScriptInvocationContext >& context )
85             SAL_THROW(( css::lang::IllegalArgumentException, css::uno::RuntimeException ));
86 
87     //XEventListener
88     //======================================================================
89 
90     virtual void SAL_CALL disposing( const css::lang::EventObject& Source )
91         throw ( css::uno::RuntimeException );
92 
93 private:
94     void addActiveMSP( const css::uno::Reference< css::uno::XInterface >& xComponent,
95                        const css::uno::Reference< css::script::provider::XScriptProvider >& msp );
96     css::uno::Reference< css::script::provider::XScriptProvider >
97         createNewMSP( const css::uno::Any& context );
98     css::uno::Reference< css::script::provider::XScriptProvider >
99         createNewMSP( const ::rtl::OUString& context )
100     {
101         return createNewMSP( css::uno::makeAny( context ) );
102     }
103 
104     void createNonDocMSPs();
105     Msp_hash m_hMsps;
106     ScriptComponent_map m_mScriptComponents;
107     osl::Mutex m_mutex;
108     ::rtl::OUString userDirString;
109     ::rtl::OUString shareDirString;
110     ::rtl::OUString bundledDirString;
111     css::uno::Reference< css::uno::XComponentContext > m_xContext;
112 };
113 } // func_provider
114 #endif
115