LCOV - code coverage report
Current view: top level - ucbhelper/source/client - content.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 397 516 76.9 %
Date: 2014-04-11 Functions: 61 71 85.9 %
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 "sal/config.h"
      21             : 
      22             : #include <cassert>
      23             : 
      24             : #include <osl/diagnose.h>
      25             : #include <osl/mutex.hxx>
      26             : #include <salhelper/simplereferenceobject.hxx>
      27             : #include <cppuhelper/weak.hxx>
      28             : 
      29             : #include <cppuhelper/implbase1.hxx>
      30             : #include <com/sun/star/ucb/CheckinArgument.hpp>
      31             : #include <com/sun/star/ucb/ContentCreationError.hpp>
      32             : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
      33             : #include <com/sun/star/ucb/XCommandInfo.hpp>
      34             : #include <com/sun/star/ucb/XCommandProcessor.hpp>
      35             : #include <com/sun/star/ucb/Command.hpp>
      36             : #include <com/sun/star/ucb/CommandInfo.hpp>
      37             : #include <com/sun/star/ucb/ContentAction.hpp>
      38             : #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
      39             : #include <com/sun/star/ucb/InsertCommandArgument.hpp>
      40             : #include <com/sun/star/ucb/GlobalTransferCommandArgument2.hpp>
      41             : #include <com/sun/star/ucb/NameClash.hpp>
      42             : #include <com/sun/star/ucb/OpenMode.hpp>
      43             : #include <com/sun/star/ucb/XContentCreator.hpp>
      44             : #include <com/sun/star/ucb/XContentEventListener.hpp>
      45             : #include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
      46             : #include <com/sun/star/ucb/XContentProvider.hpp>
      47             : #include <com/sun/star/ucb/XContentProviderManager.hpp>
      48             : #include <com/sun/star/ucb/XDynamicResultSet.hpp>
      49             : #include <com/sun/star/ucb/SortedDynamicResultSetFactory.hpp>
      50             : #include <com/sun/star/ucb/UniversalContentBroker.hpp>
      51             : #include <com/sun/star/ucb/XUniversalContentBroker.hpp>
      52             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      53             : #include <com/sun/star/beans/Property.hpp>
      54             : #include <com/sun/star/beans/PropertyValue.hpp>
      55             : #include <com/sun/star/sdbc/XResultSet.hpp>
      56             : #include <com/sun/star/sdbc/XRow.hpp>
      57             : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      58             : #include <com/sun/star/beans/UnknownPropertyException.hpp>
      59             : #include <ucbhelper/macros.hxx>
      60             : #include <ucbhelper/content.hxx>
      61             : #include <ucbhelper/activedatasink.hxx>
      62             : #include <ucbhelper/activedatastreamer.hxx>
      63             : #include <ucbhelper/interactionrequest.hxx>
      64             : #include <ucbhelper/cancelcommandexecution.hxx>
      65             : 
      66             : using namespace com::sun::star::container;
      67             : using namespace com::sun::star::beans;
      68             : using namespace com::sun::star::io;
      69             : using namespace com::sun::star::lang;
      70             : using namespace com::sun::star::sdbc;
      71             : using namespace com::sun::star::task;
      72             : using namespace com::sun::star::ucb;
      73             : using namespace com::sun::star::uno;
      74             : 
      75             : namespace ucbhelper
      76             : {
      77             : 
      78        6678 : class EmptyInputStream : public ::cppu::WeakImplHelper1< XInputStream >
      79             : {
      80             : public:
      81             :     virtual sal_Int32 SAL_CALL readBytes(
      82             :         Sequence< sal_Int8 > & data, sal_Int32 nBytesToRead )
      83             :         throw (IOException, RuntimeException, std::exception) SAL_OVERRIDE;
      84             :     virtual sal_Int32 SAL_CALL readSomeBytes(
      85             :         Sequence< sal_Int8 > & data, sal_Int32 nMaxBytesToRead )
      86             :         throw (IOException, RuntimeException, std::exception) SAL_OVERRIDE;
      87             :     virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip )
      88             :         throw (IOException, RuntimeException, std::exception) SAL_OVERRIDE;
      89             :     virtual sal_Int32 SAL_CALL available()
      90             :         throw (IOException, RuntimeException, std::exception) SAL_OVERRIDE;
      91             :     virtual void SAL_CALL closeInput()
      92             :         throw (IOException, RuntimeException, std::exception) SAL_OVERRIDE;
      93             : };
      94             : 
      95           0 : sal_Int32 EmptyInputStream::readBytes(
      96             :     Sequence< sal_Int8 > & data, sal_Int32 )
      97             :     throw (IOException, RuntimeException, std::exception)
      98             : {
      99           0 :     data.realloc( 0 );
     100           0 :     return 0;
     101             : }
     102             : 
     103           0 : sal_Int32 EmptyInputStream::readSomeBytes(
     104             :     Sequence< sal_Int8 > & data, sal_Int32 )
     105             :     throw (IOException, RuntimeException, std::exception)
     106             : {
     107           0 :     data.realloc( 0 );
     108           0 :     return 0;
     109             : }
     110             : 
     111           0 : void EmptyInputStream::skipBytes( sal_Int32 )
     112             :     throw (IOException, RuntimeException, std::exception)
     113             : {
     114           0 : }
     115             : 
     116           0 : sal_Int32 EmptyInputStream::available()
     117             :     throw (IOException, RuntimeException, std::exception)
     118             : {
     119           0 :     return 0;
     120             : }
     121             : 
     122           0 : void EmptyInputStream::closeInput()
     123             :     throw (IOException, RuntimeException, std::exception)
     124             : {
     125           0 : }
     126             : 
     127             : 
     128             : 
     129             : 
     130             : 
     131             : // class ContentEventListener_Impl.
     132             : 
     133             : 
     134             : 
     135             : 
     136      213530 : class ContentEventListener_Impl : public cppu::OWeakObject,
     137             :                                       public XContentEventListener
     138             : {
     139             :     Content_Impl& m_rContent;
     140             : 
     141             : public:
     142      106859 :     ContentEventListener_Impl( Content_Impl& rContent )
     143      106859 :     : m_rContent( rContent ) {}
     144             : 
     145             :     // XInterface
     146             :     virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType )
     147             :         throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     148             :     virtual void SAL_CALL acquire()
     149             :         throw() SAL_OVERRIDE;
     150             :     virtual void SAL_CALL release()
     151             :         throw() SAL_OVERRIDE;
     152             : 
     153             :     // XContentEventListener
     154             :     virtual void SAL_CALL contentEvent( const ContentEvent& evt )
     155             :         throw( RuntimeException, std::exception ) SAL_OVERRIDE;
     156             : 
     157             :     // XEventListener ( base of XContentEventListener )
     158             :     virtual void SAL_CALL disposing( const EventObject& Source )
     159             :         throw( RuntimeException, std::exception ) SAL_OVERRIDE;
     160             : };
     161             : 
     162             : 
     163             : 
     164             : 
     165             : // class Content_Impl.
     166             : 
     167             : 
     168             : 
     169             : 
     170             : class Content_Impl : public salhelper::SimpleReferenceObject
     171             : {
     172             : friend class ContentEventListener_Impl;
     173             : 
     174             :     mutable OUString               m_aURL;
     175             :     Reference< XComponentContext >      m_xCtx;
     176             :     Reference< XContent >               m_xContent;
     177             :     Reference< XCommandProcessor >          m_xCommandProcessor;
     178             :     Reference< XCommandEnvironment >    m_xEnv;
     179             :     Reference< XContentEventListener >  m_xContentEventListener;
     180             :     mutable osl::Mutex                  m_aMutex;
     181             : 
     182             : private:
     183             :     void reinit( const Reference< XContent >& xContent );
     184             :     void disposing(const EventObject& Source);
     185             : 
     186             : public:
     187       33743 :     Content_Impl() {};
     188             :     Content_Impl( const Reference< XComponentContext >& rCtx,
     189             :                   const Reference< XContent >& rContent,
     190             :                   const Reference< XCommandEnvironment >& rEnv );
     191             : 
     192             :     virtual ~Content_Impl();
     193             : 
     194             :     const OUString&           getURL() const;
     195             :     Reference< XContent >          getContent();
     196             :     Reference< XCommandProcessor > getCommandProcessor();
     197        4158 :     Reference< XComponentContext > getComponentContext()
     198        4158 :     { assert(m_xCtx.is()); return m_xCtx; }
     199             : 
     200             :     Any  executeCommand( const Command& rCommand );
     201             : 
     202             :     inline const Reference< XCommandEnvironment >& getEnvironment() const;
     203             :     inline void setEnvironment(
     204             :                         const Reference< XCommandEnvironment >& xNewEnv );
     205             : 
     206             :     void inserted();
     207             : };
     208             : 
     209             : 
     210             : // Helpers.
     211             : 
     212             : 
     213        3614 : static void ensureContentProviderForURL( const Reference< XUniversalContentBroker >& rBroker,
     214             :                                          const OUString & rURL )
     215             :     throw ( ContentCreationException, RuntimeException )
     216             : {
     217             :     Reference< XContentProvider > xProv
     218        3614 :         = rBroker->queryContentProvider( rURL );
     219        3614 :     if ( !xProv.is() )
     220             :     {
     221             :         throw ContentCreationException(
     222        7228 :             "No Content Provider available for URL: " + rURL,
     223             :             Reference< XInterface >(),
     224       10842 :             ContentCreationError_NO_CONTENT_PROVIDER );
     225        3614 :     }
     226           0 : }
     227             : 
     228             : 
     229       79549 : static Reference< XContentIdentifier > getContentIdentifierThrow(
     230             :                                     const Reference< XUniversalContentBroker > & rBroker,
     231             :                                     const OUString & rURL)
     232             :     throw (ContentCreationException, RuntimeException)
     233             : {
     234             :     Reference< XContentIdentifier > xId
     235       79549 :         = rBroker->createContentIdentifier( rURL );
     236             : 
     237       79549 :     if (!xId.is())
     238             :     {
     239           0 :         ensureContentProviderForURL( rBroker, rURL );
     240             : 
     241             :         throw ContentCreationException(
     242             :             "Unable to create Content Identifier!",
     243             :             Reference< XInterface >(),
     244           0 :             ContentCreationError_IDENTIFIER_CREATION_FAILED );
     245             :     }
     246             : 
     247       79549 :     return xId;
     248             : }
     249             : 
     250        7691 : static Reference< XContentIdentifier > getContentIdentifierNoThrow(
     251             :                                     const Reference< XUniversalContentBroker > & rBroker,
     252             :                                     const OUString & rURL)
     253             :     throw (RuntimeException)
     254             : {
     255        7691 :     return rBroker->createContentIdentifier(rURL);
     256             : }
     257             : 
     258       79549 : static Reference< XContent > getContentThrow(
     259             :                                     const Reference< XUniversalContentBroker > & rBroker,
     260             :                                     const Reference< XContentIdentifier > & xId)
     261             :     throw ( ContentCreationException, RuntimeException )
     262             : {
     263       79549 :     Reference< XContent > xContent;
     264      159098 :     OUString msg;
     265             :     try
     266             :     {
     267       79549 :         xContent = rBroker->queryContent( xId );
     268             :     }
     269           0 :     catch ( IllegalIdentifierException const & e )
     270             :     {
     271           0 :         msg = e.Message;
     272             :         // handled below.
     273             :     }
     274             : 
     275       79549 :     if ( !xContent.is() )
     276             :     {
     277        7228 :         ensureContentProviderForURL( rBroker, xId->getContentIdentifier() );
     278             : 
     279             :         throw ContentCreationException(
     280           0 :             "Unable to create Content! " + msg,
     281             :             Reference< XInterface >(),
     282           0 :             ContentCreationError_CONTENT_CREATION_FAILED );
     283             :     }
     284             : 
     285      151870 :     return xContent;
     286             : }
     287             : 
     288             : 
     289        7691 : static Reference< XContent > getContentNoThrow(
     290             :                                     const Reference< XUniversalContentBroker > & rBroker,
     291             :                                     const Reference< XContentIdentifier > & xId)
     292             :     throw ( RuntimeException )
     293             : {
     294        7691 :     Reference< XContent > xContent;
     295             :     try
     296             :     {
     297        7691 :         xContent = rBroker->queryContent( xId );
     298             :     }
     299           0 :     catch ( IllegalIdentifierException const & e )
     300             :     {
     301             :         SAL_WARN("ucbhelper", "getContentNoThrow: exception: " << e.Message);
     302             :     }
     303             : 
     304        7691 :     return xContent;
     305             : }
     306             : 
     307             : 
     308             : 
     309             : 
     310             : // Content Implementation.
     311             : 
     312             : 
     313             : 
     314             : 
     315       33743 : Content::Content()
     316       33743 : : m_xImpl( new Content_Impl )
     317             : {
     318       33743 : }
     319             : 
     320             : 
     321       79549 : Content::Content( const OUString& rURL,
     322             :                   const Reference< XCommandEnvironment >& rEnv,
     323             :                   const Reference< XComponentContext >& rCtx )
     324       83163 :     throw ( ContentCreationException, RuntimeException )
     325             : {
     326             :     Reference< XUniversalContentBroker > pBroker(
     327       79549 :         UniversalContentBroker::create( rCtx ) );
     328             : 
     329             :     Reference< XContentIdentifier > xId
     330      159098 :         = getContentIdentifierThrow(pBroker, rURL);
     331             : 
     332      155484 :     Reference< XContent > xContent = getContentThrow(pBroker, xId);
     333             : 
     334      155484 :     m_xImpl = new Content_Impl( rCtx, xContent, rEnv );
     335       75935 : }
     336             : 
     337             : 
     338       23381 : Content::Content( const Reference< XContent >& rContent,
     339             :                   const Reference< XCommandEnvironment >& rEnv,
     340             :                   const Reference< XComponentContext >& rCtx )
     341       23381 :     throw ( ContentCreationException, RuntimeException )
     342             : {
     343       23381 :     m_xImpl = new Content_Impl( rCtx, rContent, rEnv );
     344       23381 : }
     345             : 
     346             : 
     347        1387 : Content::Content( const Content& rOther )
     348             : {
     349        1387 :     m_xImpl = rOther.m_xImpl;
     350        1387 : }
     351             : 
     352             : 
     353             : // static
     354        7691 : bool Content::create( const OUString& rURL,
     355             :                           const Reference< XCommandEnvironment >& rEnv,
     356             :                           const Reference< XComponentContext >& rCtx,
     357             :                           Content& rContent )
     358             : {
     359             :     Reference< XUniversalContentBroker > pBroker(
     360        7691 :         UniversalContentBroker::create( rCtx ) );
     361             : 
     362             :     Reference< XContentIdentifier > xId
     363       15382 :         = getContentIdentifierNoThrow(pBroker, rURL);
     364        7691 :     if ( !xId.is() )
     365           0 :         return false;
     366             : 
     367       15382 :     Reference< XContent > xContent = getContentNoThrow(pBroker, xId);
     368        7691 :     if ( !xContent.is() )
     369         148 :         return false;
     370             : 
     371             :     rContent.m_xImpl
     372        7543 :         = new Content_Impl( rCtx, xContent, rEnv );
     373             : 
     374       15234 :     return true;
     375             : }
     376             : 
     377             : 
     378      134176 : Content::~Content()
     379             : {
     380      134176 : }
     381             : 
     382             : 
     383       23147 : Content& Content::operator=( const Content& rOther )
     384             : {
     385       23147 :     m_xImpl = rOther.m_xImpl;
     386       23147 :     return *this;
     387             : }
     388             : 
     389             : 
     390       62655 : Reference< XContent > Content::get() const
     391             : {
     392       62655 :     return m_xImpl->getContent();
     393             : }
     394             : 
     395             : 
     396        5725 : const OUString& Content::getURL() const
     397             : {
     398        5725 :     return m_xImpl->getURL();
     399             : }
     400             : 
     401             : 
     402           6 : const Reference< XCommandEnvironment >& Content::getCommandEnvironment() const
     403             : {
     404           6 :     return m_xImpl->getEnvironment();
     405             : }
     406             : 
     407             : 
     408        2305 : void Content::setCommandEnvironment(
     409             :                         const Reference< XCommandEnvironment >& xNewEnv )
     410             : {
     411        2305 :     m_xImpl->setEnvironment( xNewEnv );
     412        2305 : }
     413             : 
     414             : 
     415           0 : Reference< XCommandInfo > Content::getCommands()
     416             :     throw( CommandAbortedException, RuntimeException, Exception )
     417             : {
     418           0 :     Command aCommand;
     419           0 :     aCommand.Name     = "getCommandInfo";
     420           0 :     aCommand.Handle   = -1; // n/a
     421           0 :     aCommand.Argument = Any();
     422             : 
     423           0 :     Any aResult = m_xImpl->executeCommand( aCommand );
     424             : 
     425           0 :     Reference< XCommandInfo > xInfo;
     426           0 :     aResult >>= xInfo;
     427           0 :     return xInfo;
     428             : }
     429             : 
     430             : 
     431       13040 : Reference< XPropertySetInfo > Content::getProperties()
     432             :     throw( CommandAbortedException, RuntimeException, Exception )
     433             : {
     434       13040 :     Command aCommand;
     435       13040 :     aCommand.Name     = "getPropertySetInfo";
     436       13040 :     aCommand.Handle   = -1; // n/a
     437       13040 :     aCommand.Argument = Any();
     438             : 
     439       26080 :     Any aResult = m_xImpl->executeCommand( aCommand );
     440             : 
     441       13040 :     Reference< XPropertySetInfo > xInfo;
     442       13040 :     aResult >>= xInfo;
     443       26080 :     return xInfo;
     444             : }
     445             : 
     446             : 
     447       39446 : Any Content::getPropertyValue( const OUString& rPropertyName )
     448             :     throw( CommandAbortedException, RuntimeException, Exception )
     449             : {
     450       39446 :     Sequence< OUString > aNames( 1 );
     451       39446 :     aNames.getArray()[ 0 ] = rPropertyName;
     452             : 
     453       66878 :     Sequence< Any > aRet = getPropertyValues( aNames );
     454       54864 :     return aRet.getConstArray()[ 0 ];
     455             : }
     456             : 
     457             : 
     458         478 : Any Content::setPropertyValue( const OUString& rName,
     459             :                                 const Any& rValue )
     460             :     throw( CommandAbortedException, RuntimeException, Exception )
     461             : {
     462         478 :     Sequence< OUString > aNames( 1 );
     463         478 :     aNames.getArray()[ 0 ] = rName;
     464             : 
     465         956 :     Sequence< Any > aValues( 1 );
     466         478 :     aValues.getArray()[ 0 ] = rValue;
     467             : 
     468         956 :     Sequence< Any > aErrors = setPropertyValues( aNames, aValues );
     469         956 :     return aErrors.getConstArray()[ 0 ];
     470             : }
     471             : 
     472             : 
     473       39446 : Sequence< Any > Content::getPropertyValues(
     474             :                             const Sequence< OUString >& rPropertyNames )
     475             :     throw( CommandAbortedException, RuntimeException, Exception )
     476             : {
     477       39446 :     Reference< XRow > xRow = getPropertyValuesInterface( rPropertyNames );
     478             : 
     479       27432 :     sal_Int32 nCount = rPropertyNames.getLength();
     480       27432 :     Sequence< Any > aValues( nCount );
     481             : 
     482       27432 :     if ( xRow.is() )
     483             :     {
     484       27432 :         Any* pValues = aValues.getArray();
     485             : 
     486       54864 :         for ( sal_Int32 n = 0; n < nCount; ++n )
     487       27432 :             pValues[ n ] = xRow->getObject( n + 1, Reference< XNameAccess >() );
     488             :     }
     489             : 
     490       27432 :     return aValues;
     491             : }
     492             : 
     493             : 
     494       39446 : Reference< XRow > Content::getPropertyValuesInterface(
     495             :                             const Sequence< OUString >& rPropertyNames )
     496             :     throw( CommandAbortedException, RuntimeException, Exception )
     497             : {
     498       39446 :     sal_Int32 nCount = rPropertyNames.getLength();
     499       39446 :     Sequence< Property > aProps( nCount );
     500       39446 :     Property* pProps = aProps.getArray();
     501             : 
     502       39446 :     const OUString* pNames  = rPropertyNames.getConstArray();
     503             : 
     504       78892 :     for ( sal_Int32 n = 0; n< nCount; ++n )
     505             :     {
     506       39446 :         Property& rProp = pProps[ n ];
     507             : 
     508       39446 :         rProp.Name       = pNames[ n ];
     509       39446 :         rProp.Handle     = -1; // n/a
     510             : //        rProp.Type       =
     511             : //        rProp.Attributes = ;
     512             :     }
     513             : 
     514       78892 :     Command aCommand;
     515       39446 :     aCommand.Name     = "getPropertyValues";
     516       39446 :     aCommand.Handle   = -1; // n/a
     517       39446 :     aCommand.Argument <<= aProps;
     518             : 
     519       66878 :     Any aResult = m_xImpl->executeCommand( aCommand );
     520             : 
     521       27432 :     Reference< XRow > xRow;
     522       27432 :     aResult >>= xRow;
     523       66878 :     return xRow;
     524             : }
     525             : 
     526             : 
     527        2704 : Sequence< Any > Content::setPropertyValues(
     528             :                             const Sequence< OUString >& rPropertyNames,
     529             :                                 const Sequence< Any >& rValues )
     530             :     throw( CommandAbortedException, RuntimeException, Exception )
     531             : {
     532        2704 :     if ( rPropertyNames.getLength() != rValues.getLength() )
     533             :     {
     534             :         ucbhelper::cancelCommandExecution(
     535             :             makeAny( IllegalArgumentException(
     536             :                         OUString(
     537             :                             "Length of property names sequence and value "
     538             :                             "sequence are unequal!" ),
     539             :                         get(),
     540           0 :                         -1 ) ),
     541           0 :             m_xImpl->getEnvironment() );
     542             :         // Unreachable
     543             :     }
     544             : 
     545        2704 :     sal_Int32 nCount = rValues.getLength();
     546        2704 :     Sequence< PropertyValue > aProps( nCount );
     547        2704 :     PropertyValue* pProps = aProps.getArray();
     548             : 
     549        2704 :     const OUString* pNames  = rPropertyNames.getConstArray();
     550        2704 :     const Any* pValues = rValues.getConstArray();
     551             : 
     552        5408 :     for ( sal_Int32 n = 0; n< nCount; ++n )
     553             :     {
     554        2704 :         PropertyValue& rProp = pProps[ n ];
     555             : 
     556        2704 :         rProp.Name   = pNames[ n ];
     557        2704 :         rProp.Handle = -1; // n/a
     558        2704 :         rProp.Value  = pValues[ n ];
     559             : //        rProp.State  = ;
     560             :     }
     561             : 
     562        5408 :     Command aCommand;
     563        2704 :     aCommand.Name     = "setPropertyValues";
     564        2704 :     aCommand.Handle   = -1; // n/a
     565        2704 :     aCommand.Argument <<= aProps;
     566             : 
     567        5408 :     Any aResult = m_xImpl->executeCommand( aCommand );
     568             : 
     569        2704 :     Sequence< Any > aErrors;
     570        2704 :     aResult >>= aErrors;
     571        5408 :     return aErrors;
     572             : }
     573             : 
     574             : 
     575       30717 : Any Content::executeCommand( const OUString& rCommandName,
     576             :                              const Any& rCommandArgument )
     577             :     throw( CommandAbortedException, RuntimeException, Exception )
     578             : {
     579       30717 :     Command aCommand;
     580       30717 :     aCommand.Name     = rCommandName;
     581       30717 :     aCommand.Handle   = -1; // n/a
     582       30717 :     aCommand.Argument = rCommandArgument;
     583             : 
     584       30717 :     return m_xImpl->executeCommand( aCommand );
     585             : }
     586             : 
     587             : 
     588       27990 : Any Content::createCursorAny( const Sequence< OUString >& rPropertyNames,
     589             :                               ResultSetInclude eMode )
     590             :     throw( CommandAbortedException, RuntimeException, Exception )
     591             : {
     592       27990 :     sal_Int32 nCount = rPropertyNames.getLength();
     593       27990 :     Sequence< Property > aProps( nCount );
     594       27990 :     Property* pProps = aProps.getArray();
     595       27990 :     const OUString* pNames = rPropertyNames.getConstArray();
     596       55925 :     for ( sal_Int32 n = 0; n < nCount; ++n )
     597             :     {
     598       27935 :         Property& rProp = pProps[ n ];
     599       27935 :         rProp.Name   = pNames[ n ];
     600       27935 :         rProp.Handle = -1; // n/a
     601             :     }
     602             : 
     603       55980 :     OpenCommandArgument2 aArg;
     604             :     aArg.Mode       = ( eMode == INCLUDE_FOLDERS_ONLY )
     605             :                         ? OpenMode::FOLDERS
     606             :                         : ( eMode == INCLUDE_DOCUMENTS_ONLY )
     607       27990 :                             ? OpenMode::DOCUMENTS : OpenMode::ALL;
     608       27990 :     aArg.Priority   = 0; // unused
     609       27990 :     aArg.Sink.clear(); // unused
     610       27990 :     aArg.Properties = aProps;
     611             : 
     612       55980 :     Command aCommand;
     613       27990 :     aCommand.Name     = "open";
     614       27990 :     aCommand.Handle   = -1; // n/a
     615       27990 :     aCommand.Argument <<= aArg;
     616             : 
     617       55980 :     return m_xImpl->executeCommand( aCommand );
     618             : }
     619             : 
     620             : 
     621       27859 : Reference< XResultSet > Content::createCursor(
     622             :                             const Sequence< OUString >& rPropertyNames,
     623             :                             ResultSetInclude eMode )
     624             :     throw( CommandAbortedException, RuntimeException, Exception )
     625             : {
     626       27859 :     Any aCursorAny = createCursorAny( rPropertyNames, eMode );
     627             : 
     628       55612 :     Reference< XDynamicResultSet > xDynSet;
     629       27806 :     Reference< XResultSet > aResult;
     630             : 
     631       27806 :     aCursorAny >>= xDynSet;
     632       27806 :     if ( xDynSet.is() )
     633       27806 :         aResult = xDynSet->getStaticResultSet();
     634             : 
     635             :     OSL_ENSURE( aResult.is(), "Content::createCursor - no cursor!" );
     636             : 
     637       27806 :     if ( !aResult.is() )
     638             :     {
     639             :         // Former, the open command directly returned a XResultSet.
     640           0 :         aCursorAny >>= aResult;
     641             : 
     642             :         OSL_ENSURE( !aResult.is(),
     643             :                     "Content::createCursor - open-Command must "
     644             :                     "return a Reference< XDynnamicResultSet >!" );
     645             :     }
     646             : 
     647       55612 :     return aResult;
     648             : }
     649             : 
     650             : 
     651         131 : Reference< XDynamicResultSet > Content::createDynamicCursor(
     652             :                             const Sequence< OUString >& rPropertyNames,
     653             :                             ResultSetInclude eMode )
     654             :     throw( CommandAbortedException, RuntimeException, Exception )
     655             : {
     656         131 :     Reference< XDynamicResultSet > aResult;
     657         131 :     createCursorAny( rPropertyNames, eMode ) >>= aResult;
     658             : 
     659             :     OSL_ENSURE( aResult.is(), "Content::createDynamicCursor - no cursor!" );
     660             : 
     661         131 :     return aResult;
     662             : }
     663             : 
     664             : 
     665           0 : Reference< XResultSet > Content::createSortedCursor(
     666             :                             const Sequence< OUString >& rPropertyNames,
     667             :                             const Sequence< NumberedSortingInfo >& rSortInfo,
     668             :                             Reference< XAnyCompareFactory > rAnyCompareFactory,
     669             :                             ResultSetInclude eMode )
     670             :     throw( CommandAbortedException, RuntimeException, Exception )
     671             : {
     672           0 :     Reference< XResultSet > aResult;
     673           0 :     Reference< XDynamicResultSet > aDynSet;
     674             : 
     675           0 :     Any aCursorAny = createCursorAny( rPropertyNames, eMode );
     676             : 
     677           0 :     aCursorAny >>= aDynSet;
     678             : 
     679           0 :     if( aDynSet.is() )
     680             :     {
     681           0 :         Reference< XDynamicResultSet > aDynResult;
     682             : 
     683           0 :         if( m_xImpl->getComponentContext().is() )
     684             :         {
     685             :             Reference< XSortedDynamicResultSetFactory > aSortFactory =
     686           0 :                                 SortedDynamicResultSetFactory::create( m_xImpl->getComponentContext());
     687             : 
     688           0 :             aDynResult = aSortFactory->createSortedDynamicResultSet( aDynSet,
     689             :                                                               rSortInfo,
     690           0 :                                                               rAnyCompareFactory );
     691             :         }
     692             : 
     693             :         OSL_ENSURE( aDynResult.is(), "Content::createSortedCursor - no sorted cursor!\n" );
     694             : 
     695           0 :         if( aDynResult.is() )
     696           0 :             aResult = aDynResult->getStaticResultSet();
     697             :         else
     698           0 :             aResult = aDynSet->getStaticResultSet();
     699             :     }
     700             : 
     701             :     OSL_ENSURE( aResult.is(), "Content::createSortedCursor - no cursor!" );
     702             : 
     703           0 :     if ( !aResult.is() )
     704             :     {
     705             :         // Former, the open command directly returned a XResultSet.
     706           0 :         aCursorAny >>= aResult;
     707             : 
     708             :         OSL_ENSURE( !aResult.is(),
     709             :                     "Content::createCursor - open-Command must "
     710             :                     "return a Reference< XDynnamicResultSet >!" );
     711             :     }
     712             : 
     713           0 :     return aResult;
     714             : }
     715             : 
     716             : 
     717        2170 : Reference< XInputStream > Content::openStream()
     718             :     throw( CommandAbortedException, RuntimeException, Exception )
     719             : {
     720        2170 :     if ( !isDocument() )
     721           0 :         return Reference< XInputStream >();
     722             : 
     723        2134 :     Reference< XActiveDataSink > xSink = new ActiveDataSink;
     724             : 
     725        4268 :     OpenCommandArgument2 aArg;
     726        2134 :     aArg.Mode       = OpenMode::DOCUMENT;
     727        2134 :     aArg.Priority   = 0; // unused
     728        2134 :     aArg.Sink       = xSink;
     729        2134 :     aArg.Properties = Sequence< Property >( 0 ); // unused
     730             : 
     731        4268 :     Command aCommand;
     732        2134 :     aCommand.Name     = "open";
     733        2134 :     aCommand.Handle   = -1; // n/a
     734        2134 :     aCommand.Argument <<= aArg;
     735             : 
     736        2134 :     m_xImpl->executeCommand( aCommand );
     737             : 
     738        4268 :     return xSink->getInputStream();
     739             : }
     740             : 
     741             : 
     742        1522 : Reference< XInputStream > Content::openStreamNoLock()
     743             :     throw( CommandAbortedException, RuntimeException, Exception )
     744             : {
     745        1522 :     if ( !isDocument() )
     746           0 :         return Reference< XInputStream >();
     747             : 
     748        1420 :     Reference< XActiveDataSink > xSink = new ActiveDataSink;
     749             : 
     750        2840 :     OpenCommandArgument2 aArg;
     751        1420 :     aArg.Mode       = OpenMode::DOCUMENT_SHARE_DENY_NONE;
     752        1420 :     aArg.Priority   = 0; // unused
     753        1420 :     aArg.Sink       = xSink;
     754        1420 :     aArg.Properties = Sequence< Property >( 0 ); // unused
     755             : 
     756        2840 :     Command aCommand;
     757        1420 :     aCommand.Name     = "open";
     758        1420 :     aCommand.Handle   = -1; // n/a
     759        1420 :     aCommand.Argument <<= aArg;
     760             : 
     761        1420 :     m_xImpl->executeCommand( aCommand );
     762             : 
     763        2840 :     return xSink->getInputStream();
     764             : }
     765             : 
     766             : 
     767        1647 : Reference< XStream > Content::openWriteableStream()
     768             :     throw( CommandAbortedException, RuntimeException, Exception )
     769             : {
     770        1647 :     if ( !isDocument() )
     771           0 :         return Reference< XStream >();
     772             : 
     773        1635 :     Reference< XActiveDataStreamer > xStreamer = new ActiveDataStreamer;
     774             : 
     775        3270 :     OpenCommandArgument2 aArg;
     776        1635 :     aArg.Mode       = OpenMode::DOCUMENT;
     777        1635 :     aArg.Priority   = 0; // unused
     778        1635 :     aArg.Sink       = xStreamer;
     779        1635 :     aArg.Properties = Sequence< Property >( 0 ); // unused
     780             : 
     781        3270 :     Command aCommand;
     782        1635 :     aCommand.Name     = "open";
     783        1635 :     aCommand.Handle   = -1; // n/a
     784        1635 :     aCommand.Argument <<= aArg;
     785             : 
     786        1635 :     m_xImpl->executeCommand( aCommand );
     787             : 
     788        3270 :     return xStreamer->getStream();
     789             : }
     790             : 
     791             : 
     792           0 : Reference< XStream > Content::openWriteableStreamNoLock()
     793             :     throw( CommandAbortedException, RuntimeException, Exception )
     794             : {
     795           0 :     if ( !isDocument() )
     796           0 :         return Reference< XStream >();
     797             : 
     798           0 :     Reference< XActiveDataStreamer > xStreamer = new ActiveDataStreamer;
     799             : 
     800           0 :     OpenCommandArgument2 aArg;
     801           0 :     aArg.Mode       = OpenMode::DOCUMENT_SHARE_DENY_NONE;
     802           0 :     aArg.Priority   = 0; // unused
     803           0 :     aArg.Sink       = xStreamer;
     804           0 :     aArg.Properties = Sequence< Property >( 0 ); // unused
     805             : 
     806           0 :     Command aCommand;
     807           0 :     aCommand.Name     = "open";
     808           0 :     aCommand.Handle   = -1; // n/a
     809           0 :     aCommand.Argument <<= aArg;
     810             : 
     811           0 :     m_xImpl->executeCommand( aCommand );
     812             : 
     813           0 :     return xStreamer->getStream();
     814             : }
     815             : 
     816             : 
     817        2760 : bool Content::openStream( const Reference< XActiveDataSink >& rSink )
     818             :     throw( CommandAbortedException, RuntimeException, Exception )
     819             : {
     820        2760 :     if ( !isDocument() )
     821           0 :         return false;
     822             : 
     823        2529 :     OpenCommandArgument2 aArg;
     824        2529 :     aArg.Mode       = OpenMode::DOCUMENT;
     825        2529 :     aArg.Priority   = 0; // unused
     826        2529 :     aArg.Sink       = rSink;
     827        2529 :     aArg.Properties = Sequence< Property >( 0 ); // unused
     828             : 
     829        5058 :     Command aCommand;
     830        2529 :     aCommand.Name     = "open";
     831        2529 :     aCommand.Handle   = -1; // n/a
     832        2529 :     aCommand.Argument <<= aArg;
     833             : 
     834        2529 :     m_xImpl->executeCommand( aCommand );
     835             : 
     836        5058 :     return true;
     837             : }
     838             : 
     839             : 
     840           1 : bool Content::openStream( const Reference< XOutputStream >& rStream )
     841             :     throw( CommandAbortedException, RuntimeException, Exception )
     842             : {
     843           1 :     if ( !isDocument() )
     844           0 :         return false;
     845             : 
     846           1 :     OpenCommandArgument2 aArg;
     847           1 :     aArg.Mode       = OpenMode::DOCUMENT;
     848           1 :     aArg.Priority   = 0; // unused
     849           1 :     aArg.Sink       = rStream;
     850           1 :     aArg.Properties = Sequence< Property >( 0 ); // unused
     851             : 
     852           2 :     Command aCommand;
     853           1 :     aCommand.Name     = "open";
     854           1 :     aCommand.Handle   = -1; // n/a
     855           1 :     aCommand.Argument <<= aArg;
     856             : 
     857           1 :     m_xImpl->executeCommand( aCommand );
     858             : 
     859           2 :     return true;
     860             : }
     861             : 
     862             : 
     863         836 : void Content::writeStream( const Reference< XInputStream >& rStream,
     864             :                            bool bReplaceExisting )
     865             :     throw( CommandAbortedException, RuntimeException, Exception )
     866             : {
     867         836 :     InsertCommandArgument aArg;
     868         836 :     aArg.Data            = rStream.is() ? rStream : new EmptyInputStream;
     869         836 :     aArg.ReplaceExisting = bReplaceExisting;
     870             : 
     871        1672 :     Command aCommand;
     872         836 :     aCommand.Name     = "insert";
     873         836 :     aCommand.Handle   = -1; // n/a
     874         836 :     aCommand.Argument <<= aArg;
     875             : 
     876         836 :     m_xImpl->executeCommand( aCommand );
     877             : 
     878        1672 :     m_xImpl->inserted();
     879         836 : }
     880             : 
     881             : 
     882        2230 : Sequence< ContentInfo > Content::queryCreatableContentsInfo()
     883             :     throw( CommandAbortedException, RuntimeException, Exception )
     884             : {
     885             :     // First, try it using "CreatableContentsInfo" property -> the "new" way.
     886        2230 :     Sequence< ContentInfo > aInfo;
     887        4452 :     if ( getPropertyValue(
     888             :              OUString("CreatableContentsInfo") )
     889        4456 :          >>= aInfo )
     890        2226 :         return aInfo;
     891             : 
     892             :     // Second, try it using XContentCreator interface -> the "old" way (not
     893             :     // providing the chance to supply an XCommandEnvironment.
     894           0 :     Reference< XContentCreator > xCreator( m_xImpl->getContent(), UNO_QUERY );
     895           0 :     if ( xCreator.is() )
     896           0 :         aInfo = xCreator->queryCreatableContentsInfo();
     897             : 
     898           0 :     return aInfo;
     899             : }
     900             : 
     901             : 
     902        2226 : bool Content::insertNewContent( const OUString& rContentType,
     903             :                                     const Sequence< OUString >&
     904             :                                         rPropertyNames,
     905             :                                     const Sequence< Any >& rPropertyValues,
     906             :                                     Content& rNewContent )
     907             :     throw( CommandAbortedException, RuntimeException, Exception )
     908             : {
     909             :     return insertNewContent( rContentType,
     910             :                              rPropertyNames,
     911             :                              rPropertyValues,
     912        2226 :                              new EmptyInputStream,
     913        4452 :                              rNewContent );
     914             : }
     915             : 
     916             : 
     917        2226 : bool Content::insertNewContent( const OUString& rContentType,
     918             :                                     const Sequence< OUString >&
     919             :                                         rPropertyNames,
     920             :                                     const Sequence< Any >& rPropertyValues,
     921             :                                     const Reference< XInputStream >& rData,
     922             :                                     Content& rNewContent )
     923             :     throw( CommandAbortedException, RuntimeException, Exception )
     924             : {
     925        2226 :     if ( rContentType.isEmpty() )
     926           0 :         return false;
     927             : 
     928             :     // First, try it using "createNewContent" command -> the "new" way.
     929        2226 :     ContentInfo aInfo;
     930        2226 :     aInfo.Type = rContentType;
     931        2226 :     aInfo.Attributes = 0;
     932             : 
     933        4452 :     Command aCommand;
     934        2226 :     aCommand.Name     = "createNewContent";
     935        2226 :     aCommand.Handle   = -1; // n/a
     936        2226 :     aCommand.Argument <<= aInfo;
     937             : 
     938        4452 :     Reference< XContent > xNew;
     939             :     try
     940             :     {
     941        2226 :         m_xImpl->executeCommand( aCommand ) >>= xNew;
     942             :     }
     943           0 :     catch ( RuntimeException const & )
     944             :     {
     945           0 :         throw;
     946             :     }
     947           0 :     catch ( Exception const & )
     948             :     {
     949             :     }
     950             : 
     951        2226 :     if ( !xNew.is() )
     952             :     {
     953             :         // Second, try it using XContentCreator interface -> the "old"
     954             :         // way (not providing the chance to supply an XCommandEnvironment.
     955           0 :         Reference< XContentCreator > xCreator( m_xImpl->getContent(), UNO_QUERY );
     956             : 
     957           0 :         if ( !xCreator.is() )
     958           0 :             return false;
     959             : 
     960           0 :         xNew = xCreator->createNewContent( aInfo );
     961             : 
     962           0 :         if ( !xNew.is() )
     963           0 :             return false;
     964             :     }
     965             : 
     966             :     Content aNewContent(
     967        4452 :         xNew, m_xImpl->getEnvironment(), m_xImpl->getComponentContext() );
     968        2226 :     aNewContent.setPropertyValues( rPropertyNames, rPropertyValues );
     969             :     aNewContent.executeCommand( OUString("insert"),
     970             :                                 makeAny(
     971             :                                     InsertCommandArgument(
     972        2226 :                                         rData.is() ? rData : new EmptyInputStream,
     973        4949 :                                         sal_False /* ReplaceExisting */ ) ) );
     974        1729 :     aNewContent.m_xImpl->inserted();
     975             : 
     976        1729 :     rNewContent = aNewContent;
     977        3955 :     return true;
     978             : }
     979             : 
     980             : 
     981        1929 : bool Content::transferContent( const Content& rSourceContent,
     982             :                                    InsertOperation eOperation,
     983             :                                    const OUString & rTitle,
     984             :                                    const sal_Int32 nNameClashAction,
     985             :                                    const OUString & rMimeType,
     986             :                                    bool bMajorVersion,
     987             :                                    const OUString & rVersionComment,
     988             :                                    OUString* pResultURL,
     989             :                                    const OUString & rDocumentId )
     990             :     throw( CommandAbortedException, RuntimeException, Exception )
     991             : {
     992             :     Reference< XUniversalContentBroker > pBroker(
     993        1929 :         UniversalContentBroker::create( m_xImpl->getComponentContext() ) );
     994             : 
     995             :     // Execute command "globalTransfer" at UCB.
     996             : 
     997        1929 :     TransferCommandOperation eTransOp = TransferCommandOperation();
     998        3858 :     OUString sCommand( "globalTransfer" );
     999        1929 :     bool bCheckIn = false;
    1000        1929 :     switch ( eOperation )
    1001             :     {
    1002             :         case InsertOperation_COPY:
    1003        1928 :             eTransOp = TransferCommandOperation_COPY;
    1004        1928 :             break;
    1005             : 
    1006             :         case InsertOperation_MOVE:
    1007           1 :             eTransOp = TransferCommandOperation_MOVE;
    1008           1 :             break;
    1009             : 
    1010             :         case InsertOperation_LINK:
    1011           0 :             eTransOp = TransferCommandOperation_LINK;
    1012           0 :             break;
    1013             : 
    1014             :         case InsertOperation_CHECKIN:
    1015           0 :             eTransOp = TransferCommandOperation_COPY;
    1016           0 :             sCommand = "checkin";
    1017           0 :             bCheckIn = true;
    1018           0 :             break;
    1019             : 
    1020             :         default:
    1021             :             ucbhelper::cancelCommandExecution(
    1022             :                 makeAny( IllegalArgumentException(
    1023             :                             OUString(
    1024             :                                 "Unknown transfer operation!" ),
    1025             :                             get(),
    1026           0 :                             -1 ) ),
    1027           0 :                          m_xImpl->getEnvironment() );
    1028             :             // Unreachable
    1029             :     }
    1030        1929 :     Command aCommand;
    1031        1929 :     aCommand.Name     = sCommand;
    1032        1929 :     aCommand.Handle   = -1; // n/a
    1033             : 
    1034        1929 :     if ( !bCheckIn )
    1035             :     {
    1036             :         GlobalTransferCommandArgument2 aTransferArg(
    1037             :                                             eTransOp,
    1038        1929 :                                             rSourceContent.getURL(), // SourceURL
    1039        1929 :                                             getURL(),   // TargetFolderURL,
    1040             :                                             rTitle,
    1041             :                                             nNameClashAction,
    1042             :                                             rMimeType,
    1043        1929 :                                             rDocumentId );
    1044        1929 :         aCommand.Argument <<= aTransferArg;
    1045             :     }
    1046             :     else
    1047             :     {
    1048             :         CheckinArgument aCheckinArg( bMajorVersion, rVersionComment,
    1049           0 :                 rSourceContent.getURL(), getURL(), rTitle, rMimeType );
    1050           0 :         aCommand.Argument <<= aCheckinArg;
    1051             :     }
    1052             : 
    1053        3856 :     Any aRet = pBroker->execute( aCommand, 0, m_xImpl->getEnvironment() );
    1054        1927 :     if ( pResultURL != NULL )
    1055           0 :         aRet >>= *pResultURL;
    1056        5785 :     return true;
    1057             : }
    1058             : 
    1059             : 
    1060       18843 : bool Content::isFolder()
    1061             :     throw( CommandAbortedException, RuntimeException, Exception )
    1062             : {
    1063       18843 :     bool bFolder = false;
    1064       16494 :     if ( getPropertyValue("IsFolder")
    1065       37686 :         >>= bFolder )
    1066        8245 :         return bFolder;
    1067             : 
    1068             :      ucbhelper::cancelCommandExecution(
    1069             :          makeAny( UnknownPropertyException(
    1070             :                     OUString(
    1071             :                         "Unable to retrieve value of property 'IsFolder'!" ),
    1072           4 :                     get() ) ),
    1073           6 :          m_xImpl->getEnvironment() );
    1074             : 
    1075             : #if !(defined(_MSC_VER) && defined(ENABLE_LTO))
    1076             :     // Unreachable - cancelCommandExecution always throws an exception.
    1077             :     // But some compilers complain...
    1078           0 :     return false;
    1079             : #endif
    1080             : }
    1081             : 
    1082             : 
    1083             : 
    1084             : SAL_WNOUNREACHABLE_CODE_PUSH
    1085             : 
    1086       11409 : bool Content::isDocument()
    1087             :     throw( CommandAbortedException, RuntimeException, Exception )
    1088             : {
    1089       11409 :     bool bDoc = false;
    1090       20474 :     if ( getPropertyValue("IsDocument")
    1091       22818 :         >>= bDoc )
    1092       10237 :         return bDoc;
    1093             : 
    1094             :      ucbhelper::cancelCommandExecution(
    1095             :          makeAny( UnknownPropertyException(
    1096             :                     OUString(
    1097             :                         "Unable to retrieve value of property 'IsDocument'!" ),
    1098           0 :                     get() ) ),
    1099           0 :          m_xImpl->getEnvironment() );
    1100             : 
    1101             :     // Unreachable - cancelCommandExecution always throws an exception,
    1102             :     // But some compilers complain...
    1103           0 :     return false;
    1104             : }
    1105             : 
    1106             : SAL_WNOUNREACHABLE_CODE_POP
    1107             : 
    1108             : 
    1109             : 
    1110             : 
    1111             : // Content_Impl Implementation.
    1112             : 
    1113             : 
    1114             : 
    1115             : 
    1116      106859 : Content_Impl::Content_Impl( const Reference< XComponentContext >& rCtx,
    1117             :                             const Reference< XContent >& rContent,
    1118             :                             const Reference< XCommandEnvironment >& rEnv )
    1119             : : m_xCtx( rCtx ),
    1120             :   m_xContent( rContent ),
    1121      106859 :   m_xEnv( rEnv )
    1122             : {
    1123             :     assert(rCtx.is());
    1124      106859 :     if ( m_xContent.is() )
    1125             :     {
    1126      106859 :         m_xContentEventListener = new ContentEventListener_Impl( *this );
    1127      106859 :         m_xContent->addContentEventListener( m_xContentEventListener );
    1128             : 
    1129             : #if OSL_DEBUG_LEVEL > 1
    1130             :         // Only done on demand in product version for performance reasons,
    1131             :         // but a nice debug helper.
    1132             :         getURL();
    1133             : #endif
    1134             :     }
    1135      106859 : }
    1136             : 
    1137             : 
    1138        1221 : void Content_Impl::reinit( const Reference< XContent >& xContent )
    1139             : {
    1140        1221 :     osl::MutexGuard aGuard( m_aMutex );
    1141             : 
    1142        1221 :     m_xCommandProcessor = 0;
    1143             : 
    1144             :     // #92581# - Don't reset m_aURL!!!
    1145             : 
    1146        1221 :     if ( m_xContent.is() )
    1147             :     {
    1148             :         try
    1149             :         {
    1150        1221 :             m_xContent->removeContentEventListener( m_xContentEventListener );
    1151             :         }
    1152           0 :         catch ( RuntimeException const & )
    1153             :         {
    1154             :         }
    1155             :     }
    1156             : 
    1157        1221 :     if ( xContent.is() )
    1158             :     {
    1159           1 :         m_xContent = xContent;
    1160           1 :         m_xContent->addContentEventListener( m_xContentEventListener );
    1161             : 
    1162             : #if OSL_DEBUG_LEVEL > 1
    1163             :         // Only done on demand in product version for performance reasons,
    1164             :         // but a nice debug helper.
    1165             :         getURL();
    1166             : #endif
    1167             :     }
    1168             :     else
    1169             :     {
    1170             :         // We need m_xContent's URL in order to be able to create the
    1171             :         // content object again if demanded ( --> Content_Impl::getContent() )
    1172        1220 :         getURL();
    1173             : 
    1174        1220 :         m_xContent = 0;
    1175        1221 :     }
    1176        1221 : }
    1177             : 
    1178             : 
    1179             : // virtual
    1180      420996 : Content_Impl::~Content_Impl()
    1181             : {
    1182      140332 :     if ( m_xContent.is() )
    1183             :     {
    1184             :         try
    1185             :         {
    1186      105548 :             m_xContent->removeContentEventListener( m_xContentEventListener );
    1187             :         }
    1188           0 :         catch ( RuntimeException const & )
    1189             :         {
    1190             :         }
    1191             :     }
    1192      280664 : }
    1193             : 
    1194             : 
    1195           0 : void Content_Impl::disposing( const EventObject& Source )
    1196             : {
    1197           0 :     Reference<XContent> xContent;
    1198             : 
    1199             :     {
    1200           0 :         osl::MutexGuard aGuard( m_aMutex );
    1201           0 :         if(Source.Source != m_xContent)
    1202           0 :             return;
    1203             : 
    1204           0 :         xContent = m_xContent;
    1205             : 
    1206           0 :         m_aURL = "";
    1207           0 :         m_xCommandProcessor = 0;
    1208           0 :         m_xContent = 0;
    1209             :     }
    1210             : 
    1211           0 :     if ( xContent.is() )
    1212             :     {
    1213             :         try
    1214             :         {
    1215           0 :             xContent->removeContentEventListener( m_xContentEventListener );
    1216             :         }
    1217           0 :         catch ( RuntimeException const & )
    1218             :         {
    1219             :         }
    1220           0 :     }
    1221             : }
    1222             : 
    1223             : 
    1224        6945 : const OUString& Content_Impl::getURL() const
    1225             : {
    1226        6945 :     if ( m_aURL.isEmpty() && m_xContent.is() )
    1227             :     {
    1228        6936 :         osl::MutexGuard aGuard( m_aMutex );
    1229             : 
    1230        6936 :         if ( m_aURL.isEmpty() && m_xContent.is() )
    1231             :         {
    1232        6936 :             Reference< XContentIdentifier > xId = m_xContent->getIdentifier();
    1233        6936 :             if ( xId.is() )
    1234        6936 :                 m_aURL = xId->getContentIdentifier();
    1235        6936 :         }
    1236             :     }
    1237             : 
    1238        6945 :     return m_aURL;
    1239             : }
    1240             : 
    1241             : 
    1242      141373 : Reference< XContent > Content_Impl::getContent()
    1243             : {
    1244      141373 :     if ( !m_xContent.is() && !m_aURL.isEmpty() )
    1245             :     {
    1246           3 :         osl::MutexGuard aGuard( m_aMutex );
    1247             : 
    1248           3 :         if ( !m_xContent.is() && !m_aURL.isEmpty() )
    1249             :         {
    1250             :             Reference< XUniversalContentBroker > pBroker(
    1251           3 :                 UniversalContentBroker::create( getComponentContext() ) );
    1252             : 
    1253             :             OSL_ENSURE( pBroker->queryContentProviders().getLength(),
    1254             :                         "Content Broker not configured (no providers)!" );
    1255             : 
    1256             :             Reference< XContentIdentifier > xId
    1257           6 :                 = pBroker->createContentIdentifier( m_aURL );
    1258             : 
    1259             :             OSL_ENSURE( xId.is(), "No Content Identifier!" );
    1260             : 
    1261           3 :             if ( xId.is() )
    1262             :             {
    1263             :                 try
    1264             :                 {
    1265           3 :                     m_xContent = pBroker->queryContent( xId );
    1266             :                 }
    1267           0 :                 catch ( IllegalIdentifierException const & )
    1268             :                 {
    1269             :                 }
    1270             : 
    1271           3 :                 if ( m_xContent.is() )
    1272           3 :                     m_xContent->addContentEventListener(
    1273           3 :                         m_xContentEventListener );
    1274           3 :             }
    1275           3 :         }
    1276             :     }
    1277             : 
    1278      141373 :     return m_xContent;
    1279             : }
    1280             : 
    1281             : 
    1282      124678 : Reference< XCommandProcessor > Content_Impl::getCommandProcessor()
    1283             : {
    1284      124678 :     if ( !m_xCommandProcessor.is() )
    1285             :     {
    1286       78718 :         osl::MutexGuard aGuard( m_aMutex );
    1287             : 
    1288       78718 :         if ( !m_xCommandProcessor.is() )
    1289             :             m_xCommandProcessor
    1290       78718 :                 = Reference< XCommandProcessor >( getContent(), UNO_QUERY );
    1291             :     }
    1292             : 
    1293      124678 :     return m_xCommandProcessor;
    1294             : }
    1295             : 
    1296             : 
    1297      124678 : Any Content_Impl::executeCommand( const Command& rCommand )
    1298             : {
    1299      124678 :     Reference< XCommandProcessor > xProc = getCommandProcessor();
    1300      124678 :     if ( !xProc.is() )
    1301           0 :         return Any();
    1302             : 
    1303             :     // Execute command
    1304      124678 :     return xProc->execute( rCommand, 0, m_xEnv );
    1305             : }
    1306             : 
    1307             : 
    1308             : inline const Reference< XCommandEnvironment >&
    1309        4163 :                                         Content_Impl::getEnvironment() const
    1310             : {
    1311        4163 :     return m_xEnv;
    1312             : }
    1313             : 
    1314             : 
    1315        2305 : inline void Content_Impl::setEnvironment(
    1316             :                         const Reference< XCommandEnvironment >& xNewEnv )
    1317             : {
    1318        2305 :     osl::MutexGuard aGuard( m_aMutex );
    1319        2305 :     m_xEnv = xNewEnv;
    1320        2305 : }
    1321             : 
    1322             : 
    1323        2565 : void Content_Impl::inserted()
    1324             : {
    1325             :     // URL might have changed during 'insert' => recalculate in next getURL()
    1326        2565 :     osl::MutexGuard aGuard( m_aMutex );
    1327        2565 :     m_aURL = "";
    1328        2565 : }
    1329             : 
    1330             : 
    1331             : 
    1332             : 
    1333             : // ContentEventListener_Impl Implementation.
    1334             : 
    1335             : 
    1336             : 
    1337             : 
    1338             : 
    1339             : 
    1340             : // XInterface methods.
    1341             : 
    1342      379599 : void SAL_CALL ContentEventListener_Impl::acquire()
    1343             :     throw()
    1344             : {
    1345      379599 :     OWeakObject::acquire();
    1346      379599 : }
    1347             : 
    1348      379411 : void SAL_CALL ContentEventListener_Impl::release()
    1349             :     throw()
    1350             : {
    1351      379411 :     OWeakObject::release();
    1352      379411 : }
    1353             : 
    1354        5557 : css::uno::Any SAL_CALL ContentEventListener_Impl::queryInterface( const css::uno::Type & rType )
    1355             :     throw( css::uno::RuntimeException, std::exception )
    1356             : {
    1357             :     css::uno::Any aRet = cppu::queryInterface( rType,
    1358             :                                                (static_cast< XContentEventListener* >(this)),
    1359             :                                                (static_cast< XEventListener* >(this))
    1360        5557 :                                                );
    1361        5557 :     return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
    1362             : }
    1363             : 
    1364             : // XContentEventListener methods.
    1365             : 
    1366             : 
    1367             : 
    1368             : // virtual
    1369        5557 : void SAL_CALL ContentEventListener_Impl::contentEvent( const ContentEvent& evt )
    1370             :     throw( RuntimeException, std::exception )
    1371             : {
    1372        5557 :     if ( evt.Source == m_rContent.m_xContent )
    1373             :     {
    1374        5557 :         switch ( evt.Action )
    1375             :         {
    1376             :             case ContentAction::DELETED:
    1377        1220 :                 m_rContent.reinit( Reference< XContent >() );
    1378        1220 :                 break;
    1379             : 
    1380             :             case ContentAction::EXCHANGED:
    1381           1 :                 m_rContent.reinit( evt.Content );
    1382           1 :                 break;
    1383             : 
    1384             :             default:
    1385        4336 :                 break;
    1386             :         }
    1387             :     }
    1388        5557 : }
    1389             : 
    1390             : 
    1391             : 
    1392             : // XEventListenr methods.
    1393             : 
    1394             : 
    1395             : 
    1396             : // virtual
    1397           0 : void SAL_CALL ContentEventListener_Impl::disposing( const EventObject& Source )
    1398             :     throw( RuntimeException, std::exception )
    1399             : {
    1400           0 :     m_rContent.disposing(Source);
    1401           0 : }
    1402             : 
    1403             : } /* namespace ucbhelper */
    1404             : 
    1405             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10