diff options
author | Cédric Bosdonnat <cedric.bosdonnat@free.fr> | 2012-05-29 16:17:21 +0200 |
---|---|---|
committer | Cédric Bosdonnat <cedric.bosdonnat@free.fr> | 2012-06-04 13:28:12 +0200 |
commit | 6f34fd25cbd8d9ed43ae9c2b074f7c6fa6968b31 (patch) | |
tree | 962c4defeb8d77f4a693a41e4bf90c73f284201e /ucb/source | |
parent | 966d20e35d5a2be2fce6c204af5c156c3ead7063 (diff) |
CMIS UCP: implemented folder case for open command
Change-Id: Id0997cd99d7d80c975de3d46670a1fa8b3d602a3
Diffstat (limited to 'ucb/source')
-rw-r--r-- | ucb/source/ucp/cmis/cmis_content.cxx | 36 | ||||
-rw-r--r-- | ucb/source/ucp/cmis/cmis_content.hxx | 6 | ||||
-rw-r--r-- | ucb/source/ucp/cmis/cmis_datasupplier.cxx | 244 | ||||
-rw-r--r-- | ucb/source/ucp/cmis/cmis_datasupplier.hxx | 84 | ||||
-rw-r--r-- | ucb/source/ucp/cmis/cmis_resultset.cxx | 44 | ||||
-rw-r--r-- | ucb/source/ucp/cmis/cmis_resultset.hxx | 39 |
6 files changed, 449 insertions, 4 deletions
diff --git a/ucb/source/ucp/cmis/cmis_content.cxx b/ucb/source/ucp/cmis/cmis_content.cxx index ead9f2da4ab0..138eb36110f6 100644 --- a/ucb/source/ucp/cmis/cmis_content.cxx +++ b/ucb/source/ucp/cmis/cmis_content.cxx @@ -39,6 +39,7 @@ #include <com/sun/star/ucb/ContentInfoAttribute.hpp> #include <com/sun/star/ucb/InsertCommandArgument.hpp> #include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp> +#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp> #include <com/sun/star/ucb/MissingInputStreamException.hpp> #include <com/sun/star/ucb/NameClash.hpp> #include <com/sun/star/ucb/NameClashException.hpp> @@ -60,6 +61,7 @@ #include "cmis_content.hxx" #include "cmis_provider.hxx" +#include "cmis_resultset.hxx" #define OUSTR_TO_STDSTR(s) string( rtl::OUStringToOString( s, RTL_TEXTENCODING_UTF8 ).getStr() ) @@ -322,6 +324,21 @@ namespace cmis return uno::Reference< sdbc::XRow >( xRow.get() ); } + bool Content::exists( ) + { + bool bExists = true; + try + { + libcmis::ObjectPtr object = m_pSession->getObject( OUSTR_TO_STDSTR( m_sObjectId ) ); + } + catch ( const libcmis::Exception& ) + { + bExists = false; + } + + return bExists; + } + void Content::queryChildren( ContentRefList& /*rChildren*/ ) { SAL_INFO( "cmisucp", "TODO - Content::queryChildren()" ); @@ -334,7 +351,19 @@ namespace cmis { bool bIsFolder = isFolder( xEnv ); - // TODO Handle the case of the non-existing file + // Handle the case of the non-existing file + if ( !exists( ) ) + { + uno::Sequence< uno::Any > aArgs( 1 ); + aArgs[ 0 ] <<= m_xIdentifier->getContentIdentifier(); + uno::Any aErr = uno::makeAny( + ucb::InteractiveAugmentedIOException(rtl::OUString(), static_cast< cppu::OWeakObject * >( this ), + task::InteractionClassification_ERROR, + bIsFolder ? ucb::IOErrorCode_NOT_EXISTING_PATH : ucb::IOErrorCode_NOT_EXISTING, aArgs) + ); + + ucbhelper::cancelCommandExecution(aErr, xEnv); + } uno::Any aRet; @@ -346,8 +375,9 @@ namespace cmis if ( bOpenFolder && bIsFolder ) { - SAL_INFO( "cmisucp", "TODO - Content::open() - Folder case" ); - // TODO Handle the folder case + uno::Reference< ucb::XDynamicResultSet > xSet + = new DynamicResultSet(m_xSMgr, this, rOpenCommand, xEnv ); + aRet <<= xSet; } else if ( rOpenCommand.Sink.is() ) { diff --git a/ucb/source/ucp/cmis/cmis_content.hxx b/ucb/source/ucp/cmis/cmis_content.hxx index e80a6d278bf3..dfe8cc2fb8fd 100644 --- a/ucb/source/ucp/cmis/cmis_content.hxx +++ b/ucb/source/ucp/cmis/cmis_content.hxx @@ -89,6 +89,9 @@ private: getPropertyValues( const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& rProperties, const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& xEnv ); + + bool exists( ); + private: typedef rtl::Reference< Content > ContentRef; typedef std::list< ContentRef > ContentRefList; @@ -124,7 +127,6 @@ private: sal_Bool exchangeIdentity(const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& xNewId); void resetAuthProvider( const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& xEnv ); - libcmis::ObjectPtr getObject( ); public: Content( const com::sun::star::uno::Reference< @@ -186,6 +188,8 @@ public: com::sun::star::uno::Sequence< com::sun::star::ucb::ContentInfo > queryCreatableContentsInfo( const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& xEnv ) throw( com::sun::star::uno::RuntimeException ); + + libcmis::ObjectPtr getObject( ); }; } diff --git a/ucb/source/ucp/cmis/cmis_datasupplier.cxx b/ucb/source/ucp/cmis/cmis_datasupplier.cxx new file mode 100644 index 000000000000..2a82a9bdfc4c --- /dev/null +++ b/ucb/source/ucp/cmis/cmis_datasupplier.cxx @@ -0,0 +1,244 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright 2012 LibreOffice contributors. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <vector> + +#include <ucbhelper/contentidentifier.hxx> +#include <ucbhelper/providerhelper.hxx> + +#include <com/sun/star/ucb/OpenMode.hpp> + +#include "cmis_datasupplier.hxx" +#include "cmis_content.hxx" +#include "cmis_provider.hxx" + +using namespace com::sun::star; +using namespace std; + +namespace cmis +{ + + typedef std::vector< ResultListEntry* > ResultList; + + DataSupplier::DataSupplier( const uno::Reference< lang::XMultiServiceFactory >& rxSMgr, + const uno::Reference< ::cmis::Content >& rContent, sal_Int32 nOpenMode ) + : mxContent(rContent), m_xSMgr(rxSMgr), mnOpenMode(nOpenMode), mbCountFinal(false) + { + } + + bool DataSupplier::getData() + { + if ( mbCountFinal ) + return true; + + libcmis::ObjectPtr pObject = mxContent->getObject(); + libcmis::Folder* pFolder = dynamic_cast< libcmis::Folder* >( pObject.get( ) ); + if ( NULL != pFolder ) + { + // Get the children from pObject + try + { + vector< libcmis::ObjectPtr > children = pFolder->getChildren( ); + + // Loop over the results and filter them + for ( vector< libcmis::ObjectPtr >::iterator it = children.begin(); + it != children.end(); ++it ) + { + bool bIsFolder = ( *it )->getBaseType( ) == "cmis:folder"; + if ( ( mnOpenMode == ucb::OpenMode::FOLDERS && bIsFolder ) || + ( mnOpenMode == ucb::OpenMode::DOCUMENTS && !bIsFolder ) || + ( mnOpenMode == ucb::OpenMode::ALL ) ) + { + maResults.push_back( new ResultListEntry( *it ) ); + } + } + mbCountFinal = sal_True; + + return true; + } + catch ( const libcmis::Exception& e ) + { + SAL_INFO( "cmisucp", "Exception thrown: " << e.what() ); + return false; + } + } + + return false; + } + + DataSupplier::~DataSupplier() + { + } + + ::rtl::OUString DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex ) + { + if ( nIndex < maResults.size() ) + { + ::rtl::OUString aId = maResults[ nIndex ]->aId; + if ( aId.getLength() ) + { + // Already cached. + return aId; + } + } + + if ( getResult( nIndex ) ) + { + string sObjectId = maResults[nIndex]->pObject->getId( ); + + // Get the URL from the Id + URL aUrl( mxContent->getIdentifier( )->getContentIdentifier( ) ); + aUrl.setObjectId( rtl::OUString::createFromAscii( sObjectId.c_str( ) ) ); + rtl::OUString aId = aUrl.asString( ); + + maResults[ nIndex ]->aId = aId; + return aId; + } + + return ::rtl::OUString(); + } + + uno::Reference< ucb::XContentIdentifier > DataSupplier::queryContentIdentifier( sal_uInt32 nIndex ) + { + if ( nIndex < maResults.size() ) + { + uno::Reference< ucb::XContentIdentifier > xId = maResults[ nIndex ]->xId; + if ( xId.is() ) + { + // Already cached. + return xId; + } + } + + ::rtl::OUString aId = queryContentIdentifierString( nIndex ); + if ( aId.getLength() ) + { + uno::Reference< ucb::XContentIdentifier > xId = new ucbhelper::ContentIdentifier( aId ); + maResults[ nIndex ]->xId = xId; + return xId; + } + + return uno::Reference< ucb::XContentIdentifier >(); + } + + uno::Reference< ucb::XContent > DataSupplier::queryContent( sal_uInt32 nIndex ) + { + if ( nIndex < maResults.size() ) + { + uno::Reference< ucb::XContent > xContent = maResults[ nIndex ]->xContent; + if ( xContent.is() ) + { + // Already cached. + return xContent; + } + } + + uno::Reference< ucb::XContentIdentifier > xId = queryContentIdentifier( nIndex ); + if ( xId.is() ) + { + try + { + uno::Reference< ucb::XContent > xContent = mxContent->getProvider()->queryContent( xId ); + maResults[ nIndex ]->xContent = xContent; + return xContent; + } + catch ( ucb::IllegalIdentifierException& ) + { + } + } + return uno::Reference< ucb::XContent >(); + } + + sal_Bool DataSupplier::getResult( sal_uInt32 nIndex ) + { + if ( maResults.size() > nIndex ) // Result already present. + return sal_True; + + if ( getData() && maResults.size() > nIndex ) + return sal_True; + + return sal_False; + } + + sal_uInt32 DataSupplier::totalCount() + { + getData(); + return maResults.size(); + } + + sal_uInt32 DataSupplier::currentCount() + { + return maResults.size(); + } + + sal_Bool DataSupplier::isCountFinal() + { + return mbCountFinal; + } + + uno::Reference< sdbc::XRow > DataSupplier::queryPropertyValues( sal_uInt32 nIndex ) + { + if ( nIndex < maResults.size() ) + { + uno::Reference< sdbc::XRow > xRow = maResults[ nIndex ]->xRow; + if ( xRow.is() ) + { + // Already cached. + return xRow; + } + } + + if ( getResult( nIndex ) ) + { + uno::Reference< ucb::XContent > xContent( queryContent( nIndex ) ); + if ( xContent.is() ) + { + try + { + uno::Reference< ucb::XCommandProcessor > xCmdProc( + xContent, uno::UNO_QUERY_THROW ); + sal_Int32 nCmdId( xCmdProc->createCommandIdentifier() ); + ucb::Command aCmd; + aCmd.Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("getPropertyValues")); + aCmd.Handle = -1; + aCmd.Argument <<= getResultSet()->getProperties(); + uno::Any aResult( xCmdProc->execute( + aCmd, nCmdId, getResultSet()->getEnvironment() ) ); + uno::Reference< sdbc::XRow > xRow; + if ( aResult >>= xRow ) + { + maResults[ nIndex ]->xRow = xRow; + return xRow; + } + } + catch ( uno::Exception const & ) + { + } + } + } + return uno::Reference< sdbc::XRow >(); + } + + void DataSupplier::releasePropertyValues( sal_uInt32 nIndex ) + { + if ( nIndex < maResults.size() ) + maResults[ nIndex ]->xRow = uno::Reference< sdbc::XRow >(); + } + + void DataSupplier::close() + { + } + + void DataSupplier::validate() throw( ucb::ResultSetException ) + { + } + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/ucb/source/ucp/cmis/cmis_datasupplier.hxx b/ucb/source/ucp/cmis/cmis_datasupplier.hxx new file mode 100644 index 000000000000..14ad404c90f0 --- /dev/null +++ b/ucb/source/ucp/cmis/cmis_datasupplier.hxx @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright 2012 LibreOffice contributors. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef CMIS_DATASUPPLIER_HXX +#define CMIS_DATASUPPLIER_HXX + +#include <vector> + +#include <ucbhelper/resultset.hxx> + +#include "cmis_content.hxx" + +namespace cmis +{ + + class Content; + + struct ResultListEntry + { + ::rtl::OUString aId; + com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier > xId; + com::sun::star::uno::Reference< com::sun::star::ucb::XContent > xContent; + com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > xRow; + libcmis::ObjectPtr pObject; + + ResultListEntry( libcmis::ObjectPtr pObj ) : pObject( pObj ) + { + } + + ~ResultListEntry() + { + } + }; + + typedef std::vector< ResultListEntry* > ResultList; + + class DataSupplier : public ucbhelper::ResultSetDataSupplier + { + private: + com::sun::star::uno::Reference< ::cmis::Content > mxContent; + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xSMgr; + sal_Int32 mnOpenMode; + bool mbCountFinal; + bool getData(); + ResultList maResults; + + public: + DataSupplier( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSMgr, + const com::sun::star::uno::Reference< Content >& rContent, sal_Int32 nOpenMode ); + virtual ~DataSupplier(); + + virtual rtl::OUString queryContentIdentifierString( sal_uInt32 nIndex ); + virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier > + queryContentIdentifier( sal_uInt32 nIndex ); + virtual com::sun::star::uno::Reference< com::sun::star::ucb::XContent > + queryContent( sal_uInt32 nIndex ); + + virtual sal_Bool getResult( sal_uInt32 nIndex ); + + virtual sal_uInt32 totalCount(); + virtual sal_uInt32 currentCount(); + virtual sal_Bool isCountFinal(); + + virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > + queryPropertyValues( sal_uInt32 nIndex ); + virtual void releasePropertyValues( sal_uInt32 nIndex ); + + virtual void close(); + + virtual void validate() + throw( com::sun::star::ucb::ResultSetException ); + }; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/ucb/source/ucp/cmis/cmis_resultset.cxx b/ucb/source/ucp/cmis/cmis_resultset.cxx new file mode 100644 index 000000000000..b79b5f1bafe2 --- /dev/null +++ b/ucb/source/ucp/cmis/cmis_resultset.cxx @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright 2012 LibreOffice contributors. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "cmis_datasupplier.hxx" +#include "cmis_resultset.hxx" + +using namespace com::sun::star::lang; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; + +namespace cmis +{ + DynamicResultSet::DynamicResultSet( + const Reference< XMultiServiceFactory >& rxSMgr, + const Reference< Content >& rxContent, + const OpenCommandArgument2& rCommand, + const Reference< XCommandEnvironment >& rxEnv ) : + ResultSetImplHelper( rxSMgr, rCommand ), + m_xContent( rxContent ), + m_xEnv( rxEnv ) + { + } + + void DynamicResultSet::initStatic() + { + m_xResultSet1 = new ::ucbhelper::ResultSet( + m_xSMgr, m_aCommand.Properties, + new DataSupplier( m_xSMgr, m_xContent, m_aCommand.Mode ), m_xEnv ); + } + + void DynamicResultSet::initDynamic() + { + initStatic(); + m_xResultSet2 = m_xResultSet1; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/ucb/source/ucp/cmis/cmis_resultset.hxx b/ucb/source/ucp/cmis/cmis_resultset.hxx new file mode 100644 index 000000000000..bd40a8ce4690 --- /dev/null +++ b/ucb/source/ucp/cmis/cmis_resultset.hxx @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright 2012 LibreOffice contributors. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef CMIS_RESULTSET_HXX +#define CMIS_RESULTSET_HXX + +#include <ucbhelper/resultsethelper.hxx> + +namespace cmis +{ + + class DynamicResultSet : public ::ucbhelper::ResultSetImplHelper + { + com::sun::star::uno::Reference< Content > m_xContent; + com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > m_xEnv; + + private: + virtual void initStatic(); + virtual void initDynamic(); + + public: + DynamicResultSet( + const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSMgr, + const com::sun::star::uno::Reference< Content >& rxContent, + const com::sun::star::ucb::OpenCommandArgument2& rCommand, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& rxEnv ); + }; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |