12#include <boost/make_shared.hpp>
14#include <com/sun/star/beans/IllegalTypeException.hpp>
15#include <com/sun/star/beans/PropertyAttribute.hpp>
16#include <com/sun/star/beans/PropertyValue.hpp>
17#include <com/sun/star/beans/XPropertySetInfo.hpp>
18#include <com/sun/star/document/CmisProperty.hpp>
19#include <com/sun/star/io/XActiveDataSink.hpp>
20#include <com/sun/star/io/XActiveDataStreamer.hpp>
21#include <com/sun/star/lang/IllegalAccessException.hpp>
22#include <com/sun/star/lang/IllegalArgumentException.hpp>
23#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
24#include <com/sun/star/task/InteractionClassification.hpp>
25#include <com/sun/star/ucb/ContentInfo.hpp>
26#include <com/sun/star/ucb/ContentInfoAttribute.hpp>
27#include <com/sun/star/ucb/InsertCommandArgument2.hpp>
28#include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp>
29#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
30#include <com/sun/star/ucb/MissingInputStreamException.hpp>
31#include <com/sun/star/ucb/OpenMode.hpp>
32#include <com/sun/star/ucb/UnsupportedCommandException.hpp>
33#include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
34#include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
35#include <com/sun/star/ucb/XCommandInfo.hpp>
36#include <com/sun/star/ucb/XDynamicResultSet.hpp>
38#include <com/sun/star/xml/crypto/XDigestContext.hpp>
39#include <com/sun/star/xml/crypto/DigestID.hpp>
40#include <com/sun/star/xml/crypto/NSSInitializer.hpp>
47#include <config_oauth2.h>
70#define OUSTR_TO_STDSTR(s) std::string( OUStringToOString( s, RTL_TEXTENCODING_UTF8 ) )
71#define STD_TO_OUSTR( str ) OStringToOUString( str, RTL_TEXTENCODING_UTF8 )
77 util::DateTime lcl_boostToUnoTime(
const boost::posix_time::ptime& boostTime)
79 util::DateTime unoTime;
80 unoTime.Year = boostTime.date().year();
81 unoTime.Month = boostTime.date().month();
82 unoTime.Day = boostTime.date().day();
83 unoTime.Hours = boostTime.time_of_day().hours();
84 unoTime.Minutes = boostTime.time_of_day().minutes();
85 unoTime.Seconds = boostTime.time_of_day().seconds();
90 const tools::Long ticks = boostTime.time_of_day().fractional_seconds();
91 tools::Long nanoSeconds = ticks * ( 1000000000 / boost::posix_time::time_duration::ticks_per_second());
93 unoTime.NanoSeconds = nanoSeconds;
98 uno::Any lcl_cmisPropertyToUno(
const libcmis::PropertyPtr& pProperty )
101 switch ( pProperty->getPropertyType( )->getType( ) )
104 case libcmis::PropertyType::String:
106 auto aCmisStrings = pProperty->getStrings( );
107 uno::Sequence< OUString > aStrings( aCmisStrings.size( ) );
108 OUString* aStringsArr = aStrings.getArray( );
110 for (
const auto& rCmisStr : aCmisStrings )
117 case libcmis::PropertyType::Integer:
119 auto aCmisLongs = pProperty->getLongs( );
120 uno::Sequence< sal_Int64 > aLongs( aCmisLongs.size( ) );
121 sal_Int64* aLongsArr = aLongs.getArray( );
123 for (
const auto& rCmisLong : aCmisLongs )
125 aLongsArr[
i++] = rCmisLong;
130 case libcmis::PropertyType::Decimal:
132 auto aCmisDoubles = pProperty->getDoubles( );
137 case libcmis::PropertyType::Bool:
139 auto aCmisBools = pProperty->getBools( );
140 uno::Sequence< sal_Bool > aBools( aCmisBools.size( ) );
141 sal_Bool* aBoolsArr = aBools.getArray( );
143 for (
bool bCmisBool : aCmisBools )
145 aBoolsArr[
i++] = bCmisBool;
150 case libcmis::PropertyType::DateTime:
152 auto aCmisTimes = pProperty->getDateTimes( );
153 uno::Sequence< util::DateTime > aTimes( aCmisTimes.size( ) );
154 util::DateTime* aTimesArr = aTimes.getArray( );
156 for (
const auto& rCmisTime : aCmisTimes )
158 aTimesArr[
i++] = lcl_boostToUnoTime( rCmisTime );
167 libcmis::PropertyPtr lcl_unoToCmisProperty(
const document::CmisProperty& prop )
169 libcmis::PropertyTypePtr propertyType(
new libcmis::PropertyType( ) );
171 OUString
id = prop.Id;
172 OUString
name = prop.Name;
173 bool bUpdatable = prop.Updatable;
174 bool bRequired = prop.Required;
175 bool bMultiValued = prop.MultiValued;
176 bool bOpenChoice = prop.OpenChoice;
178 std::vector< std::string >
values;
180 libcmis::PropertyType::Type
type = libcmis::PropertyType::String;
183 uno::Sequence< OUString > seqValue;
185 std::transform(std::cbegin(seqValue), std::cend(seqValue), std::back_inserter(
values),
186 [](
const OUString& rValue) -> std::string {
return OUSTR_TO_STDSTR( rValue ); });
187 type = libcmis::PropertyType::String;
191 uno::Sequence< sal_Bool > seqValue;
193 std::transform(std::cbegin(seqValue), std::cend(seqValue), std::back_inserter(
values),
194 [](
const bool nValue) -> std::string {
return std::string( OString::boolean(
nValue ) ); });
195 type = libcmis::PropertyType::Bool;
199 uno::Sequence< sal_Int64 > seqValue;
201 std::transform(std::cbegin(seqValue), std::cend(seqValue), std::back_inserter(
values),
202 [](
const sal_Int64
nValue) -> std::string {
return std::string( OString::number(
nValue ) ); });
203 type = libcmis::PropertyType::Integer;
207 uno::Sequence< double > seqValue;
209 std::transform(std::cbegin(seqValue), std::cend(seqValue), std::back_inserter(
values),
210 [](
const double fValue) -> std::string {
return std::string( OString::number( fValue ) ); });
211 type = libcmis::PropertyType::Decimal;
215 uno::Sequence< util::DateTime > seqValue;
217 std::transform(std::cbegin(seqValue), std::cend(seqValue), std::back_inserter(
values),
218 [](
const util::DateTime& rValue) -> std::string {
223 type = libcmis::PropertyType::DateTime;
228 propertyType->setUpdatable( bUpdatable );
229 propertyType->setRequired( bRequired );
230 propertyType->setMultiValued( bMultiValued );
231 propertyType->setOpenChoice( bOpenChoice );
232 propertyType->setType(
type );
234 libcmis::PropertyPtr
property(
new libcmis::Property( propertyType, std::move(
values) ) );
239 uno::Sequence< uno::Any > generateErrorArguments(
const cmis::URL & rURL )
245 beans::PropertyState_DIRECT_VALUE )),
250 beans::PropertyState_DIRECT_VALUE )),
255 beans::PropertyState_DIRECT_VALUE )) };
263 Content::Content(
const uno::Reference< uno::XComponentContext >& rxContext,
264 ContentProvider *pProvider,
const uno::Reference< ucb::XContentIdentifier >& Identifier,
265 libcmis::ObjectPtr pObject )
266 : ContentImplHelper( rxContext, pProvider,
Identifier ),
267 m_pProvider( pProvider ),
268 m_pSession( nullptr ),
272 m_bTransient( false ),
275 SAL_INFO(
"ucb.ucp.cmis",
"Content::Content() " << m_sURL );
277 m_sObjectPath =
m_aURL.getObjectPath( );
278 m_sObjectId =
m_aURL.getObjectId( );
281 Content::Content(
const uno::Reference< uno::XComponentContext >& rxContext,
ContentProvider *pProvider,
282 const uno::Reference< ucb::XContentIdentifier >& Identifier,
284 : ContentImplHelper( rxContext, pProvider,
Identifier ),
285 m_pProvider( pProvider ),
286 m_pSession( nullptr ),
289 m_bTransient( true ),
290 m_bIsFolder( bIsFolder )
292 SAL_INFO(
"ucb.ucp.cmis",
"Content::Content() " << m_sURL );
294 m_sObjectPath =
m_aURL.getObjectPath( );
295 m_sObjectId =
m_aURL.getObjectId( );
302 libcmis::Session* Content::getSession(
const uno::Reference< ucb::XCommandEnvironment >& xEnv )
309 OUString sProxy = rProxy.
aName;
310 if ( rProxy.
nPort > 0 )
311 sProxy +=
":" + OUString::number( rProxy.
nPort );
312 libcmis::SessionFactory::setProxySettings(
OUSTR_TO_STDSTR( sProxy ), std::string(), std::string(), std::string() );
315 OUString sSessionId =
m_aURL.getBindingUrl( ) +
m_aURL.getRepositoryId( );
316 if (
nullptr == m_pSession )
317 m_pSession = m_pProvider->getSession( sSessionId,
m_aURL.getUsername( ) );
319 if (
nullptr == m_pSession )
324 uno::Reference< css::xml::crypto::XNSSInitializer >
325 xNSSInitializer = css::xml::crypto::NSSInitializer::create(
m_xContext );
327 uno::Reference< css::xml::crypto::XDigestContext > xDigestContext(
328 xNSSInitializer->getDigestContext( css::xml::crypto::DigestID::SHA256,
329 uno::Sequence< beans::NamedValue >() ),
330 uno::UNO_SET_THROW );
334 libcmis::CertValidationHandlerPtr certHandler(
336 libcmis::SessionFactory::setCertificateValidationHandler( certHandler );
339 AuthProvider aAuthProvider(xEnv, m_xIdentifier->getContentIdentifier(),
m_aURL.getBindingUrl());
340 AuthProvider::setXEnv( xEnv );
345 bool bSkipInitialPWAuth =
false;
346 if (
m_aURL.getBindingUrl() == ONEDRIVE_BASE_URL
347 ||
m_aURL.getBindingUrl() == GDRIVE_BASE_URL)
353 bSkipInitialPWAuth =
true;
357 bool bIsDone =
false;
364 libcmis::OAuth2DataPtr oauth2Data;
365 if (
m_aURL.getBindingUrl( ) == GDRIVE_BASE_URL )
368 bSkipInitialPWAuth =
false;
369 libcmis::SessionFactory::setOAuth2AuthCodeProvider(AuthProvider::copyWebAuthCodeFallback);
370 oauth2Data = boost::make_shared<libcmis::OAuth2Data>(
371 GDRIVE_AUTH_URL, GDRIVE_TOKEN_URL,
372 GDRIVE_SCOPE, GDRIVE_REDIRECT_URI,
373 GDRIVE_CLIENT_ID, GDRIVE_CLIENT_SECRET );
375 if (
m_aURL.getBindingUrl().startsWith( ALFRESCO_CLOUD_BASE_URL ) )
376 oauth2Data = boost::make_shared<libcmis::OAuth2Data>(
377 ALFRESCO_CLOUD_AUTH_URL, ALFRESCO_CLOUD_TOKEN_URL,
378 ALFRESCO_CLOUD_SCOPE, ALFRESCO_CLOUD_REDIRECT_URI,
379 ALFRESCO_CLOUD_CLIENT_ID, ALFRESCO_CLOUD_CLIENT_SECRET );
380 if (
m_aURL.getBindingUrl( ) == ONEDRIVE_BASE_URL )
383 bSkipInitialPWAuth =
false;
384 libcmis::SessionFactory::setOAuth2AuthCodeProvider(AuthProvider::copyWebAuthCodeFallback);
385 oauth2Data = boost::make_shared<libcmis::OAuth2Data>(
386 ONEDRIVE_AUTH_URL, ONEDRIVE_TOKEN_URL,
387 ONEDRIVE_SCOPE, ONEDRIVE_REDIRECT_URI,
388 ONEDRIVE_CLIENT_ID, ONEDRIVE_CLIENT_SECRET );
392 m_pSession = libcmis::SessionFactory::createSession(
396 if ( m_pSession ==
nullptr )
400 ucb::IOErrorCode_INVALID_DEVICE,
401 generateErrorArguments(
m_aURL),
404 else if ( m_pSession->getRepository() ==
nullptr )
408 ucb::IOErrorCode_INVALID_DEVICE,
409 generateErrorArguments(
m_aURL),
411 "error accessing a repository");
415 m_pProvider->registerSession(sSessionId,
m_aURL.getUsername( ), m_pSession);
416 if (
m_aURL.getBindingUrl() == ONEDRIVE_BASE_URL
417 ||
m_aURL.getBindingUrl() == GDRIVE_BASE_URL)
420 m_pSession->getRefreshToken());
426 catch(
const libcmis::Exception & e )
428 if ( e.getType() !=
"permissionDenied" )
430 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what());
439 ucb::IOErrorCode_ABORT,
440 uno::Sequence< uno::Any >( 0 ),
442 throw uno::RuntimeException( );
449 libcmis::ObjectTypePtr
const & Content::getObjectType(
const uno::Reference< ucb::XCommandEnvironment >& xEnv )
451 if (
nullptr == m_pObjectType.get( ) && m_bTransient )
453 std::string typeId = m_bIsFolder ?
"cmis:folder" :
"cmis:document";
458 libcmis::Folder* pParent =
nullptr;
459 bool bTypeRestricted =
false;
462 pParent =
dynamic_cast< libcmis::Folder*
>( getObject( xEnv ).get( ) );
464 catch (
const libcmis::Exception& )
470 std::map< std::string, libcmis::PropertyPtr >&
aProperties = pParent->getProperties( );
471 std::map< std::string, libcmis::PropertyPtr >::iterator it =
aProperties.find(
"cmis:allowedChildObjectTypeIds" );
474 libcmis::PropertyPtr pProperty = it->second;
477 std::vector< std::string > typesIds = pProperty->getStrings( );
478 for (
const auto& rType : typesIds )
480 bTypeRestricted =
true;
481 libcmis::ObjectTypePtr
type = getSession( xEnv )->getType( rType );
484 if (
type->getBaseType( )->getId( ) == typeId )
486 m_pObjectType =
type;
494 if ( !bTypeRestricted )
495 m_pObjectType = getSession( xEnv )->getType( typeId );
497 return m_pObjectType;
501 libcmis::ObjectPtr
const & Content::getObject(
const uno::Reference< ucb::XCommandEnvironment >& xEnv )
507 if ( !getSession( xEnv ) )
510 catch ( uno::RuntimeException& )
514 if ( !m_pObject.get() )
516 if ( !m_sObjectId.isEmpty( ) )
520 m_pObject = getSession( xEnv )->getObject(
OUSTR_TO_STDSTR( m_sObjectId ) );
522 catch (
const libcmis::Exception& )
525 throw libcmis::Exception(
"Object not found" );
528 else if (!(m_sObjectPath.isEmpty() || m_sObjectPath ==
"/"))
532 m_pObject = getSession( xEnv )->getObjectByPath(
OUSTR_TO_STDSTR( m_sObjectPath ) );
534 catch (
const libcmis::Exception& )
548 libcmis::FolderPtr pParentFolder = boost::dynamic_pointer_cast< libcmis::Folder >(xParent->getObject(xEnv));
551 std::vector< libcmis::ObjectPtr > children = pParentFolder->getChildren();
552 auto it = std::find_if(children.begin(), children.end(),
553 [&
sName](
const libcmis::ObjectPtr& rChild) { return rChild->getName() == sName; });
554 if (it != children.end())
560 throw libcmis::Exception(
"Object not found" );
565 m_pObject = getSession( xEnv )->getRootFolder( );
567 m_sObjectId = OUString( );
574 bool Content::isFolder(
const uno::Reference< ucb::XCommandEnvironment >& xEnv )
576 bool bIsFolder =
false;
579 libcmis::ObjectPtr obj = getObject( xEnv );
581 bIsFolder = obj->getBaseType( ) ==
"cmis:folder";
583 catch (
const libcmis::Exception& e )
585 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
588 ucb::IOErrorCode_GENERAL,
589 uno::Sequence< uno::Any >( 0 ),
591 OUString::createFromAscii( e.what( ) ) );
599 return uno::Any( lang::IllegalArgumentException(
600 "Wrong argument type!",
604 libcmis::ObjectPtr Content::updateProperties(
606 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
609 uno::Sequence< document::CmisProperty > aPropsSeq;
610 iCmisProps >>= aPropsSeq;
611 std::map< std::string, libcmis::PropertyPtr >
aProperties;
613 for (
const auto& rProp : std::as_const(aPropsSeq) )
616 libcmis::PropertyPtr prop = lcl_unoToCmisProperty( rProp );
617 aProperties.insert( std::pair<std::string, libcmis::PropertyPtr>(
id, prop ) );
619 libcmis::ObjectPtr updateObj;
622 updateObj = getObject( xEnv )->updateProperties(
aProperties );
624 catch (
const libcmis::Exception& e )
626 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: "<< e.what( ) );
632 uno::Reference< sdbc::XRow > Content::getPropertyValues(
633 const uno::Sequence< beans::Property >& rProperties,
634 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
638 for(
const beans::Property& rProp : rProperties )
642 if ( rProp.Name ==
"IsDocument" )
646 libcmis::ObjectPtr obj = getObject( xEnv );
648 xRow->appendBoolean( rProp, obj->getBaseType( ) ==
"cmis:document" );
650 catch (
const libcmis::Exception& )
652 if ( m_pObjectType.get( ) )
653 xRow->appendBoolean( rProp, getObjectType( xEnv )->getBaseType()->getId( ) ==
"cmis:document" );
655 xRow->appendVoid( rProp );
658 else if ( rProp.Name ==
"IsFolder" )
662 libcmis::ObjectPtr obj = getObject( xEnv );
664 xRow->appendBoolean( rProp, obj->getBaseType( ) ==
"cmis:folder" );
666 xRow->appendBoolean( rProp,
false );
668 catch (
const libcmis::Exception& )
670 if ( m_pObjectType.get( ) )
671 xRow->appendBoolean( rProp, getObjectType( xEnv )->getBaseType()->getId( ) ==
"cmis:folder" );
673 xRow->appendVoid( rProp );
676 else if ( rProp.Name ==
"Title" )
683 catch (
const libcmis::Exception& )
685 if ( !m_pObjectProps.empty() )
687 std::map< std::string, libcmis::PropertyPtr >::iterator it = m_pObjectProps.find(
"cmis:name" );
688 if ( it != m_pObjectProps.end( ) )
690 std::vector< std::string >
values = it->second->getStrings( );
698 if ( sTitle.isEmpty( ) )
700 OUString sPath = m_sObjectPath;
703 if ( sPath.endsWith(
"/") )
704 sPath = sPath.copy( 0, sPath.getLength() - 1 );
707 sal_Int32
nPos = sPath.lastIndexOf(
'/' );
709 sTitle = sPath.copy( nPos + 1 );
712 if ( !sTitle.isEmpty( ) )
713 xRow->appendString( rProp, sTitle );
715 xRow->appendVoid( rProp );
717 else if ( rProp.Name ==
"ObjectId" )
724 catch (
const libcmis::Exception& )
726 if ( !m_pObjectProps.empty() )
728 std::map< std::string, libcmis::PropertyPtr >::iterator it = m_pObjectProps.find(
"cmis:objectId" );
729 if ( it != m_pObjectProps.end( ) )
731 std::vector< std::string >
values = it->second->getStrings( );
738 if ( !
sId.isEmpty( ) )
739 xRow->appendString( rProp, sId );
741 xRow->appendVoid( rProp );
743 else if ( rProp.Name ==
"TitleOnServer" )
745 xRow->appendString( rProp, m_sObjectPath);
747 else if ( rProp.Name ==
"IsReadOnly" )
749 boost::shared_ptr< libcmis::AllowableActions > allowableActions = getObject( xEnv )->getAllowableActions( );
751 if ( !allowableActions->isAllowed( libcmis::ObjectAction::SetContentStream ) &&
752 !allowableActions->isAllowed( libcmis::ObjectAction::CheckIn ) )
755 xRow->appendBoolean( rProp, bReadOnly );
757 else if ( rProp.Name ==
"DateCreated" )
759 util::DateTime aTime = lcl_boostToUnoTime( getObject( xEnv )->getCreationDate( ) );
760 xRow->appendTimestamp( rProp, aTime );
762 else if ( rProp.Name ==
"DateModified" )
764 util::DateTime aTime = lcl_boostToUnoTime( getObject( xEnv )->getLastModificationDate( ) );
765 xRow->appendTimestamp( rProp, aTime );
767 else if ( rProp.Name ==
"Size" )
771 libcmis::Document* document =
dynamic_cast< libcmis::Document*
>( getObject( xEnv ).get( ) );
772 if (
nullptr != document )
773 xRow->appendLong( rProp, document->getContentLength() );
775 xRow->appendVoid( rProp );
777 catch (
const libcmis::Exception& )
779 xRow->appendVoid( rProp );
782 else if ( rProp.Name ==
"CreatableContentsInfo" )
784 xRow->appendObject( rProp,
uno::Any( queryCreatableContentsInfo( xEnv ) ) );
786 else if ( rProp.Name ==
"MediaType" )
790 libcmis::Document* document =
dynamic_cast< libcmis::Document*
>( getObject( xEnv ).get( ) );
791 if (
nullptr != document )
792 xRow->appendString( rProp,
STD_TO_OUSTR( document->getContentType() ) );
794 xRow->appendVoid( rProp );
796 catch (
const libcmis::Exception& )
798 xRow->appendVoid( rProp );
801 else if ( rProp.Name ==
"IsVolume" )
803 xRow->appendBoolean( rProp,
false );
805 else if ( rProp.Name ==
"IsRemote" )
807 xRow->appendBoolean( rProp,
false );
809 else if ( rProp.Name ==
"IsRemoveable" )
811 xRow->appendBoolean( rProp,
false );
813 else if ( rProp.Name ==
"IsFloppy" )
815 xRow->appendBoolean( rProp,
false );
817 else if ( rProp.Name ==
"IsCompactDisc" )
819 xRow->appendBoolean( rProp,
false );
821 else if ( rProp.Name ==
"IsHidden" )
823 xRow->appendBoolean( rProp,
false );
825 else if ( rProp.Name ==
"TargetURL" )
827 xRow->appendString( rProp,
"" );
829 else if ( rProp.Name ==
"BaseURI" )
831 xRow->appendString( rProp,
m_aURL.getBindingUrl( ) );
833 else if ( rProp.Name ==
"CmisProperties" )
837 libcmis::ObjectPtr
object = getObject( xEnv );
838 std::map< std::string, libcmis::PropertyPtr >&
aProperties =
object->getProperties( );
839 uno::Sequence< document::CmisProperty > aCmisProperties(
aProperties.size( ) );
840 document::CmisProperty* pCmisProps = aCmisProperties.getArray( );
842 for (
const auto& [sId, rProperty] : aProperties )
844 auto sDisplayName = rProperty->getPropertyType()->getDisplayName( );
845 bool bUpdatable = rProperty->getPropertyType()->isUpdatable( );
846 bool bRequired = rProperty->getPropertyType()->isRequired( );
847 bool bMultiValued = rProperty->getPropertyType()->isMultiValued();
848 bool bOpenChoice = rProperty->getPropertyType()->isOpenChoice();
852 pCmisProps[
i].Updatable = bUpdatable;
853 pCmisProps[
i].Required = bRequired;
854 pCmisProps[
i].MultiValued = bMultiValued;
855 pCmisProps[
i].OpenChoice = bOpenChoice;
856 pCmisProps[
i].Value = lcl_cmisPropertyToUno( rProperty );
857 switch ( rProperty->getPropertyType( )->getType( ) )
860 case libcmis::PropertyType::String:
863 case libcmis::PropertyType::Integer:
866 case libcmis::PropertyType::Decimal:
869 case libcmis::PropertyType::Bool:
872 case libcmis::PropertyType::DateTime:
878 xRow->appendObject( rProp.Name,
uno::Any( aCmisProperties ) );
880 catch (
const libcmis::Exception& )
882 xRow->appendVoid( rProp );
885 else if ( rProp.Name ==
"IsVersionable" )
889 libcmis::ObjectPtr
object = getObject( xEnv );
890 bool bIsVersionable =
object->getTypeDescription( )->isVersionable( );
891 xRow->appendBoolean( rProp, bIsVersionable );
893 catch (
const libcmis::Exception& )
895 xRow->appendVoid( rProp );
898 else if ( rProp.Name ==
"CanCheckOut" )
902 libcmis::ObjectPtr
pObject = getObject( xEnv );
903 libcmis::AllowableActionsPtr aAllowables =
pObject->getAllowableActions( );
904 bool bAllowed =
false;
907 bAllowed = aAllowables->isAllowed( libcmis::ObjectAction::CheckOut );
909 xRow->appendBoolean( rProp, bAllowed );
911 catch (
const libcmis::Exception& )
913 xRow->appendVoid( rProp );
916 else if ( rProp.Name ==
"CanCancelCheckOut" )
920 libcmis::ObjectPtr
pObject = getObject( xEnv );
921 libcmis::AllowableActionsPtr aAllowables =
pObject->getAllowableActions( );
922 bool bAllowed =
false;
925 bAllowed = aAllowables->isAllowed( libcmis::ObjectAction::CancelCheckOut );
927 xRow->appendBoolean( rProp, bAllowed );
929 catch (
const libcmis::Exception& )
931 xRow->appendVoid( rProp );
934 else if ( rProp.Name ==
"CanCheckIn" )
938 libcmis::ObjectPtr
pObject = getObject( xEnv );
939 libcmis::AllowableActionsPtr aAllowables =
pObject->getAllowableActions( );
940 bool bAllowed =
false;
943 bAllowed = aAllowables->isAllowed( libcmis::ObjectAction::CheckIn );
945 xRow->appendBoolean( rProp, bAllowed );
947 catch (
const libcmis::Exception& )
949 xRow->appendVoid( rProp );
953 SAL_INFO(
"ucb.ucp.cmis",
"Looking for unsupported property " << rProp.Name );
955 catch (
const libcmis::Exception&)
957 xRow->appendVoid( rProp );
964 uno::Any Content::open(
const ucb::OpenCommandArgument2 & rOpenCommand,
965 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
967 bool bIsFolder = isFolder( xEnv );
970 if ( !getObject( xEnv ) )
972 uno::Sequence< uno::Any > aArgs{
uno::Any(m_xIdentifier->getContentIdentifier()) };
974 ucb::InteractiveAugmentedIOException(OUString(), getXWeak(),
975 task::InteractionClassification_ERROR,
976 bIsFolder ? ucb::IOErrorCode_NOT_EXISTING_PATH : ucb::IOErrorCode_NOT_EXISTING, aArgs)
985 ( rOpenCommand.Mode == ucb::OpenMode::ALL ) ||
986 ( rOpenCommand.Mode == ucb::OpenMode::FOLDERS ) ||
987 ( rOpenCommand.Mode == ucb::OpenMode::DOCUMENTS )
990 if ( bOpenFolder && bIsFolder )
992 uno::Reference< ucb::XDynamicResultSet > xSet
993 =
new DynamicResultSet(m_xContext,
this, rOpenCommand, xEnv );
996 else if ( rOpenCommand.Sink.is() )
999 ( rOpenCommand.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_NONE ) ||
1000 ( rOpenCommand.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_WRITE )
1004 uno::Any ( ucb::UnsupportedOpenModeException
1005 ( OUString(), getXWeak(),
1006 sal_Int16( rOpenCommand.Mode ) ) ),
1010 if ( !feedSink( rOpenCommand.Sink, xEnv ) )
1015 SAL_INFO(
"ucb.ucp.cmis",
"Failed to copy data to sink" );
1018 uno::Any (ucb::UnsupportedDataSinkException
1019 ( OUString(), getXWeak(),
1020 rOpenCommand.Sink ) ),
1025 SAL_INFO(
"ucb.ucp.cmis",
"Open falling through ..." );
1030 OUString Content::checkIn(
const ucb::CheckinArgument& rArg,
1031 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1034 uno::Reference< io::XInputStream > xIn = aSourceContent.
openStream( );
1036 libcmis::ObjectPtr object;
1039 object = getObject( xEnv );
1041 catch (
const libcmis::Exception& e )
1043 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
1045 ucb::IOErrorCode_GENERAL,
1046 uno::Sequence< uno::Any >( 0 ),
1048 OUString::createFromAscii( e.what() ) );
1051 libcmis::Document* pPwc =
dynamic_cast< libcmis::Document*
>(
object.get( ) );
1055 ucb::IOErrorCode_GENERAL,
1056 uno::Sequence< uno::Any >( 0 ),
1058 "Checkin only supported by documents" );
1061 boost::shared_ptr< std::ostream >
pOut(
new std::ostringstream ( std::ios_base::binary | std::ios_base::in | std::ios_base::out ) );
1063 copyData( xIn, xOutput );
1065 std::map< std::string, libcmis::PropertyPtr > newProperties;
1066 libcmis::DocumentPtr pDoc;
1070 pDoc = pPwc->checkIn( rArg.MajorVersion,
OUSTR_TO_STDSTR( rArg.VersionComment ), newProperties,
1073 catch (
const libcmis::Exception& e )
1075 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
1077 ucb::IOErrorCode_GENERAL,
1078 uno::Sequence< uno::Any >( 0 ),
1080 OUString::createFromAscii( e.what() ) );
1085 std::vector< std::string > aPaths = pDoc->getPaths( );
1086 if ( !aPaths.empty() )
1088 auto sPath = aPaths.front( );
1095 auto sId = pDoc->getId( );
1101 OUString Content::checkOut(
const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1107 libcmis::DocumentPtr pDoc = boost::dynamic_pointer_cast< libcmis::Document >( getObject( xEnv ) );
1108 if ( pDoc.get( ) ==
nullptr )
1111 ucb::IOErrorCode_GENERAL,
1112 uno::Sequence< uno::Any >( 0 ),
1114 "Checkout only supported by documents" );
1116 libcmis::DocumentPtr pPwc = pDoc->checkOut( );
1120 std::vector< std::string > aPaths = pPwc->getPaths( );
1121 if ( !aPaths.empty() )
1123 auto sPath = aPaths.front( );
1130 auto sId = pPwc->getId( );
1135 catch (
const libcmis::Exception& e )
1137 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
1139 ucb::IOErrorCode_GENERAL,
1140 uno::Sequence< uno::Any >( 0 ),
1147 OUString Content::cancelCheckOut(
const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1152 libcmis::DocumentPtr pPwc = boost::dynamic_pointer_cast< libcmis::Document >( getObject( xEnv ) );
1153 if ( pPwc.get( ) ==
nullptr )
1156 ucb::IOErrorCode_GENERAL,
1157 uno::Sequence< uno::Any >( 0 ),
1159 "CancelCheckout only supported by documents" );
1161 pPwc->cancelCheckout( );
1164 std::vector< libcmis::DocumentPtr > aVersions = pPwc->getAllVersions( );
1165 for (
const auto& rVersion : aVersions )
1167 libcmis::DocumentPtr pVersion = rVersion;
1168 std::map< std::string, libcmis::PropertyPtr > aProps = pVersion->getProperties( );
1169 bool bIsLatestVersion =
false;
1170 std::map< std::string, libcmis::PropertyPtr >::iterator propIt = aProps.find( std::string(
"cmis:isLatestVersion" ) );
1171 if ( propIt != aProps.end( ) && !propIt->second->getBools( ).empty( ) )
1173 bIsLatestVersion = propIt->second->getBools( ).front( );
1176 if ( bIsLatestVersion )
1180 std::vector< std::string > aPaths = pVersion->getPaths( );
1181 if ( !aPaths.empty() )
1183 auto sPath = aPaths.front( );
1190 auto sId = pVersion->getId( );
1198 catch (
const libcmis::Exception& e )
1200 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
1202 ucb::IOErrorCode_GENERAL,
1203 uno::Sequence< uno::Any >( 0 ),
1210 uno::Sequence< document::CmisVersion> Content::getAllVersions(
const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1215 libcmis::DocumentPtr pDoc = boost::dynamic_pointer_cast< libcmis::Document >( getObject( xEnv ) );
1216 if ( pDoc.get( ) ==
nullptr )
1219 ucb::IOErrorCode_GENERAL,
1220 uno::Sequence< uno::Any >( 0 ),
1222 "Can not get the document" );
1224 std::vector< libcmis::DocumentPtr > aCmisVersions = pDoc->getAllVersions( );
1225 uno::Sequence< document::CmisVersion > aVersions( aCmisVersions.size( ) );
1226 auto aVersionsRange = asNonConstRange(aVersions);
1228 for (
const auto& rVersion : aCmisVersions )
1230 libcmis::DocumentPtr pVersion = rVersion;
1232 aVersionsRange[
i].Author =
STD_TO_OUSTR( pVersion->getCreatedBy( ) );
1233 aVersionsRange[
i].TimeStamp = lcl_boostToUnoTime( pVersion->getLastModificationDate( ) );
1234 aVersionsRange[
i].Comment =
STD_TO_OUSTR( pVersion->getStringProperty(
"cmis:checkinComment") );
1239 catch (
const libcmis::Exception& e )
1241 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
1243 ucb::IOErrorCode_GENERAL,
1244 uno::Sequence< uno::Any >( 0 ),
1248 return uno::Sequence< document::CmisVersion > ( );
1251 void Content::transfer(
const ucb::TransferInfo& rTransferInfo,
1252 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1256 if ( aSourceUrl.GetProtocol() != INetProtocol::Cmis )
1259 if ( sSrcBindingUrl !=
m_aURL.getBindingUrl( ) )
1263 ucb::InteractiveBadTransferURLException(
1264 "Unsupported URL scheme!",
1270 SAL_INFO(
"ucb.ucp.cmis",
"TODO - Content::transfer()" );
1273 void Content::insert(
const uno::Reference< io::XInputStream > & xInputStream,
1274 bool bReplaceExisting, std::u16string_view rMimeType,
1275 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1277 if ( !xInputStream.is() )
1280 ( ucb::MissingInputStreamException
1281 ( OUString(), getXWeak() ) ),
1286 if ( !m_bTransient )
1292 libcmis::FolderPtr pFolder;
1295 pFolder = boost::dynamic_pointer_cast< libcmis::Folder >( getObject( xEnv ) );
1297 catch (
const libcmis::Exception& )
1301 if ( pFolder ==
nullptr )
1304 libcmis::ObjectPtr object;
1305 std::map< std::string, libcmis::PropertyPtr >::iterator it = m_pObjectProps.find(
"cmis:name" );
1306 if ( it == m_pObjectProps.end( ) )
1309 ( uno::RuntimeException(
"Missing name property",
1313 auto newName = it->second->getStrings( ).front( );
1315 if ( !newPath.empty( ) && newPath[ newPath.size( ) - 1 ] !=
'/' )
1320 if ( !m_sObjectId.isEmpty( ) )
1321 object = getSession( xEnv )->getObject(
OUSTR_TO_STDSTR( m_sObjectId) );
1323 object = getSession( xEnv )->getObjectByPath( newPath );
1326 catch (
const libcmis::Exception& )
1331 if (
nullptr !=
object.
get( ) )
1334 if ( object->getBaseType( ) != m_pObjectType->getBaseType( )->getId() )
1337 ( uno::RuntimeException(
"Can't change a folder into a document and vice-versa.",
1343 libcmis::Document* document =
dynamic_cast< libcmis::Document*
>(
object.get( ) );
1344 if (
nullptr != document )
1346 boost::shared_ptr< std::ostream >
pOut(
new std::ostringstream ( std::ios_base::binary | std::ios_base::in | std::ios_base::out ) );
1347 uno::Reference < io::XOutputStream > xOutput =
new StdOutputStream( pOut );
1348 copyData( xInputStream, xOutput );
1351 document->setContentStream( pOut,
OUSTR_TO_STDSTR( rMimeType ), std::string( ), bReplaceExisting );
1353 catch (
const libcmis::Exception& )
1356 ( uno::RuntimeException(
"Error when setting document content",
1365 bool bIsFolder = getObjectType( xEnv )->getBaseType( )->getId( ) ==
"cmis:folder";
1366 setCmisProperty(
"cmis:objectTypeId", getObjectType( xEnv )->getId( ), xEnv );
1372 pFolder->createFolder( m_pObjectProps );
1375 catch (
const libcmis::Exception& )
1378 ( uno::RuntimeException(
"Error when creating folder",
1385 boost::shared_ptr< std::ostream >
pOut(
new std::ostringstream ( std::ios_base::binary | std::ios_base::in | std::ios_base::out ) );
1386 uno::Reference < io::XOutputStream > xOutput =
new StdOutputStream( pOut );
1387 copyData( xInputStream, xOutput );
1390 pFolder->createDocument( m_pObjectProps, pOut,
OUSTR_TO_STDSTR( rMimeType ), std::string() );
1393 catch (
const libcmis::Exception& )
1396 ( uno::RuntimeException(
"Error when creating document",
1403 if ( sNewPath.isEmpty( ) && m_sObjectId.isEmpty( ) )
1407 m_sObjectPath = sNewPath;
1409 aUrl.setObjectPath( m_sObjectPath );
1410 aUrl.setObjectId( m_sObjectId );
1411 m_sURL = aUrl.asString( );
1413 m_pObjectType.reset( );
1414 m_pObjectProps.clear( );
1415 m_bTransient =
false;
1421 void Content::copyData(
1422 const uno::Reference< io::XInputStream >& xIn,
1423 const uno::Reference< io::XOutputStream >& xOut )
1428 xOut->writeBytes( theData );
1430 xOut->closeOutput();
1433 uno::Sequence< uno::Any > Content::setPropertyValues(
1434 const uno::Sequence< beans::PropertyValue >& rValues,
1435 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1440 if ( !m_bTransient && getObject( xEnv ).
get( ) )
1442 m_pObjectProps.clear( );
1443 m_pObjectType = getObject( xEnv )->getTypeDescription();
1446 catch (
const libcmis::Exception& e )
1448 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
1450 ucb::IOErrorCode_GENERAL,
1451 uno::Sequence< uno::Any >( 0 ),
1456 sal_Int32
nCount = rValues.getLength();
1457 uno::Sequence< uno::Any > aRet( nCount );
1458 auto aRetRange = asNonConstRange(aRet);
1459 bool bChanged =
false;
1460 const beans::PropertyValue*
pValues = rValues.getConstArray();
1461 for ( sal_Int32 n = 0;
n <
nCount; ++
n )
1463 const beans::PropertyValue& rValue =
pValues[
n ];
1464 if ( rValue.Name ==
"ContentType" ||
1465 rValue.Name ==
"MediaType" ||
1466 rValue.Name ==
"IsDocument" ||
1467 rValue.Name ==
"IsFolder" ||
1468 rValue.Name ==
"Size" ||
1469 rValue.Name ==
"CreatableContentsInfo" )
1471 lang::IllegalAccessException e (
"Property is read-only!",
1473 aRetRange[
n ] <<= e;
1475 else if ( rValue.Name ==
"Title" )
1478 if (!( rValue.Value >>= aNewTitle ))
1480 aRetRange[
n ] <<= beans::IllegalTypeException
1481 (
"Property value has wrong type!",
1486 if ( aNewTitle.isEmpty() )
1488 aRetRange[
n ] <<= lang::IllegalArgumentException
1489 (
"Empty title not allowed!",
1500 SAL_INFO(
"ucb.ucp.cmis",
"Couldn't set property: " << rValue.Name );
1501 lang::IllegalAccessException e (
"Property is read-only!",
1503 aRetRange[
n ] <<= e;
1509 if ( !m_bTransient && bChanged )
1511 getObject( xEnv )->updateProperties( m_pObjectProps );
1514 catch (
const libcmis::Exception& e )
1516 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
1518 ucb::IOErrorCode_GENERAL,
1519 uno::Sequence< uno::Any >( 0 ),
1527 bool Content::feedSink(
const uno::Reference< uno::XInterface>& xSink,
1528 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1533 uno::Reference< io::XOutputStream > xOut(xSink, uno::UNO_QUERY );
1534 uno::Reference< io::XActiveDataSink > xDataSink(xSink, uno::UNO_QUERY );
1535 uno::Reference< io::XActiveDataStreamer > xDataStreamer( xSink, uno::UNO_QUERY );
1537 if ( !xOut.is() && !xDataSink.is() && ( !xDataStreamer.is() || !xDataStreamer->getStream().is() ) )
1540 if ( xDataStreamer.is() && !xOut.is() )
1541 xOut = xDataStreamer->getStream()->getOutputStream();
1545 libcmis::Document* document =
dynamic_cast< libcmis::Document*
>( getObject( xEnv ).get() );
1550 boost::shared_ptr< std::istream > aIn = document->getContentStream( );
1552 uno::Reference< io::XInputStream > xIn =
new StdInputStream( aIn );
1556 if ( xDataSink.is() )
1557 xDataSink->setInputStream( xIn );
1558 else if ( xOut.is() )
1559 copyData( xIn, xOut );
1561 catch (
const libcmis::Exception& e )
1563 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
1565 ucb::IOErrorCode_GENERAL,
1566 uno::Sequence< uno::Any >( 0 ),
1574 uno::Sequence< beans::Property > Content::getProperties(
1575 const uno::Reference< ucb::XCommandEnvironment > & )
1577 static const beans::Property aGenericProperties[] =
1579 beans::Property(
"IsDocument",
1581 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1582 beans::Property(
"IsFolder",
1584 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1585 beans::Property(
"Title",
1587 beans::PropertyAttribute::BOUND ),
1588 beans::Property(
"ObjectId",
1590 beans::PropertyAttribute::BOUND ),
1591 beans::Property(
"TitleOnServer",
1593 beans::PropertyAttribute::BOUND ),
1594 beans::Property(
"IsReadOnly",
1596 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1597 beans::Property(
"DateCreated",
1599 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1600 beans::Property(
"DateModified",
1602 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1603 beans::Property(
"Size",
1605 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1606 beans::Property(
"CreatableContentsInfo",
1607 -1,
cppu::UnoType<uno::Sequence< ucb::ContentInfo >>::get(),
1608 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1609 beans::Property(
"MediaType",
1611 beans::PropertyAttribute::BOUND ),
1612 beans::Property(
"CmisProperties",
1613 -1,
cppu::UnoType<uno::Sequence< document::CmisProperty>>::get(),
1614 beans::PropertyAttribute::BOUND ),
1615 beans::Property(
"IsVersionable",
1617 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1618 beans::Property(
"CanCheckOut",
1620 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1621 beans::Property(
"CanCancelCheckOut",
1623 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1624 beans::Property(
"CanCheckIn",
1626 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1630 return uno::Sequence< beans::Property > ( aGenericProperties, nProps );
1633 uno::Sequence< ucb::CommandInfo > Content::getCommands(
1634 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1636 static const ucb::CommandInfo aCommandInfoTable[] =
1643 (
"getPropertySetInfo",
1646 (
"getPropertyValues",
1647 -1,
cppu::UnoType<uno::Sequence< beans::Property >>::get() ),
1649 (
"setPropertyValues",
1650 -1,
cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get() ),
1666 ucb::CommandInfo (
"checkIn", -1,
1671 -1,
cppu::UnoType<uno::Sequence< document::CmisVersion >>::get() ),
1679 (
"createNewContent",
1684 return uno::Sequence< ucb::CommandInfo >(aCommandInfoTable, isFolder( xEnv ) ? nProps : nProps - 2);
1687 OUString Content::getParentURL( )
1689 SAL_INFO(
"ucb.ucp.cmis",
"Content::getParentURL()" );
1690 OUString parentUrl =
"/";
1691 if ( m_sObjectPath ==
"/" )
1709 void SAL_CALL Content::acquire() noexcept
1711 ContentImplHelper::acquire();
1714 void SAL_CALL Content::release() noexcept
1716 ContentImplHelper::release();
1722 return aRet.
hasValue() ? aRet : ContentImplHelper::queryInterface(rType);
1725 OUString SAL_CALL Content::getImplementationName()
1727 return "com.sun.star.comp.CmisContent";
1730 uno::Sequence< OUString > SAL_CALL Content::getSupportedServiceNames()
1732 uno::Sequence<OUString> aSNS {
"com.sun.star.ucb.CmisContent" };
1736 OUString SAL_CALL Content::getContentType()
1741 if (isFolder( uno::Reference< ucb::XCommandEnvironment >() ))
1746 catch (
const uno::RuntimeException&)
1750 catch (
const uno::Exception& e)
1753 throw lang::WrappedTargetRuntimeException(
1754 "wrapped Exception " + e.Message,
1755 uno::Reference<uno::XInterface>(),
a);
1760 uno::Any SAL_CALL Content::execute(
1761 const ucb::Command& aCommand,
1763 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1768 if (
aCommand.Name ==
"getPropertyValues" )
1771 if ( !(
aCommand.Argument >>= Properties ) )
1773 aRet <<= getPropertyValues( Properties, xEnv );
1775 else if (
aCommand.Name ==
"getPropertySetInfo" )
1776 aRet <<= getPropertySetInfo( xEnv,
false );
1777 else if (
aCommand.Name ==
"getCommandInfo" )
1778 aRet <<= getCommandInfo( xEnv,
false );
1779 else if (
aCommand.Name ==
"open" )
1781 ucb::OpenCommandArgument2 aOpenCommand;
1782 if ( !(
aCommand.Argument >>= aOpenCommand ) )
1784 aRet = open( aOpenCommand, xEnv );
1786 else if (
aCommand.Name ==
"transfer" )
1788 ucb::TransferInfo transferArgs;
1789 if ( !(
aCommand.Argument >>= transferArgs ) )
1791 transfer( transferArgs, xEnv );
1793 else if (
aCommand.Name ==
"setPropertyValues" )
1795 uno::Sequence< beans::PropertyValue >
aProperties;
1798 aRet <<= setPropertyValues( aProperties, xEnv );
1800 else if (
aCommand.Name ==
"createNewContent"
1801 && isFolder( xEnv ) )
1803 ucb::ContentInfo arg;
1804 if ( !(
aCommand.Argument >>= arg ) )
1806 aRet <<= createNewContent( arg );
1808 else if (
aCommand.Name ==
"insert" )
1810 ucb::InsertCommandArgument2 arg;
1811 if ( !(
aCommand.Argument >>= arg ) )
1813 ucb::InsertCommandArgument insertArg;
1814 if ( !(
aCommand.Argument >>= insertArg ) )
1817 arg.Data = insertArg.Data;
1818 arg.ReplaceExisting = insertArg.ReplaceExisting;
1821 m_sObjectId = arg.DocumentId;
1822 insert( arg.Data, arg.ReplaceExisting, arg.MimeType, xEnv );
1824 else if (
aCommand.Name ==
"delete" )
1828 if ( !isFolder( xEnv ) )
1830 getObject( xEnv )->remove( );
1834 libcmis::Folder* folder =
dynamic_cast< libcmis::Folder*
>( getObject( xEnv ).get() );
1836 folder->removeTree( );
1839 catch (
const libcmis::Exception& e )
1841 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
1843 ucb::IOErrorCode_GENERAL,
1844 uno::Sequence< uno::Any >( 0 ),
1849 else if (
aCommand.Name ==
"checkout" )
1851 aRet <<= checkOut( xEnv );
1853 else if (
aCommand.Name ==
"cancelCheckout" )
1855 aRet <<= cancelCheckOut( xEnv );
1857 else if (
aCommand.Name ==
"checkin" )
1859 ucb::CheckinArgument aArg;
1860 if ( !(
aCommand.Argument >>= aArg ) )
1864 aRet <<= checkIn( aArg, xEnv );
1866 else if (
aCommand.Name ==
"getAllVersions" )
1868 aRet <<= getAllVersions( xEnv );
1870 else if (
aCommand.Name ==
"updateProperties" )
1872 updateProperties(
aCommand.Argument, xEnv );
1876 SAL_INFO(
"ucb.ucp.cmis",
"Unknown command to execute" );
1879 (
uno::Any( ucb::UnsupportedCommandException
1888 void SAL_CALL Content::abort( sal_Int32 )
1890 SAL_INFO(
"ucb.ucp.cmis",
"TODO - Content::abort()" );
1894 uno::Sequence< ucb::ContentInfo > SAL_CALL Content::queryCreatableContentsInfo()
1896 return queryCreatableContentsInfo( uno::Reference< ucb::XCommandEnvironment >() );
1899 uno::Reference< ucb::XContent > SAL_CALL Content::createNewContent(
1900 const ucb::ContentInfo& Info )
1902 bool create_document;
1905 create_document =
true;
1907 create_document =
false;
1910 SAL_INFO(
"ucb.ucp.cmis",
"Unknown type of content to create" );
1911 return uno::Reference< ucb::XContent >();
1914 OUString sParentURL = m_xIdentifier->getContentIdentifier();
1917 uno::Reference< ucb::XContentIdentifier > xId(new ::ucbhelper::ContentIdentifier(sParentURL));
1921 return new ::cmis::Content( m_xContext, m_pProvider, xId, !create_document );
1923 catch ( ucb::ContentCreationException & )
1925 return uno::Reference< ucb::XContent >();
1929 uno::Sequence< uno::Type > SAL_CALL Content::getTypes()
1933 if ( isFolder( uno::Reference< ucb::XCommandEnvironment >() ) )
1947 return s_aFolderCollection.
getTypes();
1950 catch (
const uno::RuntimeException&)
1954 catch (
const uno::Exception& e)
1957 throw lang::WrappedTargetRuntimeException(
1958 "wrapped Exception " + e.Message,
1959 uno::Reference<uno::XInterface>(),
a);
1974 return s_aFileCollection.
getTypes();
1977 uno::Sequence< ucb::ContentInfo > Content::queryCreatableContentsInfo(
1978 const uno::Reference< ucb::XCommandEnvironment >& xEnv)
1982 if ( isFolder( xEnv ) )
1986 uno::Sequence< beans::Property >
props
1992 beans::PropertyAttribute::MAYBEVOID | beans::PropertyAttribute::BOUND
2000 ( ucb::ContentInfoAttribute::INSERT_WITH_INPUTSTREAM |
2001 ucb::ContentInfoAttribute::KIND_DOCUMENT ),
2006 ucb::ContentInfoAttribute::KIND_FOLDER,
2012 catch (
const uno::RuntimeException&)
2016 catch (
const uno::Exception& e)
2019 throw lang::WrappedTargetRuntimeException(
2020 "wrapped Exception " + e.Message,
2021 uno::Reference<uno::XInterface>(), a);
2026 std::vector< uno::Reference< ucb::XContent > > Content::getChildren( )
2028 std::vector< uno::Reference< ucb::XContent > > results;
2031 libcmis::FolderPtr pFolder = boost::dynamic_pointer_cast< libcmis::Folder >( getObject( uno::Reference< ucb::XCommandEnvironment >() ) );
2032 if (
nullptr != pFolder )
2037 std::vector< libcmis::ObjectPtr > children = pFolder->getChildren( );
2040 for (
const auto& rChild : children )
2048 OUString sPath( m_sObjectPath );
2049 if ( !sPath.endsWith(
"/") )
2059 uno::Reference< ucb::XContent > xContent =
new Content(
m_xContext, m_pProvider, xId, rChild );
2061 results.push_back( xContent );
2064 catch (
const libcmis::Exception& e )
2066 SAL_INFO(
"ucb.ucp.cmis",
"Exception thrown: " << e.what() );
2073 void Content::setCmisProperty(
const std::string& rName,
const std::string& rValue,
const uno::Reference< ucb::XCommandEnvironment >& xEnv )
2075 if ( !getObjectType( xEnv ).
get( ) )
2078 std::map< std::string, libcmis::PropertyPtr >::iterator propIt = m_pObjectProps.find(rName);
2080 if ( propIt == m_pObjectProps.end( ) && getObjectType( xEnv ).
get( ) )
2082 std::map< std::string, libcmis::PropertyTypePtr > propsTypes = getObjectType( xEnv )->getPropertiesTypes( );
2083 std::map< std::string, libcmis::PropertyTypePtr >::iterator typeIt = propsTypes.find(rName);
2085 if ( typeIt != propsTypes.end( ) )
2087 libcmis::PropertyTypePtr propType = typeIt->second;
2088 libcmis::PropertyPtr
property(
new libcmis::Property( propType, { rValue }) );
2089 m_pObjectProps.insert(std::pair< std::string, libcmis::PropertyPtr >(rName,
property));
2092 else if ( propIt != m_pObjectProps.end( ) )
2094 propIt->second->setValues( { rValue } );
const PropertyValue * pValues
Reference< XComponentContext > m_xContext
PropertiesInfo aProperties
OUString getName(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
sal_uInt32 GetPort() const
static OUString GetScheme(INetProtocol eTheScheme)
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool removeSegment(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true)
sal_Int32 getSegmentCount(bool bIgnoreFinalSlash=true) const
OUString GetURLPath(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString GetHost(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
INetProtocol GetProtocol() const
bool authenticationQuery(std::string &username, std::string &password) override
bool storeRefreshToken(const std::string &username, const std::string &password, const std::string &refreshToken)
std::string getRefreshToken(std::string &username)
Content(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ContentProvider *pProvider, const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier, libcmis::ObjectPtr pObject=libcmis::ObjectPtr())
Implements a OutputStream working on an std::ostream.
void setObjectId(const OUString &sId)
const OUString & getUsername() const
const OUString & getRepositoryId() const
void setObjectPath(const OUString &sPath)
const OUString & getBindingUrl() const
void setUsername(const OUString &sUser)
OUString asString() const
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
css::uno::Type const & get()
static void convertDateTime(OUStringBuffer &rBuffer, const css::util::DateTime &rDateTime, sal_Int16 const *pTimeZoneOffset, bool bAddTimeIf0AM=false)
css::uno::Reference< css::io::XInputStream > openStream()
InternetProxyServer getProxy(const OUString &rProtocol, const OUString &rHost, sal_Int32 nPort) const
#define OUSTR_TO_STDSTR(s)
#define STD_TO_OUSTR(str)
constexpr OUStringLiteral CMIS_TYPE_DATETIME
constexpr OUStringLiteral CMIS_TYPE_STRING
constexpr OUStringLiteral CMIS_TYPE_INTEGER
constexpr OUStringLiteral CMIS_TYPE_BOOL
constexpr OUStringLiteral CMIS_TYPE_DECIMAL
EmbeddedObjectRef * pObject
Sequence< PropertyValue > aArguments
tools::SvRef< SvBaseLink > xSink
DECL_LISTENERMULTIPLEXER_END void SAL_CALL inserted(::sal_Int32 ID) override
#define SAL_INFO(area, stream)
#define SAL_N_ELEMENTS(arr)
constexpr OUStringLiteral CMIS_FOLDER_TYPE
constexpr OUStringLiteral CMIS_FILE_TYPE
const int TRANSFER_BUFFER_SIZE
XTYPEPROVIDER_COMMON_IMPL(Content)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
Reference< XComponentContext > getProcessComponentContext()
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
Any SAL_CALL getCaughtException()
OUString newName(std::u16string_view aNewPrefix, std::u16string_view aOldPrefix, std::u16string_view old_Name)
OUString runtimeToOUString(char const *runtimeString)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
void cancelCommandExecution(const uno::Any &rException, const uno::Reference< ucb::XCommandEnvironment > &xEnv)
std::vector< char * > values
std::unique_ptr< char[]> aBuffer