LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sfx2/source/bastyp - helper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 33 101 32.7 %
Date: 2013-07-09 Functions: 4 7 57.1 %
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             : 
      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/task/InteractionHandler.hpp>
      26             : #include <com/sun/star/ucb/CommandAbortedException.hpp>
      27             : #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
      28             : #include <com/sun/star/ucb/NameClash.hpp>
      29             : #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
      30             : #include <com/sun/star/ucb/TransferInfo.hpp>
      31             : #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
      32             : #include <com/sun/star/ucb/XCommandInfo.hpp>
      33             : #include <com/sun/star/ucb/XContentAccess.hpp>
      34             : #include <com/sun/star/ucb/XDynamicResultSet.hpp>
      35             : #include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
      36             : #include <com/sun/star/util/DateTime.hpp>
      37             : #include <com/sun/star/io/XInputStream.hpp>
      38             : #include <unotools/localedatawrapper.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             : 
      58         133 : std::vector<OUString> SfxContentHelper::GetResultSet( const OUString& rURL )
      59             : {
      60         133 :     vector<OUString> aList;
      61             :     try
      62             :     {
      63         183 :         ::ucbhelper::Content aCnt( rURL, uno::Reference< ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
      64         166 :         uno::Reference< sdbc::XResultSet > xResultSet;
      65         166 :         uno::Reference< ucb::XDynamicResultSet > xDynResultSet;
      66         166 :         uno::Sequence< OUString > aProps(3);
      67          83 :         OUString* pProps = aProps.getArray();
      68          83 :         pProps[0] = "Title";
      69          83 :         pProps[1] = "ContentType";
      70          83 :         pProps[2] = "IsFolder";
      71             : 
      72             :         try
      73             :         {
      74          83 :             xDynResultSet = aCnt.createDynamicCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS );
      75          83 :             if ( xDynResultSet.is() )
      76          83 :                 xResultSet = xDynResultSet->getStaticResultSet();
      77             :         }
      78           0 :         catch( const ucb::CommandAbortedException& )
      79             :         {
      80             :             SAL_WARN( "sfx2.bastyp", "GetResultSet: CommandAbortedException" );
      81             :         }
      82           0 :         catch( const uno::Exception& )
      83             :         {
      84             :             SAL_WARN( "sfx2.bastyp", "GetResultSet: Any other exception" );
      85             :         }
      86             : 
      87             : 
      88          83 :         if ( xResultSet.is() )
      89             :         {
      90          83 :             uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
      91         166 :             uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
      92             : 
      93             :             try
      94             :             {
      95         166 :                 while ( xResultSet->next() )
      96             :                 {
      97           0 :                     String aTitle( xRow->getString(1) );
      98           0 :                     String aType( xRow->getString(2) );
      99           0 :                     String aRow = aTitle;
     100           0 :                     aRow += '\t';
     101           0 :                     aRow += aType;
     102           0 :                     aRow += '\t';
     103           0 :                     aRow += String( xContentAccess->queryContentIdentifierString() );
     104           0 :                     aList.push_back( OUString( aRow ) );
     105           0 :                 }
     106             :             }
     107           0 :             catch( const ucb::CommandAbortedException& )
     108             :             {
     109             :                 SAL_WARN( "sfx2.bastyp", "XContentAccess::next(): CommandAbortedException" );
     110             :             }
     111           0 :             catch( const uno::Exception& )
     112             :             {
     113             :                 SAL_WARN( "sfx2.bastyp", "XContentAccess::next(): Any other exception" );
     114          83 :             }
     115          83 :         }
     116             :     }
     117          50 :     catch( const uno::Exception& e )
     118             :     {
     119             :         SAL_WARN( "sfx2.bastyp", "GetResultSet: Any other exception: " << e.Message );
     120             :     }
     121             : 
     122         133 :     return aList;
     123             : }
     124             : 
     125             : // -----------------------------------------------------------------------
     126             : 
     127           0 : std::vector< OUString > SfxContentHelper::GetHelpTreeViewContents( const OUString& rURL )
     128             : {
     129           0 :     vector< OUString > aProperties;
     130             :     try
     131             :     {
     132           0 :         uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
     133             :         uno::Reference< task::XInteractionHandler > xInteractionHandler(
     134           0 :             task::InteractionHandler::createWithParent(xContext, 0), uno::UNO_QUERY_THROW );
     135             : 
     136           0 :         ::ucbhelper::Content aCnt( rURL, new ::ucbhelper::CommandEnvironment( xInteractionHandler, uno::Reference< ucb::XProgressHandler >() ), comphelper::getProcessComponentContext() );
     137           0 :         uno::Reference< sdbc::XResultSet > xResultSet;
     138           0 :         uno::Sequence< OUString > aProps(2);
     139           0 :         OUString* pProps = aProps.getArray();
     140           0 :         pProps[0] = "Title";
     141           0 :         pProps[1] = "IsFolder";
     142             : 
     143             :         try
     144             :         {
     145           0 :             uno::Reference< ucb::XDynamicResultSet > xDynResultSet;
     146           0 :             xDynResultSet = aCnt.createDynamicCursor( aProps, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS );
     147           0 :             if ( xDynResultSet.is() )
     148           0 :                 xResultSet = xDynResultSet->getStaticResultSet();
     149             :         }
     150           0 :         catch( const ucb::CommandAbortedException& )
     151             :         {
     152             :         }
     153           0 :         catch( const uno::Exception& )
     154             :         {
     155             :         }
     156             : 
     157           0 :         if ( xResultSet.is() )
     158             :         {
     159           0 :             uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
     160           0 :             uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
     161             : 
     162             :             try
     163             :             {
     164           0 :                 while ( xResultSet->next() )
     165             :                 {
     166           0 :                     String aTitle( xRow->getString(1) );
     167           0 :                     sal_Bool bFolder = xRow->getBoolean(2);
     168           0 :                     String aRow = aTitle;
     169           0 :                     aRow += '\t';
     170           0 :                     aRow += String( xContentAccess->queryContentIdentifierString() );
     171           0 :                     aRow += '\t';
     172           0 :                     aRow += bFolder ? '1' : '0';
     173           0 :                     aProperties.push_back( OUString( aRow ) );
     174           0 :                 }
     175             :             }
     176           0 :             catch( const ucb::CommandAbortedException& )
     177             :             {
     178             :             }
     179           0 :             catch( const uno::Exception& )
     180             :             {
     181           0 :             }
     182           0 :         }
     183             :     }
     184           0 :     catch( const uno::Exception& )
     185             :     {
     186             :     }
     187             : 
     188           0 :     return aProperties;
     189             : }
     190             : 
     191             : // -----------------------------------------------------------------------
     192             : 
     193         394 : OUString SfxContentHelper::GetActiveHelpString( const OUString& rURL )
     194             : {
     195         394 :     OUStringBuffer aRet;
     196             :     try
     197             :     {
     198         394 :         uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
     199             :         uno::Reference< task::XInteractionHandler > xInteractionHandler(
     200         788 :             task::InteractionHandler::createWithParent(xContext, 0), uno::UNO_QUERY_THROW );
     201         788 :         ::ucbhelper::Content aCnt( rURL, new ::ucbhelper::CommandEnvironment( xInteractionHandler, uno::Reference< ucb::XProgressHandler >() ), comphelper::getProcessComponentContext() );
     202             :         // open the "active help" stream
     203         788 :         uno::Reference< io::XInputStream > xStream = aCnt.openStream();
     204             :         // and convert it to a String
     205         788 :         uno::Sequence< sal_Int8 > lData;
     206         394 :         sal_Int32 nRead = xStream->readBytes( lData, 1024 );
     207         788 :         while ( nRead > 0 )
     208             :         {
     209           0 :             OString sOldString( (sal_Char*)lData.getConstArray(), nRead );
     210           0 :             OUString sString = OStringToOUString( sOldString, RTL_TEXTENCODING_UTF8 );
     211           0 :             aRet.append( sString );
     212             : 
     213           0 :             nRead = xStream->readBytes( lData, 1024 );
     214         394 :         }
     215             :     }
     216           0 :     catch( const uno::Exception& )
     217             :     {
     218             :     }
     219             : 
     220         394 :     return aRet.makeStringAndClear();
     221             : }
     222             : 
     223             : // -----------------------------------------------------------------------
     224             : 
     225           0 : bool SfxContentHelper::IsHelpErrorDocument( const OUString& rURL )
     226             : {
     227           0 :     bool bRet = false;
     228             :     try
     229             :     {
     230             :         ::ucbhelper::Content aCnt( INetURLObject( rURL ).GetMainURL( INetURLObject::NO_DECODE ),
     231             :                       uno::Reference< ucb::XCommandEnvironment >(),
     232           0 :                       comphelper::getProcessComponentContext() );
     233           0 :         if ( !( aCnt.getPropertyValue( "IsErrorDocument" ) >>= bRet ) )
     234             :         {
     235             :             SAL_WARN( "sfx2.bastyp", "Property 'IsErrorDocument' is missing" );
     236           0 :         }
     237             :     }
     238           0 :     catch( const uno::Exception& )
     239             :     {
     240             :     }
     241             : 
     242           0 :     return bRet;
     243             : }
     244             : 
     245             : // -----------------------------------------------------------------------
     246             : 
     247           0 : sal_Int64 SfxContentHelper::GetSize( const OUString& rContent )
     248             : {
     249           0 :     sal_Int64 nSize = 0;
     250           0 :     INetURLObject aObj( rContent );
     251             :     DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
     252             :     try
     253             :     {
     254           0 :         ::ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
     255           0 :         aCnt.getPropertyValue( "Size" ) >>= nSize;
     256             :     }
     257           0 :     catch( const ucb::CommandAbortedException& )
     258             :     {
     259             :         SAL_WARN( "sfx2.bastyp", "CommandAbortedException" );
     260             :     }
     261           0 :     catch( const uno::Exception& )
     262             :     {
     263             :         SAL_WARN( "sfx2.bastyp", "Any other exception" );
     264             :     }
     265           0 :     return nSize;
     266         408 : }
     267             : 
     268             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10