LCOV - code coverage report
Current view: top level - sw/source/core/unocore - swunohelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 70 105 66.7 %
Date: 2014-11-03 Functions: 7 9 77.8 %
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 <com/sun/star/uno/Sequence.h>
      21             : #include <com/sun/star/uno/Exception.hpp>
      22             : #include <com/sun/star/ucb/UniversalContentBroker.hpp>
      23             : #include <com/sun/star/ucb/XContentIdentifier.hpp>
      24             : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
      25             : #include <com/sun/star/ucb/TransferInfo.hpp>
      26             : #include <com/sun/star/ucb/NameClash.hpp>
      27             : #include <com/sun/star/sdbc/XResultSet.hpp>
      28             : #include <com/sun/star/sdbc/XRow.hpp>
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : #include <comphelper/processfactory.hxx>
      31             : #include <comphelper/types.hxx>
      32             : #include <tools/urlobj.hxx>
      33             : #include <tools/datetime.hxx>
      34             : #include <rtl/ustring.hxx>
      35             : #include <ucbhelper/contentidentifier.hxx>
      36             : #include <ucbhelper/content.hxx>
      37             : #include <swunohelper.hxx>
      38             : 
      39             : //UUUU
      40             : #include <svx/xfillit0.hxx>
      41             : #include <svl/itemset.hxx>
      42             : 
      43             : using namespace com::sun::star;
      44             : 
      45             : namespace SWUnoHelper
      46             : {
      47             : 
      48       20042 : sal_Int32 GetEnumAsInt32( const ::com::sun::star::uno::Any& rVal )
      49             : {
      50             :     sal_Int32 eVal;
      51             :     try
      52             :     {
      53       20042 :         eVal = comphelper::getEnumAsINT32( rVal );
      54             :     }
      55           0 :     catch( ::com::sun::star::uno::Exception & )
      56             :     {
      57           0 :         eVal = 0;
      58             :         OSL_FAIL( "can't get EnumAsInt32" );
      59             :     }
      60       20042 :     return eVal;
      61             : }
      62             : 
      63             : // methods for UCB actions
      64           6 : bool UCB_DeleteFile( const OUString& rURL )
      65             : {
      66             :     bool bRemoved;
      67             :     try
      68             :     {
      69             :         ucbhelper::Content aTempContent( rURL,
      70             :                                 ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(),
      71           6 :                                 comphelper::getProcessComponentContext() );
      72             :         aTempContent.executeCommand("delete",
      73           6 :                         ::com::sun::star::uno::makeAny( sal_True ) );
      74           6 :         bRemoved = true;
      75             :     }
      76           0 :     catch( ::com::sun::star::uno::Exception& )
      77             :     {
      78           0 :         bRemoved = false;
      79             :         OSL_FAIL( "Exeception from executeCommand( delete )" );
      80             :     }
      81           6 :     return bRemoved;
      82             : }
      83             : 
      84           4 : bool UCB_CopyFile( const OUString& rURL, const OUString& rNewURL, bool bCopyIsMove )
      85             : {
      86           4 :     bool bCopyCompleted = true;
      87             :     try
      88             :     {
      89           4 :         INetURLObject aURL( rNewURL );
      90           8 :         const OUString sName( aURL.GetName() );
      91           4 :         aURL.removeSegment();
      92           8 :         const OUString sMainURL( aURL.GetMainURL(INetURLObject::NO_DECODE) );
      93             : 
      94             :         ucbhelper::Content aTempContent( sMainURL,
      95             :                                 ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(),
      96           8 :                                 comphelper::getProcessComponentContext() );
      97             : 
      98           8 :         ::com::sun::star::uno::Any aAny;
      99           8 :         ::com::sun::star::ucb::TransferInfo aInfo;
     100           4 :         aInfo.NameClash = ::com::sun::star::ucb::NameClash::ERROR;
     101           4 :         aInfo.NewTitle = sName;
     102           4 :         aInfo.SourceURL = rURL;
     103           4 :         aInfo.MoveData = bCopyIsMove;
     104           4 :         aAny <<= aInfo;
     105           8 :         aTempContent.executeCommand( "transfer", aAny );
     106             :     }
     107           0 :     catch( ::com::sun::star::uno::Exception& )
     108             :     {
     109             :         OSL_FAIL( "Exeception from executeCommand( transfer )" );
     110           0 :         bCopyCompleted = false;
     111             :     }
     112           4 :     return bCopyCompleted;
     113             : }
     114             : 
     115           0 : bool UCB_IsCaseSensitiveFileName( const OUString& rURL )
     116             : {
     117             :     bool bCaseSensitive;
     118             :     try
     119             :     {
     120           0 :         INetURLObject aTempObj( rURL );
     121           0 :         aTempObj.SetBase( aTempObj.GetBase().toAsciiLowerCase() );
     122             :         ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentIdentifier > xRef1 = new
     123           0 :                 ucbhelper::ContentIdentifier( aTempObj.GetMainURL( INetURLObject::NO_DECODE ));
     124             : 
     125           0 :         aTempObj.SetBase(aTempObj.GetBase().toAsciiUpperCase());
     126             :         ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContentIdentifier > xRef2 = new
     127           0 :                 ucbhelper::ContentIdentifier( aTempObj.GetMainURL( INetURLObject::NO_DECODE ));
     128             : 
     129             :         ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XUniversalContentBroker > xUcb =
     130           0 :               com::sun::star::ucb::UniversalContentBroker::create(comphelper::getProcessComponentContext());
     131             : 
     132           0 :         sal_Int32 nCompare = xUcb->compareContentIds( xRef1, xRef2 );
     133           0 :         bCaseSensitive = 0 != nCompare;
     134             :     }
     135           0 :     catch( ::com::sun::star::uno::Exception& )
     136             :     {
     137           0 :         bCaseSensitive = false;
     138             :         OSL_FAIL( "Exeception from compareContentIds()" );
     139             :     }
     140           0 :     return bCaseSensitive;
     141             : }
     142             : 
     143           4 : bool UCB_IsReadOnlyFileName( const OUString& rURL )
     144             : {
     145           4 :     bool bIsReadOnly = false;
     146             :     try
     147             :     {
     148           4 :         ucbhelper::Content aCnt( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
     149           8 :         ::com::sun::star::uno::Any aAny = aCnt.getPropertyValue("IsReadOnly");
     150           4 :         if(aAny.hasValue())
     151           8 :             bIsReadOnly = *(sal_Bool*)aAny.getValue();
     152             :     }
     153           0 :     catch( ::com::sun::star::uno::Exception& )
     154             :     {
     155           0 :         bIsReadOnly = false;
     156             :     }
     157           4 :     return bIsReadOnly;
     158             : }
     159             : 
     160           0 : bool UCB_IsFile( const OUString& rURL )
     161             : {
     162           0 :     bool bExists = false;
     163             :     try
     164             :     {
     165           0 :         ::ucbhelper::Content aContent( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
     166           0 :         bExists = aContent.isDocument();
     167             :     }
     168           0 :     catch (::com::sun::star::uno::Exception &)
     169             :     {
     170             :     }
     171           0 :     return bExists;
     172             : }
     173             : 
     174           4 : bool UCB_IsDirectory( const OUString& rURL )
     175             : {
     176           4 :     bool bExists = false;
     177             :     try
     178             :     {
     179           4 :         ::ucbhelper::Content aContent( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
     180           4 :         bExists = aContent.isFolder();
     181             :     }
     182           0 :     catch (::com::sun::star::uno::Exception &)
     183             :     {
     184             :     }
     185           4 :     return bExists;
     186             : }
     187             : 
     188             :     // get a list of files from the folder of the URL
     189             :     // options: pExtension = 0 -> all, else this specific extension
     190             :     //          pDateTime != 0 -> returns also the modified date/time of
     191             :     //                       the files in a std::vector<OUString> -->
     192             :     //                       !! objects must be deleted from the caller!!
     193           4 : bool UCB_GetFileListOfFolder( const OUString& rURL,
     194             :                                 std::vector<OUString>& rList,
     195             :                                 const OUString* pExtension,
     196             :                                 std::vector< ::DateTime* >* pDateTimeList )
     197             : {
     198           4 :     bool bOk = false;
     199             :     try
     200             :     {
     201           4 :         ucbhelper::Content aCnt( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
     202           8 :         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > xResultSet;
     203             : 
     204           4 :         const sal_Int32 nSeqSize = pDateTimeList ? 2 : 1;
     205           8 :         ::com::sun::star::uno::Sequence < OUString > aProps( nSeqSize );
     206           4 :         OUString* pProps = aProps.getArray();
     207           4 :         pProps[ 0 ] = "Title";
     208           4 :         if( pDateTimeList )
     209           0 :             pProps[ 1 ] = "DateModified";
     210             : 
     211             :         try
     212             :         {
     213           4 :             xResultSet = aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY );
     214             :         }
     215           0 :         catch( ::com::sun::star::uno::Exception& )
     216             :         {
     217             :             OSL_FAIL( "create cursor failed!" );
     218             :         }
     219             : 
     220           4 :         if( xResultSet.is() )
     221             :         {
     222           4 :             ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow > xRow( xResultSet, ::com::sun::star::uno::UNO_QUERY );
     223           4 :             const sal_Int32 nExtLen = pExtension ? pExtension->getLength() : 0;
     224             :             try
     225             :             {
     226           4 :                 if( xResultSet->first() )
     227             :                 {
     228           8 :                     do {
     229           8 :                         const OUString sTitle( xRow->getString( 1 ) );
     230          24 :                         if( !nExtLen ||
     231          16 :                             ( sTitle.getLength() > nExtLen &&
     232           8 :                               sTitle.endsWith( *pExtension )) )
     233             :                         {
     234           8 :                             rList.push_back( sTitle );
     235             : 
     236           8 :                             if( pDateTimeList )
     237             :                             {
     238           0 :                                 ::com::sun::star::util::DateTime aStamp = xRow->getTimestamp(2);
     239             :                                 ::DateTime* pDateTime = new ::DateTime(
     240             :                                         ::Date( aStamp.Day,
     241             :                                                 aStamp.Month,
     242             :                                                 aStamp.Year ),
     243             :                                         ::tools::Time( aStamp.Hours,
     244             :                                                 aStamp.Minutes,
     245             :                                                 aStamp.Seconds,
     246           0 :                                                 aStamp.NanoSeconds ));
     247           0 :                                 pDateTimeList->push_back( pDateTime );
     248             :                             }
     249           8 :                         }
     250             : 
     251           8 :                     } while( xResultSet->next() );
     252             :                 }
     253           4 :                 bOk = true;
     254             :             }
     255           0 :             catch( ::com::sun::star::uno::Exception& )
     256             :             {
     257             :                 OSL_FAIL( "Exception caught!" );
     258           4 :             }
     259           4 :         }
     260             :     }
     261           0 :     catch( ::com::sun::star::uno::Exception& )
     262             :     {
     263             :         OSL_FAIL( "Exception caught!" );
     264           0 :         bOk = false;
     265             :     }
     266           4 :     return bOk;
     267             : }
     268             : 
     269             : //UUUU
     270       94084 : bool needToMapFillItemsToSvxBrushItemTypes(const SfxItemSet& rSet)
     271             : {
     272       94084 :     const XFillStyleItem* pXFillStyleItem(static_cast< const XFillStyleItem*  >(rSet.GetItem(XATTR_FILLSTYLE, false)));
     273             : 
     274       94084 :     if(!pXFillStyleItem)
     275             :     {
     276       93844 :         return false;
     277             :     }
     278             : 
     279             :     // here different FillStyles can be excluded for export; it will depend on the
     280             :     // quality these fallbacks can reach. That again is done in getSvxBrushItemFromSourceSet,
     281             :     // take a look there how the superset of DrawObject FillStyles is mapped to SvxBrushItem.
     282             :     // For now, take them all - except drawing::FillStyle_NONE
     283             : 
     284         240 :     if(drawing::FillStyle_NONE != pXFillStyleItem->GetValue())
     285             :     {
     286         198 :         return true;
     287             :     }
     288             : 
     289             :     // if(XFILL_SOLID == pXFillStyleItem->GetValue() || XFILL_BITMAP == pXFillStyleItem->GetValue())
     290             :     // {
     291             :     //     return true;
     292             :     // }
     293             : 
     294          42 :     return false;
     295             : }
     296             : 
     297             : }
     298             : 
     299             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10