29#include <com/sun/star/embed/InvalidStorageException.hpp>
30#include <com/sun/star/embed/StorageWrappedTargetException.hpp>
31#include <com/sun/star/io/IOException.hpp>
32#include <com/sun/star/ucb/IllegalIdentifierException.hpp>
51 const uno::Reference< uno::XComponentContext >& rxContext )
60ContentProvider::~ContentProvider()
70 return "com.sun.star.comp.ucb.TransientDocumentsContentProvider";
80 return {
"com.sun.star.ucb.TransientDocumentsContentProvider" };
87extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
89 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
98uno::Reference< ucb::XContent > SAL_CALL
100 const uno::Reference< ucb::XContentIdentifier >& Identifier )
103 if ( !aUri.isValid() )
104 throw ucb::IllegalIdentifierException(
109 uno::Reference< ucb::XContentIdentifier > xCanonicId
110 = new ::ucbhelper::ContentIdentifier( aUri.getUri() );
115 uno::Reference< ucb::XContent > xContent
116 = queryExistingContent( xCanonicId );
118 if ( !xContent.is() )
122 registerNewContent( xContent );
131uno::Reference<ucb::XContentIdentifier> SAL_CALL
133 uno::Reference<frame::XModel>
const& xModel)
138 throw lang::IllegalArgumentException(
139 "No Document Manager!",
145 if ( aDocId.isEmpty() )
147 throw lang::IllegalArgumentException(
148 "Unable to obtain document id from model!",
155 uno::Reference< ucb::XContentIdentifier > xId
156 = new ::ucbhelper::ContentIdentifier(
aBuffer );
162uno::Reference< ucb::XContent > SAL_CALL
164 uno::Reference<frame::XModel>
const& xModel)
166 uno::Reference<ucb::XContentIdentifier>
const xId(
172 uno::Reference< ucb::XContent > xContent
173 = queryExistingContent( xId );
175 if ( !xContent.is() )
185 throw lang::IllegalArgumentException(
186 "Illegal Content Identifier!",
198 osl::MutexGuard aGuard( getContentListMutex() );
201 queryExistingContents( aAllContents );
205 bool bFoundDocumentContent =
false;
208 for (
const auto& rContent : aAllContents )
210 Uri aUri( rContent->getIdentifier()->getContentIdentifier() );
212 "ContentProvider::notifyDocumentClosed - Invalid URI!" );
214 if ( !bFoundDocumentContent )
218 xRoot =
static_cast< Content *
>( rContent.get() );
224 bFoundDocumentContent =
true;
237 =
static_cast< Content *
>( rContent.get() );
239 xContent->notifyDocumentClosed();
248 xRoot->notifyChildRemoved( rDocId );
256 osl::MutexGuard aGuard( getContentListMutex() );
259 queryExistingContents( aAllContents );
263 for (
const auto& rContent : aAllContents )
265 Uri aUri( rContent->getIdentifier()->getContentIdentifier() );
267 "ContentProvider::notifyDocumentOpened - Invalid URI!" );
272 =
static_cast< Content *
>( rContent.get() );
273 xRoot->notifyChildInserted( rDocId );
285uno::Reference< embed::XStorage >
295 catch ( embed::InvalidStorageException
const & )
299 catch ( lang::IllegalArgumentException
const & )
303 catch ( io::IOException
const & )
308 catch ( embed::StorageWrappedTargetException
const & )
313 return uno::Reference< embed::XStorage >();
317uno::Reference< embed::XStorage >
325 uno::Reference< embed::XStorage > xParentStorage
327 uno::Reference< embed::XStorage > xStorage
330 xParentStorage->copyStorageElementLastCommitTo(
334 catch ( embed::InvalidStorageException
const & )
338 catch ( lang::IllegalArgumentException
const & )
342 catch ( io::IOException
const & )
347 catch ( embed::StorageWrappedTargetException
const & )
353 return uno::Reference< embed::XStorage >();
357uno::Reference< io::XInputStream >
359 const OUString & rPassword )
const
367 catch ( embed::InvalidStorageException
const & )
371 catch ( lang::IllegalArgumentException
const & )
375 catch ( io::IOException
const & )
379 catch ( embed::StorageWrappedTargetException
const & )
389 return uno::Reference< io::XInputStream >();
393uno::Reference< io::XOutputStream >
395 const OUString & rPassword,
396 bool bTruncate )
const
403 m_xStgElemFac->createOutputStream( rUri, rPassword, bTruncate );
405 catch ( embed::InvalidStorageException
const & )
409 catch ( lang::IllegalArgumentException
const & )
413 catch ( io::IOException
const & )
418 catch ( embed::StorageWrappedTargetException
const & )
428 return uno::Reference< io::XOutputStream >();
432uno::Reference< io::XStream >
434 const OUString & rPassword,
435 bool bTruncate )
const
441 return m_xStgElemFac->createStream( rUri, rPassword, bTruncate );
443 catch ( embed::InvalidStorageException
const & )
447 catch ( lang::IllegalArgumentException
const & )
451 catch ( io::IOException
const & )
456 catch ( embed::StorageWrappedTargetException
const & )
466 return uno::Reference< io::XStream >();
471 const OUString & rUri, uno::Sequence< OUString > & rNames )
const
489 uno::Reference< embed::XStorage > xStorage
492 OSL_ENSURE( xStorage.is(),
"Got no Storage!" );
496 rNames = xStorage->getElementNames();
500 catch ( embed::InvalidStorageException
const & )
504 catch ( lang::IllegalArgumentException
const & )
508 catch ( io::IOException
const & )
513 catch ( embed::StorageWrappedTargetException
const & )
547 OSL_ENSURE( !aTitle.isEmpty() || aUri.
isRoot(),
548 "ContentProvider::queryStorageTitle - empty title!" );
553uno::Reference< frame::XModel >
556 uno::Reference< frame::XModel >
xModel;
565 "ContentProvider::queryDocumentModel - no model!" );
571 return m_xDocsMgr->queryStreamDateModified(uri);
Reference< XComponentContext > m_xContext
void notifyDocumentOpened(std::u16string_view rDocId)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::util::DateTime queryStreamDateModified(OUString const &uri) const
void notifyDocumentClosed(std::u16string_view rDocId)
virtual OUString SAL_CALL getImplementationName() override
OUString queryStorageTitle(const OUString &rUri) const
css::uno::Reference< css::io::XOutputStream > queryOutputStream(const OUString &rUri, const OUString &rPassword, bool bTruncate) const
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL createDocumentContent(const css::uno::Reference< css::frame::XModel > &Model) override
rtl::Reference< StorageElementFactory > m_xStgElemFac
css::uno::Reference< css::io::XInputStream > queryInputStream(const OUString &rUri, const OUString &rPassword) const
virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL createDocumentContentIdentifier(css::uno::Reference< css::frame::XModel > const &xModel) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
css::uno::Reference< css::embed::XStorage > queryStorageClone(const OUString &rUri) const
rtl::Reference< OfficeDocumentsManager > m_xDocsMgr
bool queryNamesOfChildren(const OUString &rUri, css::uno::Sequence< OUString > &rNames) 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 rtl::Reference< Content > create(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ContentProvider *pProvider, const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier)
static OUString queryDocumentId(const css::uno::Reference< css::frame::XModel > &xModel)
const OUString & getDecodedName() const
const OUString & getDocumentId() const
const OUString & getParentUri() const
#define TOOLS_WARN_EXCEPTION(area, stream)
cppu::ImplInheritanceHelper< ::ucbhelper::ContentProviderImplHelper, css::container::XContainerListener, css::lang::XComponent > ContentProvider_Base
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::vector< ContentImplHelperRef > ContentRefList
Reference< XModel > xModel
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * ucb_tdoc_ContentProvider_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
std::unique_ptr< char[]> aBuffer