LCOV - code coverage report
Current view: top level - xmlhelp/source/cxxhelp/provider - content.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 65 179 36.3 %
Date: 2014-04-11 Functions: 12 22 54.5 %
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             :                                 TODO
      22             :  **************************************************************************
      23             : 
      24             :  *************************************************************************/
      25             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      26             : #include <com/sun/star/beans/XPropertyAccess.hpp>
      27             : #include <com/sun/star/sdbc/XRow.hpp>
      28             : #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
      29             : #include <com/sun/star/ucb/OpenMode.hpp>
      30             : #include <com/sun/star/ucb/XCommandInfo.hpp>
      31             : #include <com/sun/star/io/XActiveDataSink.hpp>
      32             : #include <com/sun/star/io/XOutputStream.hpp>
      33             : #include <com/sun/star/lang/IllegalAccessException.hpp>
      34             : #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
      35             : #include <com/sun/star/io/XActiveDataStreamer.hpp>
      36             : #include <com/sun/star/ucb/XPersistentPropertySet.hpp>
      37             : #include <osl/diagnose.h>
      38             : #include <comphelper/processfactory.hxx>
      39             : #include <ucbhelper/contentidentifier.hxx>
      40             : #include <ucbhelper/propertyvalueset.hxx>
      41             : #include <ucbhelper/cancelcommandexecution.hxx>
      42             : #include "content.hxx"
      43             : #include "provider.hxx"
      44             : #include "resultset.hxx"
      45             : #include "databases.hxx"
      46             : #include "resultsetfactory.hxx"
      47             : #include "resultsetbase.hxx"
      48             : #include "resultsetforroot.hxx"
      49             : #include "resultsetforquery.hxx"
      50             : 
      51             : using namespace com::sun::star;
      52             : using namespace chelp;
      53             : 
      54             : // Content Implementation.
      55             : 
      56         625 : Content::Content( const uno::Reference< uno::XComponentContext >& rxContext,
      57             :                   ::ucbhelper::ContentProviderImplHelper* pProvider,
      58             :                   const uno::Reference< ucb::XContentIdentifier >&
      59             :                       Identifier,
      60             :                   Databases* pDatabases )
      61             :     : ContentImplHelper( rxContext, pProvider, Identifier ),
      62         625 :       m_aURLParameter( Identifier->getContentIdentifier(),pDatabases ),
      63        1250 :       m_pDatabases( pDatabases ) // not owner
      64             : {
      65         625 : }
      66             : 
      67             : // virtual
      68        1250 : Content::~Content()
      69             : {
      70        1250 : }
      71             : 
      72             : // XInterface methods.
      73             : 
      74             : // virtual
      75        6000 : void SAL_CALL Content::acquire()
      76             :     throw( )
      77             : {
      78        6000 :     ContentImplHelper::acquire();
      79        6000 : }
      80             : 
      81             : // virtual
      82        6000 : void SAL_CALL Content::release()
      83             :     throw( )
      84             : {
      85        6000 :     ContentImplHelper::release();
      86        6000 : }
      87             : 
      88             : // virtual
      89        1250 : uno::Any SAL_CALL Content::queryInterface( const uno::Type & rType )
      90             :     throw ( uno::RuntimeException, std::exception )
      91             : {
      92        1250 :     uno::Any aRet;
      93        1250 :      return aRet.hasValue() ? aRet : ContentImplHelper::queryInterface( rType );
      94             : }
      95             : 
      96             : // XTypeProvider methods.
      97             : 
      98           0 : XTYPEPROVIDER_COMMON_IMPL( Content );
      99             : 
     100             : // virtual
     101           0 : uno::Sequence< uno::Type > SAL_CALL Content::getTypes()
     102             :     throw( uno::RuntimeException, std::exception )
     103             : {
     104             :     static cppu::OTypeCollection* pCollection = NULL;
     105             : 
     106           0 :     if ( !pCollection )
     107             :     {
     108           0 :         osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() );
     109           0 :           if ( !pCollection )
     110             :           {
     111             :               static cppu::OTypeCollection aCollection(
     112           0 :                 CPPU_TYPE_REF( lang::XTypeProvider ),
     113           0 :                    CPPU_TYPE_REF( lang::XServiceInfo ),
     114           0 :                    CPPU_TYPE_REF( lang::XComponent ),
     115           0 :                    CPPU_TYPE_REF( ucb::XContent ),
     116           0 :                    CPPU_TYPE_REF( ucb::XCommandProcessor ),
     117           0 :                    CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ),
     118           0 :                    CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ),
     119           0 :                    CPPU_TYPE_REF( beans::XPropertyContainer ),
     120           0 :                    CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ),
     121           0 :                    CPPU_TYPE_REF( container::XChild ) );
     122           0 :               pCollection = &aCollection;
     123           0 :         }
     124             :     }
     125             : 
     126           0 :     return (*pCollection).getTypes();
     127             : }
     128             : 
     129             : // XServiceInfo methods.
     130             : 
     131             : // virtual
     132           0 : OUString SAL_CALL Content::getImplementationName()
     133             :     throw( uno::RuntimeException, std::exception )
     134             : {
     135           0 :     return OUString( "CHelpContent" );
     136             : }
     137             : 
     138             : // virtual
     139           0 : uno::Sequence< OUString > SAL_CALL Content::getSupportedServiceNames()
     140             :     throw( uno::RuntimeException, std::exception )
     141             : {
     142           0 :     uno::Sequence< OUString > aSNS( 1 );
     143           0 :     aSNS.getArray()[ 0 ] = MYUCP_CONTENT_SERVICE_NAME ;
     144           0 :     return aSNS;
     145             : }
     146             : 
     147             : // XContent methods.
     148             : 
     149             : // virtual
     150           0 : OUString SAL_CALL Content::getContentType()
     151             :     throw( uno::RuntimeException, std::exception )
     152             : {
     153           0 :     return OUString( MYUCP_CONTENT_TYPE );
     154             : }
     155             : 
     156             : // XCommandProcessor methods.
     157             : 
     158             : //virtual
     159           0 : void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ )
     160             :     throw( uno::RuntimeException, std::exception )
     161             : {
     162           0 : }
     163             : 
     164           4 : class ResultSetForRootFactory
     165             :     : public ResultSetFactory
     166             : {
     167             : private:
     168             : 
     169             :     uno::Reference< uno::XComponentContext >     m_xContext;
     170             :     uno::Reference< ucb::XContentProvider >      m_xProvider;
     171             :     sal_Int32                                    m_nOpenMode;
     172             :     uno::Sequence< beans::Property >             m_seq;
     173             :     uno::Sequence< ucb::NumberedSortingInfo >    m_seqSort;
     174             :     URLParameter                                 m_aURLParameter;
     175             :     Databases*                                   m_pDatabases;
     176             : 
     177             : public:
     178             : 
     179           2 :     ResultSetForRootFactory(
     180             :         const uno::Reference< uno::XComponentContext >& xContext,
     181             :         const uno::Reference< ucb::XContentProvider >&  xProvider,
     182             :         sal_Int32 nOpenMode,
     183             :         const uno::Sequence< beans::Property >& seq,
     184             :         const uno::Sequence< ucb::NumberedSortingInfo >& seqSort,
     185             :         const URLParameter& rURLParameter,
     186             :         Databases* pDatabases )
     187             :         : m_xContext( xContext ),
     188             :           m_xProvider( xProvider ),
     189             :           m_nOpenMode( nOpenMode ),
     190             :           m_seq( seq ),
     191             :           m_seqSort( seqSort ),
     192             :           m_aURLParameter( rURLParameter ),
     193           2 :           m_pDatabases( pDatabases )
     194             :     {
     195           2 :     }
     196             : 
     197           2 :     ResultSetBase* createResultSet() SAL_OVERRIDE
     198             :     {
     199             :         return new ResultSetForRoot( m_xContext,
     200             :                                      m_xProvider,
     201             :                                      m_nOpenMode,
     202             :                                      m_seq,
     203             :                                      m_seqSort,
     204             :                                      m_aURLParameter,
     205           2 :                                      m_pDatabases );
     206             :     }
     207             : };
     208             : 
     209           0 : class ResultSetForQueryFactory
     210             :     : public ResultSetFactory
     211             : {
     212             : private:
     213             : 
     214             :     uno::Reference< uno::XComponentContext >     m_xContext;
     215             :     uno::Reference< ucb::XContentProvider >      m_xProvider;
     216             :     sal_Int32                                    m_nOpenMode;
     217             :     uno::Sequence< beans::Property >             m_seq;
     218             :     uno::Sequence< ucb::NumberedSortingInfo >    m_seqSort;
     219             :     URLParameter                                 m_aURLParameter;
     220             :     Databases*                                   m_pDatabases;
     221             : 
     222             : public:
     223             : 
     224           0 :     ResultSetForQueryFactory(
     225             :         const uno::Reference< uno::XComponentContext >& rxContext,
     226             :         const uno::Reference< ucb::XContentProvider >&  xProvider,
     227             :         sal_Int32 nOpenMode,
     228             :         const uno::Sequence< beans::Property >& seq,
     229             :         const uno::Sequence< ucb::NumberedSortingInfo >& seqSort,
     230             :         const URLParameter& rURLParameter,
     231             :         Databases* pDatabases )
     232             :         : m_xContext( rxContext ),
     233             :           m_xProvider( xProvider ),
     234             :           m_nOpenMode( nOpenMode ),
     235             :           m_seq( seq ),
     236             :           m_seqSort( seqSort ),
     237             :           m_aURLParameter( rURLParameter ),
     238           0 :           m_pDatabases( pDatabases )
     239             :     {
     240           0 :     }
     241             : 
     242           0 :     ResultSetBase* createResultSet() SAL_OVERRIDE
     243             :     {
     244             :         return new ResultSetForQuery( m_xContext,
     245             :                                       m_xProvider,
     246             :                                       m_nOpenMode,
     247             :                                       m_seq,
     248             :                                       m_seqSort,
     249             :                                       m_aURLParameter,
     250           0 :                                       m_pDatabases );
     251             :     }
     252             : };
     253             : 
     254             : // virtual
     255         999 : uno::Any SAL_CALL Content::execute(
     256             :         const ucb::Command& aCommand,
     257             :         sal_Int32 CommandId,
     258             :         const uno::Reference< ucb::XCommandEnvironment >& Environment )
     259             :     throw( uno::Exception,
     260             :            ucb::CommandAbortedException,
     261             :            uno::RuntimeException, std::exception )
     262             : {
     263         999 :     uno::Any aRet;
     264             : 
     265         999 :     if ( aCommand.Name == "getPropertyValues" )
     266             :     {
     267         622 :         uno::Sequence< beans::Property > Properties;
     268         622 :         if ( !( aCommand.Argument >>= Properties ) )
     269             :         {
     270           0 :             aRet <<= lang::IllegalArgumentException();
     271           0 :             ucbhelper::cancelCommandExecution(aRet,Environment);
     272             :         }
     273             : 
     274         622 :         aRet <<= getPropertyValues( Properties );
     275             :     }
     276         377 :     else if ( aCommand.Name == "setPropertyValues" )
     277             :     {
     278           0 :         uno::Sequence<beans::PropertyValue> propertyValues;
     279             : 
     280           0 :         if( ! ( aCommand.Argument >>= propertyValues ) ) {
     281           0 :             aRet <<= lang::IllegalArgumentException();
     282           0 :             ucbhelper::cancelCommandExecution(aRet,Environment);
     283             :         }
     284             : 
     285           0 :         uno::Sequence< uno::Any > ret(propertyValues.getLength());
     286           0 :         uno::Sequence< beans::Property > props(getProperties(Environment));
     287             :         // No properties can be set
     288           0 :         for(sal_Int32 i = 0; i < ret.getLength(); ++i) {
     289           0 :             ret[i] <<= beans::UnknownPropertyException();
     290           0 :             for(sal_Int32 j = 0; j < props.getLength(); ++j)
     291           0 :                 if(props[j].Name == propertyValues[i].Name) {
     292           0 :                     ret[i] <<= lang::IllegalAccessException();
     293           0 :                     break;
     294             :                 }
     295             :         }
     296             : 
     297           0 :         aRet <<= ret;
     298             :     }
     299         377 :     else if ( aCommand.Name == "getPropertySetInfo" )
     300             :     {
     301             :         // Note: Implemented by base class.
     302           0 :         aRet <<= getPropertySetInfo( Environment );
     303             :     }
     304         377 :     else if ( aCommand.Name == "getCommandInfo" )
     305             :     {
     306             :         // Note: Implemented by base class.
     307           0 :         aRet <<= getCommandInfo( Environment );
     308             :     }
     309         377 :     else if ( aCommand.Name == "open" )
     310             :     {
     311         377 :         ucb::OpenCommandArgument2 aOpenCommand;
     312         377 :         if ( !( aCommand.Argument >>= aOpenCommand ) )
     313             :         {
     314           0 :             aRet <<= lang::IllegalArgumentException();
     315           0 :             ucbhelper::cancelCommandExecution(aRet,Environment);
     316             :         }
     317             : 
     318             :         uno::Reference< io::XActiveDataSink > xActiveDataSink(
     319         754 :             aOpenCommand.Sink, uno::UNO_QUERY);
     320             : 
     321         377 :         if(xActiveDataSink.is())
     322             :             m_aURLParameter.open(aCommand,
     323             :                                  CommandId,
     324             :                                  Environment,
     325         375 :                                  xActiveDataSink);
     326             : 
     327             :         uno::Reference< io::XActiveDataStreamer > xActiveDataStreamer(
     328         754 :             aOpenCommand.Sink, uno::UNO_QUERY);
     329             : 
     330         377 :         if(xActiveDataStreamer.is()) {
     331           0 :             aRet <<= ucb::UnsupportedDataSinkException();
     332           0 :             ucbhelper::cancelCommandExecution(aRet,Environment);
     333             :         }
     334             : 
     335             :         uno::Reference< io::XOutputStream > xOutputStream(
     336         754 :             aOpenCommand.Sink, uno::UNO_QUERY);
     337             : 
     338         377 :         if(xOutputStream.is() )
     339             :             m_aURLParameter.open(aCommand,
     340             :                                  CommandId,
     341             :                                  Environment,
     342           0 :                                  xOutputStream);
     343             : 
     344         377 :         if( m_aURLParameter.isRoot() )
     345             :         {
     346             :             uno::Reference< ucb::XDynamicResultSet > xSet
     347             :                 = new DynamicResultSet(
     348             :                     m_xContext,
     349             :                     this,
     350             :                     aOpenCommand,
     351             :                     Environment,
     352             :                     new ResultSetForRootFactory(
     353             :                         m_xContext,
     354           2 :                         m_xProvider.get(),
     355             :                         aOpenCommand.Mode,
     356             :                         aOpenCommand.Properties,
     357             :                         aOpenCommand.SortingInfo,
     358             :                         m_aURLParameter,
     359           4 :                         m_pDatabases));
     360           2 :             aRet <<= xSet;
     361             :         }
     362         375 :         else if( m_aURLParameter.isQuery() )
     363             :         {
     364             :             uno::Reference< ucb::XDynamicResultSet > xSet
     365             :                 = new DynamicResultSet(
     366             :                     m_xContext,
     367             :                     this,
     368             :                     aOpenCommand,
     369             :                     Environment,
     370             :                     new ResultSetForQueryFactory(
     371             :                         m_xContext,
     372           0 :                         m_xProvider.get(),
     373             :                         aOpenCommand.Mode,
     374             :                         aOpenCommand.Properties,
     375             :                         aOpenCommand.SortingInfo,
     376             :                         m_aURLParameter,
     377           0 :                         m_pDatabases ) );
     378           0 :             aRet <<= xSet;
     379         377 :         }
     380             :     }
     381             :     else
     382             :     {
     383             :         // Unsupported command
     384           0 :         aRet <<= ucb::UnsupportedCommandException();
     385           0 :         ucbhelper::cancelCommandExecution(aRet,Environment);
     386             :     }
     387             : 
     388         999 :     return aRet;
     389             : }
     390             : 
     391         622 : uno::Reference< sdbc::XRow > Content::getPropertyValues(
     392             :     const uno::Sequence< beans::Property >& rProperties )
     393             : {
     394         622 :     osl::MutexGuard aGuard( m_aMutex );
     395             : 
     396             :     rtl::Reference< ::ucbhelper::PropertyValueSet > xRow =
     397        1244 :         new ::ucbhelper::PropertyValueSet( m_xContext );
     398             : 
     399        1244 :     for ( sal_Int32 n = 0; n < rProperties.getLength(); ++n )
     400             :     {
     401         622 :         const beans::Property& rProp = rProperties[n];
     402             : 
     403         622 :         if ( rProp.Name == "ContentType" )
     404             :             xRow->appendString(
     405             :                 rProp,
     406             :                 OUString(
     407           0 :                     "application/vnd.sun.star.help" ) );
     408         622 :         else if ( rProp.Name == "Title" )
     409           0 :             xRow->appendString ( rProp,m_aURLParameter.get_title() );
     410         622 :         else if ( rProp.Name == "IsReadOnly" )
     411           0 :             xRow->appendBoolean( rProp,true );
     412         622 :         else if ( rProp.Name == "IsDocument" )
     413             :             xRow->appendBoolean(
     414             :                 rProp,
     415         375 :                 m_aURLParameter.isFile() || m_aURLParameter.isRoot() );
     416         247 :         else if ( rProp.Name == "IsFolder" )
     417             :             xRow->appendBoolean(
     418             :                 rProp,
     419           0 :                 ! m_aURLParameter.isFile() || m_aURLParameter.isRoot() );
     420         247 :         else if ( rProp.Name == "IsErrorDocument" )
     421           0 :             xRow->appendBoolean( rProp, m_aURLParameter.isErrorDocument() );
     422         247 :         else if ( rProp.Name == "MediaType" )
     423           0 :             if( m_aURLParameter.isPicture() )
     424             :                 xRow->appendString(
     425             :                     rProp,
     426           0 :                     OUString( "image/gif" ) );
     427           0 :             else if( m_aURLParameter.isActive() )
     428             :                 xRow->appendString(
     429             :                     rProp,
     430           0 :                     OUString( "text/plain" ) );
     431           0 :             else if( m_aURLParameter.isFile() )
     432             :                 xRow->appendString(
     433           0 :                     rProp,OUString( "text/html" ) );
     434           0 :             else if( m_aURLParameter.isRoot() )
     435             :                 xRow->appendString(
     436             :                     rProp,
     437           0 :                     OUString( "text/css" ) );
     438             :             else
     439           0 :                 xRow->appendVoid( rProp );
     440         247 :         else if( m_aURLParameter.isModule() )
     441           0 :             if ( rProp.Name == "KeywordList" )
     442             :             {
     443             :                 KeywordInfo *inf =
     444             :                     m_pDatabases->getKeyword( m_aURLParameter.get_module(),
     445           0 :                                               m_aURLParameter.get_language() );
     446             : 
     447           0 :                 uno::Any aAny;
     448           0 :                 if( inf )
     449           0 :                     aAny <<= inf->getKeywordList();
     450           0 :                 xRow->appendObject( rProp,aAny );
     451             :             }
     452           0 :             else if ( rProp.Name == "KeywordRef" )
     453             :             {
     454             :                 KeywordInfo *inf =
     455             :                     m_pDatabases->getKeyword( m_aURLParameter.get_module(),
     456           0 :                                               m_aURLParameter.get_language() );
     457             : 
     458           0 :                 uno::Any aAny;
     459           0 :                 if( inf )
     460           0 :                     aAny <<= inf->getIdList();
     461           0 :                 xRow->appendObject( rProp,aAny );
     462             :             }
     463           0 :             else if ( rProp.Name == "KeywordAnchorForRef" )
     464             :             {
     465             :                 KeywordInfo *inf =
     466             :                     m_pDatabases->getKeyword( m_aURLParameter.get_module(),
     467           0 :                                               m_aURLParameter.get_language() );
     468             : 
     469           0 :                 uno::Any aAny;
     470           0 :                 if( inf )
     471           0 :                     aAny <<= inf->getAnchorList();
     472           0 :                 xRow->appendObject( rProp,aAny );
     473             :             }
     474           0 :             else if ( rProp.Name == "KeywordTitleForRef" )
     475             :             {
     476             :                 KeywordInfo *inf =
     477             :                     m_pDatabases->getKeyword( m_aURLParameter.get_module(),
     478           0 :                                               m_aURLParameter.get_language() );
     479             : 
     480           0 :                 uno::Any aAny;
     481           0 :                 if( inf )
     482           0 :                     aAny <<= inf->getTitleList();
     483           0 :                 xRow->appendObject( rProp,aAny );
     484             :             }
     485           0 :             else if ( rProp.Name == "SearchScopes" )
     486             :             {
     487           0 :                 uno::Sequence< OUString > seq( 2 );
     488           0 :                 seq[0] = "Heading";
     489           0 :                 seq[1] = "FullText";
     490           0 :                 uno::Any aAny;
     491           0 :                 aAny <<= seq;
     492           0 :                 xRow->appendObject( rProp,aAny );
     493             :             }
     494           0 :             else if ( rProp.Name == "Order" )
     495             :             {
     496             :                 StaticModuleInformation *inf =
     497             :                     m_pDatabases->getStaticInformationForModule(
     498             :                         m_aURLParameter.get_module(),
     499           0 :                         m_aURLParameter.get_language() );
     500             : 
     501           0 :                 uno::Any aAny;
     502           0 :                 if( inf )
     503           0 :                     aAny <<= sal_Int32( inf->get_order() );
     504           0 :                 xRow->appendObject( rProp,aAny );
     505             :             }
     506             :             else
     507           0 :                 xRow->appendVoid( rProp );
     508         494 :         else if( "AnchorName" == rProp.Name  &&
     509         247 :                  m_aURLParameter.isFile() )
     510         247 :             xRow->appendString( rProp,m_aURLParameter.get_tag() );
     511             :         else
     512           0 :             xRow->appendVoid( rProp );
     513             :     }
     514             : 
     515        1244 :     return uno::Reference< sdbc::XRow >( xRow.get() );
     516             : }
     517             : 
     518             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10