LCOV - code coverage report
Current view: top level - libreoffice/sc/source/core/data - globalx.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 35 51 68.6 %
Date: 2012-12-27 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          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             : #include "callform.hxx"
      21             : #include "global.hxx"
      22             : #include <tools/urlobj.hxx>
      23             : #include <ucbhelper/content.hxx>
      24             : #include <unotools/localfilehelper.hxx>
      25             : 
      26             : #include <unotools/pathoptions.hxx>
      27             : 
      28             : #include <com/sun/star/sdbc/XResultSet.hpp>
      29             : #include <com/sun/star/sdbc/XRow.hpp>
      30             : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
      31             : #include <com/sun/star/ucb/XContentAccess.hpp>
      32             : 
      33             : #include <com/sun/star/i18n/XOrdinalSuffix.hpp>
      34             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      35             : #include <comphelper/processfactory.hxx>
      36             : #include <comphelper/string.hxx>
      37             : #include <unotools/localedatawrapper.hxx>
      38             : 
      39             : 
      40             : using namespace ::com::sun::star;
      41             : using namespace ::com::sun::star::uno;
      42             : using namespace ::com::sun::star::ucb;
      43             : 
      44             : 
      45           5 : void ScGlobal::InitAddIns()
      46             : {
      47             :     // multi paths separated by semicolons
      48           5 :     SvtPathOptions aPathOpt;
      49           5 :     rtl::OUString aMultiPath = aPathOpt.GetAddinPath();
      50           5 :     if (aMultiPath.isEmpty())
      51           5 :         return;
      52             : 
      53           5 :     sal_Int32 nTokens = comphelper::string::getTokenCount(aMultiPath, ';');
      54          10 :     for (sal_Int32 j = 0; j < nTokens; ++j)
      55             :     {
      56           5 :         rtl::OUString aPath = comphelper::string::getToken(aMultiPath, j, ';');
      57           5 :         if (aPath.isEmpty())
      58           0 :             continue;
      59             : 
      60             :         //  use LocalFileHelper to convert the path to a URL that always points
      61             :         //  to the file on the server
      62           5 :         rtl::OUString aUrl;
      63           5 :         if ( utl::LocalFileHelper::ConvertPhysicalNameToURL( aPath, aUrl ) )
      64           5 :             aPath = aUrl;
      65             : 
      66           5 :         INetURLObject aObj;
      67           5 :         aObj.SetSmartURL( aPath );
      68           5 :         aObj.setFinalSlash();
      69             :         try
      70             :         {
      71             :             ::ucbhelper::Content aCnt( aObj.GetMainURL(INetURLObject::NO_DECODE),
      72             :                 Reference< XCommandEnvironment >(),
      73           5 :                 comphelper::getProcessComponentContext() );
      74           5 :             Reference< sdbc::XResultSet > xResultSet;
      75           5 :             Sequence< rtl::OUString > aProps;
      76             :             try
      77             :             {
      78             :                 xResultSet = aCnt.createCursor(
      79           5 :                     aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY );
      80             :             }
      81           5 :             catch ( Exception& )
      82             :             {
      83             :                 // ucb may throw different exceptions on failure now
      84             :                 // no assertion if AddIn directory doesn't exist
      85             :             }
      86             : 
      87           5 :             if ( xResultSet.is() )
      88             :             {
      89           0 :                 Reference< sdbc::XRow > xRow( xResultSet, UNO_QUERY );
      90             :                 Reference< XContentAccess >
      91           0 :                     xContentAccess( xResultSet, UNO_QUERY );
      92             :                 try
      93             :                 {
      94           0 :                     if ( xResultSet->first() )
      95             :                     {
      96           0 :                         do
      97             :                         {
      98           0 :                             rtl::OUString aId = xContentAccess->queryContentIdentifierString();
      99           0 :                             InitExternalFunc( aId );
     100             :                         }
     101           0 :                         while ( xResultSet->next() );
     102             :                     }
     103             :                 }
     104           0 :                 catch ( Exception& )
     105             :                 {
     106             :                     OSL_FAIL( "ResultSetException caught!" );
     107           0 :                 }
     108           5 :             }
     109             :         }
     110           0 :         catch ( Exception& )
     111             :         {
     112             :             OSL_FAIL( "Exception caught!" );
     113             :         }
     114           0 :         catch ( ... )
     115             :         {
     116             :             OSL_FAIL( "unexpected exception caught!" );
     117             :         }
     118          10 :     }
     119             : }
     120             : 
     121             : 
     122           2 : String ScGlobal::GetOrdinalSuffix( sal_Int32 nNumber)
     123             : {
     124           2 :     if (!xOrdinalSuffix.is())
     125             :     {
     126             :         try
     127             :         {
     128             :             Reference< lang::XMultiServiceFactory > xServiceManager =
     129           1 :                 ::comphelper::getProcessServiceFactory();
     130             :             Reference< XInterface > xInterface =
     131           1 :                 xServiceManager->createInstance(
     132           1 :                     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.i18n.OrdinalSuffix")));
     133           1 :             if  (xInterface.is())
     134           1 :                 xOrdinalSuffix = Reference< i18n::XOrdinalSuffix >( xInterface, UNO_QUERY);
     135             :         }
     136           0 :         catch ( Exception& )
     137             :         {
     138             :             OSL_FAIL( "GetOrdinalSuffix: exception caught during init" );
     139             :         }
     140             :     }
     141             :     OSL_ENSURE( xOrdinalSuffix.is(), "GetOrdinalSuffix: createInstance failed");
     142           2 :     if (xOrdinalSuffix.is())
     143             :     {
     144             :         try
     145             :         {
     146           2 :             uno::Sequence< rtl::OUString > aSuffixes = xOrdinalSuffix->getOrdinalSuffix( nNumber,
     147           2 :                     ScGlobal::pLocaleData->getLanguageTag().getLocale());
     148           2 :             if ( aSuffixes.getLength() > 0 )
     149           2 :                 return aSuffixes[0];
     150             :             else
     151           0 :                 return String();
     152             :         }
     153           0 :         catch ( Exception& )
     154             :         {
     155             :             OSL_FAIL( "GetOrdinalSuffix: exception caught during getOrdinalSuffix" );
     156             :         }
     157             :     }
     158           0 :     return String();
     159             : }
     160             : 
     161             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10