Files
libreoffice/xmlhelp/source/cxxhelp/provider/content.cxx

576 lines
19 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2001-05-16 06:36:23 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2001-05-16 06:36:23 +00:00
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
2001-05-16 06:36:23 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2001-05-16 06:36:23 +00:00
*
* This file is part of OpenOffice.org.
2001-05-16 06:36:23 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2001-05-16 06:36:23 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2001-05-16 06:36:23 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2001-05-16 06:36:23 +00:00
*
************************************************************************/
2001-05-16 06:36:23 +00:00
/**************************************************************************
TODO
**************************************************************************
*************************************************************************/
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/beans/XPropertyAccess.hpp>
#include <com/sun/star/sdbc/XRow.hpp>
#include <com/sun/star/ucb/OpenCommandArgument2.hpp>
#include <com/sun/star/ucb/OpenMode.hpp>
#include <com/sun/star/ucb/XCommandInfo.hpp>
#include <com/sun/star/io/XActiveDataSink.hpp>
#include <com/sun/star/io/XOutputStream.hpp>
#include <com/sun/star/lang/IllegalAccessException.hpp>
#include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
#include <com/sun/star/io/XActiveDataStreamer.hpp>
2001-05-16 06:36:23 +00:00
#include <com/sun/star/ucb/XPersistentPropertySet.hpp>
2010-10-10 19:46:48 -05:00
#include <osl/diagnose.h>
2001-05-16 06:36:23 +00:00
#include <ucbhelper/contentidentifier.hxx>
#include <ucbhelper/propertyvalueset.hxx>
#include <ucbhelper/cancelcommandexecution.hxx>
#include "content.hxx"
#include "provider.hxx"
#include "resultset.hxx"
#include "databases.hxx"
#include "resultsetfactory.hxx"
#include "resultsetbase.hxx"
#include "resultsetforroot.hxx"
#include "resultsetforquery.hxx"
2001-05-16 06:36:23 +00:00
using namespace com::sun::star;
2001-05-16 06:36:23 +00:00
using namespace chelp;
//=========================================================================
//=========================================================================
//
// Content Implementation.
//
//=========================================================================
//=========================================================================
Content::Content( const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
::ucbhelper::ContentProviderImplHelper* pProvider,
const uno::Reference< ucb::XContentIdentifier >&
Identifier,
Databases* pDatabases )
2001-05-16 06:36:23 +00:00
: ContentImplHelper( rxSMgr, pProvider, Identifier ),
m_aURLParameter( Identifier->getContentIdentifier(),pDatabases ),
m_pDatabases( pDatabases ) // not owner
2001-05-16 06:36:23 +00:00
{
}
//=========================================================================
// virtual
Content::~Content()
{
}
//=========================================================================
//
// XInterface methods.
//
//=========================================================================
// virtual
void SAL_CALL Content::acquire()
2001-10-02 10:48:26 +00:00
throw( )
2001-05-16 06:36:23 +00:00
{
ContentImplHelper::acquire();
}
//=========================================================================
// virtual
void SAL_CALL Content::release()
2001-10-02 10:48:26 +00:00
throw( )
2001-05-16 06:36:23 +00:00
{
ContentImplHelper::release();
}
//=========================================================================
// virtual
uno::Any SAL_CALL Content::queryInterface( const uno::Type & rType )
throw ( uno::RuntimeException )
2001-05-16 06:36:23 +00:00
{
uno::Any aRet;
2001-05-16 06:36:23 +00:00
return aRet.hasValue() ? aRet : ContentImplHelper::queryInterface( rType );
}
//=========================================================================
//
// XTypeProvider methods.
//
//=========================================================================
XTYPEPROVIDER_COMMON_IMPL( Content );
//=========================================================================
// virtual
uno::Sequence< uno::Type > SAL_CALL Content::getTypes()
throw( uno::RuntimeException )
2001-05-16 06:36:23 +00:00
{
static cppu::OTypeCollection* pCollection = NULL;
2001-05-16 06:36:23 +00:00
if ( !pCollection )
{
osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() );
2001-05-16 06:36:23 +00:00
if ( !pCollection )
{
static cppu::OTypeCollection aCollection(
CPPU_TYPE_REF( lang::XTypeProvider ),
CPPU_TYPE_REF( lang::XServiceInfo ),
CPPU_TYPE_REF( lang::XComponent ),
CPPU_TYPE_REF( ucb::XContent ),
CPPU_TYPE_REF( ucb::XCommandProcessor ),
CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ),
CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ),
CPPU_TYPE_REF( beans::XPropertyContainer ),
CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ),
CPPU_TYPE_REF( container::XChild ) );
2001-05-16 06:36:23 +00:00
pCollection = &aCollection;
}
}
return (*pCollection).getTypes();
}
//=========================================================================
//
// XServiceInfo methods.
//
//=========================================================================
// virtual
rtl::OUString SAL_CALL Content::getImplementationName()
throw( uno::RuntimeException )
2001-05-16 06:36:23 +00:00
{
return rtl::OUString( "CHelpContent" );
2001-05-16 06:36:23 +00:00
}
//=========================================================================
// virtual
uno::Sequence< rtl::OUString > SAL_CALL Content::getSupportedServiceNames()
throw( uno::RuntimeException )
2001-05-16 06:36:23 +00:00
{
uno::Sequence< rtl::OUString > aSNS( 1 );
2001-05-16 06:36:23 +00:00
aSNS.getArray()[ 0 ]
= rtl::OUString( MYUCP_CONTENT_SERVICE_NAME );
2001-05-16 06:36:23 +00:00
return aSNS;
}
//=========================================================================
//
// XContent methods.
//
//=========================================================================
// virtual
rtl::OUString SAL_CALL Content::getContentType()
throw( uno::RuntimeException )
2001-05-16 06:36:23 +00:00
{
return rtl::OUString( MYUCP_CONTENT_TYPE );
2001-05-16 06:36:23 +00:00
}
//=========================================================================
//
// XCommandProcessor methods.
//
//=========================================================================
//virtual
void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ )
throw( uno::RuntimeException )
2001-05-16 06:36:23 +00:00
{
}
class ResultSetForRootFactory
: public ResultSetFactory
{
private:
uno::Reference< lang::XMultiServiceFactory > m_xSMgr;
uno::Reference< ucb::XContentProvider > m_xProvider;
sal_Int32 m_nOpenMode;
uno::Sequence< beans::Property > m_seq;
uno::Sequence< ucb::NumberedSortingInfo > m_seqSort;
URLParameter m_aURLParameter;
Databases* m_pDatabases;
2001-05-16 06:36:23 +00:00
public:
ResultSetForRootFactory(
const uno::Reference< lang::XMultiServiceFactory >& xSMgr,
const uno::Reference< ucb::XContentProvider >& xProvider,
sal_Int32 nOpenMode,
const uno::Sequence< beans::Property >& seq,
const uno::Sequence< ucb::NumberedSortingInfo >& seqSort,
URLParameter aURLParameter,
Databases* pDatabases )
2001-05-16 06:36:23 +00:00
: m_xSMgr( xSMgr ),
m_xProvider( xProvider ),
m_nOpenMode( nOpenMode ),
m_seq( seq ),
m_seqSort( seqSort ),
m_aURLParameter( aURLParameter ),
m_pDatabases( pDatabases )
2001-05-16 06:36:23 +00:00
{
}
ResultSetBase* createResultSet()
{
return new ResultSetForRoot( m_xSMgr,
m_xProvider,
m_nOpenMode,
m_seq,
m_seqSort,
m_aURLParameter,
m_pDatabases );
2001-05-16 06:36:23 +00:00
}
};
2001-05-17 08:58:55 +00:00
class ResultSetForQueryFactory
: public ResultSetFactory
{
private:
uno::Reference< lang::XMultiServiceFactory > m_xSMgr;
uno::Reference< ucb::XContentProvider > m_xProvider;
sal_Int32 m_nOpenMode;
uno::Sequence< beans::Property > m_seq;
uno::Sequence< ucb::NumberedSortingInfo > m_seqSort;
URLParameter m_aURLParameter;
Databases* m_pDatabases;
2001-05-17 08:58:55 +00:00
public:
ResultSetForQueryFactory(
const uno::Reference< lang::XMultiServiceFactory >& xSMgr,
const uno::Reference< ucb::XContentProvider >& xProvider,
sal_Int32 nOpenMode,
const uno::Sequence< beans::Property >& seq,
const uno::Sequence< ucb::NumberedSortingInfo >& seqSort,
URLParameter aURLParameter,
Databases* pDatabases )
2001-05-17 08:58:55 +00:00
: m_xSMgr( xSMgr ),
m_xProvider( xProvider ),
m_nOpenMode( nOpenMode ),
m_seq( seq ),
m_seqSort( seqSort ),
m_aURLParameter( aURLParameter ),
m_pDatabases( pDatabases )
2001-05-17 08:58:55 +00:00
{
}
ResultSetBase* createResultSet()
{
return new ResultSetForQuery( m_xSMgr,
m_xProvider,
m_nOpenMode,
m_seq,
m_seqSort,
m_aURLParameter,
m_pDatabases );
2001-05-17 08:58:55 +00:00
}
};
2001-05-16 06:36:23 +00:00
// virtual
uno::Any SAL_CALL Content::execute(
const ucb::Command& aCommand,
sal_Int32 CommandId,
const uno::Reference< ucb::XCommandEnvironment >& Environment )
throw( uno::Exception,
ucb::CommandAbortedException,
uno::RuntimeException )
2001-05-16 06:36:23 +00:00
{
uno::Any aRet;
2001-05-16 06:36:23 +00:00
if ( aCommand.Name == "getPropertyValues" )
{
uno::Sequence< beans::Property > Properties;
if ( !( aCommand.Argument >>= Properties ) )
{
aRet <<= lang::IllegalArgumentException();
ucbhelper::cancelCommandExecution(aRet,Environment);
}
2001-05-16 06:36:23 +00:00
aRet <<= getPropertyValues( Properties );
2001-05-16 06:36:23 +00:00
}
else if ( aCommand.Name == "setPropertyValues" )
2001-05-16 06:36:23 +00:00
{
uno::Sequence<beans::PropertyValue> propertyValues;
if( ! ( aCommand.Argument >>= propertyValues ) ) {
aRet <<= lang::IllegalArgumentException();
ucbhelper::cancelCommandExecution(aRet,Environment);
}
uno::Sequence< uno::Any > ret(propertyValues.getLength());
uno::Sequence< beans::Property > props(getProperties(Environment));
// No properties can be set
for(sal_Int32 i = 0; i < ret.getLength(); ++i) {
ret[i] <<= beans::UnknownPropertyException();
for(sal_Int32 j = 0; j < props.getLength(); ++j)
if(props[j].Name == propertyValues[i].Name) {
ret[i] <<= lang::IllegalAccessException();
break;
}
}
aRet <<= ret;
2001-05-16 06:36:23 +00:00
}
else if ( aCommand.Name == "getPropertySetInfo" )
2001-05-16 06:36:23 +00:00
{
// Note: Implemented by base class.
aRet <<= getPropertySetInfo( Environment );
2001-05-16 06:36:23 +00:00
}
else if ( aCommand.Name == "getCommandInfo" )
{
// Note: Implemented by base class.
aRet <<= getCommandInfo( Environment );
}
else if ( aCommand.Name == "open" )
{
ucb::OpenCommandArgument2 aOpenCommand;
if ( !( aCommand.Argument >>= aOpenCommand ) )
{
aRet <<= lang::IllegalArgumentException();
ucbhelper::cancelCommandExecution(aRet,Environment);
}
uno::Reference< io::XActiveDataSink > xActiveDataSink(
aOpenCommand.Sink, uno::UNO_QUERY);
if(xActiveDataSink.is())
m_aURLParameter.open(m_xSMgr,
aCommand,
CommandId,
Environment,
xActiveDataSink);
uno::Reference< io::XActiveDataStreamer > xActiveDataStreamer(
aOpenCommand.Sink, uno::UNO_QUERY);
if(xActiveDataStreamer.is()) {
aRet <<= ucb::UnsupportedDataSinkException();
ucbhelper::cancelCommandExecution(aRet,Environment);
}
uno::Reference< io::XOutputStream > xOutputStream(
aOpenCommand.Sink, uno::UNO_QUERY);
if(xOutputStream.is() )
m_aURLParameter.open(m_xSMgr,
aCommand,
CommandId,
Environment,
xOutputStream);
if( m_aURLParameter.isRoot() )
{
uno::Reference< ucb::XDynamicResultSet > xSet
= new DynamicResultSet(
m_xSMgr,
this,
aOpenCommand,
Environment,
new ResultSetForRootFactory(
m_xSMgr,
m_xProvider.get(),
aOpenCommand.Mode,
aOpenCommand.Properties,
aOpenCommand.SortingInfo,
m_aURLParameter,
m_pDatabases));
aRet <<= xSet;
}
else if( m_aURLParameter.isQuery() )
{
uno::Reference< ucb::XDynamicResultSet > xSet
= new DynamicResultSet(
m_xSMgr,
this,
aOpenCommand,
Environment,
new ResultSetForQueryFactory(
m_xSMgr,
m_xProvider.get(),
aOpenCommand.Mode,
aOpenCommand.Properties,
aOpenCommand.SortingInfo,
m_aURLParameter,
m_pDatabases ) );
aRet <<= xSet;
}
2001-05-16 06:36:23 +00:00
}
else
2001-05-16 06:36:23 +00:00
{
//////////////////////////////////////////////////////////////////
// Unsupported command
//////////////////////////////////////////////////////////////////
aRet <<= ucb::UnsupportedCommandException();
ucbhelper::cancelCommandExecution(aRet,Environment);
2001-05-16 06:36:23 +00:00
}
return aRet;
2001-05-16 06:36:23 +00:00
}
//=========================================================================
uno::Reference< sdbc::XRow > Content::getPropertyValues(
const uno::Sequence< beans::Property >& rProperties )
2001-05-16 06:36:23 +00:00
{
2001-05-16 13:53:27 +00:00
osl::MutexGuard aGuard( m_aMutex );
rtl::Reference< ::ucbhelper::PropertyValueSet > xRow =
new ::ucbhelper::PropertyValueSet( m_xSMgr );
2001-05-16 13:53:27 +00:00
for ( sal_Int32 n = 0; n < rProperties.getLength(); ++n )
{
const beans::Property& rProp = rProperties[n];
2001-05-16 13:53:27 +00:00
if ( rProp.Name == "ContentType" )
xRow->appendString(
rProp,
rtl::OUString(
"application/vnd.sun.star.help" ) );
else if ( rProp.Name == "Title" )
2001-05-16 13:53:27 +00:00
xRow->appendString ( rProp,m_aURLParameter.get_title() );
else if ( rProp.Name == "IsReadOnly" )
2001-07-02 07:08:24 +00:00
xRow->appendBoolean( rProp,true );
else if ( rProp.Name == "IsDocument" )
xRow->appendBoolean(
rProp,
m_aURLParameter.isFile() || m_aURLParameter.isRoot() );
else if ( rProp.Name == "IsFolder" )
xRow->appendBoolean(
rProp,
! m_aURLParameter.isFile() || m_aURLParameter.isRoot() );
else if ( rProp.Name == "IsErrorDocument" )
xRow->appendBoolean( rProp, m_aURLParameter.isErrorDocument() );
else if ( rProp.Name == "MediaType" )
2001-05-16 13:53:27 +00:00
if( m_aURLParameter.isPicture() )
xRow->appendString(
rProp,
rtl::OUString( "image/gif" ) );
2001-06-13 08:10:13 +00:00
else if( m_aURLParameter.isActive() )
xRow->appendString(
rProp,
rtl::OUString( "text/plain" ) );
2001-05-16 13:53:27 +00:00
else if( m_aURLParameter.isFile() )
xRow->appendString(
rProp,rtl::OUString( "text/html" ) );
2001-05-16 13:53:27 +00:00
else if( m_aURLParameter.isRoot() )
xRow->appendString(
rProp,
rtl::OUString( "text/css" ) );
2001-05-16 13:53:27 +00:00
else
xRow->appendVoid( rProp );
else if( m_aURLParameter.isModule() )
if ( rProp.Name == "KeywordList" )
2001-05-16 13:53:27 +00:00
{
KeywordInfo *inf =
m_pDatabases->getKeyword( m_aURLParameter.get_module(),
m_aURLParameter.get_language() );
2001-05-16 13:53:27 +00:00
uno::Any aAny;
if( inf )
aAny <<= inf->getKeywordList();
2001-05-16 13:53:27 +00:00
xRow->appendObject( rProp,aAny );
}
else if ( rProp.Name == "KeywordRef" )
2001-05-16 13:53:27 +00:00
{
KeywordInfo *inf =
m_pDatabases->getKeyword( m_aURLParameter.get_module(),
m_aURLParameter.get_language() );
2001-05-16 13:53:27 +00:00
uno::Any aAny;
if( inf )
aAny <<= inf->getIdList();
2001-05-16 13:53:27 +00:00
xRow->appendObject( rProp,aAny );
}
else if ( rProp.Name == "KeywordAnchorForRef" )
2001-05-16 13:53:27 +00:00
{
KeywordInfo *inf =
m_pDatabases->getKeyword( m_aURLParameter.get_module(),
m_aURLParameter.get_language() );
2001-05-16 13:53:27 +00:00
uno::Any aAny;
if( inf )
aAny <<= inf->getAnchorList();
2001-05-16 13:53:27 +00:00
xRow->appendObject( rProp,aAny );
}
else if ( rProp.Name == "KeywordTitleForRef" )
2001-05-16 13:53:27 +00:00
{
KeywordInfo *inf =
m_pDatabases->getKeyword( m_aURLParameter.get_module(),
m_aURLParameter.get_language() );
2001-05-16 13:53:27 +00:00
uno::Any aAny;
if( inf )
aAny <<= inf->getTitleList();
2001-05-16 13:53:27 +00:00
xRow->appendObject( rProp,aAny );
}
else if ( rProp.Name == "SearchScopes" )
2001-05-16 13:53:27 +00:00
{
uno::Sequence< rtl::OUString > seq( 2 );
seq[0] = rtl::OUString( "Heading" );
seq[1] = rtl::OUString( "FullText" );
uno::Any aAny;
2001-05-16 13:53:27 +00:00
aAny <<= seq;
xRow->appendObject( rProp,aAny );
}
else if ( rProp.Name == "Order" )
{
StaticModuleInformation *inf =
m_pDatabases->getStaticInformationForModule(
m_aURLParameter.get_module(),
m_aURLParameter.get_language() );
uno::Any aAny;
if( inf )
aAny <<= sal_Int32( inf->get_order() );
xRow->appendObject( rProp,aAny );
}
2001-05-16 13:53:27 +00:00
else
xRow->appendVoid( rProp );
else if( "AnchorName" == rProp.Name &&
m_aURLParameter.isFile() )
2001-05-16 13:53:27 +00:00
xRow->appendString( rProp,m_aURLParameter.get_tag() );
else
xRow->appendVoid( rProp );
}
return uno::Reference< sdbc::XRow >( xRow.get() );
2001-05-16 06:36:23 +00:00
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */