1*2c696243SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2c696243SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2c696243SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2c696243SAndrew Rist  * distributed with this work for additional information
6*2c696243SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2c696243SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2c696243SAndrew Rist  * "License"); you may not use this file except in compliance
9*2c696243SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2c696243SAndrew Rist  *
11*2c696243SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2c696243SAndrew Rist  *
13*2c696243SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2c696243SAndrew Rist  * software distributed under the License is distributed on an
15*2c696243SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2c696243SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2c696243SAndrew Rist  * specific language governing permissions and limitations
18*2c696243SAndrew Rist  * under the License.
19*2c696243SAndrew Rist  *
20*2c696243SAndrew Rist  *************************************************************/
21*2c696243SAndrew Rist 
22*2c696243SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_scripting.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <comphelper/documentinfo.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx>
30cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
31cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
32cdf0e10cSrcweir #include <tools/diagnose_ex.h>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
35cdf0e10cSrcweir #include <com/sun/star/lang/EventObject.hpp>
36cdf0e10cSrcweir #include <com/sun/star/container/XContentEnumerationAccess.hpp>
37cdf0e10cSrcweir #include <com/sun/star/document/XScriptInvocationContext.hpp>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <com/sun/star/uri/XUriReference.hpp>
40cdf0e10cSrcweir #include <com/sun/star/uri/XUriReferenceFactory.hpp>
41cdf0e10cSrcweir #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include <com/sun/star/deployment/XPackage.hpp>
44cdf0e10cSrcweir #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
45cdf0e10cSrcweir #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
46cdf0e10cSrcweir #include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include <util/scriptingconstants.hxx>
49cdf0e10cSrcweir #include <util/util.hxx>
50cdf0e10cSrcweir #include <util/MiscUtils.hxx>
51cdf0e10cSrcweir 
52cdf0e10cSrcweir #include "ActiveMSPList.hxx"
53cdf0e10cSrcweir #include "MasterScriptProvider.hxx"
54cdf0e10cSrcweir #include "URIHelper.hxx"
55cdf0e10cSrcweir 
56cdf0e10cSrcweir using namespace ::com::sun::star;
57cdf0e10cSrcweir using namespace ::com::sun::star::uno;
58cdf0e10cSrcweir using namespace ::com::sun::star::script;
59cdf0e10cSrcweir using namespace ::com::sun::star::document;
60cdf0e10cSrcweir using namespace ::sf_misc;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir namespace func_provider
63cdf0e10cSrcweir {
64cdf0e10cSrcweir //*************************************************************************
65cdf0e10cSrcweir //  Definitions for MasterScriptProviderFactory global methods.
66cdf0e10cSrcweir //*************************************************************************
67cdf0e10cSrcweir 
68cdf0e10cSrcweir ::rtl::OUString SAL_CALL mspf_getImplementationName() ;
69cdf0e10cSrcweir Reference< XInterface > SAL_CALL mspf_create( Reference< XComponentContext > const & xComponentContext );
70cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL mspf_getSupportedServiceNames();
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 
endsWith(const::rtl::OUString & target,const::rtl::OUString & item)73cdf0e10cSrcweir bool endsWith( const ::rtl::OUString& target,
74cdf0e10cSrcweir     const ::rtl::OUString& item )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     sal_Int32 index = 0;
77cdf0e10cSrcweir     if (  ( index = target.indexOf( item ) ) != -1  &&
78cdf0e10cSrcweir        ( index == ( target.getLength() - item.getLength() ) ) )
79cdf0e10cSrcweir     {
80cdf0e10cSrcweir         return true;
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir     return false;
83cdf0e10cSrcweir }
84cdf0e10cSrcweir //::rtl_StandardModuleCount s_moduleCount = MODULE_COUNT_INIT;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir /* should be available in some central location. */
87cdf0e10cSrcweir //*************************************************************************
88cdf0e10cSrcweir // XScriptProvider implementation
89cdf0e10cSrcweir //
90cdf0e10cSrcweir //*************************************************************************
MasterScriptProvider(const Reference<XComponentContext> & xContext)91cdf0e10cSrcweir MasterScriptProvider::MasterScriptProvider( const Reference< XComponentContext > & xContext ) throw ( RuntimeException ):
92cdf0e10cSrcweir         m_xContext( xContext ), m_bIsValid( false ), m_bInitialised( false ),
93cdf0e10cSrcweir         m_bIsPkgMSP( false ), m_pPCache( 0 )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir     ENSURE_OR_THROW( m_xContext.is(), "MasterScriptProvider::MasterScriptProvider: No context available\n" );
96cdf0e10cSrcweir     m_xMgr = m_xContext->getServiceManager();
97cdf0e10cSrcweir     ENSURE_OR_THROW( m_xMgr.is(), "MasterScriptProvider::MasterScriptProvider: No service manager available\n" );
98cdf0e10cSrcweir     m_bIsValid = true;
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
101cdf0e10cSrcweir //*************************************************************************
~MasterScriptProvider()102cdf0e10cSrcweir MasterScriptProvider::~MasterScriptProvider()
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     //s_moduleCount.modCnt.release( &s_moduleCount.modCnt );
105cdf0e10cSrcweir     if ( m_pPCache )
106cdf0e10cSrcweir     {
107cdf0e10cSrcweir         delete m_pPCache;
108cdf0e10cSrcweir     }
109cdf0e10cSrcweir     m_pPCache = 0;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir //*************************************************************************
initialize(const Sequence<Any> & args)113cdf0e10cSrcweir void SAL_CALL MasterScriptProvider::initialize( const Sequence < Any >& args )
114cdf0e10cSrcweir throw ( Exception, RuntimeException )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir     if ( m_bInitialised )
117cdf0e10cSrcweir         return;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     m_bIsValid = false;
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     sal_Int32 len = args.getLength();
122cdf0e10cSrcweir     if ( len > 1  )
123cdf0e10cSrcweir     {
124cdf0e10cSrcweir         throw RuntimeException(
125cdf0e10cSrcweir             OUSTR( "MasterScriptProvider::initialize: invalid number of arguments" ),
126cdf0e10cSrcweir             Reference< XInterface >() );
127cdf0e10cSrcweir     }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     Sequence< Any > invokeArgs( len );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     if ( len != 0 )
132cdf0e10cSrcweir     {
133cdf0e10cSrcweir         // check if first parameter is a string
134cdf0e10cSrcweir         // if it is, this implies that this is a MSP created
135cdf0e10cSrcweir         // with a user or share ctx ( used for browse functionality )
136cdf0e10cSrcweir         //
137cdf0e10cSrcweir         if ( args[ 0 ] >>= m_sCtxString )
138cdf0e10cSrcweir         {
139cdf0e10cSrcweir             invokeArgs[ 0  ] = args[ 0 ];
140cdf0e10cSrcweir             if ( m_sCtxString.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "vnd.sun.star.tdoc" ) ) == 0 )
141cdf0e10cSrcweir             {
142cdf0e10cSrcweir                 m_xModel =  MiscUtils::tDocUrlToModel( m_sCtxString );
143cdf0e10cSrcweir             }
144cdf0e10cSrcweir         }
145cdf0e10cSrcweir         else if ( args[ 0 ] >>= m_xInvocationContext )
146cdf0e10cSrcweir         {
147cdf0e10cSrcweir             m_xModel.set( m_xInvocationContext->getScriptContainer(), UNO_QUERY_THROW );
148cdf0e10cSrcweir         }
149cdf0e10cSrcweir         else
150cdf0e10cSrcweir         {
151cdf0e10cSrcweir             args[ 0 ] >>= m_xModel;
152cdf0e10cSrcweir         }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir         if ( m_xModel.is() )
155cdf0e10cSrcweir         {
156cdf0e10cSrcweir             // from the arguments, we were able to deduce a model. That alone doesn't
157cdf0e10cSrcweir             // suffice, we also need an XEmbeddedScripts which actually indicates support
158cdf0e10cSrcweir             // for embeddeding scripts
159cdf0e10cSrcweir             Reference< XEmbeddedScripts > xScripts( m_xModel, UNO_QUERY );
160cdf0e10cSrcweir             if ( !xScripts.is() )
161cdf0e10cSrcweir             {
162cdf0e10cSrcweir                 throw lang::IllegalArgumentException(
163cdf0e10cSrcweir                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
164cdf0e10cSrcweir                         "The given document does not support embedding scripts into it, and cannot be associated with such a document."
165cdf0e10cSrcweir                     ) ),
166cdf0e10cSrcweir                     *this,
167cdf0e10cSrcweir                     1
168cdf0e10cSrcweir                 );
169cdf0e10cSrcweir             }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir             try
172cdf0e10cSrcweir             {
173cdf0e10cSrcweir                 m_sCtxString =  MiscUtils::xModelToTdocUrl( m_xModel, m_xContext );
174cdf0e10cSrcweir             }
175cdf0e10cSrcweir             catch ( const Exception& )
176cdf0e10cSrcweir             {
177cdf0e10cSrcweir                 Any aError( ::cppu::getCaughtException() );
178cdf0e10cSrcweir 
179cdf0e10cSrcweir                 ::rtl::OUStringBuffer buf;
180cdf0e10cSrcweir                 buf.appendAscii( "MasterScriptProvider::initialize: caught " );
181cdf0e10cSrcweir                 buf.append     ( aError.getValueTypeName() );
182cdf0e10cSrcweir                 buf.appendAscii( ":" );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir                 Exception aException; aError >>= aException;
185cdf0e10cSrcweir                 buf.append     ( aException.Message );
186cdf0e10cSrcweir                 throw lang::WrappedTargetException( buf.makeStringAndClear(), *this, aError );
187cdf0e10cSrcweir             }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir             if ( m_xInvocationContext.is() && m_xInvocationContext != m_xModel )
190cdf0e10cSrcweir                 invokeArgs[ 0 ] <<= m_xInvocationContext;
191cdf0e10cSrcweir             else
192cdf0e10cSrcweir                 invokeArgs[ 0 ] <<= m_sCtxString;
193cdf0e10cSrcweir         }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir         ::rtl::OUString pkgSpec = OUSTR("uno_packages");
196cdf0e10cSrcweir         sal_Int32 indexOfPkgSpec = m_sCtxString.lastIndexOf( pkgSpec );
197cdf0e10cSrcweir 
198cdf0e10cSrcweir         // if contex string ends with "uno_packages"
199cdf0e10cSrcweir         if ( indexOfPkgSpec > -1 && ( m_sCtxString.match( pkgSpec, indexOfPkgSpec ) == sal_True ) )
200cdf0e10cSrcweir         {
201cdf0e10cSrcweir             m_bIsPkgMSP = sal_True;
202cdf0e10cSrcweir         }
203cdf0e10cSrcweir         else
204cdf0e10cSrcweir         {
205cdf0e10cSrcweir             m_bIsPkgMSP = sal_False;
206cdf0e10cSrcweir         }
207cdf0e10cSrcweir     }
208cdf0e10cSrcweir     else // no args
209cdf0e10cSrcweir     {
210cdf0e10cSrcweir         // use either scriping context or maybe zero args?
211cdf0e10cSrcweir         invokeArgs = Sequence< Any >( 0 ); // no arguments
212cdf0e10cSrcweir     }
213cdf0e10cSrcweir     m_sAargs = invokeArgs;
214cdf0e10cSrcweir     // don't create pkg mgr MSP for documents, not supported
215cdf0e10cSrcweir     if ( m_bIsPkgMSP == sal_False && !m_xModel.is() )
216cdf0e10cSrcweir     {
217cdf0e10cSrcweir         createPkgProvider();
218cdf0e10cSrcweir     }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir     m_bInitialised = true;
221cdf0e10cSrcweir     m_bIsValid = true;
222cdf0e10cSrcweir }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir 
225cdf0e10cSrcweir //*************************************************************************
createPkgProvider()226cdf0e10cSrcweir void MasterScriptProvider::createPkgProvider()
227cdf0e10cSrcweir {
228cdf0e10cSrcweir     try
229cdf0e10cSrcweir     {
230cdf0e10cSrcweir         ::rtl::OUString loc = m_sCtxString;
231cdf0e10cSrcweir         Any location;
232cdf0e10cSrcweir         ::rtl::OUString sPkgCtx =  m_sCtxString.concat( OUSTR(":uno_packages") );
233cdf0e10cSrcweir         location <<= sPkgCtx;
234cdf0e10cSrcweir 
235cdf0e10cSrcweir         Reference< provider::XScriptProviderFactory > xFac(
236cdf0e10cSrcweir             m_xContext->getValueByName(
237cdf0e10cSrcweir                 OUSTR( "/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory") ), UNO_QUERY_THROW );
238cdf0e10cSrcweir 
239cdf0e10cSrcweir         m_xMSPPkg.set(
240cdf0e10cSrcweir             xFac->createScriptProvider( location ), UNO_QUERY_THROW );
241cdf0e10cSrcweir 
242cdf0e10cSrcweir     }
243cdf0e10cSrcweir     catch ( Exception& e )
244cdf0e10cSrcweir     {
245cdf0e10cSrcweir         (void)e;
246cdf0e10cSrcweir         OSL_TRACE("Exception creating MasterScriptProvider for uno_packages in context %s: %s",
247cdf0e10cSrcweir                 ::rtl::OUStringToOString( m_sCtxString,
248cdf0e10cSrcweir                     RTL_TEXTENCODING_ASCII_US ).pData->buffer,
249cdf0e10cSrcweir                 ::rtl::OUStringToOString( e.Message,
250cdf0e10cSrcweir                     RTL_TEXTENCODING_ASCII_US ).pData->buffer );
251cdf0e10cSrcweir     }
252cdf0e10cSrcweir }
253cdf0e10cSrcweir 
254cdf0e10cSrcweir //*************************************************************************
255cdf0e10cSrcweir Reference< provider::XScript >
getScript(const::rtl::OUString & scriptURI)256cdf0e10cSrcweir MasterScriptProvider::getScript( const ::rtl::OUString& scriptURI )
257cdf0e10cSrcweir throw ( provider::ScriptFrameworkErrorException,
258cdf0e10cSrcweir         RuntimeException )
259cdf0e10cSrcweir {
260cdf0e10cSrcweir     if ( !isValid() )
261cdf0e10cSrcweir     {
262cdf0e10cSrcweir         throw provider::ScriptFrameworkErrorException(
263cdf0e10cSrcweir             OUSTR( "MasterScriptProvider not initialised" ), Reference< XInterface >(),
264cdf0e10cSrcweir             scriptURI, OUSTR(""),
265cdf0e10cSrcweir             provider::ScriptFrameworkErrorType::UNKNOWN );
266cdf0e10cSrcweir     }
267cdf0e10cSrcweir 
268cdf0e10cSrcweir     // need to get the language from the string
269cdf0e10cSrcweir 
270cdf0e10cSrcweir     Reference< uri::XUriReferenceFactory > xFac (
271cdf0e10cSrcweir          m_xMgr->createInstanceWithContext( rtl::OUString::createFromAscii(
272cdf0e10cSrcweir             "com.sun.star.uri.UriReferenceFactory"), m_xContext ) , UNO_QUERY );
273cdf0e10cSrcweir     if ( !xFac.is() )
274cdf0e10cSrcweir     {
275cdf0e10cSrcweir         ::rtl::OUString message = ::rtl::OUString::createFromAscii("Failed to instantiate  UriReferenceFactory");
276cdf0e10cSrcweir         throw provider::ScriptFrameworkErrorException(
277cdf0e10cSrcweir             message, Reference< XInterface >(),
278cdf0e10cSrcweir             scriptURI, ::rtl::OUString(),
279cdf0e10cSrcweir             provider::ScriptFrameworkErrorType::UNKNOWN );
280cdf0e10cSrcweir     }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir     Reference<  uri::XUriReference > uriRef(
283cdf0e10cSrcweir         xFac->parse( scriptURI ), UNO_QUERY );
284cdf0e10cSrcweir 
285cdf0e10cSrcweir     Reference < uri::XVndSunStarScriptUrl > sfUri( uriRef, UNO_QUERY );
286cdf0e10cSrcweir 
287cdf0e10cSrcweir     if ( !uriRef.is() || !sfUri.is() )
288cdf0e10cSrcweir     {
289cdf0e10cSrcweir         ::rtl::OUString errorMsg = OUSTR( "Incorrect format for Script URI: " );
290cdf0e10cSrcweir         errorMsg = errorMsg.concat( scriptURI );
291cdf0e10cSrcweir         throw provider::ScriptFrameworkErrorException(
292cdf0e10cSrcweir             errorMsg, Reference< XInterface >(),
293cdf0e10cSrcweir             scriptURI, OUSTR(""),
294cdf0e10cSrcweir             provider::ScriptFrameworkErrorType::UNKNOWN );
295cdf0e10cSrcweir     }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir     ::rtl::OUString langKey = ::rtl::OUString::createFromAscii( "language" );
298cdf0e10cSrcweir     ::rtl::OUString locKey = ::rtl::OUString::createFromAscii( "location" );
299cdf0e10cSrcweir 
300cdf0e10cSrcweir     if ( sfUri->hasParameter( langKey ) == sal_False ||
301cdf0e10cSrcweir          sfUri->hasParameter( locKey ) == sal_False ||
302cdf0e10cSrcweir          ( sfUri->getName().getLength() == 0  ) )
303cdf0e10cSrcweir     {
304cdf0e10cSrcweir         ::rtl::OUString errorMsg = OUSTR( "Incorrect format for Script URI: " );
305cdf0e10cSrcweir         errorMsg = errorMsg.concat( scriptURI );
306cdf0e10cSrcweir         throw provider::ScriptFrameworkErrorException(
307cdf0e10cSrcweir             errorMsg, Reference< XInterface >(),
308cdf0e10cSrcweir             scriptURI, OUSTR(""),
309cdf0e10cSrcweir             provider::ScriptFrameworkErrorType::UNKNOWN );
310cdf0e10cSrcweir     }
311cdf0e10cSrcweir 
312cdf0e10cSrcweir     ::rtl::OUString language = sfUri->getParameter( langKey );
313cdf0e10cSrcweir     ::rtl::OUString location = sfUri->getParameter( locKey );
314cdf0e10cSrcweir 
315cdf0e10cSrcweir     // if script us located in uno pkg
316cdf0e10cSrcweir     sal_Int32 index = -1;
317cdf0e10cSrcweir     ::rtl::OUString pkgTag =
318cdf0e10cSrcweir         ::rtl::OUString::createFromAscii( ":uno_packages" );
319cdf0e10cSrcweir     // for languages other than basic,  scripts located in uno packages
320cdf0e10cSrcweir     // are merged into the user/share location context.
321cdf0e10cSrcweir     // For other languages the location attribute in script url has the form
322cdf0e10cSrcweir     // location = [user|share]:uno_packages or location :uno_pacakges/xxxx.uno.pkg
323cdf0e10cSrcweir     // we need to extract the value of location part from the
324cdf0e10cSrcweir     // location attribute of the script, if the script is located in an
325cdf0e10cSrcweir     // uno package then that is the location part up to and including
326cdf0e10cSrcweir     // ":uno_packages", if the script is not in an uno package then the
327cdf0e10cSrcweir     // normal value is used e.g. user or share.
328cdf0e10cSrcweir     // The value extracted will be used to determine if the script is
329cdf0e10cSrcweir     // located in the same location context as this MSP.
330cdf0e10cSrcweir     // For Basic, the language script provider can handle the execution of a
331cdf0e10cSrcweir     // script in any location context
332cdf0e10cSrcweir     if ( ( index = location.indexOf( pkgTag ) ) > -1 )
333cdf0e10cSrcweir     {
334cdf0e10cSrcweir         location = location.copy( 0, index + pkgTag.getLength() );
335cdf0e10cSrcweir     }
336cdf0e10cSrcweir 
337cdf0e10cSrcweir     Reference< provider::XScript > xScript;
338cdf0e10cSrcweir 
339cdf0e10cSrcweir     // If the script location is in the same location context as this
340cdf0e10cSrcweir     // MSP then delate to the lanaguage provider controlled by this MSP
341cdf0e10cSrcweir     // ** Special case is BASIC, all calls to getScript will be handled
342cdf0e10cSrcweir     // by the language script provider in the current location context
343cdf0e10cSrcweir     // even if its different
344cdf0e10cSrcweir     if  (   (   location.equals( OUSTR( "document" ) )
345cdf0e10cSrcweir             &&  m_xModel.is()
346cdf0e10cSrcweir             )
347cdf0e10cSrcweir             ||  ( endsWith( m_sCtxString, location ) )
348cdf0e10cSrcweir             ||  ( language.equals( OUSTR( "Basic" ) ) )
349cdf0e10cSrcweir          )
350cdf0e10cSrcweir     {
351cdf0e10cSrcweir         Reference< provider::XScriptProvider > xScriptProvider;
352cdf0e10cSrcweir         ::rtl::OUStringBuffer buf( 80 );
353cdf0e10cSrcweir         buf.appendAscii( "com.sun.star.script.provider.ScriptProviderFor");
354cdf0e10cSrcweir         buf.append( language );
355cdf0e10cSrcweir         ::rtl::OUString serviceName = buf.makeStringAndClear();
356cdf0e10cSrcweir         if ( providerCache() )
357cdf0e10cSrcweir         {
358cdf0e10cSrcweir             try
359cdf0e10cSrcweir             {
360cdf0e10cSrcweir                 xScriptProvider.set(
361cdf0e10cSrcweir                     providerCache()->getProvider( serviceName ),
362cdf0e10cSrcweir                     UNO_QUERY_THROW );
363cdf0e10cSrcweir             }
364cdf0e10cSrcweir             catch( const Exception& e )
365cdf0e10cSrcweir             {
366cdf0e10cSrcweir                 throw provider::ScriptFrameworkErrorException(
367cdf0e10cSrcweir                     e.Message, Reference< XInterface >(),
368cdf0e10cSrcweir                     sfUri->getName(), language,
369cdf0e10cSrcweir                     provider::ScriptFrameworkErrorType::NOTSUPPORTED );
370cdf0e10cSrcweir             }
371cdf0e10cSrcweir         }
372cdf0e10cSrcweir         else
373cdf0e10cSrcweir         {
374cdf0e10cSrcweir             throw provider::ScriptFrameworkErrorException(
375cdf0e10cSrcweir                 OUSTR( "No LanguageProviders detected" ),
376cdf0e10cSrcweir                 Reference< XInterface >(),
377cdf0e10cSrcweir                 sfUri->getName(), language,
378cdf0e10cSrcweir                 provider::ScriptFrameworkErrorType::NOTSUPPORTED );
379cdf0e10cSrcweir         }
380cdf0e10cSrcweir         xScript=xScriptProvider->getScript( scriptURI );
381cdf0e10cSrcweir     }
382cdf0e10cSrcweir     else
383cdf0e10cSrcweir     {
384cdf0e10cSrcweir         Reference< provider::XScriptProviderFactory > xFac_(
385cdf0e10cSrcweir             m_xContext->getValueByName(
386cdf0e10cSrcweir                 OUSTR( "/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory") ), UNO_QUERY_THROW );
387cdf0e10cSrcweir 
388cdf0e10cSrcweir         Reference< provider::XScriptProvider > xSP(
389cdf0e10cSrcweir             xFac_->createScriptProvider( makeAny( location ) ), UNO_QUERY_THROW );
390cdf0e10cSrcweir         xScript = xSP->getScript( scriptURI );
391cdf0e10cSrcweir     }
392cdf0e10cSrcweir 
393cdf0e10cSrcweir     return xScript;
394cdf0e10cSrcweir }
395cdf0e10cSrcweir //*************************************************************************
396cdf0e10cSrcweir bool
isValid()397cdf0e10cSrcweir MasterScriptProvider::isValid()
398cdf0e10cSrcweir {
399cdf0e10cSrcweir     return m_bIsValid;
400cdf0e10cSrcweir }
401cdf0e10cSrcweir 
402cdf0e10cSrcweir //*************************************************************************
403cdf0e10cSrcweir ProviderCache*
providerCache()404cdf0e10cSrcweir MasterScriptProvider::providerCache()
405cdf0e10cSrcweir {
406cdf0e10cSrcweir     if ( !m_pPCache )
407cdf0e10cSrcweir     {
408cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_mutex );
409cdf0e10cSrcweir         if ( !m_pPCache )
410cdf0e10cSrcweir         {
411cdf0e10cSrcweir             ::rtl::OUString serviceName1 = OUSTR("com.sun.star.script.provider.ScriptProviderForBasic");
412cdf0e10cSrcweir             Sequence< ::rtl::OUString > blacklist(1);
413cdf0e10cSrcweir             blacklist[ 0 ] = serviceName1;
414cdf0e10cSrcweir 
415cdf0e10cSrcweir             if ( !m_bIsPkgMSP )
416cdf0e10cSrcweir             {
417cdf0e10cSrcweir                 m_pPCache = new ProviderCache( m_xContext, m_sAargs );
418cdf0e10cSrcweir             }
419cdf0e10cSrcweir             else
420cdf0e10cSrcweir             {
421cdf0e10cSrcweir                 m_pPCache = new ProviderCache( m_xContext, m_sAargs, blacklist );
422cdf0e10cSrcweir             }
423cdf0e10cSrcweir         }
424cdf0e10cSrcweir     }
425cdf0e10cSrcweir     return m_pPCache;
426cdf0e10cSrcweir }
427cdf0e10cSrcweir 
428cdf0e10cSrcweir 
429cdf0e10cSrcweir //*************************************************************************
430cdf0e10cSrcweir ::rtl::OUString SAL_CALL
getName()431cdf0e10cSrcweir MasterScriptProvider::getName()
432cdf0e10cSrcweir         throw ( css::uno::RuntimeException )
433cdf0e10cSrcweir {
434cdf0e10cSrcweir     if ( !isPkgProvider() )
435cdf0e10cSrcweir     {
436cdf0e10cSrcweir         ::rtl::OUString sCtx = getContextString();
437cdf0e10cSrcweir         if ( sCtx.indexOf( OUSTR( "vnd.sun.star.tdoc" ) ) == 0 )
438cdf0e10cSrcweir         {
439cdf0e10cSrcweir             Reference< frame::XModel > xModel = m_xModel;
440cdf0e10cSrcweir             if ( !xModel.is() )
441cdf0e10cSrcweir             {
442cdf0e10cSrcweir                 xModel = MiscUtils::tDocUrlToModel( sCtx );
443cdf0e10cSrcweir             }
444cdf0e10cSrcweir 
445cdf0e10cSrcweir             m_sNodeName = ::comphelper::DocumentInfo::getDocumentTitle( xModel );
446cdf0e10cSrcweir         }
447cdf0e10cSrcweir         else
448cdf0e10cSrcweir         {
449cdf0e10cSrcweir             m_sNodeName = parseLocationName( getContextString() );
450cdf0e10cSrcweir         }
451cdf0e10cSrcweir     }
452cdf0e10cSrcweir     else
453cdf0e10cSrcweir     {
454cdf0e10cSrcweir         m_sNodeName = OUSTR("uno_packages");
455cdf0e10cSrcweir     }
456cdf0e10cSrcweir     return m_sNodeName;
457cdf0e10cSrcweir }
458cdf0e10cSrcweir 
459cdf0e10cSrcweir //*************************************************************************
460cdf0e10cSrcweir Sequence< Reference< browse::XBrowseNode > > SAL_CALL
getChildNodes()461cdf0e10cSrcweir MasterScriptProvider::getChildNodes()
462cdf0e10cSrcweir         throw ( css::uno::RuntimeException )
463cdf0e10cSrcweir {
464cdf0e10cSrcweir     Sequence< Reference< provider::XScriptProvider > > providers = getAllProviders();
465cdf0e10cSrcweir 
466cdf0e10cSrcweir     Reference< provider::XScriptProvider > pkgProv = getPkgProvider();
467cdf0e10cSrcweir     sal_Int32 size = providers.getLength();
468cdf0e10cSrcweir     bool hasPkgs = pkgProv.is();
469cdf0e10cSrcweir     if ( hasPkgs  )
470cdf0e10cSrcweir     {
471cdf0e10cSrcweir         size++;
472cdf0e10cSrcweir     }
473cdf0e10cSrcweir     Sequence<  Reference< browse::XBrowseNode > > children( size );
474cdf0e10cSrcweir     sal_Int32 provIndex = 0;
475cdf0e10cSrcweir     for ( ; provIndex < providers.getLength(); provIndex++ )
476cdf0e10cSrcweir     {
477cdf0e10cSrcweir         children[ provIndex ] = Reference< browse::XBrowseNode >( providers[ provIndex ], UNO_QUERY );
478cdf0e10cSrcweir     }
479cdf0e10cSrcweir 
480cdf0e10cSrcweir     if ( hasPkgs  )
481cdf0e10cSrcweir     {
482cdf0e10cSrcweir         children[ provIndex ] = Reference< browse::XBrowseNode >( pkgProv, UNO_QUERY );
483cdf0e10cSrcweir 
484cdf0e10cSrcweir     }
485cdf0e10cSrcweir 
486cdf0e10cSrcweir     return children;
487cdf0e10cSrcweir }
488cdf0e10cSrcweir 
489cdf0e10cSrcweir //*************************************************************************
490cdf0e10cSrcweir sal_Bool SAL_CALL
hasChildNodes()491cdf0e10cSrcweir MasterScriptProvider::hasChildNodes()
492cdf0e10cSrcweir         throw ( css::uno::RuntimeException )
493cdf0e10cSrcweir {
494cdf0e10cSrcweir     return sal_True;
495cdf0e10cSrcweir }
496cdf0e10cSrcweir 
497cdf0e10cSrcweir //*************************************************************************
498cdf0e10cSrcweir sal_Int16 SAL_CALL
getType()499cdf0e10cSrcweir MasterScriptProvider::getType()
500cdf0e10cSrcweir         throw ( css::uno::RuntimeException )
501cdf0e10cSrcweir {
502cdf0e10cSrcweir     return browse::BrowseNodeTypes::CONTAINER;
503cdf0e10cSrcweir }
504cdf0e10cSrcweir 
505cdf0e10cSrcweir //*************************************************************************
506cdf0e10cSrcweir 
507cdf0e10cSrcweir ::rtl::OUString
parseLocationName(const::rtl::OUString & location)508cdf0e10cSrcweir MasterScriptProvider::parseLocationName( const ::rtl::OUString& location )
509cdf0e10cSrcweir {
510cdf0e10cSrcweir     // strip out the last leaf of location name
511cdf0e10cSrcweir     // e.g. file://dir1/dir2/Blah.sxw - > Blah.sxw
512cdf0e10cSrcweir     ::rtl::OUString temp = location;
513cdf0e10cSrcweir     INetURLObject aURLObj( temp );
514cdf0e10cSrcweir     if ( !aURLObj.HasError() )
515cdf0e10cSrcweir         temp = aURLObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
516cdf0e10cSrcweir     return temp;
517cdf0e10cSrcweir }
518cdf0e10cSrcweir 
519cdf0e10cSrcweir //*************************************************************************
520cdf0e10cSrcweir // Register Package
521cdf0e10cSrcweir void SAL_CALL
insertByName(const::rtl::OUString & aName,const Any & aElement)522cdf0e10cSrcweir MasterScriptProvider::insertByName( const ::rtl::OUString& aName, const Any& aElement ) throw ( lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, css::uno::RuntimeException)
523cdf0e10cSrcweir {
524cdf0e10cSrcweir     if ( !m_bIsPkgMSP )
525cdf0e10cSrcweir     {
526cdf0e10cSrcweir         if ( m_xMSPPkg.is() )
527cdf0e10cSrcweir         {
528cdf0e10cSrcweir             Reference< container::XNameContainer > xCont( m_xMSPPkg, UNO_QUERY );
529cdf0e10cSrcweir             if ( !xCont.is() )
530cdf0e10cSrcweir             {
531cdf0e10cSrcweir                 throw RuntimeException(
532cdf0e10cSrcweir                     OUSTR("PackageMasterScriptProvider doesn't implement XNameContainer"),
533cdf0e10cSrcweir                     Reference< XInterface >() );
534cdf0e10cSrcweir             }
535cdf0e10cSrcweir             xCont->insertByName( aName, aElement );
536cdf0e10cSrcweir         }
537cdf0e10cSrcweir         else
538cdf0e10cSrcweir         {
539cdf0e10cSrcweir             throw RuntimeException( OUSTR("PackageMasterScriptProvider is unitialised"),
540cdf0e10cSrcweir                                         Reference< XInterface >() );
541cdf0e10cSrcweir         }
542cdf0e10cSrcweir 
543cdf0e10cSrcweir     }
544cdf0e10cSrcweir     else
545cdf0e10cSrcweir     {
546cdf0e10cSrcweir         Reference< deployment::XPackage > xPkg( aElement, UNO_QUERY );
547cdf0e10cSrcweir         if ( !xPkg.is() )
548cdf0e10cSrcweir         {
549cdf0e10cSrcweir             throw lang::IllegalArgumentException( OUSTR("Couldn't convert to XPackage"),
550cdf0e10cSrcweir                                                       Reference < XInterface > (), 2 );
551cdf0e10cSrcweir         }
552cdf0e10cSrcweir         if ( !aName.getLength() )
553cdf0e10cSrcweir         {
554cdf0e10cSrcweir             throw lang::IllegalArgumentException( OUSTR("Name not set!!"),
555cdf0e10cSrcweir                                                       Reference < XInterface > (), 1 );
556cdf0e10cSrcweir         }
557cdf0e10cSrcweir         // TODO for library pacakge parse the language, for the moment will try
558cdf0e10cSrcweir         // to get each provider to process the new Package, the first one the succeeds
559cdf0e10cSrcweir         // will terminate processing
560cdf0e10cSrcweir         if ( !providerCache() )
561cdf0e10cSrcweir         {
562cdf0e10cSrcweir             throw RuntimeException(
563cdf0e10cSrcweir                 OUSTR("insertByName cannot instantiate "
564cdf0e10cSrcweir                     "child script providers."),
565cdf0e10cSrcweir                 Reference< XInterface >() );
566cdf0e10cSrcweir         }
567cdf0e10cSrcweir         Sequence < Reference< provider::XScriptProvider > > xSProviders =
568cdf0e10cSrcweir             providerCache()->getAllProviders();
569cdf0e10cSrcweir         sal_Int32 index = 0;
570cdf0e10cSrcweir 
571cdf0e10cSrcweir         for ( ; index < xSProviders.getLength(); index++ )
572cdf0e10cSrcweir         {
573cdf0e10cSrcweir             Reference< container::XNameContainer > xCont( xSProviders[ index ], UNO_QUERY );
574cdf0e10cSrcweir             if ( !xCont.is() )
575cdf0e10cSrcweir             {
576cdf0e10cSrcweir                 continue;
577cdf0e10cSrcweir             }
578cdf0e10cSrcweir             try
579cdf0e10cSrcweir             {
580cdf0e10cSrcweir                 xCont->insertByName( aName, aElement );
581cdf0e10cSrcweir                 break;
582cdf0e10cSrcweir             }
583cdf0e10cSrcweir             catch ( Exception& )
584cdf0e10cSrcweir             {
585cdf0e10cSrcweir             }
586cdf0e10cSrcweir 
587cdf0e10cSrcweir         }
588cdf0e10cSrcweir         if ( index == xSProviders.getLength() )
589cdf0e10cSrcweir         {
590cdf0e10cSrcweir             // No script providers could process the package
591cdf0e10cSrcweir             ::rtl::OUString message = OUSTR("Failed to register package for ");
592cdf0e10cSrcweir             message = message.concat( aName );
593cdf0e10cSrcweir             throw lang::IllegalArgumentException( message,
594cdf0e10cSrcweir                 Reference < XInterface > (), 2 );
595cdf0e10cSrcweir         }
596cdf0e10cSrcweir    }
597cdf0e10cSrcweir }
598cdf0e10cSrcweir 
599cdf0e10cSrcweir //*************************************************************************
600cdf0e10cSrcweir // Revoke Package
601cdf0e10cSrcweir void SAL_CALL
removeByName(const::rtl::OUString & Name)602cdf0e10cSrcweir MasterScriptProvider::removeByName( const ::rtl::OUString& Name ) throw ( container::NoSuchElementException, lang::WrappedTargetException, RuntimeException)
603cdf0e10cSrcweir {
604cdf0e10cSrcweir     if ( !m_bIsPkgMSP )
605cdf0e10cSrcweir     {
606cdf0e10cSrcweir         if ( m_xMSPPkg.is() )
607cdf0e10cSrcweir         {
608cdf0e10cSrcweir             Reference< container::XNameContainer > xCont( m_xMSPPkg, UNO_QUERY );
609cdf0e10cSrcweir             if ( !xCont.is() )
610cdf0e10cSrcweir             {
611cdf0e10cSrcweir                 throw RuntimeException(
612cdf0e10cSrcweir                     OUSTR("PackageMasterScriptProvider doesn't implement XNameContainer"),
613cdf0e10cSrcweir                     Reference< XInterface >() );
614cdf0e10cSrcweir             }
615cdf0e10cSrcweir             xCont->removeByName( Name );
616cdf0e10cSrcweir         }
617cdf0e10cSrcweir         else
618cdf0e10cSrcweir         {
619cdf0e10cSrcweir             throw RuntimeException( OUSTR("PackageMasterScriptProvider is unitialised"),
620cdf0e10cSrcweir                                         Reference< XInterface >() );
621cdf0e10cSrcweir         }
622cdf0e10cSrcweir 
623cdf0e10cSrcweir    }
624cdf0e10cSrcweir    else
625cdf0e10cSrcweir    {
626cdf0e10cSrcweir         if ( !Name.getLength() )
627cdf0e10cSrcweir         {
628cdf0e10cSrcweir             throw lang::IllegalArgumentException( OUSTR("Name not set!!"),
629cdf0e10cSrcweir                                                       Reference < XInterface > (), 1 );
630cdf0e10cSrcweir         }
631cdf0e10cSrcweir         // TODO for Script library pacakge url parse the language,
632cdf0e10cSrcweir         // for the moment will just try to get each provider to process remove/revoke
633cdf0e10cSrcweir         // request, the first one the succeeds will terminate processing
634cdf0e10cSrcweir 
635cdf0e10cSrcweir         if ( !providerCache() )
636cdf0e10cSrcweir         {
637cdf0e10cSrcweir             throw RuntimeException(
638cdf0e10cSrcweir                 OUSTR("removeByName() cannot instantiate "
639cdf0e10cSrcweir                     "child script providers."),
640cdf0e10cSrcweir                 Reference< XInterface >() );
641cdf0e10cSrcweir         }
642cdf0e10cSrcweir         Sequence < Reference< provider::XScriptProvider > > xSProviders =
643cdf0e10cSrcweir             providerCache()->getAllProviders();
644cdf0e10cSrcweir         sal_Int32 index = 0;
645cdf0e10cSrcweir         for ( ; index < xSProviders.getLength(); index++ )
646cdf0e10cSrcweir         {
647cdf0e10cSrcweir             Reference< container::XNameContainer > xCont( xSProviders[ index ], UNO_QUERY );
648cdf0e10cSrcweir             if ( !xCont.is() )
649cdf0e10cSrcweir             {
650cdf0e10cSrcweir                 continue;
651cdf0e10cSrcweir             }
652cdf0e10cSrcweir             try
653cdf0e10cSrcweir             {
654cdf0e10cSrcweir                 xCont->removeByName( Name );
655cdf0e10cSrcweir                 break;
656cdf0e10cSrcweir             }
657cdf0e10cSrcweir             catch ( Exception& )
658cdf0e10cSrcweir             {
659cdf0e10cSrcweir             }
660cdf0e10cSrcweir 
661cdf0e10cSrcweir         }
662cdf0e10cSrcweir         if ( index == xSProviders.getLength() )
663cdf0e10cSrcweir         {
664cdf0e10cSrcweir             // No script providers could process the package
665cdf0e10cSrcweir             ::rtl::OUString message = OUSTR("Failed to revoke package for ");
666cdf0e10cSrcweir             message = message.concat( Name );
667cdf0e10cSrcweir             throw lang::IllegalArgumentException( message,
668cdf0e10cSrcweir                                                       Reference < XInterface > (), 1 );
669cdf0e10cSrcweir         }
670cdf0e10cSrcweir 
671cdf0e10cSrcweir     }
672cdf0e10cSrcweir }
673cdf0e10cSrcweir 
674cdf0e10cSrcweir //*************************************************************************
675cdf0e10cSrcweir void SAL_CALL
replaceByName(const::rtl::OUString & aName,const Any & aElement)676cdf0e10cSrcweir MasterScriptProvider::replaceByName( const ::rtl::OUString& aName, const Any& aElement ) throw ( lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, RuntimeException)
677cdf0e10cSrcweir {
678cdf0e10cSrcweir 	(void)aName;
679cdf0e10cSrcweir 	(void)aElement;
680cdf0e10cSrcweir 
681cdf0e10cSrcweir     // TODO needs implementing
682cdf0e10cSrcweir     if ( true )
683cdf0e10cSrcweir     {
684cdf0e10cSrcweir         throw RuntimeException(  OUSTR("replaceByName not implemented!!!!") ,
685cdf0e10cSrcweir                 Reference< XInterface >() );
686cdf0e10cSrcweir     }
687cdf0e10cSrcweir }
688cdf0e10cSrcweir //*************************************************************************
689cdf0e10cSrcweir Any SAL_CALL
getByName(const::rtl::OUString & aName)690cdf0e10cSrcweir MasterScriptProvider::getByName( const ::rtl::OUString& aName ) throw ( container::NoSuchElementException, lang::WrappedTargetException, RuntimeException)
691cdf0e10cSrcweir {
692cdf0e10cSrcweir 	(void)aName;
693cdf0e10cSrcweir 
694cdf0e10cSrcweir     // TODO needs to be implemented
695cdf0e10cSrcweir     Any result;
696cdf0e10cSrcweir     if ( true )
697cdf0e10cSrcweir     {
698cdf0e10cSrcweir         throw RuntimeException(  OUSTR("getByName not implemented!!!!") ,
699cdf0e10cSrcweir                 Reference< XInterface >() );
700cdf0e10cSrcweir     }
701cdf0e10cSrcweir     return result;
702cdf0e10cSrcweir }
703cdf0e10cSrcweir //*************************************************************************
704cdf0e10cSrcweir sal_Bool SAL_CALL
hasByName(const::rtl::OUString & aName)705cdf0e10cSrcweir MasterScriptProvider::hasByName( const ::rtl::OUString& aName ) throw (RuntimeException)
706cdf0e10cSrcweir {
707cdf0e10cSrcweir     sal_Bool result = sal_False;
708cdf0e10cSrcweir     if ( !m_bIsPkgMSP )
709cdf0e10cSrcweir     {
710cdf0e10cSrcweir         if ( m_xMSPPkg.is() )
711cdf0e10cSrcweir         {
712cdf0e10cSrcweir             Reference< container::XNameContainer > xCont( m_xMSPPkg, UNO_QUERY );
713cdf0e10cSrcweir             if ( !xCont.is() )
714cdf0e10cSrcweir             {
715cdf0e10cSrcweir                 throw RuntimeException(
716cdf0e10cSrcweir                     OUSTR("PackageMasterScriptProvider doesn't implement XNameContainer"),
717cdf0e10cSrcweir                     Reference< XInterface >() );
718cdf0e10cSrcweir             }
719cdf0e10cSrcweir 
720cdf0e10cSrcweir             result = xCont->hasByName( aName );
721cdf0e10cSrcweir         }
722cdf0e10cSrcweir         else
723cdf0e10cSrcweir         {
724cdf0e10cSrcweir             throw RuntimeException( OUSTR("PackageMasterScriptProvider is unitialised"),
725cdf0e10cSrcweir                                         Reference< XInterface >() );
726cdf0e10cSrcweir         }
727cdf0e10cSrcweir 
728cdf0e10cSrcweir    }
729cdf0e10cSrcweir    else
730cdf0e10cSrcweir    {
731cdf0e10cSrcweir         if ( !aName.getLength() )
732cdf0e10cSrcweir         {
733cdf0e10cSrcweir             throw lang::IllegalArgumentException( OUSTR("Name not set!!"),
734cdf0e10cSrcweir                                                       Reference < XInterface > (), 1 );
735cdf0e10cSrcweir         }
736cdf0e10cSrcweir         // TODO for Script library pacakge url parse the language,
737cdf0e10cSrcweir         // for the moment will just try to get each provider to see if the
738cdf0e10cSrcweir         // package exists in any provider, first one that succeed will
739cdf0e10cSrcweir         // terminate the loop
740cdf0e10cSrcweir 
741cdf0e10cSrcweir         if ( !providerCache() )
742cdf0e10cSrcweir         {
743cdf0e10cSrcweir             throw RuntimeException(
744cdf0e10cSrcweir                 OUSTR("removeByName() cannot instantiate "
745cdf0e10cSrcweir                     "child script providers."),
746cdf0e10cSrcweir                 Reference< XInterface >() );
747cdf0e10cSrcweir         }
748cdf0e10cSrcweir         Sequence < Reference< provider::XScriptProvider > > xSProviders =
749cdf0e10cSrcweir             providerCache()->getAllProviders();
750cdf0e10cSrcweir         for ( sal_Int32 index = 0; index < xSProviders.getLength(); index++ )
751cdf0e10cSrcweir         {
752cdf0e10cSrcweir             Reference< container::XNameContainer > xCont( xSProviders[ index ], UNO_QUERY );
753cdf0e10cSrcweir             if ( !xCont.is() )
754cdf0e10cSrcweir             {
755cdf0e10cSrcweir                 continue;
756cdf0e10cSrcweir             }
757cdf0e10cSrcweir             try
758cdf0e10cSrcweir             {
759cdf0e10cSrcweir                 result = xCont->hasByName( aName );
760cdf0e10cSrcweir                 if ( result == sal_True )
761cdf0e10cSrcweir                 {
762cdf0e10cSrcweir                     break;
763cdf0e10cSrcweir                 }
764cdf0e10cSrcweir             }
765cdf0e10cSrcweir             catch ( Exception& )
766cdf0e10cSrcweir             {
767cdf0e10cSrcweir             }
768cdf0e10cSrcweir 
769cdf0e10cSrcweir         }
770cdf0e10cSrcweir     }
771cdf0e10cSrcweir     return result;
772cdf0e10cSrcweir }
773cdf0e10cSrcweir 
774cdf0e10cSrcweir //*************************************************************************
775cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL
getElementNames()776cdf0e10cSrcweir MasterScriptProvider::getElementNames(  ) throw ( RuntimeException)
777cdf0e10cSrcweir {
778cdf0e10cSrcweir     // TODO needs implementing
779cdf0e10cSrcweir     Sequence< ::rtl::OUString >  names;
780cdf0e10cSrcweir     if ( true )
781cdf0e10cSrcweir     {
782cdf0e10cSrcweir         throw RuntimeException(  OUSTR("getElementNames not implemented!!!!") ,
783cdf0e10cSrcweir                 Reference< XInterface >() );
784cdf0e10cSrcweir     }
785cdf0e10cSrcweir     return names;
786cdf0e10cSrcweir }
787cdf0e10cSrcweir //*************************************************************************
788cdf0e10cSrcweir Type SAL_CALL
getElementType()789cdf0e10cSrcweir MasterScriptProvider::getElementType(  ) throw ( RuntimeException)
790cdf0e10cSrcweir {
791cdf0e10cSrcweir     // TODO needs implementing
792cdf0e10cSrcweir     Type t;
793cdf0e10cSrcweir     return t;
794cdf0e10cSrcweir }
795cdf0e10cSrcweir //*************************************************************************
hasElements()796cdf0e10cSrcweir sal_Bool SAL_CALL MasterScriptProvider::hasElements(  ) throw ( RuntimeException)
797cdf0e10cSrcweir {
798cdf0e10cSrcweir     // TODO needs implementing
799cdf0e10cSrcweir     if ( true )
800cdf0e10cSrcweir     {
801cdf0e10cSrcweir         throw RuntimeException(  OUSTR("hasElements not implemented!!!!") ,
802cdf0e10cSrcweir                 Reference< XInterface >() );
803cdf0e10cSrcweir     }
804cdf0e10cSrcweir     return false;
805cdf0e10cSrcweir }
806cdf0e10cSrcweir 
807cdf0e10cSrcweir //*************************************************************************
808cdf0e10cSrcweir Sequence< Reference< provider::XScriptProvider > > SAL_CALL
getAllProviders()809cdf0e10cSrcweir MasterScriptProvider::getAllProviders() throw ( css::uno::RuntimeException )
810cdf0e10cSrcweir {
811cdf0e10cSrcweir     if ( providerCache() )
812cdf0e10cSrcweir     {
813cdf0e10cSrcweir         return providerCache()->getAllProviders();
814cdf0e10cSrcweir     }
815cdf0e10cSrcweir     else
816cdf0e10cSrcweir     {
817cdf0e10cSrcweir         ::rtl::OUString errorMsg = ::rtl::OUString::createFromAscii(
818cdf0e10cSrcweir             "MasterScriptProvider::getAllProviders, cache not initialised");
819cdf0e10cSrcweir         throw RuntimeException( errorMsg.concat( errorMsg ),
820cdf0e10cSrcweir             Reference< XInterface >() );
821cdf0e10cSrcweir     }
822cdf0e10cSrcweir }
823cdf0e10cSrcweir 
824cdf0e10cSrcweir 
825cdf0e10cSrcweir //*************************************************************************
getImplementationName()826cdf0e10cSrcweir ::rtl::OUString SAL_CALL MasterScriptProvider::getImplementationName( )
827cdf0e10cSrcweir throw( RuntimeException )
828cdf0e10cSrcweir {
829cdf0e10cSrcweir     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM (
830cdf0e10cSrcweir         "com.sun.star.script.provider.MasterScriptProvider" ) );
831cdf0e10cSrcweir }
832cdf0e10cSrcweir 
833cdf0e10cSrcweir //*************************************************************************
supportsService(const::rtl::OUString & serviceName)834cdf0e10cSrcweir sal_Bool SAL_CALL MasterScriptProvider::supportsService( const ::rtl::OUString& serviceName )
835cdf0e10cSrcweir throw( RuntimeException )
836cdf0e10cSrcweir {
837cdf0e10cSrcweir     Sequence< ::rtl::OUString > serviceNames( getSupportedServiceNames() );
838cdf0e10cSrcweir     ::rtl::OUString const * pNames = serviceNames.getConstArray();
839cdf0e10cSrcweir     for ( sal_Int32 nPos = serviceNames.getLength(); nPos--; )
840cdf0e10cSrcweir     {
841cdf0e10cSrcweir         if ( serviceName.equals( pNames[ nPos ] ) )
842cdf0e10cSrcweir         {
843cdf0e10cSrcweir             return sal_True;
844cdf0e10cSrcweir         }
845cdf0e10cSrcweir     }
846cdf0e10cSrcweir     return sal_False;
847cdf0e10cSrcweir }
848cdf0e10cSrcweir 
849cdf0e10cSrcweir //*************************************************************************
getSupportedServiceNames()850cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL MasterScriptProvider::getSupportedServiceNames( )
851cdf0e10cSrcweir throw( RuntimeException )
852cdf0e10cSrcweir {
853cdf0e10cSrcweir     ::rtl::OUString names[3];
854cdf0e10cSrcweir 
855cdf0e10cSrcweir     names[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM (
856cdf0e10cSrcweir         "com.sun.star.script.provider.MasterScriptProvider" ) );
857cdf0e10cSrcweir     names[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM (
858cdf0e10cSrcweir         "com.sun.star.script.browse.BrowseNode" ) );
859cdf0e10cSrcweir     names[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM (
860cdf0e10cSrcweir         "com.sun.star.script.provider.ScriptProvider" ) );
861cdf0e10cSrcweir 
862cdf0e10cSrcweir     return Sequence< ::rtl::OUString >( names, 3 );
863cdf0e10cSrcweir }
864cdf0e10cSrcweir 
865cdf0e10cSrcweir } // namespace func_provider
866cdf0e10cSrcweir 
867cdf0e10cSrcweir 
868cdf0e10cSrcweir namespace browsenodefactory
869cdf0e10cSrcweir {
870cdf0e10cSrcweir ::rtl::OUString SAL_CALL bnf_getImplementationName() ;
871cdf0e10cSrcweir Reference< XInterface > SAL_CALL bnf_create( Reference< XComponentContext > const & xComponentContext );
872cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL bnf_getSupportedServiceNames();
873cdf0e10cSrcweir }
874cdf0e10cSrcweir 
875cdf0e10cSrcweir namespace scripting_runtimemgr
876cdf0e10cSrcweir {
877cdf0e10cSrcweir //*************************************************************************
sp_create(const Reference<XComponentContext> & xCompC)878cdf0e10cSrcweir Reference< XInterface > SAL_CALL sp_create(
879cdf0e10cSrcweir     const Reference< XComponentContext > & xCompC )
880cdf0e10cSrcweir {
881cdf0e10cSrcweir     return ( cppu::OWeakObject * ) new ::func_provider::MasterScriptProvider( xCompC );
882cdf0e10cSrcweir }
883cdf0e10cSrcweir 
884cdf0e10cSrcweir //*************************************************************************
sp_getSupportedServiceNames()885cdf0e10cSrcweir Sequence< ::rtl::OUString > sp_getSupportedServiceNames( )
886cdf0e10cSrcweir     SAL_THROW( () )
887cdf0e10cSrcweir {
888cdf0e10cSrcweir     ::rtl::OUString names[3];
889cdf0e10cSrcweir 
890cdf0e10cSrcweir     names[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM (
891cdf0e10cSrcweir         "com.sun.star.script.provider.MasterScriptProvider" ) );
892cdf0e10cSrcweir     names[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM (
893cdf0e10cSrcweir         "com.sun.star.script.browse.BrowseNode" ) );
894cdf0e10cSrcweir     names[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM (
895cdf0e10cSrcweir         "com.sun.star.script.provider.ScriptProvider" ) );
896cdf0e10cSrcweir 
897cdf0e10cSrcweir     return Sequence< ::rtl::OUString >( names, 3 );
898cdf0e10cSrcweir }
899cdf0e10cSrcweir 
900cdf0e10cSrcweir //*************************************************************************
sp_getImplementationName()901cdf0e10cSrcweir ::rtl::OUString sp_getImplementationName( )
902cdf0e10cSrcweir SAL_THROW( () )
903cdf0e10cSrcweir {
904cdf0e10cSrcweir     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM (
905cdf0e10cSrcweir         "com.sun.star.script.provider.MasterScriptProvider" ) );
906cdf0e10cSrcweir }
907cdf0e10cSrcweir 
908cdf0e10cSrcweir // ***** registration or ScriptingFrameworkURIHelper
urihelper_create(const Reference<XComponentContext> & xCompC)909cdf0e10cSrcweir Reference< XInterface > SAL_CALL urihelper_create(
910cdf0e10cSrcweir     const Reference< XComponentContext > & xCompC )
911cdf0e10cSrcweir {
912cdf0e10cSrcweir     return ( cppu::OWeakObject * )
913cdf0e10cSrcweir         new ::func_provider::ScriptingFrameworkURIHelper( xCompC );
914cdf0e10cSrcweir }
915cdf0e10cSrcweir 
urihelper_getSupportedServiceNames()916cdf0e10cSrcweir Sequence< ::rtl::OUString > urihelper_getSupportedServiceNames( )
917cdf0e10cSrcweir     SAL_THROW( () )
918cdf0e10cSrcweir {
919cdf0e10cSrcweir     ::rtl::OUString serviceNameList[] = {
920cdf0e10cSrcweir         ::rtl::OUString::createFromAscii(
921cdf0e10cSrcweir             "com.sun.star.script.provider.ScriptURIHelper" ) };
922cdf0e10cSrcweir 
923cdf0e10cSrcweir     Sequence< ::rtl::OUString > serviceNames = Sequence <
924cdf0e10cSrcweir         ::rtl::OUString > ( serviceNameList, 1 );
925cdf0e10cSrcweir 
926cdf0e10cSrcweir     return serviceNames;
927cdf0e10cSrcweir }
928cdf0e10cSrcweir 
urihelper_getImplementationName()929cdf0e10cSrcweir ::rtl::OUString urihelper_getImplementationName( )
930cdf0e10cSrcweir     SAL_THROW( () )
931cdf0e10cSrcweir {
932cdf0e10cSrcweir     return ::rtl::OUString::createFromAscii(
933cdf0e10cSrcweir         "com.sun.star.script.provider.ScriptURIHelper");
934cdf0e10cSrcweir }
935cdf0e10cSrcweir 
936cdf0e10cSrcweir static struct cppu::ImplementationEntry s_entries [] =
937cdf0e10cSrcweir     {
938cdf0e10cSrcweir         {
939cdf0e10cSrcweir             sp_create, sp_getImplementationName,
940cdf0e10cSrcweir             sp_getSupportedServiceNames, cppu::createSingleComponentFactory,
941cdf0e10cSrcweir             0, 0
942cdf0e10cSrcweir         },
943cdf0e10cSrcweir         {
944cdf0e10cSrcweir             urihelper_create,
945cdf0e10cSrcweir             urihelper_getImplementationName,
946cdf0e10cSrcweir             urihelper_getSupportedServiceNames,
947cdf0e10cSrcweir             cppu::createSingleComponentFactory,
948cdf0e10cSrcweir             0, 0
949cdf0e10cSrcweir         },
950cdf0e10cSrcweir         {
951cdf0e10cSrcweir             func_provider::mspf_create, func_provider::mspf_getImplementationName,
952cdf0e10cSrcweir             func_provider::mspf_getSupportedServiceNames, cppu::createSingleComponentFactory,
953cdf0e10cSrcweir             0, 0
954cdf0e10cSrcweir         },
955cdf0e10cSrcweir         {
956cdf0e10cSrcweir             browsenodefactory::bnf_create, browsenodefactory::bnf_getImplementationName,
957cdf0e10cSrcweir             browsenodefactory::bnf_getSupportedServiceNames, cppu::createSingleComponentFactory,
958cdf0e10cSrcweir             0, 0
959cdf0e10cSrcweir         },
960cdf0e10cSrcweir         { 0, 0, 0, 0, 0, 0 }
961cdf0e10cSrcweir     };
962cdf0e10cSrcweir }
963cdf0e10cSrcweir 
964cdf0e10cSrcweir //############################################################################
965cdf0e10cSrcweir //#### EXPORTED ##############################################################
966cdf0e10cSrcweir //############################################################################
967cdf0e10cSrcweir 
968cdf0e10cSrcweir /**
969cdf0e10cSrcweir  * Gives the environment this component belongs to.
970cdf0e10cSrcweir  */
971cdf0e10cSrcweir extern "C"
972cdf0e10cSrcweir {
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment ** ppEnv)973cdf0e10cSrcweir     SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(
974cdf0e10cSrcweir             const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
975cdf0e10cSrcweir     {
976cdf0e10cSrcweir 		(void)ppEnv;
977cdf0e10cSrcweir         *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
978cdf0e10cSrcweir     }
979cdf0e10cSrcweir 
980cdf0e10cSrcweir     /**
981cdf0e10cSrcweir      * This function is called to get service factories for an implementation.
982cdf0e10cSrcweir      *
983cdf0e10cSrcweir      * @param pImplName       name of implementation
984cdf0e10cSrcweir      * @param pServiceManager a service manager, need for component creation
985cdf0e10cSrcweir      * @param pRegistryKey    the registry key for this component, need for persistent
986cdf0e10cSrcweir      *                        data
987cdf0e10cSrcweir      * @return a component factory
988cdf0e10cSrcweir      */
component_getFactory(const sal_Char * pImplName,lang::XMultiServiceFactory * pServiceManager,registry::XRegistryKey * pRegistryKey)989cdf0e10cSrcweir     SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
990cdf0e10cSrcweir         const sal_Char * pImplName,
991cdf0e10cSrcweir         lang::XMultiServiceFactory * pServiceManager,
992cdf0e10cSrcweir         registry::XRegistryKey * pRegistryKey )
993cdf0e10cSrcweir     {
994cdf0e10cSrcweir         return ::cppu::component_getFactoryHelper( pImplName, pServiceManager,
995cdf0e10cSrcweir             pRegistryKey, ::scripting_runtimemgr::s_entries );
996cdf0e10cSrcweir     }
997cdf0e10cSrcweir }
998