1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_desktop.hxx"
30*cdf0e10cSrcweir #include "dp_sfwk.hrc"
31*cdf0e10cSrcweir #include "dp_backend.h"
32*cdf0e10cSrcweir #include "dp_ucb.h"
33*cdf0e10cSrcweir #include "dp_parceldesc.hxx"
34*cdf0e10cSrcweir #include "rtl/uri.hxx"
35*cdf0e10cSrcweir #include "ucbhelper/content.hxx"
36*cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx"
37*cdf0e10cSrcweir #include "comphelper/servicedecl.hxx"
38*cdf0e10cSrcweir #include "svl/inettype.hxx"
39*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
41*cdf0e10cSrcweir #include <memory>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir using namespace ::dp_misc;
45*cdf0e10cSrcweir using namespace ::com::sun::star;
46*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
47*cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
48*cdf0e10cSrcweir using namespace ::com::sun::star::script;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir using ::rtl::OUString;
51*cdf0e10cSrcweir namespace css = ::com::sun::star;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir namespace dp_registry
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir namespace backend
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir namespace sfwk
58*cdf0e10cSrcweir {
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir //==============================================================================
61*cdf0e10cSrcweir class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend
62*cdf0e10cSrcweir {
63*cdf0e10cSrcweir     class PackageImpl : public ::dp_registry::backend::Package
64*cdf0e10cSrcweir     {
65*cdf0e10cSrcweir         BackendImpl * getMyBackend() const;
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir         Reference< container::XNameContainer > m_xNameCntrPkgHandler;
68*cdf0e10cSrcweir         OUString m_descr;
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir         void initPackageHandler();
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir         // Package
73*cdf0e10cSrcweir         virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
74*cdf0e10cSrcweir             ::osl::ResettableMutexGuard & guard,
75*cdf0e10cSrcweir             ::rtl::Reference<AbortChannel> const & abortChannel,
76*cdf0e10cSrcweir             Reference<XCommandEnvironment> const & xCmdEnv );
77*cdf0e10cSrcweir         virtual void processPackage_(
78*cdf0e10cSrcweir             ::osl::ResettableMutexGuard & guard,
79*cdf0e10cSrcweir             bool registerPackage,
80*cdf0e10cSrcweir             bool startup,
81*cdf0e10cSrcweir             ::rtl::Reference<AbortChannel> const & abortChannel,
82*cdf0e10cSrcweir             Reference<XCommandEnvironment> const & xCmdEnv );
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir     public:
85*cdf0e10cSrcweir         PackageImpl(
86*cdf0e10cSrcweir             ::rtl::Reference<BackendImpl> const & myBackend,
87*cdf0e10cSrcweir             OUString const & url, OUString const & libType, bool bRemoved,
88*cdf0e10cSrcweir             OUString const & identifier);
89*cdf0e10cSrcweir         // XPackage
90*cdf0e10cSrcweir         virtual OUString SAL_CALL getDescription() throw (RuntimeException);
91*cdf0e10cSrcweir         virtual OUString SAL_CALL getLicenseText() throw (RuntimeException);
92*cdf0e10cSrcweir     };
93*cdf0e10cSrcweir     friend class PackageImpl;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir     // PackageRegistryBackend
96*cdf0e10cSrcweir     virtual Reference<deployment::XPackage> bindPackage_(
97*cdf0e10cSrcweir         OUString const & url, OUString const & mediaType,
98*cdf0e10cSrcweir         sal_Bool bRemoved, OUString const & identifier,
99*cdf0e10cSrcweir         Reference<XCommandEnvironment> const & xCmdEnv );
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir     const Reference<deployment::XPackageTypeInfo> m_xTypeInfo;
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir public:
105*cdf0e10cSrcweir     BackendImpl(
106*cdf0e10cSrcweir         Sequence<Any> const & args,
107*cdf0e10cSrcweir         Reference<XComponentContext> const & xComponentContext );
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir     // XPackageRegistry
110*cdf0e10cSrcweir     virtual Sequence< Reference<deployment::XPackageTypeInfo> > SAL_CALL
111*cdf0e10cSrcweir     getSupportedPackageTypes() throw (RuntimeException);
112*cdf0e10cSrcweir     virtual void SAL_CALL packageRemoved(OUString const & url, OUString const & mediaType)
113*cdf0e10cSrcweir         throw (deployment::DeploymentException,
114*cdf0e10cSrcweir                uno::RuntimeException);
115*cdf0e10cSrcweir };
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir BackendImpl * BackendImpl::PackageImpl::getMyBackend() const
118*cdf0e10cSrcweir {
119*cdf0e10cSrcweir     BackendImpl * pBackend = static_cast<BackendImpl *>(m_myBackend.get());
120*cdf0e10cSrcweir     if (NULL == pBackend)
121*cdf0e10cSrcweir     {
122*cdf0e10cSrcweir         //May throw a DisposedException
123*cdf0e10cSrcweir         check();
124*cdf0e10cSrcweir         //We should never get here...
125*cdf0e10cSrcweir         throw RuntimeException(
126*cdf0e10cSrcweir             OUSTR("Failed to get the BackendImpl"),
127*cdf0e10cSrcweir             static_cast<OWeakObject*>(const_cast<PackageImpl *>(this)));
128*cdf0e10cSrcweir     }
129*cdf0e10cSrcweir     return pBackend;
130*cdf0e10cSrcweir }
131*cdf0e10cSrcweir //______________________________________________________________________________
132*cdf0e10cSrcweir OUString BackendImpl::PackageImpl::getDescription() throw (RuntimeException)
133*cdf0e10cSrcweir {
134*cdf0e10cSrcweir     if (m_descr.getLength() == 0)
135*cdf0e10cSrcweir         return Package::getDescription();
136*cdf0e10cSrcweir     else
137*cdf0e10cSrcweir         return m_descr;
138*cdf0e10cSrcweir }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir //______________________________________________________________________________
141*cdf0e10cSrcweir OUString BackendImpl::PackageImpl::getLicenseText() throw (RuntimeException)
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir     return Package::getDescription();
144*cdf0e10cSrcweir }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir //______________________________________________________________________________
147*cdf0e10cSrcweir BackendImpl::PackageImpl::PackageImpl(
148*cdf0e10cSrcweir     ::rtl::Reference<BackendImpl> const & myBackend,
149*cdf0e10cSrcweir     OUString const & url, OUString const & libType, bool bRemoved,
150*cdf0e10cSrcweir     OUString const & identifier)
151*cdf0e10cSrcweir     : Package( myBackend.get(), url, OUString(), OUString(),
152*cdf0e10cSrcweir                myBackend->m_xTypeInfo, bRemoved, identifier),
153*cdf0e10cSrcweir       m_descr(libType)
154*cdf0e10cSrcweir {
155*cdf0e10cSrcweir     initPackageHandler();
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir     sal_Int32 segmEnd = url.getLength();
158*cdf0e10cSrcweir     if (url.getLength() > 0 && url[ url.getLength() - 1 ] == '/')
159*cdf0e10cSrcweir         --segmEnd;
160*cdf0e10cSrcweir     sal_Int32 segmStart = (url.lastIndexOf( '/', segmEnd ) + 1);
161*cdf0e10cSrcweir     if (segmStart < 0)
162*cdf0e10cSrcweir         segmStart = 0;
163*cdf0e10cSrcweir     // name and display name default the same:
164*cdf0e10cSrcweir     m_displayName = ::rtl::Uri::decode(
165*cdf0e10cSrcweir         url.copy( segmStart, segmEnd - segmStart ),
166*cdf0e10cSrcweir         rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
167*cdf0e10cSrcweir     m_name = m_displayName;
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir     dp_misc::TRACE(OUSTR("PakageImpl displayName is ") + m_displayName);
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir //______________________________________________________________________________
173*cdf0e10cSrcweir BackendImpl::BackendImpl(
174*cdf0e10cSrcweir     Sequence<Any> const & args,
175*cdf0e10cSrcweir     Reference<XComponentContext> const & xComponentContext )
176*cdf0e10cSrcweir     : PackageRegistryBackend( args, xComponentContext ),
177*cdf0e10cSrcweir       m_xTypeInfo( new Package::TypeInfo(
178*cdf0e10cSrcweir                        OUSTR("application/vnd.sun.star.framework-script"),
179*cdf0e10cSrcweir                        OUString() /* no file filter */,
180*cdf0e10cSrcweir                        OUSTR("Scripting Framework Script Library"),
181*cdf0e10cSrcweir                        RID_IMG_SCRIPTLIB, RID_IMG_SCRIPTLIB_HC ) )
182*cdf0e10cSrcweir {
183*cdf0e10cSrcweir     if (! transientMode())
184*cdf0e10cSrcweir     {
185*cdf0e10cSrcweir /*
186*cdf0e10cSrcweir         if (office_is_running())
187*cdf0e10cSrcweir         {
188*cdf0e10cSrcweir             Reference<XComponentContext> xContext( getComponentContext() );
189*cdf0e10cSrcweir             m_xScriptLibs.set(
190*cdf0e10cSrcweir                 xContext->getServiceManager()->createInstanceWithContext(
191*cdf0e10cSrcweir                     OUSTR("com.sun.star."
192*cdf0e10cSrcweir                           "script.ApplicationScriptLibraryContainer"),
193*cdf0e10cSrcweir                     xContext ), UNO_QUERY_THROW );
194*cdf0e10cSrcweir             m_xDialogLibs.set(
195*cdf0e10cSrcweir                 xContext->getServiceManager()->createInstanceWithContext(
196*cdf0e10cSrcweir                     OUSTR("com.sun.star."
197*cdf0e10cSrcweir                           "script.ApplicationDialogLibraryContainer"),
198*cdf0e10cSrcweir                     xContext ), UNO_QUERY_THROW );
199*cdf0e10cSrcweir         }
200*cdf0e10cSrcweir         else
201*cdf0e10cSrcweir         {
202*cdf0e10cSrcweir             OUString basic_path(
203*cdf0e10cSrcweir                 m_eContext == CONTEXT_USER
204*cdf0e10cSrcweir                 ? OUSTR("vnd.sun.star.expand:${$BRAND_BASE_DIR/program/"
205*cdf0e10cSrcweir                         SAL_CONFIGFILE("bootstrap")
206*cdf0e10cSrcweir                         ":UserInstallation}/user/basic")
207*cdf0e10cSrcweir                 : OUSTR("vnd.sun.star.expand:${$BRAND_BASE_DIR/program/"
208*cdf0e10cSrcweir                         SAL_CONFIGFILE("bootstrap")
209*cdf0e10cSrcweir                         ":BaseInstallation}/share/basic") );
210*cdf0e10cSrcweir             m_basic_script_libs.reset(
211*cdf0e10cSrcweir                 new LibraryContainer(
212*cdf0e10cSrcweir                     makeURL( basic_path, OUSTR("script.xlc") ),
213*cdf0e10cSrcweir                     getMutex(),
214*cdf0e10cSrcweir                     getComponentContext() ) );
215*cdf0e10cSrcweir             m_dialog_libs.reset(
216*cdf0e10cSrcweir                 new LibraryContainer(
217*cdf0e10cSrcweir                     makeURL( basic_path, OUSTR("dialog.xlc") ),
218*cdf0e10cSrcweir                     getMutex(),
219*cdf0e10cSrcweir                     getComponentContext() ) );
220*cdf0e10cSrcweir         }
221*cdf0e10cSrcweir */
222*cdf0e10cSrcweir     }
223*cdf0e10cSrcweir }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir // XPackageRegistry
228*cdf0e10cSrcweir //______________________________________________________________________________
229*cdf0e10cSrcweir Sequence< Reference<deployment::XPackageTypeInfo> >
230*cdf0e10cSrcweir BackendImpl::getSupportedPackageTypes() throw (RuntimeException)
231*cdf0e10cSrcweir {
232*cdf0e10cSrcweir     return Sequence< Reference<deployment::XPackageTypeInfo> >(&m_xTypeInfo, 1);
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir void BackendImpl::packageRemoved(OUString const & /*url*/, OUString const & /*mediaType*/)
236*cdf0e10cSrcweir         throw (deployment::DeploymentException,
237*cdf0e10cSrcweir                uno::RuntimeException)
238*cdf0e10cSrcweir {
239*cdf0e10cSrcweir }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir // PackageRegistryBackend
242*cdf0e10cSrcweir //______________________________________________________________________________
243*cdf0e10cSrcweir Reference<deployment::XPackage> BackendImpl::bindPackage_(
244*cdf0e10cSrcweir     OUString const & url, OUString const & mediaType_, sal_Bool bRemoved,
245*cdf0e10cSrcweir     OUString const & identifier, Reference<XCommandEnvironment> const & xCmdEnv )
246*cdf0e10cSrcweir {
247*cdf0e10cSrcweir     OUString mediaType( mediaType_ );
248*cdf0e10cSrcweir     if (mediaType.getLength() == 0)
249*cdf0e10cSrcweir     {
250*cdf0e10cSrcweir         // detect media-type:
251*cdf0e10cSrcweir         ::ucbhelper::Content ucbContent;
252*cdf0e10cSrcweir         if (create_ucb_content( &ucbContent, url, xCmdEnv ) &&
253*cdf0e10cSrcweir             ucbContent.isFolder())
254*cdf0e10cSrcweir         {
255*cdf0e10cSrcweir             // probe for parcel-descriptor.xml:
256*cdf0e10cSrcweir             if (create_ucb_content(
257*cdf0e10cSrcweir                     0, makeURL( url, OUSTR("parcel-descriptor.xml") ),
258*cdf0e10cSrcweir                     xCmdEnv, false /* no throw */ ))
259*cdf0e10cSrcweir             {
260*cdf0e10cSrcweir                 mediaType = OUSTR("application/vnd.sun.star.framework-script");
261*cdf0e10cSrcweir             }
262*cdf0e10cSrcweir         }
263*cdf0e10cSrcweir         if (mediaType.getLength() == 0)
264*cdf0e10cSrcweir             throw lang::IllegalArgumentException(
265*cdf0e10cSrcweir                 StrCannotDetectMediaType::get() + url,
266*cdf0e10cSrcweir                 static_cast<OWeakObject *>(this), static_cast<sal_Int16>(-1) );
267*cdf0e10cSrcweir     }
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir     String type, subType;
270*cdf0e10cSrcweir     INetContentTypeParameterList params;
271*cdf0e10cSrcweir     if (INetContentTypes::parse( mediaType, type, subType, &params ))
272*cdf0e10cSrcweir     {
273*cdf0e10cSrcweir         if (type.EqualsIgnoreCaseAscii("application"))
274*cdf0e10cSrcweir         {
275*cdf0e10cSrcweir             if (subType.EqualsIgnoreCaseAscii("vnd.sun.star.framework-script"))
276*cdf0e10cSrcweir             {
277*cdf0e10cSrcweir                 OUString lang = OUString::createFromAscii("Script");
278*cdf0e10cSrcweir                 OUString sParcelDescURL = makeURL(
279*cdf0e10cSrcweir                     url, OUSTR("parcel-descriptor.xml") );
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir                 ::ucbhelper::Content ucb_content;
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir                 if (create_ucb_content( &ucb_content, sParcelDescURL,
284*cdf0e10cSrcweir                         xCmdEnv, false /* no throw */ ))
285*cdf0e10cSrcweir                 {
286*cdf0e10cSrcweir                     ParcelDescDocHandler* pHandler =
287*cdf0e10cSrcweir                         new ParcelDescDocHandler();
288*cdf0e10cSrcweir                     Reference< xml::sax::XDocumentHandler >
289*cdf0e10cSrcweir                         xDocHandler = pHandler;
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir                     Reference<XComponentContext>
292*cdf0e10cSrcweir                         xContext( getComponentContext() );
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir                     Reference< xml::sax::XParser > xParser(
295*cdf0e10cSrcweir                       xContext->getServiceManager()->createInstanceWithContext(
296*cdf0e10cSrcweir                             OUSTR("com.sun.star.xml.sax.Parser"), xContext ),
297*cdf0e10cSrcweir                                 UNO_QUERY_THROW );
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir                     xParser->setDocumentHandler( xDocHandler );
300*cdf0e10cSrcweir                     xml::sax::InputSource source;
301*cdf0e10cSrcweir                     source.aInputStream = ucb_content.openStream();
302*cdf0e10cSrcweir                     source.sSystemId = ucb_content.getURL();
303*cdf0e10cSrcweir                     xParser->parseStream( source );
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir                     if ( pHandler->isParsed() )
306*cdf0e10cSrcweir                     {
307*cdf0e10cSrcweir                         lang = pHandler->getParcelLanguage();
308*cdf0e10cSrcweir                     }
309*cdf0e10cSrcweir                 }
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir                 OUString sfwkLibType = getResourceString( RID_STR_SFWK_LIB );
312*cdf0e10cSrcweir                 // replace %MACRONAME placeholder with language name
313*cdf0e10cSrcweir                 OUString MACRONAME( OUSTR("%MACROLANG" ) );
314*cdf0e10cSrcweir                 sal_Int32 startOfReplace = sfwkLibType.indexOf( MACRONAME );
315*cdf0e10cSrcweir                 sal_Int32 charsToReplace = MACRONAME.getLength();
316*cdf0e10cSrcweir                 sfwkLibType = sfwkLibType.replaceAt( startOfReplace, charsToReplace, lang );
317*cdf0e10cSrcweir                 dp_misc::TRACE("******************************\n");
318*cdf0e10cSrcweir                 dp_misc::TRACE(OUSTR(" BackEnd detected lang = ") + lang + OUSTR("\n"));
319*cdf0e10cSrcweir                 dp_misc::TRACE(OUSTR(" for url ") + sParcelDescURL + OUSTR("\n") );
320*cdf0e10cSrcweir                 dp_misc::TRACE("******************************\n");
321*cdf0e10cSrcweir                 return new PackageImpl( this, url, sfwkLibType, bRemoved, identifier);
322*cdf0e10cSrcweir             }
323*cdf0e10cSrcweir         }
324*cdf0e10cSrcweir     }
325*cdf0e10cSrcweir     throw lang::IllegalArgumentException(
326*cdf0e10cSrcweir         StrUnsupportedMediaType::get() + mediaType,
327*cdf0e10cSrcweir         static_cast<OWeakObject *>(this),
328*cdf0e10cSrcweir         static_cast<sal_Int16>(-1) );
329*cdf0e10cSrcweir }
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir //##############################################################################
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir void BackendImpl::PackageImpl:: initPackageHandler()
334*cdf0e10cSrcweir {
335*cdf0e10cSrcweir     if (m_xNameCntrPkgHandler.is())
336*cdf0e10cSrcweir         return;
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir     BackendImpl * that = getMyBackend();
339*cdf0e10cSrcweir     Any aContext;
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir     if ( that->m_eContext == CONTEXT_USER )
342*cdf0e10cSrcweir     {
343*cdf0e10cSrcweir         aContext  <<= OUSTR("user");
344*cdf0e10cSrcweir     }
345*cdf0e10cSrcweir     else if ( that->m_eContext == CONTEXT_SHARED )
346*cdf0e10cSrcweir     {
347*cdf0e10cSrcweir         aContext  <<= OUSTR("share");
348*cdf0e10cSrcweir     }
349*cdf0e10cSrcweir     else if ( that->m_eContext == CONTEXT_BUNDLED )
350*cdf0e10cSrcweir     {
351*cdf0e10cSrcweir         aContext  <<= OUSTR("bundled");
352*cdf0e10cSrcweir     }
353*cdf0e10cSrcweir     else if ( that->m_eContext == CONTEXT_BUNDLED_PREREG )
354*cdf0e10cSrcweir     {
355*cdf0e10cSrcweir         aContext  <<= OUSTR("bundled_prereg");
356*cdf0e10cSrcweir     }
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir     else
359*cdf0e10cSrcweir     {
360*cdf0e10cSrcweir         OSL_ASSERT( 0 );
361*cdf0e10cSrcweir         // NOT supported at the momemtn // TODO
362*cdf0e10cSrcweir     }
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir     Reference< provider::XScriptProviderFactory > xFac(
365*cdf0e10cSrcweir         that->getComponentContext()->getValueByName(
366*cdf0e10cSrcweir             OUSTR( "/singletons/com.sun.star.script.provider.theMasterScriptProviderFactory") ), UNO_QUERY );
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir     if ( xFac.is() )
369*cdf0e10cSrcweir     {
370*cdf0e10cSrcweir         Reference< container::XNameContainer > xName( xFac->createScriptProvider( aContext ), UNO_QUERY );
371*cdf0e10cSrcweir         if ( xName.is() )
372*cdf0e10cSrcweir         {
373*cdf0e10cSrcweir             m_xNameCntrPkgHandler.set( xName );
374*cdf0e10cSrcweir         }
375*cdf0e10cSrcweir     }
376*cdf0e10cSrcweir     // TODO what happens if above fails??
377*cdf0e10cSrcweir }
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir // Package
380*cdf0e10cSrcweir //______________________________________________________________________________
381*cdf0e10cSrcweir beans::Optional< beans::Ambiguous<sal_Bool> >
382*cdf0e10cSrcweir BackendImpl::PackageImpl::isRegistered_(
383*cdf0e10cSrcweir     ::osl::ResettableMutexGuard &,
384*cdf0e10cSrcweir     ::rtl::Reference<AbortChannel> const &,
385*cdf0e10cSrcweir     Reference<XCommandEnvironment> const & )
386*cdf0e10cSrcweir {
387*cdf0e10cSrcweir     return beans::Optional< beans::Ambiguous<sal_Bool> >(
388*cdf0e10cSrcweir         true /* IsPresent */,
389*cdf0e10cSrcweir         beans::Ambiguous<sal_Bool>(
390*cdf0e10cSrcweir             m_xNameCntrPkgHandler.is() && m_xNameCntrPkgHandler->hasByName(
391*cdf0e10cSrcweir                 m_url ),
392*cdf0e10cSrcweir             false /* IsAmbiguous */ ) );
393*cdf0e10cSrcweir }
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir //______________________________________________________________________________
396*cdf0e10cSrcweir void BackendImpl::PackageImpl::processPackage_(
397*cdf0e10cSrcweir     ::osl::ResettableMutexGuard &,
398*cdf0e10cSrcweir     bool doRegisterPackage,
399*cdf0e10cSrcweir     bool /* startup */,
400*cdf0e10cSrcweir     ::rtl::Reference<AbortChannel> const &,
401*cdf0e10cSrcweir     Reference<XCommandEnvironment> const & )
402*cdf0e10cSrcweir {
403*cdf0e10cSrcweir     if ( !m_xNameCntrPkgHandler.is() )
404*cdf0e10cSrcweir     {
405*cdf0e10cSrcweir         dp_misc::TRACE("no package handler!!!!\n");
406*cdf0e10cSrcweir         throw RuntimeException( OUSTR("No package Handler " ),
407*cdf0e10cSrcweir             Reference< XInterface >() );
408*cdf0e10cSrcweir     }
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir     if (doRegisterPackage)
411*cdf0e10cSrcweir     {
412*cdf0e10cSrcweir         // will throw if it fails
413*cdf0e10cSrcweir         m_xNameCntrPkgHandler->insertByName( m_url, makeAny( Reference< XPackage >(this) ) );
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir     }
416*cdf0e10cSrcweir     else // revokePackage()
417*cdf0e10cSrcweir     {
418*cdf0e10cSrcweir         m_xNameCntrPkgHandler->removeByName( m_url );
419*cdf0e10cSrcweir     }
420*cdf0e10cSrcweir }
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir namespace sdecl = comphelper::service_decl;
423*cdf0e10cSrcweir sdecl::class_<BackendImpl, sdecl::with_args<true> > serviceBI;
424*cdf0e10cSrcweir extern sdecl::ServiceDecl const serviceDecl(
425*cdf0e10cSrcweir     serviceBI,
426*cdf0e10cSrcweir     "com.sun.star.comp.deployment.sfwk.PackageRegistryBackend",
427*cdf0e10cSrcweir     BACKEND_SERVICE_NAME );
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir } // namespace sfwk
430*cdf0e10cSrcweir } // namespace backend
431*cdf0e10cSrcweir } // namespace dp_registry
432*cdf0e10cSrcweir 
433