29#include <com/sun/star/util/XUpdatable.hpp>
30#include <com/sun/star/script/XLibraryContainer3.hpp>
45typedef ::cppu::ImplInheritanceHelper<
52 BackendImpl * getMyBackend()
const;
59 virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
60 ::osl::ResettableMutexGuard & guard,
62 Reference<XCommandEnvironment>
const & xCmdEnv )
override;
63 virtual void processPackage_(
64 ::osl::ResettableMutexGuard & guard,
68 Reference<XCommandEnvironment>
const & xCmdEnv )
override;
74 Reference<XCommandEnvironment>
const &xCmdEnv,
75 OUString
const & scriptURL, OUString
const & dialogURL,
76 bool bRemoved, OUString
const & identifier);
78 friend class PackageImpl;
81 virtual Reference<deployment::XPackage> bindPackage_(
82 OUString
const & url, OUString
const & mediaType,
83 bool bRemoved, OUString
const & identifier,
84 Reference<XCommandEnvironment>
const & xCmdEnv )
override;
86 void addDataToDb(OUString
const & url);
87 bool hasActiveEntry(std::u16string_view url);
88 void revokeEntryFromDb(std::u16string_view url);
92 Sequence< Reference<deployment::XPackageTypeInfo> >
m_typeInfos;
95 BackendImpl( Sequence<Any>
const & args,
96 Reference<XComponentContext>
const & xComponentContext );
104 virtual void SAL_CALL
update()
override;
107 virtual Sequence< Reference<deployment::XPackageTypeInfo> > SAL_CALL
108 getSupportedPackageTypes()
override;
109 virtual void SAL_CALL packageRemoved(OUString
const & url, OUString
const & mediaType)
override;
114BackendImpl::PackageImpl::PackageImpl(
116 OUString
const & url,
117 Reference<XCommandEnvironment>
const &xCmdEnv,
118 OUString
const & scriptURL, OUString
const & dialogURL,
bool bRemoved,
119 OUString
const & identifier)
121 OUString(), OUString(),
128 if (!dialogURL.isEmpty()) {
130 dialogURL, xCmdEnv, myBackend->getComponentContext() );
132 if (!scriptURL.isEmpty()) {
134 m_name = LibraryContainer::get_libname(
135 scriptURL, xCmdEnv, myBackend->getComponentContext() );
143BackendImpl::BackendImpl(
144 Sequence<Any>
const & args,
145 Reference<XComponentContext>
const & xComponentContext )
148 "application/vnd.sun.star.basic-library",
153 "application/vnd.sun.star.dialog-library",
159 OSL_ASSERT( ! transientMode() );
161 if (!transientMode())
163 OUString dbFile =
makeURL(getCachePath(),
"backenddb.xml");
171OUString BackendImpl::getImplementationName()
173 return "com.sun.star.comp.deployment.script.PackageRegistryBackend";
176sal_Bool BackendImpl::supportsService(
const OUString& ServiceName )
181css::uno::Sequence< OUString > BackendImpl::getSupportedServiceNames()
186void BackendImpl::addDataToDb(OUString
const & url)
192bool BackendImpl::hasActiveEntry(std::u16string_view url)
208Sequence< Reference<deployment::XPackageTypeInfo> >
209BackendImpl::getSupportedPackageTypes()
213void BackendImpl::revokeEntryFromDb(std::u16string_view url)
219void BackendImpl::packageRemoved(OUString
const & url, OUString
const & )
227Reference<deployment::XPackage> BackendImpl::bindPackage_(
228 OUString
const & url, OUString
const & mediaType_,
229 bool bRemoved, OUString
const & identifier,
230 Reference<XCommandEnvironment>
const & xCmdEnv )
232 OUString mediaType( mediaType_ );
233 if (mediaType.isEmpty())
242 nullptr,
makeURL( url,
"script.xlb" ),
244 mediaType =
"application/vnd.sun.star.basic-library";
247 nullptr,
makeURL( url,
"dialog.xlb" ),
249 mediaType =
"application/vnd.sun.star.dialog-library";
251 if (mediaType.isEmpty())
252 throw lang::IllegalArgumentException(
253 StrCannotDetectMediaType() + url,
254 static_cast<OWeakObject *
>(
this),
static_cast<sal_Int16
>(-1) );
257 OUString
type, subType;
261 if (
type.equalsIgnoreAsciiCase(
"application"))
263 OUString dialogURL(
makeURL( url,
"dialog.xlb" ) );
265 nullptr, dialogURL, xCmdEnv,
false )) {
269 if (subType.equalsIgnoreAsciiCase(
"vnd.sun.star.basic-library"))
271 OUString scriptURL(
makeURL( url,
"script.xlb"));
273 nullptr, scriptURL, xCmdEnv,
false )) {
277 return new PackageImpl(
278 this, url, xCmdEnv, scriptURL,
279 dialogURL, bRemoved, identifier);
281 else if (subType.equalsIgnoreAsciiCase(
282 "vnd.sun.star.dialog-library")) {
283 return new PackageImpl(
287 bRemoved, identifier);
291 throw lang::IllegalArgumentException(
292 StrUnsupportedMediaType() + mediaType,
293 static_cast<OWeakObject *
>(
this),
294 static_cast<sal_Int16
>(-1) );
299BackendImpl * BackendImpl::PackageImpl::getMyBackend()
const
301 BackendImpl * pBackend =
static_cast<BackendImpl *
>(m_myBackend.get());
302 if (
nullptr == pBackend)
308 "Failed to get the BackendImpl",
309 static_cast<OWeakObject*
>(
const_cast<PackageImpl *
>(
this)));
314beans::Optional< beans::Ambiguous<sal_Bool> >
315BackendImpl::PackageImpl::isRegistered_(
316 ::osl::ResettableMutexGuard & ,
318 Reference<XCommandEnvironment>
const & )
320 BackendImpl * that = getMyBackend();
321 Reference< deployment::XPackage > xThisPackage(
this );
323 bool registered = that->hasActiveEntry(getURL());
324 return beans::Optional< beans::Ambiguous<sal_Bool> >(
326 beans::Ambiguous<sal_Bool>( registered,
false ) );
330lcl_maybeRemoveScript(
332 OUString
const& rName,
333 std::u16string_view rScriptURL,
334 Reference<css::script::XLibraryContainer3>
const& xScriptLibs)
336 if (bExists && xScriptLibs.is() && xScriptLibs->hasByName(rName))
338 const OUString sScriptUrl = xScriptLibs->getOriginalLibraryLinkURL(rName);
339 if (sScriptUrl == rScriptURL)
340 xScriptLibs->removeLibrary(rName);
347 OUString
const& rName,
348 OUString
const& rScriptURL,
349 Reference<css::script::XLibraryContainer3>
const& xScriptLibs)
351 if (!bExists || !xScriptLibs)
355 if (xScriptLibs->hasByName(rName))
357 const OUString sOriginalUrl = xScriptLibs->getOriginalLibraryLinkURL(rName);
361 if (sOriginalUrl.match(
"vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE")
362 || sOriginalUrl.match(
"vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE")
363 || sOriginalUrl.match(
"vnd.sun.star.expand:$BUNDLED_EXTENSIONS")
364 || sOriginalUrl.match(
"$(INST)/share/basic/Access2Base/"))
366 xScriptLibs->removeLibrary(rName);
377 xScriptLibs->createLibraryLink(rName, rScriptURL,
false);
378 return xScriptLibs->hasByName(rName);
384void BackendImpl::PackageImpl::processPackage_(
385 ::osl::ResettableMutexGuard & ,
386 bool doRegisterPackage,
389 Reference<XCommandEnvironment>
const & )
391 BackendImpl * that = getMyBackend();
393 Reference< deployment::XPackage > xThisPackage(
this );
394 Reference<XComponentContext>
const & xComponentContext = that->getComponentContext();
397 Reference<css::script::XLibraryContainer3> xScriptLibs;
400 Reference<css::script::XLibraryContainer3> xDialogLibs;
408 xComponentContext->getServiceManager()->createInstanceWithContext(
409 "com.sun.star.script.ApplicationScriptLibraryContainer",
410 xComponentContext ), UNO_QUERY_THROW );
416 xComponentContext->getServiceManager()->createInstanceWithContext(
417 "com.sun.star.script.ApplicationDialogLibraryContainer",
418 xComponentContext ), UNO_QUERY_THROW );
421 bool bRegistered = getMyBackend()->hasActiveEntry(getURL());
422 if( !doRegisterPackage )
437 if (!isRemoved() && !startup)
439 lcl_maybeRemoveScript(bScript, m_name,
m_scriptURL, xScriptLibs);
442 getMyBackend()->revokeEntryFromDb(getURL());
450 bool bScriptSuccess =
false;
451 bool bDialogSuccess =
false;
457 bScriptSuccess = lcl_maybeAddScript(bScript, m_name,
m_scriptURL, xScriptLibs);
460 bool bSuccess = bScript || bDialog;
462 if( (bScript && !bScriptSuccess) || (bDialog && !bDialogSuccess) )
466 getMyBackend()->addDataToDb(getURL());
473extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
475 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const& args)
477 return cppu::acquire(
new dp_registry::backend::script::BackendImpl(
args, context));
static bool parse(OUString const &rMediaType, OUString &rType, OUString &rSubType, INetContentTypeParameterList *pParameters=nullptr)
OUString DpResId(TranslateId aId)
const OUString m_dialogURL
Sequence< Reference< deployment::XPackageTypeInfo > > m_typeInfos
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_deployment_script_PackageRegistryBackend_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
const Reference< deployment::XPackageTypeInfo > m_xDialogLibTypeInfo
std::unique_ptr< ScriptBackendDb > m_backendDb
const OUString m_scriptURL
const Reference< deployment::XPackageTypeInfo > m_xBasicLibTypeInfo
std::unordered_map< OString, INetContentTypeParameter > INetContentTypeParameterList
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
OUString makeURL(std::u16string_view baseURL, OUString const &relPath_)
appends a relative path to a url.
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC bool create_ucb_content(::ucbhelper::Content *ucb_content, OUString const &url, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv, bool throw_exc=true)
constexpr OUStringLiteral BACKEND_SERVICE_NAME
::cppu::WeakImplHelper< css::script::provider::XScriptProvider, css::script::browse::XBrowseNode, css::lang::XServiceInfo, css::lang::XInitialization, css::container::XNameContainer > t_helper
::boost::spirit::classic::rule< ScannerT > identifier