diff options
author | Cédric Bosdonnat <cedric.bosdonnat@free.fr> | 2012-07-09 17:30:11 +0200 |
---|---|---|
committer | Cédric Bosdonnat <cedric.bosdonnat@free.fr> | 2012-07-09 17:36:12 +0200 |
commit | 4cb0143327155b6678989a3fe63f11df5014f3a5 (patch) | |
tree | 71260f7ed19dd41f50846fef6442acf4dfa35093 | |
parent | 5db77d15790b154d7a066afabd73ab89d48915d6 (diff) |
CMIS UCP: Added support for Binding URL and Repository as folders
This feature needed to change quite some code in the way children are
fetched in CMIS UCP to avoid running several times the same HTTP
requests.
The new URLs will find the following scheme:
+ Children of vnd.libreoffice.cmis+atom://admin@http-encoded-binding-url-no-repoid/
are the repositories listed by the binding URL
+ Children of vnd.libreoffice.cmis+atom://admin@http-encoded-binding-url-no-repoid/repoid
are the root folder of the repository
Change-Id: I405d88c82e6fc9f1110a84165a151257c4ce60db
-rw-r--r-- | ucb/Library_ucpcmis1.mk | 3 | ||||
-rw-r--r-- | ucb/source/ucp/cmis/cmis_content.cxx | 106 | ||||
-rw-r--r-- | ucb/source/ucp/cmis/cmis_content.hxx | 12 | ||||
-rw-r--r-- | ucb/source/ucp/cmis/cmis_datasupplier.cxx | 132 | ||||
-rw-r--r-- | ucb/source/ucp/cmis/cmis_datasupplier.hxx | 12 | ||||
-rw-r--r-- | ucb/source/ucp/cmis/cmis_provider.cxx | 21 | ||||
-rw-r--r-- | ucb/source/ucp/cmis/cmis_resultset.cxx | 6 | ||||
-rw-r--r-- | ucb/source/ucp/cmis/cmis_resultset.hxx | 8 | ||||
-rw-r--r-- | ucb/source/ucp/cmis/cmis_url.hxx | 2 |
9 files changed, 109 insertions, 193 deletions
diff --git a/ucb/Library_ucpcmis1.mk b/ucb/Library_ucpcmis1.mk index 635aaa2cac87..1fb12264652a 100644 --- a/ucb/Library_ucpcmis1.mk +++ b/ucb/Library_ucpcmis1.mk @@ -32,6 +32,7 @@ $(eval $(call gb_Library_set_componentfile,ucpcmis1,ucb/source/ucp/cmis/ucpcmis1 $(eval $(call gb_Library_use_sdk_api,ucpcmis1)) $(eval $(call gb_Library_use_libraries,ucpcmis1,\ + comphelper \ cppu \ cppuhelper \ sal \ @@ -49,7 +50,9 @@ $(eval $(call gb_Library_use_externals,ucpcmis1,\ )) $(eval $(call gb_Library_add_exception_objects,ucpcmis1,\ + ucb/source/ucp/cmis/auth_provider \ ucb/source/ucp/cmis/cmis_content \ + ucb/source/ucp/cmis/cmis_repo_content \ ucb/source/ucp/cmis/cmis_datasupplier \ ucb/source/ucp/cmis/cmis_provider \ ucb/source/ucp/cmis/cmis_resultset \ diff --git a/ucb/source/ucp/cmis/cmis_content.cxx b/ucb/source/ucp/cmis/cmis_content.cxx index 057b3d62704d..f0464623bd6e 100644 --- a/ucb/source/ucp/cmis/cmis_content.cxx +++ b/ucb/source/ucp/cmis/cmis_content.cxx @@ -57,8 +57,8 @@ #include <ucbhelper/std_inputstream.hxx> #include <ucbhelper/std_outputstream.hxx> #include <ucbhelper/propertyvalueset.hxx> -#include <ucbhelper/simpleauthenticationrequest.hxx> +#include "auth_provider.hxx" #include "cmis_content.hxx" #include "cmis_provider.hxx" #include "cmis_resultset.hxx" @@ -71,64 +71,6 @@ using namespace std; namespace { - class AuthProvider : public libcmis::AuthProvider - { - const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment>& m_xEnv; - rtl::OUString m_sUrl; - rtl::OUString m_sBindingUrl; - - public: - AuthProvider ( const com::sun::star::uno::Reference< - com::sun::star::ucb::XCommandEnvironment>& xEnv, - rtl::OUString sUrl, - rtl::OUString sBindingUrl ): - m_xEnv( xEnv ), m_sUrl( sUrl ), m_sBindingUrl( sBindingUrl ) { } - - bool authenticationQuery( string& username, string& password ); - }; - - bool AuthProvider::authenticationQuery( string& username, string& password ) - { - if ( m_xEnv.is() ) - { - uno::Reference< task::XInteractionHandler > xIH - = m_xEnv->getInteractionHandler(); - - if ( xIH.is() ) - { - rtl::Reference< ucbhelper::SimpleAuthenticationRequest > xRequest - = new ucbhelper::SimpleAuthenticationRequest( - m_sUrl, m_sBindingUrl, ::rtl::OUString(), - STD_TO_OUSTR( username ), - STD_TO_OUSTR( password ), - ::rtl::OUString(), true, false ); - xIH->handle( xRequest.get() ); - - rtl::Reference< ucbhelper::InteractionContinuation > xSelection - = xRequest->getSelection(); - - if ( xSelection.is() ) - { - // Handler handled the request. - uno::Reference< task::XInteractionAbort > xAbort( - xSelection.get(), uno::UNO_QUERY ); - if ( !xAbort.is() ) - { - const rtl::Reference< - ucbhelper::InteractionSupplyAuthentication > & xSupp - = xRequest->getAuthenticationSupplier(); - - username = OUSTR_TO_STDSTR( xSupp->getUserName() ); - password = OUSTR_TO_STDSTR( xSupp->getPassword() ); - - return true; - } - } - } - } - return false; - } - util::DateTime lcl_boostToUnoTime( boost::posix_time::ptime boostTime ) { util::DateTime unoTime; @@ -152,11 +94,13 @@ namespace namespace cmis { Content::Content( const uno::Reference< lang::XMultiServiceFactory >& rxSMgr, - ContentProvider *pProvider, const uno::Reference< ucb::XContentIdentifier >& Identifier) + ContentProvider *pProvider, const uno::Reference< ucb::XContentIdentifier >& Identifier, + libcmis::ObjectPtr pObject ) throw ( ucb::ContentCreationException ) : ContentImplHelper( rxSMgr, pProvider, Identifier ), m_pProvider( pProvider ), m_pSession( NULL ), + m_pObject( pObject ), m_bTransient( false ) { // Split the URL into bits @@ -459,12 +403,6 @@ namespace cmis return bExists; } - void Content::queryChildren( ContentRefList& /*rChildren*/ ) - { - SAL_INFO( "cmisucp", "TODO - Content::queryChildren()" ); - // TODO Implement me - } - uno::Any Content::open(const ucb::OpenCommandArgument2 & rOpenCommand, const uno::Reference< ucb::XCommandEnvironment > & xEnv ) throw( uno::Exception ) @@ -1210,6 +1148,42 @@ namespace cmis } } + list< uno::Reference< ucb::XContent > > Content::getChildren( ) + { + list< uno::Reference< ucb::XContent > > results; + SAL_INFO( "cmisucp", "Content::getChildren() " << m_sURL ); + + libcmis::Folder* pFolder = dynamic_cast< libcmis::Folder* >( getObject( ).get( ) ); + if ( NULL != pFolder ) + { + // Get the children from pObject + try + { + vector< libcmis::ObjectPtr > children = pFolder->getChildren( ); + + // Loop over the results + for ( vector< libcmis::ObjectPtr >::iterator it = children.begin(); + it != children.end(); ++it ) + { + // TODO Cache the objects + + URL aUrl( m_sURL ); + aUrl.setObjectPath( m_sObjectPath + STD_TO_OUSTR( ( *it )->getName( ) ) ); + uno::Reference< ucb::XContentIdentifier > xId = new ucbhelper::ContentIdentifier( aUrl.asString( ) ); + uno::Reference< ucb::XContent > xContent = new Content( m_xSMgr, m_pProvider, xId, *it ); + + results.push_back( xContent ); + } + } + catch ( const libcmis::Exception& e ) + { + SAL_INFO( "cmisucp", "Exception thrown: " << e.what() ); + } + } + + return results; + } + void Content::setCmisProperty( std::string sName, std::string sValue ) { if ( m_pObjectType.get( ) ) diff --git a/ucb/source/ucp/cmis/cmis_content.hxx b/ucb/source/ucp/cmis/cmis_content.hxx index 28ff5cd14d25..0c24b6aff26e 100644 --- a/ucb/source/ucp/cmis/cmis_content.hxx +++ b/ucb/source/ucp/cmis/cmis_content.hxx @@ -30,6 +30,7 @@ #define CMIS_CONTENT_HXX #include "cmis_url.hxx" +#include "children_provider.hxx" #include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/io/XOutputStream.hpp> @@ -64,7 +65,9 @@ namespace cmis #define CMIS_FOLDER_TYPE "application/vnd.sun.staroffice.cmis-folder" class ContentProvider; -class Content : public ::ucbhelper::ContentImplHelper, public com::sun::star::ucb::XContentCreator +class Content : public ::ucbhelper::ContentImplHelper, + public com::sun::star::ucb::XContentCreator, + public ChildrenProvider { private: ContentProvider* m_pProvider; @@ -96,8 +99,6 @@ private: typedef rtl::Reference< Content > ContentRef; typedef std::list< ContentRef > ContentRefList; - void queryChildren( ContentRefList& rChildren ); - com::sun::star::uno::Any open(const com::sun::star::ucb::OpenCommandArgument2 & rArg, const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > & xEnv ) throw( com::sun::star::uno::Exception ); @@ -131,7 +132,8 @@ private: public: Content( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSMgr, ContentProvider *pProvider, - const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& Identifier) + const com::sun::star::uno::Reference< com::sun::star::ucb::XContentIdentifier >& Identifier, + libcmis::ObjectPtr pObject = libcmis::ObjectPtr( ) ) throw ( com::sun::star::ucb::ContentCreationException ); Content( const com::sun::star::uno::Reference< @@ -189,6 +191,8 @@ public: queryCreatableContentsInfo( const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& xEnv ) throw( com::sun::star::uno::RuntimeException ); + virtual std::list< com::sun::star::uno::Reference< com::sun::star::ucb::XContent > > getChildren( ); + libcmis::ObjectPtr getObject( ) throw ( libcmis::Exception ); }; diff --git a/ucb/source/ucp/cmis/cmis_datasupplier.cxx b/ucb/source/ucp/cmis/cmis_datasupplier.cxx index c459dde42f11..5d075740b0de 100644 --- a/ucb/source/ucp/cmis/cmis_datasupplier.cxx +++ b/ucb/source/ucp/cmis/cmis_datasupplier.cxx @@ -29,8 +29,8 @@ 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) + ChildrenProvider* pChildrenProvider, sal_Int32 nOpenMode ) + : m_pChildrenProvider( pChildrenProvider ), m_xSMgr(rxSMgr), mnOpenMode(nOpenMode), mbCountFinal(false) { } @@ -39,132 +39,52 @@ namespace cmis 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; + list< uno::Reference< ucb::XContent > > aChildren = m_pChildrenProvider->getChildren( ); - return true; - } - catch ( const libcmis::Exception& e ) + // Loop over the results and filter them + for ( list< uno::Reference< ucb::XContent > >::iterator it = aChildren.begin(); + it != aChildren.end(); ++it ) + { + rtl::OUString sContentType = ( *it )->getContentType( ); + bool bIsFolder = sContentType != CMIS_FILE_TYPE; + if ( ( mnOpenMode == ucb::OpenMode::FOLDERS && bIsFolder ) || + ( mnOpenMode == ucb::OpenMode::DOCUMENTS && !bIsFolder ) || + ( mnOpenMode == ucb::OpenMode::ALL ) ) { - SAL_INFO( "cmisucp", "Exception thrown: " << e.what() ); - return false; + maResults.push_back( new ResultListEntry( *it ) ); } } + mbCountFinal = sal_True; - return false; + return true; } DataSupplier::~DataSupplier() { + while ( maResults.size( ) > 0 ) + { + ResultListEntry* back = maResults.back( ); + maResults.pop_back( ); + delete( back ); + } } ::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 sObjectPath; - vector< string > paths = maResults[nIndex]->pObject->getPaths( ); - if ( !paths.empty( ) ) - sObjectPath = paths.front( ); - else - { - // Handle the unfiled objects with their id... - // They manage to sneak here if we don't have the permission to get the object - // parents (and then the path) - sObjectPath += "#" + maResults[nIndex]->pObject->getId( ); - } - - // Get the URL from the Path - URL aUrl( mxContent->getIdentifier( )->getContentIdentifier( ) ); - aUrl.setObjectPath( STD_TO_OUSTR( sObjectPath ) ); - rtl::OUString aId = aUrl.asString( ); - - maResults[ nIndex ]->aId = aId; - return aId; - } - - return ::rtl::OUString(); + return queryContentIdentifier( nIndex )->getContentIdentifier( ); } 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 >(); + return queryContent( nIndex )->getIdentifier( ); } 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; - } - } + if ( nIndex > maResults.size() ) + getData( ); - 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 >(); + return maResults[ nIndex ]->xContent; } sal_Bool DataSupplier::getResult( sal_uInt32 nIndex ) diff --git a/ucb/source/ucp/cmis/cmis_datasupplier.hxx b/ucb/source/ucp/cmis/cmis_datasupplier.hxx index 14ad404c90f0..7a3b42060ffa 100644 --- a/ucb/source/ucp/cmis/cmis_datasupplier.hxx +++ b/ucb/source/ucp/cmis/cmis_datasupplier.hxx @@ -14,7 +14,7 @@ #include <ucbhelper/resultset.hxx> -#include "cmis_content.hxx" +#include "children_provider.hxx" namespace cmis { @@ -23,13 +23,10 @@ namespace cmis 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( com::sun::star::uno::Reference< com::sun::star::ucb::XContent > xCnt ) : xContent( xCnt ) { } @@ -43,7 +40,7 @@ namespace cmis class DataSupplier : public ucbhelper::ResultSetDataSupplier { private: - com::sun::star::uno::Reference< ::cmis::Content > mxContent; + ChildrenProvider* m_pChildrenProvider; com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xSMgr; sal_Int32 mnOpenMode; bool mbCountFinal; @@ -52,7 +49,8 @@ namespace cmis 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 ); + ChildrenProvider* pChildrenProvider, sal_Int32 nOpenMode ); + virtual ~DataSupplier(); virtual rtl::OUString queryContentIdentifierString( sal_uInt32 nIndex ); diff --git a/ucb/source/ucp/cmis/cmis_provider.cxx b/ucb/source/ucp/cmis/cmis_provider.cxx index f65a1ca47969..14a3b81c4cc8 100644 --- a/ucb/source/ucp/cmis/cmis_provider.cxx +++ b/ucb/source/ucp/cmis/cmis_provider.cxx @@ -26,13 +26,15 @@ * instead of those above. */ +#include <stdio.h> + #include <ucbhelper/contentidentifier.hxx> #include <ucbhelper/contenthelper.hxx> #include <com/sun/star/ucb/ContentCreationException.hpp> -#include "cmis_provider.hxx" -#include "cmis_content.hxx" -#include <stdio.h> +#include "cmis_content.hxx" +#include "cmis_provider.hxx" +#include "cmis_repo_content.hxx" using namespace com::sun::star; @@ -54,8 +56,17 @@ ContentProvider::queryContent( try { - xContent = new ::cmis::Content( m_xSMgr, this, Identifier ); - registerNewContent( xContent ); + URL aUrl( Identifier->getContentIdentifier( ) ); + if ( aUrl.getRepositoryId( ).isEmpty( ) ) + { + xContent = new RepoContent( m_xSMgr, this, Identifier ); + registerNewContent( xContent ); + } + else + { + xContent = new Content( m_xSMgr, this, Identifier ); + registerNewContent( xContent ); + } } catch ( com::sun::star::ucb::ContentCreationException const & ) { diff --git a/ucb/source/ucp/cmis/cmis_resultset.cxx b/ucb/source/ucp/cmis/cmis_resultset.cxx index b79b5f1bafe2..86ed3cacccce 100644 --- a/ucb/source/ucp/cmis/cmis_resultset.cxx +++ b/ucb/source/ucp/cmis/cmis_resultset.cxx @@ -18,11 +18,11 @@ namespace cmis { DynamicResultSet::DynamicResultSet( const Reference< XMultiServiceFactory >& rxSMgr, - const Reference< Content >& rxContent, + ChildrenProvider* pChildrenProvider, const OpenCommandArgument2& rCommand, const Reference< XCommandEnvironment >& rxEnv ) : ResultSetImplHelper( rxSMgr, rCommand ), - m_xContent( rxContent ), + m_pChildrenProvider( pChildrenProvider ), m_xEnv( rxEnv ) { } @@ -31,7 +31,7 @@ namespace cmis { m_xResultSet1 = new ::ucbhelper::ResultSet( m_xSMgr, m_aCommand.Properties, - new DataSupplier( m_xSMgr, m_xContent, m_aCommand.Mode ), m_xEnv ); + new DataSupplier( m_xSMgr, m_pChildrenProvider, m_aCommand.Mode ), m_xEnv ); } void DynamicResultSet::initDynamic() diff --git a/ucb/source/ucp/cmis/cmis_resultset.hxx b/ucb/source/ucp/cmis/cmis_resultset.hxx index bd40a8ce4690..7d7c3753deba 100644 --- a/ucb/source/ucp/cmis/cmis_resultset.hxx +++ b/ucb/source/ucp/cmis/cmis_resultset.hxx @@ -12,12 +12,14 @@ #include <ucbhelper/resultsethelper.hxx> +#include "children_provider.hxx" + namespace cmis { class DynamicResultSet : public ::ucbhelper::ResultSetImplHelper { - com::sun::star::uno::Reference< Content > m_xContent; + ChildrenProvider* m_pChildrenProvider; com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > m_xEnv; private: @@ -25,12 +27,14 @@ namespace cmis 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, + ChildrenProvider* pChildrenProvider, const com::sun::star::ucb::OpenCommandArgument2& rCommand, const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& rxEnv ); + }; } diff --git a/ucb/source/ucp/cmis/cmis_url.hxx b/ucb/source/ucp/cmis/cmis_url.hxx index 3d416901cf29..aa3d93ce4fa0 100644 --- a/ucb/source/ucp/cmis/cmis_url.hxx +++ b/ucb/source/ucp/cmis/cmis_url.hxx @@ -54,6 +54,8 @@ namespace cmis rtl::OUString& getObjectId( ); rtl::OUString& getBindingUrl( ); rtl::OUString& getRepositoryId( ); + rtl::OUString& getUsername( ) { return m_sUser; } + rtl::OUString& getPassword( ) { return m_sPass; } void setObjectPath( rtl::OUString sPath ); rtl::OUString asString( ); |