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>
69#define OUSTR_TO_STDSTR(s) std::string( OUStringToOString( s, RTL_TEXTENCODING_UTF8 ).getStr() )
70#define STD_TO_OUSTR( str ) OUString( str.c_str(), str.length( ), RTL_TEXTENCODING_UTF8 )
76 util::DateTime lcl_boostToUnoTime(
const boost::posix_time::ptime& boostTime)
78 util::DateTime unoTime;
79 unoTime.Year = boostTime.date().year();
80 unoTime.Month = boostTime.date().month();
81 unoTime.Day = boostTime.date().day();
82 unoTime.Hours = boostTime.time_of_day().hours();
83 unoTime.Minutes = boostTime.time_of_day().minutes();
84 unoTime.Seconds = boostTime.time_of_day().seconds();
89 const tools::Long ticks = boostTime.time_of_day().fractional_seconds();
90 tools::Long nanoSeconds = ticks * ( 1000000000 / boost::posix_time::time_duration::ticks_per_second());
92 unoTime.NanoSeconds = nanoSeconds;
97 uno::Any lcl_cmisPropertyToUno(
const libcmis::PropertyPtr& pProperty )
100 switch ( pProperty->getPropertyType( )->getType( ) )
103 case libcmis::PropertyType::String:
105 auto aCmisStrings = pProperty->getStrings( );
106 uno::Sequence< OUString > aStrings( aCmisStrings.size( ) );
107 OUString* aStringsArr = aStrings.getArray( );
109 for (
const auto& rCmisStr : aCmisStrings )
116 case libcmis::PropertyType::Integer:
118 auto aCmisLongs = pProperty->getLongs( );
119 uno::Sequence< sal_Int64 > aLongs( aCmisLongs.size( ) );
120 sal_Int64* aLongsArr = aLongs.getArray( );
122 for (
const auto& rCmisLong : aCmisLongs )
124 aLongsArr[
i++] = rCmisLong;
129 case libcmis::PropertyType::Decimal:
131 auto aCmisDoubles = pProperty->getDoubles( );
136 case libcmis::PropertyType::Bool:
138 auto aCmisBools = pProperty->getBools( );
139 uno::Sequence< sal_Bool > aBools( aCmisBools.size( ) );
140 sal_Bool* aBoolsArr = aBools.getArray( );
142 for (
bool bCmisBool : aCmisBools )
144 aBoolsArr[
i++] = bCmisBool;
149 case libcmis::PropertyType::DateTime:
151 auto aCmisTimes = pProperty->getDateTimes( );
152 uno::Sequence< util::DateTime > aTimes( aCmisTimes.size( ) );
153 util::DateTime* aTimesArr = aTimes.getArray( );
155 for (
const auto& rCmisTime : aCmisTimes )
157 aTimesArr[
i++] = lcl_boostToUnoTime( rCmisTime );
166 libcmis::PropertyPtr lcl_unoToCmisProperty(
const document::CmisProperty& prop )
168 libcmis::PropertyTypePtr propertyType(
new libcmis::PropertyType( ) );
170 OUString
id = prop.Id;
171 OUString
name = prop.Name;
172 bool bUpdatable = prop.Updatable;
173 bool bRequired = prop.Required;
174 bool bMultiValued = prop.MultiValued;
175 bool bOpenChoice = prop.OpenChoice;
177 std::vector< std::string >
values;
179 libcmis::PropertyType::Type
type = libcmis::PropertyType::String;
182 uno::Sequence< OUString > seqValue;
184 std::transform(std::cbegin(seqValue), std::cend(seqValue), std::back_inserter(
values),
185 [](
const OUString& rValue) -> std::string {
return OUSTR_TO_STDSTR( rValue ); });
186 type = libcmis::PropertyType::String;
190 uno::Sequence< sal_Bool > seqValue;
192 std::transform(std::cbegin(seqValue), std::cend(seqValue), std::back_inserter(
values),
194 type = libcmis::PropertyType::Bool;
198 uno::Sequence< sal_Int64 > seqValue;
200 std::transform(std::cbegin(seqValue), std::cend(seqValue), std::back_inserter(
values),
202 type = libcmis::PropertyType::Integer;
206 uno::Sequence< double > seqValue;
208 std::transform(std::cbegin(seqValue), std::cend(seqValue), std::back_inserter(
values),
209 [](
const double fValue) -> std::string {
return OUSTR_TO_STDSTR( OUString::number( fValue ) ); });
210 type = libcmis::PropertyType::Decimal;
214 uno::Sequence< util::DateTime > seqValue;
216 std::transform(std::cbegin(seqValue), std::cend(seqValue), std::back_inserter(
values),
217 [](
const util::DateTime& rValue) -> std::string {
222 type = libcmis::PropertyType::DateTime;
227 propertyType->setUpdatable( bUpdatable );
228 propertyType->setRequired( bRequired );
229 propertyType->setMultiValued( bMultiValued );
230 propertyType->setOpenChoice( bOpenChoice );
231 propertyType->setType(
type );
233 libcmis::PropertyPtr
property(
new libcmis::Property( propertyType, std::move(
values) ) );
238 uno::Sequence< uno::Any > generateErrorArguments(
const cmis::URL & rURL )
244 beans::PropertyState_DIRECT_VALUE )),
249 beans::PropertyState_DIRECT_VALUE )),
254 beans::PropertyState_DIRECT_VALUE )) };
262 Content::Content(
const uno::Reference< uno::XComponentContext >& rxContext,
263 ContentProvider *pProvider,
const uno::Reference< ucb::XContentIdentifier >& Identifier,
264 libcmis::ObjectPtr
const & pObject )
265 : ContentImplHelper( rxContext, pProvider,
Identifier ),
266 m_pProvider( pProvider ),
267 m_pSession( nullptr ),
271 m_bTransient( false ),
274 SAL_INFO(
"ucb.ucp.cmis",
"Content::Content() " << m_sURL );
276 m_sObjectPath =
m_aURL.getObjectPath( );
277 m_sObjectId =
m_aURL.getObjectId( );
280 Content::Content(
const uno::Reference< uno::XComponentContext >& rxContext,
ContentProvider *pProvider,
281 const uno::Reference< ucb::XContentIdentifier >& Identifier,
283 : ContentImplHelper( rxContext, pProvider,
Identifier ),
284 m_pProvider( pProvider ),
285 m_pSession( nullptr ),
288 m_bTransient( true ),
289 m_bIsFolder( bIsFolder )
291 SAL_INFO(
"ucb.ucp.cmis",
"Content::Content() " << m_sURL );
293 m_sObjectPath =
m_aURL.getObjectPath( );
294 m_sObjectId =
m_aURL.getObjectId( );
301 libcmis::Session* Content::getSession(
const uno::Reference< ucb::XCommandEnvironment >& xEnv )
308 OUString sProxy = rProxy.
aName;
309 if ( rProxy.
nPort > 0 )
310 sProxy +=
":" + OUString::number( rProxy.
nPort );
311 libcmis::SessionFactory::setProxySettings(
OUSTR_TO_STDSTR( sProxy ), std::string(), std::string(), std::string() );
314 OUString sSessionId =
m_aURL.getBindingUrl( ) +
m_aURL.getRepositoryId( );
315 if (
nullptr == m_pSession )
316 m_pSession = m_pProvider->getSession( sSessionId,
m_aURL.getUsername( ) );
318 if (
nullptr == m_pSession )
323 uno::Reference< css::xml::crypto::XNSSInitializer >
324 xNSSInitializer = css::xml::crypto::NSSInitializer::create(
m_xContext );
326 uno::Reference< css::xml::crypto::XDigestContext > xDigestContext(
327 xNSSInitializer->getDigestContext( css::xml::crypto::DigestID::SHA256,
328 uno::Sequence< beans::NamedValue >() ),
329 uno::UNO_SET_THROW );
333 libcmis::CertValidationHandlerPtr certHandler(
335 libcmis::SessionFactory::setCertificateValidationHandler( certHandler );
338 AuthProvider aAuthProvider(xEnv, m_xIdentifier->getContentIdentifier(),
m_aURL.getBindingUrl());
339 AuthProvider::setXEnv( xEnv );
344 bool bSkipInitialPWAuth =
false;
345 if (
m_aURL.getBindingUrl() == ONEDRIVE_BASE_URL
346 ||
m_aURL.getBindingUrl() == GDRIVE_BASE_URL)
352 bSkipInitialPWAuth =
true;
356 bool bIsDone =
false;
363 libcmis::OAuth2DataPtr oauth2Data;
364 if (
m_aURL.getBindingUrl( ) == GDRIVE_BASE_URL )
367 bSkipInitialPWAuth =
false;
368 libcmis::SessionFactory::setOAuth2AuthCodeProvider(AuthProvider::copyWebAuthCodeFallback);
369 oauth2Data = boost::make_shared<libcmis::OAuth2Data>(
370 GDRIVE_AUTH_URL, GDRIVE_TOKEN_URL,
371 GDRIVE_SCOPE, GDRIVE_REDIRECT_URI,
372 GDRIVE_CLIENT_ID, GDRIVE_CLIENT_SECRET );
374 if (
m_aURL.getBindingUrl().startsWith( ALFRESCO_CLOUD_BASE_URL ) )
375 oauth2Data = boost::make_shared<libcmis::OAuth2Data>(
376 ALFRESCO_CLOUD_AUTH_URL, ALFRESCO_CLOUD_TOKEN_URL,
377 ALFRESCO_CLOUD_SCOPE, ALFRESCO_CLOUD_REDIRECT_URI,
378 ALFRESCO_CLOUD_CLIENT_ID, ALFRESCO_CLOUD_CLIENT_SECRET );
379 if (
m_aURL.getBindingUrl( ) == ONEDRIVE_BASE_URL )
382 bSkipInitialPWAuth =
false;
383 libcmis::SessionFactory::setOAuth2AuthCodeProvider(AuthProvider::copyWebAuthCodeFallback);
384 oauth2Data = boost::make_shared<libcmis::OAuth2Data>(
385 ONEDRIVE_AUTH_URL, ONEDRIVE_TOKEN_URL,
386 ONEDRIVE_SCOPE, ONEDRIVE_REDIRECT_URI,
387 ONEDRIVE_CLIENT_ID, ONEDRIVE_CLIENT_SECRET );
391 m_pSession = libcmis::SessionFactory::createSession(
395 if ( m_pSession ==
nullptr )
399 ucb::IOErrorCode_INVALID_DEVICE,
400 generateErrorArguments(
m_aURL),
403 else if ( m_pSession->getRepository() ==
nullptr )
407 ucb::IOErrorCode_INVALID_DEVICE,
408 generateErrorArguments(
m_aURL),
410 "error accessing a repository");
414 m_pProvider->registerSession(sSessionId,
m_aURL.getUsername( ), m_pSession);
415 if (
m_aURL.getBindingUrl() == ONEDRIVE_BASE_URL
416 ||
m_aURL.getBindingUrl() == GDRIVE_BASE_URL)
419 m_pSession->getRefreshToken());
425 catch(
const libcmis::Exception & e )
427 if ( e.getType() !=
"permissionDenied" )
429 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what());
438 ucb::IOErrorCode_ABORT,
439 uno::Sequence< uno::Any >( 0 ),
441 throw uno::RuntimeException( );
448 libcmis::ObjectTypePtr
const & Content::getObjectType(
const uno::Reference< ucb::XCommandEnvironment >& xEnv )
450 if (
nullptr == m_pObjectType.get( ) && m_bTransient )
452 std::string typeId = m_bIsFolder ?
"cmis:folder" :
"cmis:document";
457 libcmis::Folder* pParent =
nullptr;
458 bool bTypeRestricted =
false;
461 pParent =
dynamic_cast< libcmis::Folder*
>( getObject( xEnv ).get( ) );
463 catch (
const libcmis::Exception& )
469 std::map< std::string, libcmis::PropertyPtr >&
aProperties = pParent->getProperties( );
470 std::map< std::string, libcmis::PropertyPtr >::iterator it =
aProperties.find(
"cmis:allowedChildObjectTypeIds" );
473 libcmis::PropertyPtr pProperty = it->second;
476 std::vector< std::string > typesIds = pProperty->getStrings( );
477 for (
const auto& rType : typesIds )
479 bTypeRestricted =
true;
480 libcmis::ObjectTypePtr
type = getSession( xEnv )->getType( rType );
483 if (
type->getBaseType( )->getId( ) == typeId )
485 m_pObjectType =
type;
493 if ( !bTypeRestricted )
494 m_pObjectType = getSession( xEnv )->getType( typeId );
496 return m_pObjectType;
500 libcmis::ObjectPtr
const & Content::getObject(
const uno::Reference< ucb::XCommandEnvironment >& xEnv )
506 if ( !getSession( xEnv ) )
509 catch ( uno::RuntimeException& )
513 if ( !m_pObject.get() )
515 if ( !m_sObjectId.isEmpty( ) )
519 m_pObject = getSession( xEnv )->getObject(
OUSTR_TO_STDSTR( m_sObjectId ) );
521 catch (
const libcmis::Exception& )
524 throw libcmis::Exception(
"Object not found" );
527 else if (!(m_sObjectPath.isEmpty() || m_sObjectPath ==
"/"))
531 m_pObject = getSession( xEnv )->getObjectByPath(
OUSTR_TO_STDSTR( m_sObjectPath ) );
533 catch (
const libcmis::Exception& )
547 libcmis::FolderPtr pParentFolder = boost::dynamic_pointer_cast< libcmis::Folder >(xParent->getObject(xEnv));
550 std::vector< libcmis::ObjectPtr > children = pParentFolder->getChildren();
551 auto it = std::find_if(children.begin(), children.end(),
552 [&
sName](
const libcmis::ObjectPtr& rChild) { return rChild->getName() == sName; });
553 if (it != children.end())
559 throw libcmis::Exception(
"Object not found" );
564 m_pObject = getSession( xEnv )->getRootFolder( );
566 m_sObjectId = OUString( );
573 bool Content::isFolder(
const uno::Reference< ucb::XCommandEnvironment >& xEnv )
575 bool bIsFolder =
false;
578 libcmis::ObjectPtr obj = getObject( xEnv );
580 bIsFolder = obj->getBaseType( ) ==
"cmis:folder";
582 catch (
const libcmis::Exception& e )
584 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
587 ucb::IOErrorCode_GENERAL,
588 uno::Sequence< uno::Any >( 0 ),
590 OUString::createFromAscii( e.what( ) ) );
598 return uno::Any( lang::IllegalArgumentException(
599 "Wrong argument type!",
603 libcmis::ObjectPtr Content::updateProperties(
605 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
608 uno::Sequence< document::CmisProperty > aPropsSeq;
609 iCmisProps >>= aPropsSeq;
610 std::map< std::string, libcmis::PropertyPtr >
aProperties;
612 for (
const auto& rProp : std::as_const(aPropsSeq) )
615 libcmis::PropertyPtr prop = lcl_unoToCmisProperty( rProp );
616 aProperties.insert( std::pair<std::string, libcmis::PropertyPtr>(
id, prop ) );
618 libcmis::ObjectPtr updateObj;
621 updateObj = getObject( xEnv )->updateProperties(
aProperties );
623 catch (
const libcmis::Exception& e )
625 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: "<< e.what( ) );
631 uno::Reference< sdbc::XRow > Content::getPropertyValues(
632 const uno::Sequence< beans::Property >& rProperties,
633 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
637 for(
const beans::Property& rProp : rProperties )
641 if ( rProp.Name ==
"IsDocument" )
645 libcmis::ObjectPtr obj = getObject( xEnv );
647 xRow->appendBoolean( rProp, obj->getBaseType( ) ==
"cmis:document" );
649 catch (
const libcmis::Exception& )
651 if ( m_pObjectType.get( ) )
652 xRow->appendBoolean( rProp, getObjectType( xEnv )->getBaseType()->getId( ) ==
"cmis:document" );
654 xRow->appendVoid( rProp );
657 else if ( rProp.Name ==
"IsFolder" )
661 libcmis::ObjectPtr obj = getObject( xEnv );
663 xRow->appendBoolean( rProp, obj->getBaseType( ) ==
"cmis:folder" );
665 xRow->appendBoolean( rProp,
false );
667 catch (
const libcmis::Exception& )
669 if ( m_pObjectType.get( ) )
670 xRow->appendBoolean( rProp, getObjectType( xEnv )->getBaseType()->getId( ) ==
"cmis:folder" );
672 xRow->appendVoid( rProp );
675 else if ( rProp.Name ==
"Title" )
682 catch (
const libcmis::Exception& )
684 if ( !m_pObjectProps.empty() )
686 std::map< std::string, libcmis::PropertyPtr >::iterator it = m_pObjectProps.find(
"cmis:name" );
687 if ( it != m_pObjectProps.end( ) )
689 std::vector< std::string >
values = it->second->getStrings( );
697 if ( sTitle.isEmpty( ) )
699 OUString sPath = m_sObjectPath;
702 if ( sPath.endsWith(
"/") )
703 sPath = sPath.copy( 0, sPath.getLength() - 1 );
706 sal_Int32
nPos = sPath.lastIndexOf(
'/' );
708 sTitle = sPath.copy( nPos + 1 );
711 if ( !sTitle.isEmpty( ) )
712 xRow->appendString( rProp, sTitle );
714 xRow->appendVoid( rProp );
716 else if ( rProp.Name ==
"ObjectId" )
723 catch (
const libcmis::Exception& )
725 if ( !m_pObjectProps.empty() )
727 std::map< std::string, libcmis::PropertyPtr >::iterator it = m_pObjectProps.find(
"cmis:objectId" );
728 if ( it != m_pObjectProps.end( ) )
730 std::vector< std::string >
values = it->second->getStrings( );
737 if ( !
sId.isEmpty( ) )
738 xRow->appendString( rProp, sId );
740 xRow->appendVoid( rProp );
742 else if ( rProp.Name ==
"TitleOnServer" )
744 xRow->appendString( rProp, m_sObjectPath);
746 else if ( rProp.Name ==
"IsReadOnly" )
748 boost::shared_ptr< libcmis::AllowableActions > allowableActions = getObject( xEnv )->getAllowableActions( );
750 if ( !allowableActions->isAllowed( libcmis::ObjectAction::SetContentStream ) &&
751 !allowableActions->isAllowed( libcmis::ObjectAction::CheckIn ) )
754 xRow->appendBoolean( rProp, bReadOnly );
756 else if ( rProp.Name ==
"DateCreated" )
758 util::DateTime aTime = lcl_boostToUnoTime( getObject( xEnv )->getCreationDate( ) );
759 xRow->appendTimestamp( rProp, aTime );
761 else if ( rProp.Name ==
"DateModified" )
763 util::DateTime aTime = lcl_boostToUnoTime( getObject( xEnv )->getLastModificationDate( ) );
764 xRow->appendTimestamp( rProp, aTime );
766 else if ( rProp.Name ==
"Size" )
770 libcmis::Document* document =
dynamic_cast< libcmis::Document*
>( getObject( xEnv ).get( ) );
771 if (
nullptr != document )
772 xRow->appendLong( rProp, document->getContentLength() );
774 xRow->appendVoid( rProp );
776 catch (
const libcmis::Exception& )
778 xRow->appendVoid( rProp );
781 else if ( rProp.Name ==
"CreatableContentsInfo" )
783 xRow->appendObject( rProp,
uno::Any( queryCreatableContentsInfo( xEnv ) ) );
785 else if ( rProp.Name ==
"MediaType" )
789 libcmis::Document* document =
dynamic_cast< libcmis::Document*
>( getObject( xEnv ).get( ) );
790 if (
nullptr != document )
793 xRow->appendVoid( rProp );
795 catch (
const libcmis::Exception& )
797 xRow->appendVoid( rProp );
800 else if ( rProp.Name ==
"IsVolume" )
802 xRow->appendBoolean( rProp,
false );
804 else if ( rProp.Name ==
"IsRemote" )
806 xRow->appendBoolean( rProp,
false );
808 else if ( rProp.Name ==
"IsRemoveable" )
810 xRow->appendBoolean( rProp,
false );
812 else if ( rProp.Name ==
"IsFloppy" )
814 xRow->appendBoolean( rProp,
false );
816 else if ( rProp.Name ==
"IsCompactDisc" )
818 xRow->appendBoolean( rProp,
false );
820 else if ( rProp.Name ==
"IsHidden" )
822 xRow->appendBoolean( rProp,
false );
824 else if ( rProp.Name ==
"TargetURL" )
826 xRow->appendString( rProp,
"" );
828 else if ( rProp.Name ==
"BaseURI" )
830 xRow->appendString( rProp,
m_aURL.getBindingUrl( ) );
832 else if ( rProp.Name ==
"CmisProperties" )
836 libcmis::ObjectPtr
object = getObject( xEnv );
837 std::map< std::string, libcmis::PropertyPtr >&
aProperties =
object->getProperties( );
838 uno::Sequence< document::CmisProperty > aCmisProperties(
aProperties.size( ) );
839 document::CmisProperty* pCmisProps = aCmisProperties.getArray( );
841 for (
const auto& [sId, rProperty] : aProperties )
843 auto sDisplayName = rProperty->getPropertyType()->getDisplayName( );
844 bool bUpdatable = rProperty->getPropertyType()->isUpdatable( );
845 bool bRequired = rProperty->getPropertyType()->isRequired( );
846 bool bMultiValued = rProperty->getPropertyType()->isMultiValued();
847 bool bOpenChoice = rProperty->getPropertyType()->isOpenChoice();
851 pCmisProps[
i].Updatable = bUpdatable;
852 pCmisProps[
i].Required = bRequired;
853 pCmisProps[
i].MultiValued = bMultiValued;
854 pCmisProps[
i].OpenChoice = bOpenChoice;
855 pCmisProps[
i].Value = lcl_cmisPropertyToUno( rProperty );
856 switch ( rProperty->getPropertyType( )->getType( ) )
859 case libcmis::PropertyType::String:
862 case libcmis::PropertyType::Integer:
865 case libcmis::PropertyType::Decimal:
868 case libcmis::PropertyType::Bool:
871 case libcmis::PropertyType::DateTime:
877 xRow->appendObject( rProp.Name,
uno::Any( aCmisProperties ) );
879 catch (
const libcmis::Exception& )
881 xRow->appendVoid( rProp );
884 else if ( rProp.Name ==
"IsVersionable" )
888 libcmis::ObjectPtr
object = getObject( xEnv );
889 bool bIsVersionable =
object->getTypeDescription( )->isVersionable( );
890 xRow->appendBoolean( rProp, bIsVersionable );
892 catch (
const libcmis::Exception& )
894 xRow->appendVoid( rProp );
897 else if ( rProp.Name ==
"CanCheckOut" )
901 libcmis::ObjectPtr
pObject = getObject( xEnv );
902 libcmis::AllowableActionsPtr aAllowables =
pObject->getAllowableActions( );
903 bool bAllowed =
false;
906 bAllowed = aAllowables->isAllowed( libcmis::ObjectAction::CheckOut );
908 xRow->appendBoolean( rProp, bAllowed );
910 catch (
const libcmis::Exception& )
912 xRow->appendVoid( rProp );
915 else if ( rProp.Name ==
"CanCancelCheckOut" )
919 libcmis::ObjectPtr
pObject = getObject( xEnv );
920 libcmis::AllowableActionsPtr aAllowables =
pObject->getAllowableActions( );
921 bool bAllowed =
false;
924 bAllowed = aAllowables->isAllowed( libcmis::ObjectAction::CancelCheckOut );
926 xRow->appendBoolean( rProp, bAllowed );
928 catch (
const libcmis::Exception& )
930 xRow->appendVoid( rProp );
933 else if ( rProp.Name ==
"CanCheckIn" )
937 libcmis::ObjectPtr
pObject = getObject( xEnv );
938 libcmis::AllowableActionsPtr aAllowables =
pObject->getAllowableActions( );
939 bool bAllowed =
false;
942 bAllowed = aAllowables->isAllowed( libcmis::ObjectAction::CheckIn );
944 xRow->appendBoolean( rProp, bAllowed );
946 catch (
const libcmis::Exception& )
948 xRow->appendVoid( rProp );
952 SAL_INFO(
"ucb.ucp.cmis",
"Looking for unsupported property " << rProp.Name );
954 catch (
const libcmis::Exception&)
956 xRow->appendVoid( rProp );
963 uno::Any Content::open(
const ucb::OpenCommandArgument2 & rOpenCommand,
964 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
966 bool bIsFolder = isFolder( xEnv );
969 if ( !getObject( xEnv ) )
971 uno::Sequence< uno::Any > aArgs{
uno::Any(m_xIdentifier->getContentIdentifier()) };
973 ucb::InteractiveAugmentedIOException(OUString(),
static_cast< cppu::OWeakObject *
>(
this ),
974 task::InteractionClassification_ERROR,
975 bIsFolder ? ucb::IOErrorCode_NOT_EXISTING_PATH : ucb::IOErrorCode_NOT_EXISTING, aArgs)
984 ( rOpenCommand.Mode == ucb::OpenMode::ALL ) ||
985 ( rOpenCommand.Mode == ucb::OpenMode::FOLDERS ) ||
986 ( rOpenCommand.Mode == ucb::OpenMode::DOCUMENTS )
989 if ( bOpenFolder && bIsFolder )
991 uno::Reference< ucb::XDynamicResultSet > xSet
992 =
new DynamicResultSet(m_xContext,
this, rOpenCommand, xEnv );
995 else if ( rOpenCommand.Sink.is() )
998 ( rOpenCommand.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_NONE ) ||
999 ( rOpenCommand.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_WRITE )
1003 uno::Any ( ucb::UnsupportedOpenModeException
1005 sal_Int16( rOpenCommand.Mode ) ) ),
1009 if ( !feedSink( rOpenCommand.Sink, xEnv ) )
1014 SAL_INFO(
"ucb.ucp.cmis",
"Failed to copy data to sink" );
1017 uno::Any (ucb::UnsupportedDataSinkException
1019 rOpenCommand.Sink ) ),
1024 SAL_INFO(
"ucb.ucp.cmis",
"Open falling through ..." );
1029 OUString Content::checkIn(
const ucb::CheckinArgument& rArg,
1030 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1033 uno::Reference< io::XInputStream > xIn = aSourceContent.
openStream( );
1035 libcmis::ObjectPtr object;
1038 object = getObject( xEnv );
1040 catch (
const libcmis::Exception& e )
1042 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
1044 ucb::IOErrorCode_GENERAL,
1045 uno::Sequence< uno::Any >( 0 ),
1047 OUString::createFromAscii( e.what() ) );
1050 libcmis::Document* pPwc =
dynamic_cast< libcmis::Document*
>(
object.get( ) );
1054 ucb::IOErrorCode_GENERAL,
1055 uno::Sequence< uno::Any >( 0 ),
1057 "Checkin only supported by documents" );
1060 boost::shared_ptr< std::ostream >
pOut(
new std::ostringstream ( std::ios_base::binary | std::ios_base::in | std::ios_base::out ) );
1062 copyData( xIn, xOutput );
1064 std::map< std::string, libcmis::PropertyPtr > newProperties;
1065 libcmis::DocumentPtr pDoc;
1069 pDoc = pPwc->checkIn( rArg.MajorVersion,
OUSTR_TO_STDSTR( rArg.VersionComment ), newProperties,
1072 catch (
const libcmis::Exception& e )
1074 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
1076 ucb::IOErrorCode_GENERAL,
1077 uno::Sequence< uno::Any >( 0 ),
1079 OUString::createFromAscii( e.what() ) );
1084 std::vector< std::string > aPaths = pDoc->getPaths( );
1085 if ( !aPaths.empty() )
1087 auto sPath = aPaths.front( );
1094 auto sId = pDoc->getId( );
1100 OUString Content::checkOut(
const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1106 libcmis::DocumentPtr pDoc = boost::dynamic_pointer_cast< libcmis::Document >( getObject( xEnv ) );
1107 if ( pDoc.get( ) ==
nullptr )
1110 ucb::IOErrorCode_GENERAL,
1111 uno::Sequence< uno::Any >( 0 ),
1113 "Checkout only supported by documents" );
1115 libcmis::DocumentPtr pPwc = pDoc->checkOut( );
1119 std::vector< std::string > aPaths = pPwc->getPaths( );
1120 if ( !aPaths.empty() )
1122 auto sPath = aPaths.front( );
1129 auto sId = pPwc->getId( );
1134 catch (
const libcmis::Exception& e )
1136 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
1138 ucb::IOErrorCode_GENERAL,
1139 uno::Sequence< uno::Any >( 0 ),
1146 OUString Content::cancelCheckOut(
const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1151 libcmis::DocumentPtr pPwc = boost::dynamic_pointer_cast< libcmis::Document >( getObject( xEnv ) );
1152 if ( pPwc.get( ) ==
nullptr )
1155 ucb::IOErrorCode_GENERAL,
1156 uno::Sequence< uno::Any >( 0 ),
1158 "CancelCheckout only supported by documents" );
1160 pPwc->cancelCheckout( );
1163 std::vector< libcmis::DocumentPtr > aVersions = pPwc->getAllVersions( );
1164 for (
const auto& rVersion : aVersions )
1166 libcmis::DocumentPtr pVersion = rVersion;
1167 std::map< std::string, libcmis::PropertyPtr > aProps = pVersion->getProperties( );
1168 bool bIsLatestVersion =
false;
1169 std::map< std::string, libcmis::PropertyPtr >::iterator propIt = aProps.find( std::string(
"cmis:isLatestVersion" ) );
1170 if ( propIt != aProps.end( ) && !propIt->second->getBools( ).empty( ) )
1172 bIsLatestVersion = propIt->second->getBools( ).front( );
1175 if ( bIsLatestVersion )
1179 std::vector< std::string > aPaths = pVersion->getPaths( );
1180 if ( !aPaths.empty() )
1182 auto sPath = aPaths.front( );
1189 auto sId = pVersion->getId( );
1197 catch (
const libcmis::Exception& e )
1199 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
1201 ucb::IOErrorCode_GENERAL,
1202 uno::Sequence< uno::Any >( 0 ),
1209 uno::Sequence< document::CmisVersion> Content::getAllVersions(
const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1214 libcmis::DocumentPtr pDoc = boost::dynamic_pointer_cast< libcmis::Document >( getObject( xEnv ) );
1215 if ( pDoc.get( ) ==
nullptr )
1218 ucb::IOErrorCode_GENERAL,
1219 uno::Sequence< uno::Any >( 0 ),
1221 "Can not get the document" );
1223 std::vector< libcmis::DocumentPtr > aCmisVersions = pDoc->getAllVersions( );
1224 uno::Sequence< document::CmisVersion > aVersions( aCmisVersions.size( ) );
1225 auto aVersionsRange = asNonConstRange(aVersions);
1227 for (
const auto& rVersion : aCmisVersions )
1229 libcmis::DocumentPtr pVersion = rVersion;
1231 aVersionsRange[
i].Author =
STD_TO_OUSTR( pVersion->getCreatedBy( ) );
1232 aVersionsRange[
i].TimeStamp = lcl_boostToUnoTime( pVersion->getLastModificationDate( ) );
1233 aVersionsRange[
i].Comment =
STD_TO_OUSTR( pVersion->getStringProperty(
"cmis:checkinComment") );
1238 catch (
const libcmis::Exception& e )
1240 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
1242 ucb::IOErrorCode_GENERAL,
1243 uno::Sequence< uno::Any >( 0 ),
1247 return uno::Sequence< document::CmisVersion > ( );
1250 void Content::transfer(
const ucb::TransferInfo& rTransferInfo,
1251 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1255 if ( aSourceUrl.GetProtocol() != INetProtocol::Cmis )
1258 if ( sSrcBindingUrl !=
m_aURL.getBindingUrl( ) )
1262 ucb::InteractiveBadTransferURLException(
1263 "Unsupported URL scheme!",
1269 SAL_INFO(
"ucb.ucp.cmis",
"TODO - Content::transfer()" );
1272 void Content::insert(
const uno::Reference< io::XInputStream > & xInputStream,
1273 bool bReplaceExisting, std::u16string_view rMimeType,
1274 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1276 if ( !xInputStream.is() )
1279 ( ucb::MissingInputStreamException
1285 if ( !m_bTransient )
1291 libcmis::FolderPtr pFolder;
1294 pFolder = boost::dynamic_pointer_cast< libcmis::Folder >( getObject( xEnv ) );
1296 catch (
const libcmis::Exception& )
1300 if ( pFolder ==
nullptr )
1303 libcmis::ObjectPtr object;
1304 std::map< std::string, libcmis::PropertyPtr >::iterator it = m_pObjectProps.find(
"cmis:name" );
1305 if ( it == m_pObjectProps.end( ) )
1308 ( uno::RuntimeException(
"Missing name property",
1312 auto newName = it->second->getStrings( ).front( );
1314 if ( !newPath.empty( ) && newPath[ newPath.size( ) - 1 ] !=
'/' )
1319 if ( !m_sObjectId.isEmpty( ) )
1320 object = getSession( xEnv )->getObject(
OUSTR_TO_STDSTR( m_sObjectId) );
1322 object = getSession( xEnv )->getObjectByPath( newPath );
1325 catch (
const libcmis::Exception& )
1330 if (
nullptr !=
object.
get( ) )
1333 if ( object->getBaseType( ) != m_pObjectType->getBaseType( )->getId() )
1336 ( uno::RuntimeException(
"Can't change a folder into a document and vice-versa.",
1342 libcmis::Document* document =
dynamic_cast< libcmis::Document*
>(
object.get( ) );
1343 if (
nullptr != document )
1345 boost::shared_ptr< std::ostream >
pOut(
new std::ostringstream ( std::ios_base::binary | std::ios_base::in | std::ios_base::out ) );
1346 uno::Reference < io::XOutputStream > xOutput =
new StdOutputStream( pOut );
1347 copyData( xInputStream, xOutput );
1350 document->setContentStream( pOut,
OUSTR_TO_STDSTR( rMimeType ), std::string( ), bReplaceExisting );
1352 catch (
const libcmis::Exception& )
1355 ( uno::RuntimeException(
"Error when setting document content",
1364 bool bIsFolder = getObjectType( xEnv )->getBaseType( )->getId( ) ==
"cmis:folder";
1365 setCmisProperty(
"cmis:objectTypeId", getObjectType( xEnv )->getId( ), xEnv );
1371 pFolder->createFolder( m_pObjectProps );
1374 catch (
const libcmis::Exception& )
1377 ( uno::RuntimeException(
"Error when creating folder",
1384 boost::shared_ptr< std::ostream >
pOut(
new std::ostringstream ( std::ios_base::binary | std::ios_base::in | std::ios_base::out ) );
1385 uno::Reference < io::XOutputStream > xOutput =
new StdOutputStream( pOut );
1386 copyData( xInputStream, xOutput );
1389 pFolder->createDocument( m_pObjectProps, pOut,
OUSTR_TO_STDSTR( rMimeType ), std::string() );
1392 catch (
const libcmis::Exception& )
1395 ( uno::RuntimeException(
"Error when creating document",
1402 if ( sNewPath.isEmpty( ) && m_sObjectId.isEmpty( ) )
1406 m_sObjectPath = sNewPath;
1408 aUrl.setObjectPath( m_sObjectPath );
1409 aUrl.setObjectId( m_sObjectId );
1410 m_sURL = aUrl.asString( );
1412 m_pObjectType.reset( );
1413 m_pObjectProps.clear( );
1414 m_bTransient =
false;
1420 void Content::copyData(
1421 const uno::Reference< io::XInputStream >& xIn,
1422 const uno::Reference< io::XOutputStream >& xOut )
1427 xOut->writeBytes( theData );
1429 xOut->closeOutput();
1432 uno::Sequence< uno::Any > Content::setPropertyValues(
1433 const uno::Sequence< beans::PropertyValue >& rValues,
1434 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1439 if ( !m_bTransient && getObject( xEnv ).
get( ) )
1441 m_pObjectProps.clear( );
1442 m_pObjectType = getObject( xEnv )->getTypeDescription();
1445 catch (
const libcmis::Exception& e )
1447 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
1449 ucb::IOErrorCode_GENERAL,
1450 uno::Sequence< uno::Any >( 0 ),
1455 sal_Int32
nCount = rValues.getLength();
1456 uno::Sequence< uno::Any > aRet( nCount );
1457 auto aRetRange = asNonConstRange(aRet);
1458 bool bChanged =
false;
1459 const beans::PropertyValue*
pValues = rValues.getConstArray();
1460 for ( sal_Int32 n = 0;
n <
nCount; ++
n )
1462 const beans::PropertyValue& rValue =
pValues[
n ];
1463 if ( rValue.Name ==
"ContentType" ||
1464 rValue.Name ==
"MediaType" ||
1465 rValue.Name ==
"IsDocument" ||
1466 rValue.Name ==
"IsFolder" ||
1467 rValue.Name ==
"Size" ||
1468 rValue.Name ==
"CreatableContentsInfo" )
1470 lang::IllegalAccessException e (
"Property is read-only!",
1472 aRetRange[
n ] <<= e;
1474 else if ( rValue.Name ==
"Title" )
1477 if (!( rValue.Value >>= aNewTitle ))
1479 aRetRange[
n ] <<= beans::IllegalTypeException
1480 (
"Property value has wrong type!",
1485 if ( aNewTitle.isEmpty() )
1487 aRetRange[
n ] <<= lang::IllegalArgumentException
1488 (
"Empty title not allowed!",
1499 SAL_INFO(
"ucb.ucp.cmis",
"Couldn't set property: " << rValue.Name );
1500 lang::IllegalAccessException e (
"Property is read-only!",
1502 aRetRange[
n ] <<= e;
1508 if ( !m_bTransient && bChanged )
1510 getObject( xEnv )->updateProperties( m_pObjectProps );
1513 catch (
const libcmis::Exception& e )
1515 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
1517 ucb::IOErrorCode_GENERAL,
1518 uno::Sequence< uno::Any >( 0 ),
1526 bool Content::feedSink(
const uno::Reference< uno::XInterface>& xSink,
1527 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1532 uno::Reference< io::XOutputStream > xOut(xSink, uno::UNO_QUERY );
1533 uno::Reference< io::XActiveDataSink > xDataSink(xSink, uno::UNO_QUERY );
1534 uno::Reference< io::XActiveDataStreamer > xDataStreamer( xSink, uno::UNO_QUERY );
1536 if ( !xOut.is() && !xDataSink.is() && ( !xDataStreamer.is() || !xDataStreamer->getStream().is() ) )
1539 if ( xDataStreamer.is() && !xOut.is() )
1540 xOut = xDataStreamer->getStream()->getOutputStream();
1544 libcmis::Document* document =
dynamic_cast< libcmis::Document*
>( getObject( xEnv ).get() );
1549 boost::shared_ptr< std::istream > aIn = document->getContentStream( );
1551 uno::Reference< io::XInputStream > xIn =
new StdInputStream( aIn );
1555 if ( xDataSink.is() )
1556 xDataSink->setInputStream( xIn );
1557 else if ( xOut.is() )
1558 copyData( xIn, xOut );
1560 catch (
const libcmis::Exception& e )
1562 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
1564 ucb::IOErrorCode_GENERAL,
1565 uno::Sequence< uno::Any >( 0 ),
1573 uno::Sequence< beans::Property > Content::getProperties(
1574 const uno::Reference< ucb::XCommandEnvironment > & )
1576 static const beans::Property aGenericProperties[] =
1578 beans::Property(
"IsDocument",
1580 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1581 beans::Property(
"IsFolder",
1583 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1584 beans::Property(
"Title",
1586 beans::PropertyAttribute::BOUND ),
1587 beans::Property(
"ObjectId",
1589 beans::PropertyAttribute::BOUND ),
1590 beans::Property(
"TitleOnServer",
1592 beans::PropertyAttribute::BOUND ),
1593 beans::Property(
"IsReadOnly",
1595 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1596 beans::Property(
"DateCreated",
1598 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1599 beans::Property(
"DateModified",
1601 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1602 beans::Property(
"Size",
1604 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1605 beans::Property(
"CreatableContentsInfo",
1606 -1,
cppu::UnoType<uno::Sequence< ucb::ContentInfo >>::get(),
1607 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1608 beans::Property(
"MediaType",
1610 beans::PropertyAttribute::BOUND ),
1611 beans::Property(
"CmisProperties",
1612 -1,
cppu::UnoType<uno::Sequence< document::CmisProperty>>::get(),
1613 beans::PropertyAttribute::BOUND ),
1614 beans::Property(
"IsVersionable",
1616 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1617 beans::Property(
"CanCheckOut",
1619 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1620 beans::Property(
"CanCancelCheckOut",
1622 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1623 beans::Property(
"CanCheckIn",
1625 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
1629 return uno::Sequence< beans::Property > ( aGenericProperties, nProps );
1632 uno::Sequence< ucb::CommandInfo > Content::getCommands(
1633 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1635 static const ucb::CommandInfo aCommandInfoTable[] =
1642 (
"getPropertySetInfo",
1645 (
"getPropertyValues",
1646 -1,
cppu::UnoType<uno::Sequence< beans::Property >>::get() ),
1648 (
"setPropertyValues",
1649 -1,
cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get() ),
1665 ucb::CommandInfo (
"checkIn", -1,
1670 -1,
cppu::UnoType<uno::Sequence< document::CmisVersion >>::get() ),
1678 (
"createNewContent",
1683 return uno::Sequence< ucb::CommandInfo >(aCommandInfoTable, isFolder( xEnv ) ? nProps : nProps - 2);
1686 OUString Content::getParentURL( )
1688 SAL_INFO(
"ucb.ucp.cmis",
"Content::getParentURL()" );
1689 OUString parentUrl =
"/";
1690 if ( m_sObjectPath ==
"/" )
1708 void SAL_CALL Content::acquire() noexcept
1710 ContentImplHelper::acquire();
1713 void SAL_CALL Content::release() noexcept
1715 ContentImplHelper::release();
1721 return aRet.
hasValue() ? aRet : ContentImplHelper::queryInterface(rType);
1724 OUString SAL_CALL Content::getImplementationName()
1726 return "com.sun.star.comp.CmisContent";
1729 uno::Sequence< OUString > SAL_CALL Content::getSupportedServiceNames()
1731 uno::Sequence<OUString> aSNS {
"com.sun.star.ucb.CmisContent" };
1735 OUString SAL_CALL Content::getContentType()
1740 if (isFolder( uno::Reference< ucb::XCommandEnvironment >() ))
1745 catch (
const uno::RuntimeException&)
1749 catch (
const uno::Exception& e)
1752 throw lang::WrappedTargetRuntimeException(
1753 "wrapped Exception " + e.Message,
1754 uno::Reference<uno::XInterface>(),
a);
1759 uno::Any SAL_CALL Content::execute(
1760 const ucb::Command& aCommand,
1762 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1767 if (
aCommand.Name ==
"getPropertyValues" )
1770 if ( !(
aCommand.Argument >>= Properties ) )
1772 aRet <<= getPropertyValues( Properties, xEnv );
1774 else if (
aCommand.Name ==
"getPropertySetInfo" )
1775 aRet <<= getPropertySetInfo( xEnv,
false );
1776 else if (
aCommand.Name ==
"getCommandInfo" )
1777 aRet <<= getCommandInfo( xEnv,
false );
1778 else if (
aCommand.Name ==
"open" )
1780 ucb::OpenCommandArgument2 aOpenCommand;
1781 if ( !(
aCommand.Argument >>= aOpenCommand ) )
1783 aRet = open( aOpenCommand, xEnv );
1785 else if (
aCommand.Name ==
"transfer" )
1787 ucb::TransferInfo transferArgs;
1788 if ( !(
aCommand.Argument >>= transferArgs ) )
1790 transfer( transferArgs, xEnv );
1792 else if (
aCommand.Name ==
"setPropertyValues" )
1794 uno::Sequence< beans::PropertyValue >
aProperties;
1797 aRet <<= setPropertyValues( aProperties, xEnv );
1799 else if (
aCommand.Name ==
"createNewContent"
1800 && isFolder( xEnv ) )
1802 ucb::ContentInfo arg;
1803 if ( !(
aCommand.Argument >>= arg ) )
1805 aRet <<= createNewContent( arg );
1807 else if (
aCommand.Name ==
"insert" )
1809 ucb::InsertCommandArgument2 arg;
1810 if ( !(
aCommand.Argument >>= arg ) )
1812 ucb::InsertCommandArgument insertArg;
1813 if ( !(
aCommand.Argument >>= insertArg ) )
1816 arg.Data = insertArg.Data;
1817 arg.ReplaceExisting = insertArg.ReplaceExisting;
1820 m_sObjectId = arg.DocumentId;
1821 insert( arg.Data, arg.ReplaceExisting, arg.MimeType, xEnv );
1823 else if (
aCommand.Name ==
"delete" )
1827 if ( !isFolder( xEnv ) )
1829 getObject( xEnv )->remove( );
1833 libcmis::Folder* folder =
dynamic_cast< libcmis::Folder*
>( getObject( xEnv ).get() );
1835 folder->removeTree( );
1838 catch (
const libcmis::Exception& e )
1840 SAL_INFO(
"ucb.ucp.cmis",
"Unexpected libcmis exception: " << e.what( ) );
1842 ucb::IOErrorCode_GENERAL,
1843 uno::Sequence< uno::Any >( 0 ),
1848 else if (
aCommand.Name ==
"checkout" )
1850 aRet <<= checkOut( xEnv );
1852 else if (
aCommand.Name ==
"cancelCheckout" )
1854 aRet <<= cancelCheckOut( xEnv );
1856 else if (
aCommand.Name ==
"checkin" )
1858 ucb::CheckinArgument aArg;
1859 if ( !(
aCommand.Argument >>= aArg ) )
1863 aRet <<= checkIn( aArg, xEnv );
1865 else if (
aCommand.Name ==
"getAllVersions" )
1867 aRet <<= getAllVersions( xEnv );
1869 else if (
aCommand.Name ==
"updateProperties" )
1871 updateProperties(
aCommand.Argument, xEnv );
1875 SAL_INFO(
"ucb.ucp.cmis",
"Unknown command to execute" );
1878 (
uno::Any( ucb::UnsupportedCommandException
1887 void SAL_CALL Content::abort( sal_Int32 )
1889 SAL_INFO(
"ucb.ucp.cmis",
"TODO - Content::abort()" );
1893 uno::Sequence< ucb::ContentInfo > SAL_CALL Content::queryCreatableContentsInfo()
1895 return queryCreatableContentsInfo( uno::Reference< ucb::XCommandEnvironment >() );
1898 uno::Reference< ucb::XContent > SAL_CALL Content::createNewContent(
1899 const ucb::ContentInfo& Info )
1901 bool create_document;
1904 create_document =
true;
1906 create_document =
false;
1909 SAL_INFO(
"ucb.ucp.cmis",
"Unknown type of content to create" );
1910 return uno::Reference< ucb::XContent >();
1913 OUString sParentURL = m_xIdentifier->getContentIdentifier();
1916 uno::Reference< ucb::XContentIdentifier >
xId(new ::ucbhelper::ContentIdentifier(sParentURL));
1920 return new ::cmis::Content( m_xContext, m_pProvider, xId, !create_document );
1922 catch ( ucb::ContentCreationException & )
1924 return uno::Reference< ucb::XContent >();
1928 uno::Sequence< uno::Type > SAL_CALL Content::getTypes()
1932 if ( isFolder( uno::Reference< ucb::XCommandEnvironment >() ) )
1946 return s_aFolderCollection.
getTypes();
1949 catch (
const uno::RuntimeException&)
1953 catch (
const uno::Exception& e)
1956 throw lang::WrappedTargetRuntimeException(
1957 "wrapped Exception " + e.Message,
1958 uno::Reference<uno::XInterface>(),
a);
1973 return s_aFileCollection.
getTypes();
1976 uno::Sequence< ucb::ContentInfo > Content::queryCreatableContentsInfo(
1977 const uno::Reference< ucb::XCommandEnvironment >& xEnv)
1981 if ( isFolder( xEnv ) )
1985 uno::Sequence< beans::Property >
props
1991 beans::PropertyAttribute::MAYBEVOID | beans::PropertyAttribute::BOUND
1999 ( ucb::ContentInfoAttribute::INSERT_WITH_INPUTSTREAM |
2000 ucb::ContentInfoAttribute::KIND_DOCUMENT ),
2005 ucb::ContentInfoAttribute::KIND_FOLDER,
2011 catch (
const uno::RuntimeException&)
2015 catch (
const uno::Exception& e)
2018 throw lang::WrappedTargetRuntimeException(
2019 "wrapped Exception " + e.Message,
2020 uno::Reference<uno::XInterface>(), a);
2025 std::vector< uno::Reference< ucb::XContent > > Content::getChildren( )
2027 std::vector< uno::Reference< ucb::XContent > > results;
2030 libcmis::FolderPtr pFolder = boost::dynamic_pointer_cast< libcmis::Folder >( getObject( uno::Reference< ucb::XCommandEnvironment >() ) );
2031 if (
nullptr != pFolder )
2036 std::vector< libcmis::ObjectPtr > children = pFolder->getChildren( );
2039 for (
const auto& rChild : children )
2047 OUString sPath( m_sObjectPath );
2048 if ( !sPath.endsWith(
"/") )
2063 catch (
const libcmis::Exception& e )
2065 SAL_INFO(
"ucb.ucp.cmis",
"Exception thrown: " << e.what() );
2072 void Content::setCmisProperty(
const std::string& rName,
const std::string& rValue,
const uno::Reference< ucb::XCommandEnvironment >& xEnv )
2074 if ( !getObjectType( xEnv ).
get( ) )
2077 std::map< std::string, libcmis::PropertyPtr >::iterator propIt = m_pObjectProps.find(rName);
2079 if ( propIt == m_pObjectProps.end( ) && getObjectType( xEnv ).
get( ) )
2081 std::map< std::string, libcmis::PropertyTypePtr > propsTypes = getObjectType( xEnv )->getPropertiesTypes( );
2082 std::map< std::string, libcmis::PropertyTypePtr >::iterator typeIt = propsTypes.find(rName);
2084 if ( typeIt != propsTypes.end( ) )
2086 libcmis::PropertyTypePtr propType = typeIt->second;
2087 libcmis::PropertyPtr
property(
new libcmis::Property( propType, { rValue }) );
2088 m_pObjectProps.insert(std::pair< std::string, libcmis::PropertyPtr >(rName,
property));
2091 else if ( propIt != m_pObjectProps.end( ) )
2093 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 const &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)
::rtl::Reference< OContentHelper > xContent
Reference< XContentIdentifier > xId
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, const OUString &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