LCOV - code coverage report
Current view: top level - desktop/source/deployment/registry/sfwk - dp_sfwk.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 22 118 18.6 %
Date: 2012-08-25 Functions: 6 17 35.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 25 256 9.8 %

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

Generated by: LCOV version 1.10