LCOV - code coverage report
Current view: top level - sfx2/source/bastyp - helper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 47 138 34.1 %
Date: 2012-08-25 Functions: 2 6 33.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 57 357 16.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 "helper.hxx"
      22                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      23                 :            : #include <com/sun/star/sdbc/XResultSet.hpp>
      24                 :            : #include <com/sun/star/sdbc/XRow.hpp>
      25                 :            : #include <com/sun/star/ucb/CommandAbortedException.hpp>
      26                 :            : #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
      27                 :            : #include <com/sun/star/ucb/NameClash.hpp>
      28                 :            : #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
      29                 :            : #include <com/sun/star/ucb/TransferInfo.hpp>
      30                 :            : #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
      31                 :            : #include <com/sun/star/ucb/XCommandInfo.hpp>
      32                 :            : #include <com/sun/star/ucb/XContentAccess.hpp>
      33                 :            : #include <com/sun/star/ucb/XDynamicResultSet.hpp>
      34                 :            : #include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
      35                 :            : #include <com/sun/star/util/DateTime.hpp>
      36                 :            : #include <com/sun/star/io/XInputStream.hpp>
      37                 :            : #include <unotools/localedatawrapper.hxx>
      38                 :            : #include <rtl/oustringostreaminserter.hxx>
      39                 :            : #include <rtl/strbuf.hxx>
      40                 :            : 
      41                 :            : #include <tools/debug.hxx>
      42                 :            : #include <tools/urlobj.hxx>
      43                 :            : #include <tools/datetime.hxx>
      44                 :            : #include <vcl/svapp.hxx>
      45                 :            : #include <ucbhelper/content.hxx>
      46                 :            : #include <ucbhelper/commandenvironment.hxx>
      47                 :            : #include <comphelper/processfactory.hxx>
      48                 :            : #include <osl/file.hxx>
      49                 :            : #include <vector>
      50                 :            : 
      51                 :            : using namespace com::sun::star;
      52                 :            : using namespace comphelper;
      53                 :            : using namespace osl;
      54                 :            : 
      55                 :            : using ::std::vector;
      56                 :            : 
      57                 :            : using ::rtl::OUString;
      58                 :            : using ::rtl::OStringBuffer;
      59                 :            : using ::rtl::OStringToOUString;
      60                 :            : 
      61                 :            : typedef vector< OUString* > StringList_Impl;
      62                 :            : 
      63                 :            : #define CONVERT_DATETIME( aUnoDT, aToolsDT ) \
      64                 :            :     aToolsDT = DateTime( Date( aUnoDT.Day, aUnoDT.Month, aUnoDT.Year ), \
      65                 :            :                          Time( aUnoDT.Hours, aUnoDT.Minutes, aUnoDT.Seconds, aUnoDT.HundredthSeconds ) );
      66                 :            : 
      67                 :          0 : void AppendDateTime_Impl( const util::DateTime rDT,
      68                 :            :                           String& rRow, const LocaleDataWrapper& rWrapper )
      69                 :            : {
      70                 :          0 :     DateTime aDT( DateTime::EMPTY );
      71 [ #  # ][ #  # ]:          0 :     CONVERT_DATETIME( rDT, aDT );
                 [ #  # ]
      72 [ #  # ][ #  # ]:          0 :     String aDateStr = rWrapper.getDate( aDT );
      73         [ #  # ]:          0 :     aDateStr += rtl::OUString(", ");
      74 [ #  # ][ #  # ]:          0 :     aDateStr += rWrapper.getTime( aDT );
      75 [ #  # ][ #  # ]:          0 :     rRow += aDateStr;
      76                 :          0 : }
      77                 :            : 
      78                 :            : // -----------------------------------------------------------------------
      79                 :            : 
      80                 :         75 : uno::Sequence < OUString > SfxContentHelper::GetResultSet( const String& rURL )
      81                 :            : {
      82                 :         75 :     StringList_Impl* pList = NULL;
      83                 :            :     try
      84                 :            :     {
      85 [ +  - ][ +  + ]:         75 :         ::ucbhelper::Content aCnt( rURL, uno::Reference< ucb::XCommandEnvironment >() );
      86                 :         12 :         uno::Reference< sdbc::XResultSet > xResultSet;
      87                 :         12 :         uno::Reference< ucb::XDynamicResultSet > xDynResultSet;
      88         [ +  - ]:         12 :         uno::Sequence< OUString > aProps(3);
      89         [ +  - ]:         12 :         OUString* pProps = aProps.getArray();
      90                 :         12 :         pProps[0] = "Title";
      91                 :         12 :         pProps[1] = "ContentType";
      92                 :         12 :         pProps[2] = "IsFolder";
      93                 :            : 
      94                 :            :         try
      95                 :            :         {
      96 [ +  - ][ +  - ]:         12 :             xDynResultSet = aCnt.createDynamicCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS );
      97         [ +  - ]:         12 :             if ( xDynResultSet.is() )
      98 [ +  - ][ +  - ]:         12 :                 xResultSet = xDynResultSet->getStaticResultSet();
                 [ +  - ]
              [ #  #  # ]
      99                 :            :         }
     100         [ #  # ]:          0 :         catch( const ucb::CommandAbortedException& )
     101                 :            :         {
     102                 :            :             SAL_WARN( "sfx2.bastyp", "GetResultSet: CommandAbortedException" );
     103                 :            :         }
     104         [ #  # ]:          0 :         catch( const uno::Exception& )
     105                 :            :         {
     106                 :            :             SAL_WARN( "sfx2.bastyp", "GetResultSet: Any other exception" );
     107                 :            :         }
     108                 :            : 
     109                 :            : 
     110         [ +  - ]:         12 :         if ( xResultSet.is() )
     111                 :            :         {
     112 [ +  - ][ +  - ]:         12 :             pList = new StringList_Impl();
     113         [ +  - ]:         12 :             uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
     114         [ +  - ]:         12 :             uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
     115                 :            : 
     116                 :            :             try
     117                 :            :             {
     118 [ +  - ][ +  - ]:         12 :                 while ( xResultSet->next() )
                 [ -  + ]
     119                 :            :                 {
     120 [ #  # ][ #  # ]:          0 :                     String aTitle( xRow->getString(1) );
                 [ #  # ]
     121 [ #  # ][ #  # ]:          0 :                     String aType( xRow->getString(2) );
                 [ #  # ]
     122         [ #  # ]:          0 :                     String aRow = aTitle;
     123         [ #  # ]:          0 :                     aRow += '\t';
     124         [ #  # ]:          0 :                     aRow += aType;
     125         [ #  # ]:          0 :                     aRow += '\t';
     126 [ #  # ][ #  # ]:          0 :                     aRow += String( xContentAccess->queryContentIdentifierString() );
         [ #  # ][ #  # ]
                 [ #  # ]
     127 [ #  # ][ #  # ]:          0 :                     OUString* pRow = new OUString( aRow );
     128         [ #  # ]:          0 :                     pList->push_back( pRow );
     129 [ #  # ][ #  # ]:          0 :                 }
                 [ #  # ]
              [ #  #  # ]
     130                 :            :             }
     131         [ #  # ]:          0 :             catch( const ucb::CommandAbortedException& )
     132                 :            :             {
     133                 :            :                 SAL_WARN( "sfx2.bastyp", "XContentAccess::next(): CommandAbortedException" );
     134                 :            :             }
     135         [ #  # ]:          0 :             catch( const uno::Exception& )
     136                 :            :             {
     137                 :            :                 SAL_WARN( "sfx2.bastyp", "XContentAccess::next(): Any other exception" );
     138                 :         12 :             }
     139 [ +  - ][ +  - ]:         75 :         }
                 [ -  + ]
     140                 :            :     }
     141                 :         63 :     catch( const uno::Exception& e )
     142                 :            :     {
     143                 :            :         SAL_WARN( "sfx2.bastyp", "GetResultSet: Any other exception: " << e.Message );
     144                 :            :     }
     145                 :            : 
     146         [ +  + ]:         75 :     if ( pList )
     147                 :            :     {
     148                 :         12 :         size_t nCount = pList->size();
     149         [ +  - ]:         12 :         uno::Sequence < OUString > aRet( nCount );
     150         [ +  - ]:         12 :         OUString* pRet = aRet.getArray();
     151         [ -  + ]:         12 :         for ( size_t i = 0; i < nCount; ++i )
     152                 :            :         {
     153         [ #  # ]:          0 :             OUString* pEntry = pList->at(i);
     154                 :          0 :             pRet[i] = *( pEntry );
     155         [ #  # ]:          0 :             delete pEntry;
     156                 :            :         }
     157                 :         12 :         pList->clear();
     158         [ +  - ]:         12 :         delete pList;
     159 [ +  - ][ +  - ]:         12 :         return aRet;
     160                 :            :     }
     161                 :            :     else
     162                 :         75 :         return uno::Sequence < OUString > ();
     163                 :            : }
     164                 :            : 
     165                 :            : // -----------------------------------------------------------------------
     166                 :            : 
     167                 :          0 : uno::Sequence< OUString > SfxContentHelper::GetHelpTreeViewContents( const String& rURL )
     168                 :            : {
     169                 :          0 :     StringList_Impl* pProperties = NULL;
     170                 :            :     try
     171                 :            :     {
     172         [ #  # ]:          0 :         uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
     173                 :            :         uno::Reference< task::XInteractionHandler > xInteractionHandler = uno::Reference< task::XInteractionHandler > (
     174 [ #  # ][ #  # ]:          0 :                     xFactory->createInstance( "com.sun.star.task.InteractionHandler" ), uno::UNO_QUERY );
                 [ #  # ]
     175                 :            : 
     176 [ #  # ][ #  # ]:          0 :         ::ucbhelper::Content aCnt( rURL, new ::ucbhelper::CommandEnvironment( xInteractionHandler, uno::Reference< ucb::XProgressHandler >() ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     177                 :          0 :         uno::Reference< sdbc::XResultSet > xResultSet;
     178         [ #  # ]:          0 :         uno::Sequence< OUString > aProps(2);
     179         [ #  # ]:          0 :         OUString* pProps = aProps.getArray();
     180                 :          0 :         pProps[0] = "Title";
     181                 :          0 :         pProps[1] = "IsFolder";
     182                 :            : 
     183                 :            :         try
     184                 :            :         {
     185                 :          0 :             uno::Reference< ucb::XDynamicResultSet > xDynResultSet;
     186 [ #  # ][ #  # ]:          0 :             xDynResultSet = aCnt.createDynamicCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS );
     187         [ #  # ]:          0 :             if ( xDynResultSet.is() )
     188 [ #  # ][ #  # ]:          0 :                 xResultSet = xDynResultSet->getStaticResultSet();
                 [ #  # ]
              [ #  #  # ]
     189                 :            :         }
     190         [ #  # ]:          0 :         catch( const ucb::CommandAbortedException& )
     191                 :            :         {
     192                 :            :         }
     193         [ #  # ]:          0 :         catch( const uno::Exception& )
     194                 :            :         {
     195                 :            :         }
     196                 :            : 
     197         [ #  # ]:          0 :         if ( xResultSet.is() )
     198                 :            :         {
     199 [ #  # ][ #  # ]:          0 :             pProperties = new StringList_Impl();
     200         [ #  # ]:          0 :             uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
     201         [ #  # ]:          0 :             uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
     202                 :            : 
     203                 :            :             try
     204                 :            :             {
     205 [ #  # ][ #  # ]:          0 :                 while ( xResultSet->next() )
                 [ #  # ]
     206                 :            :                 {
     207 [ #  # ][ #  # ]:          0 :                     String aTitle( xRow->getString(1) );
                 [ #  # ]
     208 [ #  # ][ #  # ]:          0 :                     sal_Bool bFolder = xRow->getBoolean(2);
     209         [ #  # ]:          0 :                     String aRow = aTitle;
     210         [ #  # ]:          0 :                     aRow += '\t';
     211 [ #  # ][ #  # ]:          0 :                     aRow += String( xContentAccess->queryContentIdentifierString() );
         [ #  # ][ #  # ]
                 [ #  # ]
     212         [ #  # ]:          0 :                     aRow += '\t';
     213 [ #  # ][ #  # ]:          0 :                     aRow += bFolder ? '1' : '0';
     214 [ #  # ][ #  # ]:          0 :                     OUString* pRow = new OUString( aRow );
     215         [ #  # ]:          0 :                     pProperties->push_back( pRow );
     216 [ #  # ][ #  # ]:          0 :                 }
              [ #  #  # ]
     217                 :            :             }
     218         [ #  # ]:          0 :             catch( const ucb::CommandAbortedException& )
     219                 :            :             {
     220                 :            :             }
     221         [ #  # ]:          0 :             catch( const uno::Exception& )
     222                 :            :             {
     223                 :          0 :             }
     224 [ #  # ][ #  # ]:          0 :         }
                 [ #  # ]
     225                 :            :     }
     226                 :          0 :     catch( const uno::Exception& )
     227                 :            :     {
     228                 :            :     }
     229                 :            : 
     230         [ #  # ]:          0 :     if ( pProperties )
     231                 :            :     {
     232                 :          0 :         size_t nCount = pProperties->size();
     233         [ #  # ]:          0 :         uno::Sequence < OUString > aRet( nCount );
     234         [ #  # ]:          0 :         OUString* pRet = aRet.getArray();
     235         [ #  # ]:          0 :         for ( size_t i = 0; i < nCount; ++i )
     236                 :            :         {
     237         [ #  # ]:          0 :             OUString* pProperty = pProperties->at(i);
     238                 :          0 :             pRet[i] = *( pProperty );
     239         [ #  # ]:          0 :             delete pProperty;
     240                 :            :         }
     241                 :          0 :         pProperties->clear();
     242         [ #  # ]:          0 :         delete pProperties;
     243 [ #  # ][ #  # ]:          0 :         return aRet;
     244                 :            :     }
     245                 :            :     else
     246                 :          0 :         return uno::Sequence < OUString > ();
     247                 :            : }
     248                 :            : 
     249                 :            : // -----------------------------------------------------------------------
     250                 :            : 
     251                 :        386 : String SfxContentHelper::GetActiveHelpString( const String& rURL )
     252                 :            : {
     253                 :        386 :     String aRet;
     254                 :            :     try
     255                 :            :     {
     256         [ +  - ]:        386 :         uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
     257                 :            :         uno::Reference< task::XInteractionHandler > xInteractionHandler = uno::Reference< task::XInteractionHandler > (
     258 [ +  - ][ +  - ]:        386 :                     xFactory->createInstance( "com.sun.star.task.InteractionHandler" ), uno::UNO_QUERY );
                 [ +  - ]
     259 [ +  - ][ +  - ]:        386 :         ::ucbhelper::Content aCnt( rURL, new ::ucbhelper::CommandEnvironment( xInteractionHandler, uno::Reference< ucb::XProgressHandler >() ) );
         [ +  - ][ +  - ]
                 [ +  - ]
     260                 :            :         // open the "active help" stream
     261         [ +  - ]:        386 :         uno::Reference< io::XInputStream > xStream = aCnt.openStream();
     262                 :            :         // and convert it to a String
     263         [ +  - ]:        386 :         uno::Sequence< sal_Int8 > lData;
     264 [ +  - ][ +  - ]:        386 :         sal_Int32 nRead = xStream->readBytes( lData, 1024 );
     265         [ +  + ]:        480 :         while ( nRead > 0 )
     266                 :            :         {
     267                 :         94 :             OStringBuffer sBuffer( nRead );
     268         [ +  + ]:       8440 :             for( sal_Int32 i = 0; i < nRead; ++i )
     269 [ +  - ][ +  - ]:       8346 :                 sBuffer.append( (sal_Char)lData[i] );
     270         [ +  - ]:         94 :             OUString sString = OStringToOUString( sBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 );
     271 [ +  - ][ +  - ]:         94 :             aRet += String( sString );
                 [ +  - ]
     272                 :            : 
     273 [ +  - ][ +  - ]:         94 :             nRead = xStream->readBytes( lData, 1024 );
     274 [ +  - ][ +  - ]:        480 :         }
                 [ #  # ]
     275                 :            :     }
     276         [ #  # ]:          0 :     catch( const uno::Exception& )
     277                 :            :     {
     278                 :            :     }
     279                 :            : 
     280                 :        386 :     return aRet;
     281                 :            : }
     282                 :            : 
     283                 :            : // -----------------------------------------------------------------------
     284                 :            : 
     285                 :          0 : sal_Bool SfxContentHelper::IsHelpErrorDocument( const String& rURL )
     286                 :            : {
     287                 :          0 :     sal_Bool bRet = sal_False;
     288                 :            :     try
     289                 :            :     {
     290                 :            :         ::ucbhelper::Content aCnt( INetURLObject( rURL ).GetMainURL( INetURLObject::NO_DECODE ),
     291 [ #  # ][ #  # ]:          0 :                       uno::Reference< ucb::XCommandEnvironment > () );
         [ #  # ][ #  # ]
                 [ #  # ]
     292         [ #  # ]:          0 :         if ( !( aCnt.getPropertyValue( "IsErrorDocument" ) >>= bRet ) )
     293                 :            :         {
     294                 :            :             SAL_WARN( "sfx2.bastyp", "Property 'IsErrorDocument' is missing" );
     295 [ #  # ][ #  # ]:          0 :         }
     296                 :            :     }
     297         [ #  # ]:          0 :     catch( const uno::Exception& )
     298                 :            :     {
     299                 :            :     }
     300                 :            : 
     301                 :          0 :     return bRet;
     302                 :            : }
     303                 :            : 
     304                 :            : // -----------------------------------------------------------------------
     305                 :            : 
     306                 :          0 : sal_uIntPtr SfxContentHelper::GetSize( const String& rContent )
     307                 :            : {
     308                 :          0 :     sal_uIntPtr nSize = 0;
     309                 :          0 :     sal_Int64 nTemp = 0;
     310 [ #  # ][ #  # ]:          0 :     INetURLObject aObj( rContent );
     311                 :            :     DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
     312                 :            :     try
     313                 :            :     {
     314 [ #  # ][ #  # ]:          0 :         ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment > () );
     315         [ #  # ]:          0 :         aCnt.getPropertyValue( "Size" ) >>= nTemp;
              [ #  #  # ]
                 [ #  # ]
     316                 :            :     }
     317         [ #  # ]:          0 :     catch( const ucb::CommandAbortedException& )
     318                 :            :     {
     319                 :            :         SAL_WARN( "sfx2.bastyp", "CommandAbortedException" );
     320                 :            :     }
     321         [ #  # ]:          0 :     catch( const uno::Exception& )
     322                 :            :     {
     323                 :            :         SAL_WARN( "sfx2.bastyp", "Any other exception" );
     324                 :            :     }
     325                 :          0 :     nSize = (sal_uInt32)nTemp;
     326         [ #  # ]:          0 :     return nSize;
     327                 :            : }
     328                 :            : 
     329                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10