33#include <rtl/ustrbuf.hxx>
34#include <com/sun/star/beans/IllegalTypeException.hpp>
35#include <com/sun/star/beans/PropertyAttribute.hpp>
36#include <com/sun/star/beans/XPropertySet.hpp>
37#include <com/sun/star/embed/InvalidStorageException.hpp>
38#include <com/sun/star/embed/StorageWrappedTargetException.hpp>
39#include <com/sun/star/embed/XTransactedObject.hpp>
40#include <com/sun/star/io/BufferSizeExceededException.hpp>
41#include <com/sun/star/io/IOException.hpp>
42#include <com/sun/star/io/NotConnectedException.hpp>
43#include <com/sun/star/io/XActiveDataSink.hpp>
44#include <com/sun/star/io/XActiveDataStreamer.hpp>
45#include <com/sun/star/lang/IllegalAccessException.hpp>
46#include <com/sun/star/packages/WrongPasswordException.hpp>
47#include <com/sun/star/task/DocumentPasswordRequest.hpp>
48#include <com/sun/star/task/XInteractionPassword.hpp>
49#include <com/sun/star/ucb/CommandFailedException.hpp>
50#include <com/sun/star/ucb/ContentAction.hpp>
51#include <com/sun/star/ucb/ContentInfoAttribute.hpp>
52#include <com/sun/star/ucb/IllegalIdentifierException.hpp>
53#include <com/sun/star/ucb/InsertCommandArgument.hpp>
54#include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp>
55#include <com/sun/star/ucb/MissingInputStreamException.hpp>
56#include <com/sun/star/ucb/NameClash.hpp>
57#include <com/sun/star/ucb/NameClashException.hpp>
58#include <com/sun/star/ucb/OpenCommandArgument2.hpp>
59#include <com/sun/star/ucb/OpenMode.hpp>
60#include <com/sun/star/ucb/TransferInfo.hpp>
61#include <com/sun/star/ucb/UnsupportedCommandException.hpp>
62#include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
63#include <com/sun/star/ucb/UnsupportedNameClashException.hpp>
64#include <com/sun/star/ucb/UnsupportedOpenModeException.hpp>
65#include <com/sun/star/ucb/XCommandInfo.hpp>
66#include <com/sun/star/ucb/XPersistentPropertySet.hpp>
80#include "../inc/urihelper.hxx"
98 OSL_FAIL(
"Content::Content - unsupported content type string" );
109 const uno::Reference< uno::XComponentContext >& rxContext,
111 const uno::Reference< ucb::XContentIdentifier >& Identifier )
120 return new Content( rxContext, pProvider, Identifier, std::move(aProps) );
126 const uno::Reference< uno::XComponentContext >& rxContext,
128 const uno::Reference< ucb::XContentIdentifier >& Identifier,
129 const ucb::ContentInfo& Info )
131 if (
Info.Type.isEmpty() )
136 OSL_FAIL(
"Content::create - unsupported content type!" );
140 return new Content( rxContext, pProvider, Identifier, Info );
145 const uno::Reference< uno::XComponentContext > & rxContext,
147 const uno::Reference< ucb::XContentIdentifier > & Identifier,
149: ContentImplHelper( rxContext, pProvider,
Identifier ),
151 m_eState( PERSISTENT ),
152 m_pProvider( pProvider )
159 const uno::Reference< uno::XComponentContext >& rxContext,
161 const uno::Reference< ucb::XContentIdentifier >& Identifier,
162 const ucb::ContentInfo& Info )
163 : ContentImplHelper( rxContext, pProvider,
Identifier ),
166 m_pProvider( pProvider )
184 ContentImplHelper::acquire();
192 ContentImplHelper::release();
199 uno::Any aRet = ContentImplHelper::queryInterface( rType );
204 rType,
static_cast< ucb::XContentCreator *
>(
this ) );
267 return "com.sun.star.comp.ucb.TransientDocumentsContent";
274 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
276 uno::Sequence< OUString > aSNS( 1 );
279 aSNS.getArray()[ 0 ] =
"com.sun.star.ucb.TransientDocumentsStreamContent";
281 aSNS.getArray()[ 0 ] =
"com.sun.star.ucb.TransientDocumentsFolderContent";
283 aSNS.getArray()[ 0 ] =
"com.sun.star.ucb.TransientDocumentsDocumentContent";
285 aSNS.getArray()[ 0 ] =
"com.sun.star.ucb.TransientDocumentsRootContent";
297 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
303uno::Reference< ucb::XContentIdentifier > SAL_CALL
307 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
313 return uno::Reference< ucb::XContentIdentifier >();
316 return ContentImplHelper::getIdentifier();
325 const ucb::Command& aCommand,
327 const uno::Reference< ucb::XCommandEnvironment >& Environment )
331 if (
aCommand.Name ==
"getPropertyValues" )
338 if ( !(
aCommand.Argument >>= Properties ) )
341 uno::Any( lang::IllegalArgumentException(
342 "Wrong argument type!",
351 else if (
aCommand.Name ==
"setPropertyValues" )
358 if ( !(
aCommand.Argument >>= aProperties ) )
361 uno::Any( lang::IllegalArgumentException(
362 "Wrong argument type!",
372 uno::Any( lang::IllegalArgumentException(
382 else if (
aCommand.Name ==
"getPropertySetInfo" )
390 else if (
aCommand.Name ==
"getCommandInfo" )
404 ucb::OpenCommandArgument2 aOpenCommand;
405 if ( !(
aCommand.Argument >>= aOpenCommand ) )
408 uno::Any( lang::IllegalArgumentException(
409 "Wrong argument type!",
416 aRet =
open( aOpenCommand, Environment );
418 else if (
aCommand.Name ==
"insert" )
428 uno::Any( ucb::UnsupportedCommandException(
429 "insert command only supported by "
430 "folders and streams!",
439 Uri aParentUri( aUri.getParentUri() );
440 if ( aParentUri.isDocument() )
443 uno::Any( ucb::UnsupportedCommandException(
444 "insert command not supported by "
445 "streams that are direct children "
453 ucb::InsertCommandArgument aArg;
454 if ( !(
aCommand.Argument >>= aArg ) )
457 uno::Any( lang::IllegalArgumentException(
458 "Wrong argument type!",
465 sal_Int32 nNameClash = aArg.ReplaceExisting
466 ? ucb::NameClash::OVERWRITE
467 : ucb::NameClash::ERROR;
468 insert( aArg.Data, nNameClash, Environment );
470 else if (
aCommand.Name ==
"delete" )
483 uno::Any( ucb::UnsupportedCommandException(
484 "delete command only supported by "
485 "folders and streams!",
492 bool bDeletePhysical =
false;
493 aCommand.Argument >>= bDeletePhysical;
494 destroy( bDeletePhysical, Environment );
504 ucb::IOErrorCode_CANT_WRITE,
507 "Cannot remove persistent data!",
515 else if (
aCommand.Name ==
"transfer" )
528 uno::Any( ucb::UnsupportedCommandException(
529 "transfer command only supported "
530 "by folders and documents!",
537 ucb::TransferInfo aInfo;
538 if ( !(
aCommand.Argument >>= aInfo ) )
540 OSL_FAIL(
"Wrong argument type!" );
542 uno::Any( lang::IllegalArgumentException(
543 "Wrong argument type!",
552 else if (
aCommand.Name ==
"createNewContent" )
565 uno::Any( ucb::UnsupportedCommandException(
566 "createNewContent command only "
567 "supported by folders and "
575 ucb::ContentInfo aInfo;
576 if ( !(
aCommand.Argument >>= aInfo ) )
578 OSL_FAIL(
"Wrong argument type!" );
580 uno::Any( lang::IllegalArgumentException(
581 "Wrong argument type!",
597 uno::Any( ucb::UnsupportedCommandException(
618uno::Sequence< ucb::ContentInfo > SAL_CALL
626uno::Reference< ucb::XContent > SAL_CALL
631 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
633 if (
Info.Type.isEmpty() )
634 return uno::Reference< ucb::XContent >();
641 OSL_FAIL(
"Content::createNewContent - streams cannot be "
642 "created as direct children of document root!" );
643 return uno::Reference< ucb::XContent >();
647 OSL_FAIL(
"Content::createNewContent - unsupported type!" );
648 return uno::Reference< ucb::XContent >();
653 OSL_ENSURE( !
aURL.isEmpty(),
654 "Content::createNewContent - empty identifier!" );
656 if ( (
aURL.lastIndexOf(
'/' ) + 1 ) !=
aURL.getLength() )
660 aURL +=
"New_Folder";
662 aURL +=
"New_Stream";
664 uno::Reference< ucb::XContentIdentifier > xId
665 = new ::ucbhelper::ContentIdentifier( aURL );
671 OSL_FAIL(
"createNewContent called on non-contentcreator object!" );
672 return uno::Reference< ucb::XContent >();
680 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
686uno::Reference< ucb::XContentIdentifier >
689 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
696 uno::Reference< ucb::XContentIdentifier >(
697 new ::ucbhelper::ContentIdentifier( aNewURL ) );
703 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
714 m_xProvider->queryExistingContents( aAllContents );
717 sal_Int32 nURLPos =
aURL.lastIndexOf(
'/' );
719 if ( nURLPos != (
aURL.getLength() - 1 ) )
725 sal_Int32 nLen =
aURL.getLength();
727 for (
const auto& rContent : aAllContents )
731 = xChild->getIdentifier()->getContentIdentifier();
734 if ( ( aChildURL.getLength() > nLen ) &&
735 ( aChildURL.startsWith(
aURL ) ) )
737 sal_Int32
nPos = aChildURL.indexOf(
'/', nLen );
739 if ( (
nPos == -1 ) ||
740 (
nPos == ( aChildURL.getLength() - 1 ) ) )
743 rChildren.emplace_back(
744 static_cast< Content *
>( xChild.get() ) );
752 const uno::Reference< ucb::XContentIdentifier >& xNewId )
757 osl::ClearableGuard< osl::Mutex > aGuard(
m_aMutex );
759 uno::Reference< ucb::XContent > xThis =
this;
764 OSL_FAIL(
"Content::exchangeIdentity - Not persistent!" );
772 OSL_FAIL(
"Content::exchangeIdentity - "
773 "Not supported by root or document!" );
780 if ( !
hasData(
Uri( xNewId->getContentIdentifier() ) ) )
794 for (
const auto& rChild : aChildren )
799 uno::Reference< ucb::XContentIdentifier > xOldChildId
800 = xChild->getIdentifier();
801 OUString aOldChildURL
802 = xOldChildId->getContentIdentifier();
803 OUString aNewChildURL
804 = aOldChildURL.replaceAt(
807 xNewId->getContentIdentifier() );
808 uno::Reference< ucb::XContentIdentifier > xNewChildId
809 = new ::ucbhelper::ContentIdentifier( aNewChildURL );
811 if ( !xChild->exchangeIdentity( xNewChildId ) )
819 OSL_FAIL(
"Content::exchangeIdentity - "
820 "Panic! Cannot exchange identity!" );
827 const uno::Reference< uno::XComponentContext >& rxContext,
828 const uno::Sequence< beans::Property >& rProperties,
830 const OUString& rContentId )
833 if (
loadData( pProvider,
Uri(rContentId), aData ) )
836 rxContext, rProperties, aData, pProvider, rContentId );
841 = new ::ucbhelper::PropertyValueSet( rxContext );
843 for (
const beans::Property& rProp : rProperties )
844 xRow->appendVoid( rProp );
853 const uno::Reference< uno::XComponentContext >& rxContext,
854 const uno::Sequence< beans::Property >& rProperties,
857 const OUString& rContentId )
862 = new ::ucbhelper::PropertyValueSet( rxContext );
864 if ( rProperties.hasElements() )
866 uno::Reference< beans::XPropertySet > xAdditionalPropSet;
867 bool bTriedToGetAdditionalPropSet =
false;
869 for (
const beans::Property& rProp : rProperties )
873 if ( rProp.Name ==
"ContentType" )
877 else if ( rProp.Name ==
"Title" )
879 xRow->appendString ( rProp, rData.
getTitle() );
881 else if ( rProp.Name ==
"IsDocument" )
885 else if ( rProp.Name ==
"IsFolder" )
889 else if ( rProp.Name ==
"CreatableContentsInfo" )
894 else if ( rProp.Name ==
"DateModified" )
906 xRow->appendVoid( rProp );
908 else if ( rProp.Name ==
"Storage" )
918 xRow->appendVoid( rProp );
920 else if ( rProp.Name ==
"DocumentModel" )
930 xRow->appendVoid( rProp );
936 if ( !bTriedToGetAdditionalPropSet && !xAdditionalPropSet.is() )
939 pProvider->getAdditionalPropertySet( rContentId,
941 bTriedToGetAdditionalPropSet =
true;
944 if ( xAdditionalPropSet.is() )
946 if ( !xRow->appendPropertySetValue(
951 xRow->appendVoid( rProp );
957 xRow->appendVoid( rProp );
966 beans::Property(
"ContentType",
969 beans::PropertyAttribute::BOUND
970 | beans::PropertyAttribute::READONLY ),
976 beans::Property(
"Title",
980 beans::PropertyAttribute::BOUND |
982 ? beans::PropertyAttribute::READONLY
986 beans::Property(
"IsDocument",
989 beans::PropertyAttribute::BOUND
990 | beans::PropertyAttribute::READONLY ),
993 beans::Property(
"IsFolder",
996 beans::PropertyAttribute::BOUND
997 | beans::PropertyAttribute::READONLY ),
1001 "CreatableContentsInfo",
1004 beans::PropertyAttribute::BOUND
1005 | beans::PropertyAttribute::READONLY ),
1012 beans::Property(
"DateModified",
1015 beans::PropertyAttribute::BOUND
1016 | beans::PropertyAttribute::READONLY ),
1023 beans::Property(
"Storage",
1026 beans::PropertyAttribute::BOUND
1027 | beans::PropertyAttribute::READONLY ),
1033 beans::Property(
"DocumentModel",
1036 beans::PropertyAttribute::BOUND
1037 | beans::PropertyAttribute::READONLY ),
1043 uno::Reference< beans::XPropertySet > xSet =
1044 pProvider->getAdditionalPropertySet( rContentId,
false );
1045 xRow->appendPropertySet( xSet );
1053 const uno::Sequence< beans::Property >& rProperties )
1055 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
1065 const uno::Sequence< beans::PropertyValue >& rValues,
1066 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1068 osl::ClearableGuard< osl::Mutex > aGuard(
m_aMutex );
1070 uno::Sequence< uno::Any > aRet( rValues.getLength() );
1071 auto aRetRange = asNonConstRange(aRet);
1072 uno::Sequence< beans::PropertyChangeEvent > aChanges( rValues.getLength() );
1073 sal_Int32 nChanged = 0;
1075 beans::PropertyChangeEvent
aEvent;
1076 aEvent.Source = getXWeak();
1079 aEvent.PropertyHandle = -1;
1083 const beans::PropertyValue*
pValues = rValues.getConstArray();
1084 sal_Int32
nCount = rValues.getLength();
1086 uno::Reference< ucb::XPersistentPropertySet > xAdditionalPropSet;
1087 bool bTriedToGetAdditionalPropSet =
false;
1089 bool bExchange =
false;
1091 sal_Int32 nTitlePos = -1;
1093 for ( sal_Int32 n = 0;
n <
nCount; ++
n )
1095 const beans::PropertyValue& rValue =
pValues[
n ];
1097 if ( rValue.Name ==
"ContentType" )
1100 aRetRange[
n ] <<= lang::IllegalAccessException(
1101 "Property is read-only!",
1104 else if ( rValue.Name ==
"IsDocument" )
1107 aRetRange[
n ] <<= lang::IllegalAccessException(
1108 "Property is read-only!",
1111 else if ( rValue.Name ==
"IsFolder" )
1114 aRetRange[
n ] <<= lang::IllegalAccessException(
1115 "Property is read-only!",
1118 else if ( rValue.Name ==
"CreatableContentsInfo" )
1121 aRetRange[
n ] <<= lang::IllegalAccessException(
1122 "Property is read-only!",
1125 else if ( rValue.Name ==
"Title" )
1131 aRetRange[
n ] <<= lang::IllegalAccessException(
1132 "Property is read-only!",
1138 if ( rValue.Value >>= aNewValue )
1141 if ( !aNewValue.isEmpty() )
1161 aRetRange[
n ] <<= lang::IllegalArgumentException(
1162 "Empty Title not allowed!",
1169 aRetRange[
n ] <<= beans::IllegalTypeException(
1170 "Title Property value has wrong type!",
1175 else if ( rValue.Name ==
"Storage" )
1180 aRetRange[
n ] <<= lang::IllegalAccessException(
1181 "Property is read-only!",
1187 aRetRange[
n ] <<= beans::UnknownPropertyException(
1188 "Storage property only supported by folders",
1192 else if ( rValue.Name ==
"DocumentModel" )
1197 aRetRange[
n ] <<= lang::IllegalAccessException(
1198 "Property is read-only!",
1204 aRetRange[
n ] <<= beans::UnknownPropertyException(
1205 "DocumentModel property only supported by documents",
1213 if ( !bTriedToGetAdditionalPropSet && !xAdditionalPropSet.is() )
1216 bTriedToGetAdditionalPropSet =
true;
1219 if ( xAdditionalPropSet.is() )
1223 uno::Any aOldValue = xAdditionalPropSet->getPropertyValue(
1225 if ( aOldValue != rValue.Value )
1227 xAdditionalPropSet->setPropertyValue(
1228 rValue.Name, rValue.Value );
1230 aEvent.PropertyName = rValue.Name;
1231 aEvent.OldValue = aOldValue;
1232 aEvent.NewValue = rValue.Value;
1234 aChanges.getArray()[ nChanged ] =
aEvent;
1238 catch ( beans::UnknownPropertyException
const & e )
1240 aRetRange[
n ] <<= e;
1242 catch ( lang::WrappedTargetException
const & e )
1244 aRetRange[
n ] <<= e;
1246 catch ( beans::PropertyVetoException
const & e )
1248 aRetRange[
n ] <<= e;
1250 catch ( lang::IllegalArgumentException
const & e )
1252 aRetRange[
n ] <<= e;
1257 aRetRange[
n ] <<= uno::Exception(
1258 "No property set for storing the value!",
1266 uno::Reference< ucb::XContentIdentifier > xOldId
1268 uno::Reference< ucb::XContentIdentifier > xNewId
1279 xNewId->getContentIdentifier() );
1288 aRetRange[ nTitlePos ] <<= uno::Exception(
1294 if ( !aOldTitle.isEmpty() )
1296 aEvent.PropertyName =
"Title";
1297 aEvent.OldValue <<= aOldTitle;
1300 aChanges.getArray()[ nChanged ] =
aEvent;
1309 if ( !
storeData( uno::Reference< io::XInputStream >(), xEnv ) )
1316 ucb::IOErrorCode_CANT_WRITE,
1319 "Cannot store persistent data!",
1325 aChanges.realloc( nChanged );
1336 const ucb::OpenCommandArgument2& rArg,
1337 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
1339 if ( rArg.Mode == ucb::OpenMode::ALL ||
1340 rArg.Mode == ucb::OpenMode::FOLDERS ||
1341 rArg.Mode == ucb::OpenMode::DOCUMENTS )
1347 uno::Reference< ucb::XDynamicResultSet > xSet
1357 if ( ( rArg.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_NONE ) ||
1358 ( rArg.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_WRITE ) )
1362 uno::Any( ucb::UnsupportedOpenModeException(
1365 sal_Int16( rArg.Mode ) ) ),
1370 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
1372 uno::Reference< io::XActiveDataStreamer > xDataStreamer(
1373 rArg.Sink, uno::UNO_QUERY );
1374 if ( xDataStreamer.is() )
1386 ucb::IOErrorCode_CANT_READ,
1390 : uno::Reference< ucb::XCommandEnvironment >(),
1391 "Got no data stream!",
1397 xDataStreamer->setStream( xStream );
1401 uno::Reference< io::XOutputStream > xOut( rArg.Sink, uno::UNO_QUERY );
1416 ucb::IOErrorCode_CANT_READ,
1420 : uno::Reference< ucb::XCommandEnvironment >(),
1421 "Got no data stream!",
1428 uno::Sequence< sal_Int8 >
aBuffer;
1432 sal_Int32 nRead = xIn->readSomeBytes( aBuffer, 65536 );
1436 xOut->writeBytes( aBuffer );
1439 xOut->closeOutput();
1441 catch ( io::NotConnectedException
const & )
1445 catch ( io::BufferSizeExceededException
const & )
1449 catch ( io::IOException
const & )
1456 uno::Reference< io::XActiveDataSink > xDataSink(
1457 rArg.Sink, uno::UNO_QUERY );
1458 if ( xDataSink.is() )
1472 ucb::IOErrorCode_CANT_READ,
1477 ucb::XCommandEnvironment >(),
1478 "Got no data stream!",
1484 xDataSink->setInputStream( xIn );
1490 ucb::UnsupportedDataSinkException(
1506 sal_Int32 nNameClashResolve,
1507 const uno::Reference<
1508 ucb::XCommandEnvironment > & xEnv )
1510 osl::ClearableGuard< osl::Mutex > aGuard(
m_aMutex );
1514 OSL_ENSURE( ( eType ==
FOLDER ) || ( eType ==
STREAM ),
1515 "insert command only supported by streams and folders!" );
1519#if OSL_DEBUG_LEVEL > 0
1522 Uri aParentUri( aUri.getParentUri() );
1523 OSL_ENSURE( !aParentUri.isDocument(),
1524 "insert command not supported by streams that are direct "
1525 "children of document root!" );
1544 uno::Any( ucb::MissingInputStreamException(
1560 switch ( nNameClashResolve )
1563 case ucb::NameClash::ERROR:
1570 task::InteractionClassification_ERROR,
1578 case ucb::NameClash::OVERWRITE:
1582 case ucb::NameClash::RENAME:
1589 aNewUri.setUri( aNewUri.getUri() +
"_" + OUString::number(++nTry) );
1591 while (
hasData( aNewUri ) && ( nTry < 1000 ) );
1597 ucb::UnsupportedNameClashException(
1598 "Unable to resolve name clash!",
1600 nNameClashResolve ) ),
1611 case ucb::NameClash::KEEP:
1612 case ucb::NameClash::ASK:
1618 ucb::UnsupportedNameClashException(
1621 nNameClashResolve ) ),
1629 bool bNewId = ( aUri != aNewUri );
1634 = new ::ucbhelper::ContentIdentifier( aNewUri.getUri() );
1644 ucb::IOErrorCode_CANT_WRITE,
1647 "Cannot store persistent data!",
1665 const uno::Reference<
1666 ucb::XCommandEnvironment > & xEnv )
1670 osl::ClearableGuard< osl::Mutex > aGuard(
m_aMutex );
1674 OSL_ENSURE( ( eType ==
FOLDER ) || ( eType ==
STREAM ),
1675 "delete command only supported by streams and folders!" );
1677 uno::Reference< ucb::XContent > xThis =
this;
1683 uno::Any( ucb::UnsupportedCommandException(
1702 for (
auto& rChild : aChildren )
1704 rChild->destroy( bDeletePhysical, xEnv );
1712 osl::ClearableGuard< osl::Mutex > aGuard(
m_aMutex );
1727uno::Reference< ucb::XContent >
1730 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
1732 const OUString aMyId =
getIdentifier()->getContentIdentifier();
1733 OUStringBuffer
aBuf( aMyId );
1734 if ( !aMyId.endsWith(
"/") )
1737 aBuf.append( rRelativeChildUri );
1739 aBuf.append( rRelativeChildUri.substr(1) );
1741 uno::Reference< ucb::XContentIdentifier > xChildId
1742 = new ::ucbhelper::ContentIdentifier(
aBuf.makeStringAndClear() );
1744 uno::Reference< ucb::XContent > xChild;
1749 catch ( ucb::IllegalIdentifierException
const & )
1754 OSL_ENSURE( xChild.is(),
1755 "Content::queryChildContent - unable to create child content!" );
1762 osl::ClearableGuard< osl::Mutex > aGuard(
m_aMutex );
1765 uno::Reference< ucb::XContent > xChild
1775 ucb::ContentEvent aEvt(
1777 ucb::ContentAction::REMOVED,
1786 osl::ClearableGuard< osl::Mutex > aGuard(
m_aMutex );
1789 uno::Reference< ucb::XContent > xChild
1799 ucb::ContentEvent aEvt(
1801 ucb::ContentAction::INSERTED,
1809 const ucb::TransferInfo& rInfo,
1810 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
1812 osl::ClearableGuard< osl::Mutex > aGuard(
m_aMutex );
1818 uno::Any( ucb::UnsupportedCommandException(
1831 uno::Any( ucb::InteractiveBadTransferURLException(
1840 .toAsciiLowerCase();
1845 uno::Any( ucb::InteractiveBadTransferURLException(
1853 Uri aSourceUri( rInfo.SourceURL );
1854 if ( !aSourceUri.isValid() )
1857 uno::Any( lang::IllegalArgumentException(
1858 "Invalid source URI! Syntax!",
1865 if ( aSourceUri.isRoot() || aSourceUri.isDocument() )
1868 uno::Any( lang::IllegalArgumentException(
1869 "Invalid source URI! Must describe a folder or stream!",
1878 sal_Int32
nPos = aId.lastIndexOf(
'/' );
1879 if ( nPos != ( aId.getLength() - 1 ) )
1885 if ( rInfo.SourceURL.getLength() <= aId.getLength() )
1887 if ( aId.startsWith( rInfo.SourceURL ) )
1894 ucb::IOErrorCode_RECURSIVE,
1897 "Target is equal to or is a child of source!",
1907 uno::Reference< embed::XStorage > xStorage
1910 if ( xStorage.is() )
1914 if ( xStorage->isStreamElement( aSourceUri.getDecodedName() ) )
1917 uno::Any( lang::IllegalArgumentException(
1918 "Invalid source URI! "
1919 "Streams cannot be created as "
1920 "children of document root!",
1928 catch ( container::NoSuchElementException
const & )
1932 catch ( lang::IllegalArgumentException
const & )
1936 catch ( embed::InvalidStorageException
const & )
1945 uno::Any( lang::IllegalArgumentException(
1946 "Invalid source URI! Unable to determine source type!",
1958 OUString aNewName( !rInfo.NewTitle.isEmpty()
1960 : aSourceUri.getDecodedName() );
1962 if ( !
copyData( aSourceUri, aNewName ) )
1969 ucb::IOErrorCode_CANT_WRITE,
1972 "Cannot copy data!",
1981 OUString aTargetUri =
m_xIdentifier->getContentIdentifier();
1982 if ( ( aTargetUri.lastIndexOf(
'/' ) + 1 ) != aTargetUri.getLength() )
1985 if ( !rInfo.NewTitle.isEmpty() )
1988 aTargetUri += aSourceUri.getName();
1997 ucb::IOErrorCode_CANT_WRITE,
2000 "Cannot copy additional properties!",
2012 uno::Reference< ucb::XContentIdentifier > xTargetId
2013 = new ::ucbhelper::ContentIdentifier( aTargetUri );
2021 catch ( ucb::IllegalIdentifierException
const & )
2033 ucb::IOErrorCode_CANT_READ,
2036 "Cannot instantiate target object!",
2048 if ( !rInfo.MoveData )
2054 uno::Reference< ucb::XContentIdentifier >
2055 xSourceId = new ::ucbhelper::ContentIdentifier( rInfo.SourceURL );
2059 xSource =
static_cast< Content *
>(
2062 catch ( ucb::IllegalIdentifierException
const & )
2067 if ( !xSource.is() )
2074 ucb::IOErrorCode_CANT_READ,
2077 "Cannot instantiate target object!",
2083 xSource->destroy(
true, xEnv );
2086 if ( !xSource->removeData() )
2093 ucb::IOErrorCode_CANT_WRITE,
2096 "Cannot remove persistent data of source object!",
2102 if ( xSource->removeAdditionalPropertySet() )
2110 ucb::IOErrorCode_CANT_WRITE,
2113 "Cannot remove additional properties of source object!",
2128 uno::Reference< embed::XStorage > xStorage
2130 return xStorage.is();
2139 uno::Reference< embed::XStorage > xStorage
2142 if ( !xStorage.is() )
2163 uno::Reference< embed::XStorage > xStorage
2166 if ( !xStorage.is() )
2175 uno::Reference< embed::XStorage > xStorage
2178 if ( !xStorage.is() )
2195 catch ( container::NoSuchElementException
const & )
2201 catch ( lang::IllegalArgumentException
const & )
2207 catch ( embed::InvalidStorageException
const & )
2219 const uno::Reference<
2220 ucb::XCommandEnvironment >& xEnv )
2222 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
2227 OSL_FAIL(
"storeData not supported by root and documents!" );
2235 uno::Reference< embed::XStorage > xStorage
2238 if ( !xStorage.is() )
2241 uno::Reference< beans::XPropertySet > xPropSet(
2242 xStorage, uno::UNO_QUERY );
2243 OSL_ENSURE( xPropSet.is(),
2244 "Content::storeData - Got no XPropertySet interface!" );
2245 if ( !xPropSet.is() )
2252 xPropSet->setPropertyValue(
2256 "application/binary" ) ) );
2258 catch ( beans::UnknownPropertyException
const & )
2260 OSL_FAIL(
"Property MediaType not supported!" );
2263 catch ( beans::PropertyVetoException
const & )
2268 catch ( lang::IllegalArgumentException
const & )
2273 catch ( lang::WrappedTargetException
const & )
2282 else if ( eType ==
STREAM )
2288 uno::Reference< embed::XStorage > xStorage
2291 uno::Reference< io::XOutputStream > xOut;
2293 if ( !xStorage.is() )
2301 OSL_ENSURE( xOut.is(),
"No target data stream!" );
2305 uno::Sequence< sal_Int8 >
aBuffer;
2308 sal_Int32 nRead = xData->readSomeBytes( aBuffer, 65536 );
2312 xOut->writeBytes( aBuffer );
2317 catch ( io::NotConnectedException
const & )
2324 catch ( io::BufferSizeExceededException
const & )
2331 catch ( io::IOException
const & )
2351 OSL_FAIL(
"Unknown content type!" );
2359 const uno::Reference< ucb::XContentIdentifier >& xOldId,
2360 const uno::Reference< ucb::XContentIdentifier >& xNewId )
2362 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
2367 OSL_FAIL(
"renameData not supported by root and documents!" );
2371 Uri aOldUri( xOldId->getContentIdentifier() );
2372 uno::Reference< embed::XStorage > xStorage
2376 if ( !xStorage.is() )
2381 Uri aNewUri( xNewId->getContentIdentifier() );
2382 xStorage->renameElement(
2383 aOldUri.getDecodedName(), aNewUri.getDecodedName() );
2385 catch ( embed::InvalidStorageException
const & )
2391 catch ( lang::IllegalArgumentException
const & )
2397 catch ( container::NoSuchElementException
const & )
2403 catch ( container::ElementExistException
const & )
2409 catch ( io::IOException
const & )
2415 catch ( embed::StorageWrappedTargetException
const & )
2428 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
2433 OSL_FAIL(
"removeData not supported by root and documents!" );
2438 uno::Reference< embed::XStorage > xStorage
2442 if ( !xStorage.is() )
2449 catch ( embed::InvalidStorageException
const & )
2455 catch ( lang::IllegalArgumentException
const & )
2461 catch ( container::NoSuchElementException
const & )
2467 catch ( io::IOException
const & )
2473 catch ( embed::StorageWrappedTargetException
const & )
2486 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
2491 OSL_FAIL(
"copyData not supported by root and streams!" );
2496 uno::Reference< embed::XStorage > xDestStorage
2499 if ( !xDestStorage.is() )
2502 uno::Reference< embed::XStorage > xSourceStorage
2505 if ( !xSourceStorage.is() )
2514 catch ( embed::InvalidStorageException
const & )
2520 catch ( lang::IllegalArgumentException
const & )
2526 catch ( container::NoSuchElementException
const & )
2532 catch ( container::ElementExistException
const & )
2538 catch ( io::IOException
const & )
2544 catch ( embed::StorageWrappedTargetException
const & )
2559 uno::Reference< embed::XTransactedObject > xTO( xStorage, uno::UNO_QUERY );
2561 OSL_ENSURE( xTO.is(),
2562 "Required interface css.embed.XTransactedObject missing!" );
2567 catch ( io::IOException
const & )
2572 catch ( lang::WrappedTargetException
const & )
2584 const uno::Reference< io::XOutputStream > & xOut )
2590 xOut->closeOutput();
2593 catch ( io::NotConnectedException
const & )
2597 catch ( io::BufferSizeExceededException
const & )
2601 catch ( io::IOException
const & )
2612 const OUString & rName,
2613 task::PasswordRequestMode eMode,
2614 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
2621 uno::Reference< task::XInteractionHandler > xIH
2622 = xEnv->getInteractionHandler();
2625 xIH->handle( xRequest );
2628 = xRequest->getSelection();
2630 if ( xSelection.is() )
2633 uno::Reference< task::XInteractionAbort > xAbort(
2634 xSelection.get(), uno::UNO_QUERY );
2637 throw ucb::CommandFailedException(
2638 "Abort requested by Interaction Handler.",
2639 uno::Reference< uno::XInterface >(),
2640 xRequest->getRequest() );
2643 uno::Reference< task::XInteractionPassword > xPassword(
2644 xSelection.get(), uno::UNO_QUERY );
2645 if ( xPassword.is() )
2647 return xPassword->getPassword();
2651 throw ucb::CommandFailedException(
2652 "Interaction Handler selected unknown continuation!",
2653 uno::Reference< uno::XInterface >(),
2654 xRequest->getRequest() );
2660 task::DocumentPasswordRequest aRequest;
2661 xRequest->getRequest() >>= aRequest;
2667 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
2671 bool bPasswordRequested =
false;
2674 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
2677 "Content::getInputStream - content is no stream!" );
2686 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
2689 catch ( packages::WrongPasswordException
const & )
2695 ? task::PasswordRequestMode_PASSWORD_REENTER
2696 : task::PasswordRequestMode_PASSWORD_ENTER,
2698 bPasswordRequested =
true;
2707 const OUString & rUri,
2709 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
2712 bool bPasswordRequested =
false;
2718 rUri, aPassword,
true );
2720 catch ( packages::WrongPasswordException
const & )
2726 ? task::PasswordRequestMode_PASSWORD_REENTER
2727 : task::PasswordRequestMode_PASSWORD_ENTER,
2729 bPasswordRequested =
true;
2736 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
2739 "Content::getTruncatedOutputStream - content is no stream!" );
2749 const uno::Reference< ucb::XCommandEnvironment > & xEnv )
2751 osl::Guard< osl::Mutex > aGuard(
m_aMutex );
2754 "Content::getStream - content is no stream!" );
2758 bool bPasswordRequested =
false;
2764 aUri, aPassword,
false );
2766 catch ( packages::WrongPasswordException
const & )
2772 ? task::PasswordRequestMode_PASSWORD_REENTER
2773 : task::PasswordRequestMode_PASSWORD_ENTER,
2775 bPasswordRequested =
true;
2784uno::Sequence< ucb::ContentInfo >
2789 uno::Sequence< beans::Property > aProps( 1 );
2790 aProps.getArray()[ 0 ] = beans::Property(
2794 beans::PropertyAttribute::BOUND );
2799 uno::Sequence< ucb::ContentInfo >
aSeq( 1 );
2803 aSeq.getArray()[ 0 ].Attributes = ucb::ContentInfoAttribute::KIND_FOLDER;
2804 aSeq.getArray()[ 0 ].Properties = aProps;
2810 uno::Sequence< ucb::ContentInfo >
aSeq( 2 );
2814 aSeq.getArray()[ 0 ].Attributes
2815 = ucb::ContentInfoAttribute::KIND_FOLDER;
2816 aSeq.getArray()[ 0 ].Properties = aProps;
2820 aSeq.getArray()[ 1 ].Attributes
2821 = ucb::ContentInfoAttribute::INSERT_WITH_INPUTSTREAM
2822 | ucb::ContentInfoAttribute::KIND_DOCUMENT;
2823 aSeq.getArray()[ 1 ].Properties = aProps;
2830 OSL_FAIL(
"getCreatableContentsInfo called on non-contentcreator "
2833 return uno::Sequence< ucb::ContentInfo >( 0 );
const PropertyValue * pValues
PropertiesInfo aProperties
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
bool isContentCreator() const
ContentType getType() const
css::uno::Sequence< css::ucb::ContentInfo > getCreatableContentsInfo() const
bool getIsDocument() const
const OUString & getContentType() const
void setTitle(const OUString &rTitle)
const OUString & getTitle() const
css::util::DateTime queryStreamDateModified(OUString const &uri) const
OUString queryStorageTitle(const OUString &rUri) const
css::uno::Reference< css::io::XOutputStream > queryOutputStream(const OUString &rUri, const OUString &rPassword, bool bTruncate) const
css::uno::Reference< css::io::XInputStream > queryInputStream(const OUString &rUri, const OUString &rPassword) const
css::uno::Reference< css::embed::XStorage > queryStorageClone(const OUString &rUri) const
css::uno::Reference< css::frame::XModel > queryDocumentModel(const OUString &rUri) const
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier) override
css::uno::Reference< css::io::XStream > queryStream(const OUString &rUri, const OUString &rPassword, bool bTruncate) const
css::uno::Reference< css::embed::XStorage > queryStorage(const OUString &rUri, StorageAccessMode eMode) const
static bool hasData(ContentProvider const *pProvider, const Uri &rUri)
static bool commitStorage(const css::uno::Reference< css::embed::XStorage > &xStorage)
css::uno::Reference< css::io::XOutputStream > getTruncatedOutputStream(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL getIdentifier() override
bool exchangeIdentity(const css::uno::Reference< css::ucb::XContentIdentifier > &xNewId)
void renameData(const css::uno::Reference< css::ucb::XContentIdentifier > &xOldId, const css::uno::Reference< css::ucb::XContentIdentifier > &xNewId)
css::uno::Sequence< css::uno::Any > setPropertyValues(const css::uno::Sequence< css::beans::PropertyValue > &rValues, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
void notifyDocumentClosed()
bool copyData(const Uri &rSourceUri, const OUString &rNewName)
virtual css::uno::Sequence< css::ucb::ContentInfo > SAL_CALL queryCreatableContentsInfo() override
ContentProvider * m_pProvider
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual css::uno::Any SAL_CALL execute(const css::ucb::Command &aCommand, sal_Int32 CommandId, const css::uno::Reference< css::ucb::XCommandEnvironment > &Environment) override
void insert(const css::uno::Reference< css::io::XInputStream > &xData, sal_Int32 nNameClashResolve, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
std::vector< ContentRef > ContentRefList
css::uno::Any open(const css::ucb::OpenCommandArgument2 &rArg, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
void destroy(bool bDeletePhysical, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL createNewContent(const css::ucb::ContentInfo &Info) override
rtl::Reference< Content > ContentRef
static rtl::Reference< Content > create(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ContentProvider *pProvider, const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier)
css::uno::Reference< css::sdbc::XRow > getPropertyValues(const css::uno::Sequence< css::beans::Property > &rProperties)
void notifyChildInserted(std::u16string_view rRelativeChildUri)
css::uno::Reference< css::io::XStream > getStream(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
css::uno::Reference< css::io::XInputStream > getInputStream(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
void notifyChildRemoved(std::u16string_view rRelativeChildUri)
virtual OUString SAL_CALL getImplementationName() override
void transfer(const css::ucb::TransferInfo &rInfo, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual void SAL_CALL acquire() noexcept override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::Reference< css::ucb::XContentIdentifier > makeNewIdentifier(const OUString &rTitle)
virtual void SAL_CALL release() noexcept override
static bool closeOutputStream(const css::uno::Reference< css::io::XOutputStream > &xOut)
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
bool storeData(const css::uno::Reference< css::io::XInputStream > &xData, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
void queryChildren(ContentRefList &rChildren)
virtual OUString SAL_CALL getContentType() override
virtual void SAL_CALL abort(sal_Int32 CommandId) override
virtual OUString getParentURL() override
ContentProperties m_aProps
static bool loadData(ContentProvider const *pProvider, const Uri &rUri, ContentProperties &rProps)
Content(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ContentProvider *pProvider, const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier, ContentProperties aProps)
css::uno::Reference< css::ucb::XContent > queryChildContent(std::u16string_view rRelativeChildUri)
const OUString & getDecodedName() const
const OUString & getParentUri() const
const OUString & getUri() const
css::uno::Reference< css::ucb::XPersistentPropertySet > getAdditionalPropertySet(bool bCreate)
css::uno::Reference< css::ucb::XCommandInfo > getCommandInfo(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, bool bCache=true)
bool renameAdditionalPropertySet(const OUString &rOldKey, const OUString &rNewKey)
rtl::Reference< ContentProviderImplHelper > m_xProvider
void notifyContentEvent(const css::ucb::ContentEvent &evt) const
bool removeAdditionalPropertySet()
bool copyAdditionalPropertySet(const OUString &rSourceKey, const OUString &rTargetKey)
bool exchange(const css::uno::Reference< css::ucb::XContentIdentifier > &rNewId)
css::uno::Reference< css::beans::XPropertySetInfo > getPropertySetInfo(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, bool bCache=true)
css::uno::Reference< css::ucb::XContentIdentifier > m_xIdentifier
css::uno::Reference< css::uno::XComponentContext > m_xContext
void notifyPropertiesChange(const css::uno::Sequence< css::beans::PropertyChangeEvent > &evt) const
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XInterface > xTarget
Sequence< sal_Int8 > aSeq
constexpr OUStringLiteral aData
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
constexpr OUStringLiteral TDOC_ROOT_CONTENT_TYPE
constexpr OUStringLiteral TDOC_STREAM_CONTENT_TYPE
constexpr OUStringLiteral TDOC_DOCUMENT_CONTENT_TYPE
constexpr OUStringLiteral TDOC_FOLDER_CONTENT_TYPE
OUString encodeSegment(const OUString &rSegment)
std::vector< ContentImplHelperRef > ContentRefList
void cancelCommandExecution(const uno::Any &rException, const uno::Reference< ucb::XCommandEnvironment > &xEnv)
uno::Sequence< beans::Property > m_aProps
static OUString obtainPassword(const OUString &rName, task::PasswordRequestMode eMode, const uno::Reference< ucb::XCommandEnvironment > &xEnv)
static ContentType lcl_getContentType(std::u16string_view rType)
XTYPEPROVIDER_COMMON_IMPL(Content)
static uno::Reference< io::XOutputStream > lcl_getTruncatedOutputStream(const OUString &rUri, ContentProvider const *pProvider, const uno::Reference< ucb::XCommandEnvironment > &xEnv)
#define TDOC_URL_SCHEME_LENGTH
std::unique_ptr< char[]> aBuffer