LCOV - code coverage report
Current view: top level - scripting/source/provider - URIHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 106 0.0 %
Date: 2012-08-25 Functions: 0 13 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 138 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : 
      21                 :            : #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
      22                 :            : #include <rtl/ustrbuf.hxx>
      23                 :            : #include "URIHelper.hxx"
      24                 :            : 
      25                 :            : #define PRTSTR(x) ::rtl::OUStringToOString(x, RTL_TEXTENCODING_ASCII_US).pData->buffer
      26                 :            : 
      27                 :            : namespace func_provider
      28                 :            : {
      29                 :            : 
      30                 :            : using ::rtl::OUString;
      31                 :            : namespace uno = ::com::sun::star::uno;
      32                 :            : namespace ucb = ::com::sun::star::ucb;
      33                 :            : namespace lang = ::com::sun::star::lang;
      34                 :            : namespace uri = ::com::sun::star::uri;
      35                 :            : namespace script = ::com::sun::star::script;
      36                 :            : 
      37                 :            : static const char SHARE[] = "share";
      38                 :            : static const char SHARE_URI[] = "vnd.sun.star.expand:$BRAND_BASE_DIR";
      39                 :            : 
      40                 :            : static const char SHARE_UNO_PACKAGES[] = "share:uno_packages";
      41                 :            : static const char SHARE_UNO_PACKAGES_URI[] =
      42                 :            :     "vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE";
      43                 :            : 
      44                 :            : static const char USER[] = "user";
      45                 :            : static const char USER_URI[] =
      46                 :            :     "vnd.sun.star.expand:${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE( "bootstrap") "::UserInstallation}";
      47                 :            : 
      48                 :            : static const char USER_UNO_PACKAGES[] = "user:uno_packages";
      49                 :            : static const char USER_UNO_PACKAGES_DIR[] =
      50                 :            :     "/user/uno_packages/cache";
      51                 :            : 
      52                 :            : static const char DOCUMENT[] = "document";
      53                 :            : static const char TDOC_SCHEME[] = "vnd.sun.star.tdoc";
      54                 :            : 
      55                 :          0 : ScriptingFrameworkURIHelper::ScriptingFrameworkURIHelper(
      56                 :            :     const uno::Reference< uno::XComponentContext >& xContext)
      57                 :          0 :         throw( uno::RuntimeException )
      58                 :            : {
      59                 :            :     try
      60                 :            :     {
      61 [ #  # ][ #  # ]:          0 :         m_xSimpleFileAccess = uno::Reference< ucb::XSimpleFileAccess2 >( ucb::SimpleFileAccess::create(xContext) );
                 [ #  # ]
      62                 :            :     }
      63         [ #  # ]:          0 :     catch (uno::Exception&)
      64                 :            :     {
      65                 :            :         OSL_FAIL("Scripting Framework error initialising XSimpleFileAccess");
      66                 :            :     }
      67                 :            : 
      68                 :            :     try
      69                 :            :     {
      70                 :            :         m_xUriReferenceFactory = uno::Reference< uri::XUriReferenceFactory >(
      71 [ #  # ][ #  # ]:          0 :             xContext->getServiceManager()->createInstanceWithContext(
           [ #  #  #  # ]
      72                 :            :                 OUString(
      73                 :            :                     "com.sun.star.uri.UriReferenceFactory"),
      74 [ #  # ][ #  # ]:          0 :             xContext ), uno::UNO_QUERY_THROW );
                 [ #  # ]
      75                 :            :     }
      76         [ #  # ]:          0 :     catch (uno::Exception&)
      77                 :            :     {
      78                 :            :         OSL_FAIL("Scripting Framework error initialising XUriReferenceFactory");
      79                 :            :     }
      80                 :          0 : }
      81                 :            : 
      82                 :          0 : ScriptingFrameworkURIHelper::~ScriptingFrameworkURIHelper()
      83                 :            : {
      84                 :            :     // currently does nothing
      85         [ #  # ]:          0 : }
      86                 :            : 
      87                 :            : void SAL_CALL
      88                 :          0 : ScriptingFrameworkURIHelper::initialize(
      89                 :            :     const uno::Sequence < uno::Any >& args )
      90                 :            : throw ( uno::Exception, uno::RuntimeException )
      91                 :            : {
      92   [ #  #  #  #  :          0 :     if ( args.getLength() != 2 ||
           #  # ][ #  # ]
      93                 :          0 :          args[0].getValueType() != ::getCppuType((const OUString*)NULL) ||
      94                 :          0 :          args[1].getValueType() != ::getCppuType((const OUString*)NULL) )
      95                 :            :     {
      96                 :            :         throw uno::RuntimeException( OUString(
      97                 :            :             "ScriptingFrameworkURIHelper got invalid argument list" ),
      98         [ #  # ]:          0 :                 uno::Reference< uno::XInterface >() );
      99                 :            :     }
     100                 :            : 
     101   [ #  #  #  # ]:          0 :     if ( (args[0] >>= m_sLanguage) == sal_False ||
                 [ #  # ]
     102                 :          0 :          (args[1] >>= m_sLocation) == sal_False )
     103                 :            :     {
     104                 :            :         throw uno::RuntimeException( OUString(
     105                 :            :             "ScriptingFrameworkURIHelper error parsing args" ),
     106         [ #  # ]:          0 :                 uno::Reference< uno::XInterface >() );
     107                 :            :     }
     108                 :            : 
     109                 :          0 :     SCRIPTS_PART = OUString("/Scripts/");
     110                 :          0 :     SCRIPTS_PART = SCRIPTS_PART.concat( m_sLanguage.toAsciiLowerCase() );
     111                 :            : 
     112         [ #  # ]:          0 :     if ( !initBaseURI() )
     113                 :            :     {
     114                 :            :         throw uno::RuntimeException( OUString(
     115                 :            :             "ScriptingFrameworkURIHelper cannot find script directory"),
     116         [ #  # ]:          0 :                 uno::Reference< uno::XInterface >() );
     117                 :            :     }
     118                 :          0 : }
     119                 :            : 
     120                 :            : bool
     121                 :          0 : ScriptingFrameworkURIHelper::initBaseURI()
     122                 :            : {
     123                 :          0 :     OUString uri, test;
     124                 :          0 :     bool bAppendScriptsPart = false;
     125                 :            : 
     126         [ #  # ]:          0 :     if ( m_sLocation.equalsAscii(USER))
     127                 :            :     {
     128                 :          0 :         test = OUString(USER);
     129                 :          0 :         uri = OUString(USER_URI);
     130                 :          0 :         bAppendScriptsPart = true;
     131                 :            :     }
     132         [ #  # ]:          0 :     else if ( m_sLocation.equalsAscii(USER_UNO_PACKAGES))
     133                 :            :     {
     134                 :          0 :         test = OUString("uno_packages");
     135                 :          0 :         uri = OUString(USER_URI);
     136                 :          0 :         uri = uri.concat(OUString(USER_UNO_PACKAGES_DIR));
     137                 :            :     }
     138         [ #  # ]:          0 :     else if (m_sLocation.equalsAscii(SHARE))
     139                 :            :     {
     140                 :          0 :         test = OUString(SHARE);
     141                 :          0 :         uri = OUString(SHARE_URI);
     142                 :          0 :         bAppendScriptsPart = true;
     143                 :            :     }
     144         [ #  # ]:          0 :     else if (m_sLocation.equalsAscii(SHARE_UNO_PACKAGES))
     145                 :            :     {
     146                 :          0 :         test = OUString("uno_packages");
     147                 :          0 :         uri = OUString(SHARE_UNO_PACKAGES_URI);
     148                 :            :     }
     149         [ #  # ]:          0 :     else if (m_sLocation.indexOf(TDOC_SCHEME) == 0)
     150                 :            :     {
     151                 :          0 :         m_sBaseURI = m_sLocation.concat( SCRIPTS_PART );
     152                 :          0 :         m_sLocation = OUString(DOCUMENT );
     153                 :          0 :         return true;
     154                 :            :     }
     155                 :            :     else
     156                 :            :     {
     157                 :          0 :         return false;
     158                 :            :     }
     159                 :            : 
     160 [ #  # ][ #  # ]:          0 :     if ( !m_xSimpleFileAccess->exists( uri ) ||
         [ #  # ][ #  # ]
                 [ #  # ]
     161 [ #  # ][ #  # ]:          0 :          !m_xSimpleFileAccess->isFolder( uri ) )
     162                 :            :     {
     163                 :          0 :         return false;
     164                 :            :     }
     165                 :            : 
     166                 :            :     uno::Sequence< OUString > children =
     167 [ #  # ][ #  # ]:          0 :         m_xSimpleFileAccess->getFolderContents( uri, true );
     168                 :            : 
     169         [ #  # ]:          0 :     for ( sal_Int32 i = 0; i < children.getLength(); i++ )
     170                 :            :     {
     171         [ #  # ]:          0 :         OUString child = children[i];
     172                 :          0 :         sal_Int32 idx = child.lastIndexOf(test);
     173                 :            : 
     174                 :            :         // OSL_TRACE("Trying: %s", PRTSTR(child));
     175                 :            :         // OSL_TRACE("idx=%d, testlen=%d, children=%d",
     176                 :            :         //     idx, test.getLength(), child.getLength());
     177                 :            : 
     178 [ #  # ][ #  # ]:          0 :         if ( idx != -1 && (idx + test.getLength()) == child.getLength() )
                 [ #  # ]
     179                 :            :         {
     180                 :            :             // OSL_TRACE("FOUND PATH: %s", PRTSTR(child));
     181         [ #  # ]:          0 :             if ( bAppendScriptsPart )
     182                 :            :             {
     183                 :          0 :                 m_sBaseURI = child.concat( SCRIPTS_PART );
     184                 :            :             }
     185                 :            :             else
     186                 :            :             {
     187                 :          0 :                 m_sBaseURI = child;
     188                 :            :             }
     189                 :          0 :             return true;
     190                 :            :         }
     191         [ #  # ]:          0 :     }
     192         [ #  # ]:          0 :     return false;
     193                 :            : }
     194                 :            : 
     195                 :            : OUString
     196                 :          0 : ScriptingFrameworkURIHelper::getLanguagePart(const OUString& rStorageURI)
     197                 :            : {
     198                 :          0 :     OUString result;
     199                 :            : 
     200                 :          0 :     sal_Int32 idx = rStorageURI.indexOf(m_sBaseURI);
     201                 :          0 :     sal_Int32 len = m_sBaseURI.getLength() + 1;
     202                 :            : 
     203         [ #  # ]:          0 :     if ( idx != -1 )
     204                 :            :     {
     205                 :          0 :         result = rStorageURI.copy(idx + len);
     206                 :          0 :         result = result.replace('/', '|');
     207                 :            :     }
     208                 :          0 :     return result;
     209                 :            : }
     210                 :            : 
     211                 :            : OUString
     212                 :          0 : ScriptingFrameworkURIHelper::getLanguagePath(const OUString& rLanguagePart)
     213                 :            : {
     214                 :          0 :     OUString result;
     215                 :          0 :     result = rLanguagePart.replace('|', '/');
     216                 :          0 :     return result;
     217                 :            : }
     218                 :            : 
     219                 :            : OUString SAL_CALL
     220                 :          0 : ScriptingFrameworkURIHelper::getScriptURI(const OUString& rStorageURI)
     221                 :            :     throw( lang::IllegalArgumentException, uno::RuntimeException )
     222                 :            : {
     223                 :          0 :     ::rtl::OUStringBuffer buf(120);
     224                 :            : 
     225         [ #  # ]:          0 :     buf.appendAscii("vnd.sun.star.script:");
     226         [ #  # ]:          0 :     buf.append(getLanguagePart(rStorageURI));
     227         [ #  # ]:          0 :     buf.appendAscii("?language=");
     228         [ #  # ]:          0 :     buf.append(m_sLanguage);
     229         [ #  # ]:          0 :     buf.appendAscii("&location=");
     230         [ #  # ]:          0 :     buf.append(m_sLocation);
     231                 :            : 
     232         [ #  # ]:          0 :     return buf.makeStringAndClear();
     233                 :            : }
     234                 :            : 
     235                 :            : OUString SAL_CALL
     236                 :          0 : ScriptingFrameworkURIHelper::getStorageURI(const OUString& rScriptURI)
     237                 :            :     throw( lang::IllegalArgumentException, uno::RuntimeException )
     238                 :            : {
     239                 :          0 :     OUString sLanguagePart;
     240                 :            :     try
     241                 :            :     {
     242                 :            :         uno::Reference < uri::XVndSunStarScriptUrl > xURI(
     243 [ #  # ][ #  # ]:          0 :             m_xUriReferenceFactory->parse( rScriptURI ), uno::UNO_QUERY_THROW );
                 [ #  # ]
     244 [ #  # ][ #  # ]:          0 :         sLanguagePart = xURI->getName();
     245                 :            :     }
     246         [ #  # ]:          0 :     catch ( uno::Exception& )
     247                 :            :     {
     248                 :            :         throw lang::IllegalArgumentException(
     249                 :            :             OUString("Script URI not valid"),
     250         [ #  # ]:          0 :                 uno::Reference< uno::XInterface >(), 1 );
     251                 :            :     }
     252                 :            : 
     253                 :          0 :     ::rtl::OUStringBuffer buf(120);
     254         [ #  # ]:          0 :     buf.append(m_sBaseURI);
     255         [ #  # ]:          0 :     buf.append(OUString("/"));
     256         [ #  # ]:          0 :     buf.append(getLanguagePath(sLanguagePart));
     257                 :            : 
     258         [ #  # ]:          0 :     OUString result = buf.makeStringAndClear();
     259                 :            : 
     260                 :          0 :     return result;
     261                 :            : }
     262                 :            : 
     263                 :            : OUString SAL_CALL
     264                 :          0 : ScriptingFrameworkURIHelper::getRootStorageURI()
     265                 :            :     throw( uno::RuntimeException )
     266                 :            : {
     267                 :          0 :     return m_sBaseURI;
     268                 :            : }
     269                 :            : 
     270                 :            : OUString SAL_CALL
     271                 :          0 : ScriptingFrameworkURIHelper::getImplementationName()
     272                 :            :     throw( uno::RuntimeException )
     273                 :            : {
     274                 :            :     return OUString(
     275                 :          0 :         "com.sun.star.script.provider.ScriptURIHelper" );
     276                 :            : }
     277                 :            : 
     278                 :            : sal_Bool SAL_CALL
     279                 :          0 : ScriptingFrameworkURIHelper::supportsService( const OUString& serviceName )
     280                 :            :     throw( uno::RuntimeException )
     281                 :            : {
     282                 :            :     OUString m_sServiceName(
     283                 :          0 :         "com.sun.star.script.provider.ScriptURIHelper" );
     284                 :            : 
     285         [ #  # ]:          0 :     if ( serviceName.equals( m_sServiceName ) )
     286                 :            :     {
     287                 :          0 :         return sal_True;
     288                 :            :     }
     289                 :          0 :     return sal_False;
     290                 :            : }
     291                 :            : 
     292                 :            : uno::Sequence< ::rtl::OUString > SAL_CALL
     293                 :          0 : ScriptingFrameworkURIHelper::getSupportedServiceNames()
     294                 :            :     throw( uno::RuntimeException )
     295                 :            : {
     296                 :            :     ::rtl::OUString serviceNameList[] = {
     297                 :            :         ::rtl::OUString(
     298                 :          0 :             "com.sun.star.script.provider.ScriptURIHelper" ) };
     299                 :            : 
     300                 :            :     uno::Sequence< ::rtl::OUString > serviceNames = uno::Sequence <
     301         [ #  # ]:          0 :         ::rtl::OUString > ( serviceNameList, 1 );
     302                 :            : 
     303 [ #  # ][ #  # ]:          0 :     return serviceNames;
     304                 :            : }
     305                 :            : }
     306                 :            : 
     307                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10