diff options
author | Cédric Bosdonnat <cedric.bosdonnat@free.fr> | 2012-06-01 10:46:25 +0200 |
---|---|---|
committer | Cédric Bosdonnat <cedric.bosdonnat@free.fr> | 2012-06-04 13:28:13 +0200 |
commit | 2c4588340ee8387513dd067ecb53dc0058b12ccc (patch) | |
tree | 1ee5f1f88918de407b7b19ed0526b96522e618d4 | |
parent | 99465489aa24a2d9d81c0daccfcf512e4f82c841 (diff) |
CMIS UCP: Fixed folder creation and nodes renaming
Change-Id: I2c49b95279d90ebb06f38ed83061a5f1a905a555
-rw-r--r-- | fpicker/source/office/fpsmartcontent.cxx | 40 | ||||
-rw-r--r-- | fpicker/source/office/fpsmartcontent.hxx | 9 | ||||
-rw-r--r-- | fpicker/source/office/iodlg.cxx | 9 | ||||
-rw-r--r-- | svtools/inc/svtools/fileview.hxx | 2 | ||||
-rw-r--r-- | svtools/source/contnr/fileview.cxx | 22 | ||||
-rw-r--r-- | ucb/source/ucp/cmis/cmis_content.cxx | 88 |
6 files changed, 135 insertions, 35 deletions
diff --git a/fpicker/source/office/fpsmartcontent.cxx b/fpicker/source/office/fpsmartcontent.cxx index 0e4c9fe29d4b..69bb4034d0a0 100644 --- a/fpicker/source/office/fpsmartcontent.cxx +++ b/fpicker/source/office/fpsmartcontent.cxx @@ -310,6 +310,46 @@ namespace svt return bRet; } + rtl::OUString SmartContent::createFolder( const rtl::OUString& _rTitle ) + { + rtl::OUString aCreatedUrl; + try + { + rtl::OUString sFolderType; + + Sequence< ContentInfo > aInfo = m_pContent->queryCreatableContentsInfo(); + const ContentInfo* pInfo = aInfo.getConstArray(); + sal_Int32 nCount = aInfo.getLength(); + for ( sal_Int32 i = 0; i < nCount; ++i, ++pInfo ) + { + // Simply look for the first KIND_FOLDER... + if ( pInfo->Attributes & ContentInfoAttribute::KIND_FOLDER ) + { + sFolderType = pInfo->Type; + break; + } + } + + if ( !sFolderType.isEmpty() ) + { + ucbhelper::Content aCreated; + Sequence< rtl::OUString > aNames( 1 ); + rtl::OUString* pNames = aNames.getArray(); + pNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ); + Sequence< Any > aValues( 1 ); + Any* pValues = aValues.getArray(); + pValues[0] = makeAny( _rTitle ); + m_pContent->insertNewContent( sFolderType, aNames, aValues, aCreated ); + + aCreatedUrl = aCreated.getURL(); + } + } + catch( const Exception& ) + { + } + return aCreatedUrl; + } + //........................................................................ } // namespace svt //........................................................................ diff --git a/fpicker/source/office/fpsmartcontent.hxx b/fpicker/source/office/fpsmartcontent.hxx index e16c288678b1..81aff5b2e020 100644 --- a/fpicker/source/office/fpsmartcontent.hxx +++ b/fpicker/source/office/fpsmartcontent.hxx @@ -61,7 +61,7 @@ namespace svt private: ::rtl::OUString m_sURL; - ::ucbhelper::Content* m_pContent; + ::ucbhelper::Content* m_pContent; State m_eState; ::com::sun::star::uno::Reference < ::com::sun::star::ucb::XCommandEnvironment > m_xCmdEnv; ::com::sun::star::uno::Reference < ::com::sun::star::task::XInteractionHandler > m_xOwnInteraction; @@ -174,6 +174,13 @@ namespace svt */ sal_Bool canCreateFolder( ); + /** creates a new folder with the given title and return the corresponding URL. + + @return + the URL of the created folder or an empty string + */ + rtl::OUString createFolder( const rtl::OUString& _rTitle ); + /** binds to the given URL, checks whether or not it refers to a folder @postcond diff --git a/fpicker/source/office/iodlg.cxx b/fpicker/source/office/iodlg.cxx index 258edd9493f9..cc57c5bc7565 100644 --- a/fpicker/source/office/iodlg.cxx +++ b/fpicker/source/office/iodlg.cxx @@ -819,7 +819,14 @@ IMPL_STATIC_LINK( SvtFileDialog, NewFolderHdl_Impl, PushButton*, EMPTYARG ) while ( !bHandled ) { if ( aDlg.Execute() == RET_OK ) - bHandled = pThis->_pFileView->CreateNewFolder( aDlg.GetName() ); + { + rtl::OUString aUrl = aContent.createFolder( aDlg.GetName( ) ); + if ( !aUrl.isEmpty( ) ) + { + pThis->_pFileView->CreatedFolder( aUrl, aDlg.GetName() ); + bHandled = sal_True; + } + } else bHandled = sal_True; } diff --git a/svtools/inc/svtools/fileview.hxx b/svtools/inc/svtools/fileview.hxx index c5ec78ead9fb..4778bd9a6e0f 100644 --- a/svtools/inc/svtools/fileview.hxx +++ b/svtools/inc/svtools/fileview.hxx @@ -98,7 +98,7 @@ public: String GetCurrentURL() const; sal_Bool GetParentURL( String& _rParentURL ) const; - sal_Bool CreateNewFolder( const String& rNewFolder ); + void CreatedFolder( const String& rUrl, const String& rNewFolder ); void SetHelpId( const rtl::OString& rHelpId ); const rtl::OString& GetHelpId( ) const; diff --git a/svtools/source/contnr/fileview.cxx b/svtools/source/contnr/fileview.cxx index 11f80bf73bc0..9f100f8ca79d 100644 --- a/svtools/source/contnr/fileview.cxx +++ b/svtools/source/contnr/fileview.cxx @@ -1293,23 +1293,13 @@ String SvtFileView::GetCurrentURL() const } // ----------------------------------------------------------------------------- -sal_Bool SvtFileView::CreateNewFolder( const String& rNewFolder ) +void SvtFileView::CreatedFolder( const String& rUrl, const String& rNewFolder ) { - sal_Bool bRet = sal_False; - INetURLObject aObj( mpImp->maViewURL ); - aObj.insertName( rNewFolder, false, INetURLObject::LAST_SEGMENT, true, INetURLObject::ENCODE_ALL ); - String sURL = aObj.GetMainURL( INetURLObject::NO_DECODE ); - if ( ::utl::UCBContentHelper::MakeFolder( sURL, sal_True ) ) - { - String sTitle = aObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); - String sEntry = mpImp->FolderInserted( sURL, sTitle ); - SvLBoxEntry* pEntry = mpImp->mpView->InsertEntry( sEntry, mpImp->maFolderImage, mpImp->maFolderImage ); - SvtContentEntry* pUserData = new SvtContentEntry( sURL, sal_True ); - pEntry->SetUserData( pUserData ); - mpImp->mpView->MakeVisible( pEntry ); - bRet = sal_True; - } - return bRet; + String sEntry = mpImp->FolderInserted( rUrl, rNewFolder ); + SvLBoxEntry* pEntry = mpImp->mpView->InsertEntry( sEntry, mpImp->maFolderImage, mpImp->maFolderImage ); + SvtContentEntry* pUserData = new SvtContentEntry( rUrl, sal_True ); + pEntry->SetUserData( pUserData ); + mpImp->mpView->MakeVisible( pEntry ); } // ----------------------------------------------------------------------- diff --git a/ucb/source/ucp/cmis/cmis_content.cxx b/ucb/source/ucp/cmis/cmis_content.cxx index aacfaaa003e4..d40deabb19f7 100644 --- a/ucb/source/ucp/cmis/cmis_content.cxx +++ b/ucb/source/ucp/cmis/cmis_content.cxx @@ -466,8 +466,6 @@ namespace cmis sal_Bool bReplaceExisting, const uno::Reference< ucb::XCommandEnvironment >& xEnv ) throw( uno::Exception ) { - SAL_INFO( "cmisucp", "TODO - Content::insert()" ); - if ( !xInputStream.is() ) { ucbhelper::cancelCommandExecution( uno::makeAny @@ -481,6 +479,8 @@ namespace cmis // For transient content, the URL is the one of the parent if ( m_bTransient ) { + string sNewId; + // Try to get the object from the server if there is any libcmis::Folder* pFolder = dynamic_cast< libcmis::Folder* >( getObject( ).get( ) ); if ( pFolder != NULL ) @@ -499,7 +499,16 @@ namespace cmis newPath += "/"; newPath += newName; - libcmis::ObjectPtr object = m_pSession->getObjectByPath( newPath ); + libcmis::ObjectPtr object; + try + { + object = m_pSession->getObjectByPath( newPath ); + sNewId = object->getId( ); + } + catch ( const libcmis::Exception& ) + { + // Nothing matched the path + } if ( NULL != object.get( ) ) { @@ -524,14 +533,41 @@ namespace cmis } else { - // TODO We need to create a brand new object... either folder or document + // We need to create a brand new object... either folder or document + bool bIsFolder = m_pObjectType->getBaseType( )->getId( ) == "cmis:folder"; + setCmisProperty( "cmis:objectTypeId", m_pObjectType->getId( ) ); + + if ( bIsFolder ) + { + libcmis::FolderPtr pNew = pFolder->createFolder( m_pObjectProps ); + sNewId = pNew->getId( ); + } + else + { + boost::shared_ptr< ostream > pOut( new ostringstream ( ios_base::binary | ios_base::in | ios_base::out ) ); + uno::Reference < io::XOutputStream > xOutput = new ucbhelper::StdOutputStream( pOut ); + copyData( xInputStream, xOutput ); + libcmis::DocumentPtr pNew = pFolder->createDocument( m_pObjectProps, pOut, string() ); + sNewId = pNew->getId( ); + } + } + + if ( !sNewId.empty( ) ) + { + // Update the current content: it's no longer transient + m_sObjectId = rtl::OUString::createFromAscii( sNewId.c_str( ) ); + URL aUrl( m_sURL ); + aUrl.setObjectId( m_sObjectId ); + m_sURL = aUrl.asString( ); + m_pObject.reset( ); + m_pObjectType.reset( ); + m_pObjectProps.clear( ); + m_bTransient = false; + + inserted(); } } } - else - { - // TODO Update the current object... but I'm not sure this case can happen with UCB - } } catch ( const libcmis::Exception& e ) { @@ -559,11 +595,15 @@ namespace cmis { // Get the already set properties if possible if ( !m_bTransient && getObject( ).get( ) ) + { m_pObjectProps = getObject()->getProperties( ); + m_pObjectType = getObject()->getTypeDescription(); + } sal_Int32 nCount = rValues.getLength(); uno::Sequence< uno::Any > aRet( nCount ); + bool bChanged = false; const beans::PropertyValue* pValues = rValues.getConstArray(); for ( sal_Int32 n = 0; n < nCount; ++n ) { @@ -600,15 +640,22 @@ namespace cmis } setCmisProperty( "cmis:name", OUSTR_TO_STDSTR( aNewTitle ) ); + bChanged = true; } else { + SAL_INFO( "cmisucp", "Couln't set property: " << rValue.Name ); lang::IllegalAccessException e ( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Property is read-only!")), static_cast< cppu::OWeakObject* >( this ) ); aRet[ n ] <<= e; } } + if ( !m_bTransient && bChanged ) + { + getObject()->updateProperties(); + } + return aRet; } @@ -1030,16 +1077,25 @@ namespace cmis { if ( m_pObjectType.get( ) ) { - map< string, libcmis::PropertyTypePtr > propsTypes = m_pObjectType->getPropertiesTypes( ); - map< string, libcmis::PropertyTypePtr >::iterator typeIt = propsTypes.find( sName ); + map< string, libcmis::PropertyPtr >::iterator propIt = m_pObjectProps.find( sName ); + vector< string > values; + values.push_back( sValue ); + + if ( propIt == m_pObjectProps.end( ) && m_pObjectType.get( ) ) + { + map< string, libcmis::PropertyTypePtr > propsTypes = m_pObjectType->getPropertiesTypes( ); + map< string, libcmis::PropertyTypePtr >::iterator typeIt = propsTypes.find( sName ); - if ( typeIt != propsTypes.end( ) ) + if ( typeIt != propsTypes.end( ) ) + { + libcmis::PropertyTypePtr propType = typeIt->second; + libcmis::PropertyPtr property( new libcmis::Property( propType, values ) ); + m_pObjectProps.insert( pair< string, libcmis::PropertyPtr >( sName, property ) ); + } + } + else if ( propIt != m_pObjectProps.end( ) ) { - libcmis::PropertyTypePtr propType = typeIt->second; - vector< string > values; - values.push_back( sValue ); - libcmis::PropertyPtr property( new libcmis::Property( propType, values ) ); - m_pObjectProps.insert( pair< string, libcmis::PropertyPtr >( sName, property ) ); + propIt->second->setValues( values ); } } } |