summaryrefslogtreecommitdiff
path: root/sfx2/source/doc/sfxbasemodel.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sfx2/source/doc/sfxbasemodel.cxx')
-rw-r--r--sfx2/source/doc/sfxbasemodel.cxx394
1 files changed, 387 insertions, 7 deletions
diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx
index 43ce1593bbaf..53673b505d6d 100644
--- a/sfx2/source/doc/sfxbasemodel.cxx
+++ b/sfx2/source/doc/sfxbasemodel.cxx
@@ -66,6 +66,7 @@
#include <com/sun/star/embed/ElementModes.hpp>
#include <com/sun/star/embed/Aspects.hpp>
#include <com/sun/star/document/XDocumentProperties.hpp>
+#include <com/sun/star/frame/XTransientDocumentsDocumentContentFactory.hpp>
#include <comphelper/enumhelper.hxx> // can be removed when this is a "real" service
#include <cppuhelper/interfacecontainer.hxx>
@@ -124,6 +125,8 @@
#include "brokenpackageint.hxx"
#include "graphhelp.hxx"
#include <sfx2/msgpool.hxx>
+#include <sfx2/DocumentMetadataAccess.hxx>
+
#include <sfxresid.hxx>
//________________________________________________________________________________________________________
@@ -135,13 +138,14 @@ static const ::rtl::OUString SERVICENAME_DESKTOP = ::rtl::OUString::createFromAs
//________________________________________________________________________________________________________
namespace css = ::com::sun::star;
-using namespace com::sun::star;
+using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
//________________________________________________________________________________________________________
// impl. declarations
//________________________________________________________________________________________________________
+
struct IMPL_SfxBaseModel_DataContainer : public ::sfx2::IModifiableDocument
{
// counter for SfxBaseModel instances created.
@@ -172,6 +176,8 @@ struct IMPL_SfxBaseModel_DataContainer : public ::sfx2::IModifiableDocument
::rtl::OUString m_sModuleIdentifier;
css::uno::Reference< css::frame::XTitle > m_xTitleHelper;
css::uno::Reference< css::frame::XUntitledNumbers > m_xNumberedControllers;
+ uno::Reference< rdf::XDocumentMetadataAccess> m_xDocumentMetadata;
+
IMPL_SfxBaseModel_DataContainer( ::osl::Mutex& rMutex, SfxObjectShell* pObjectShell )
: m_pObjectShell ( pObjectShell )
@@ -184,6 +190,7 @@ struct IMPL_SfxBaseModel_DataContainer : public ::sfx2::IModifiableDocument
, m_pStorageModifyListen ( NULL )
, m_xTitleHelper ()
, m_xNumberedControllers ()
+ , m_xDocumentMetadata () // lazy
{
// increase global instance counter.
++g_nInstanceCounter;
@@ -201,6 +208,58 @@ struct IMPL_SfxBaseModel_DataContainer : public ::sfx2::IModifiableDocument
if ( m_pObjectShell.Is() && !m_pObjectShell->IsModified() )
m_pObjectShell->SetModified( sal_True );
}
+
+ uno::Reference<rdf::XDocumentMetadataAccess> GetDMA()
+ {
+ if (!m_xDocumentMetadata.is())
+ {
+ OSL_ENSURE(m_pObjectShell, "GetDMA: no object shell?");
+ if (!m_pObjectShell)
+ {
+ return 0;
+ }
+
+ const uno::Reference<uno::XComponentContext> xContext(
+ ::comphelper::getProcessComponentContext());
+ ::rtl::OUString uri;
+ const uno::Reference<frame::XModel> xModel(
+ m_pObjectShell->GetModel());
+ const uno::Reference<lang::XMultiComponentFactory> xMsf(
+ xContext->getServiceManager());
+ const uno::Reference<frame::
+ XTransientDocumentsDocumentContentFactory> xTDDCF(
+ xMsf->createInstanceWithContext(
+ ::rtl::OUString::createFromAscii( "com.sun.star.frame."
+ "TransientDocumentsDocumentContentFactory"),
+ xContext),
+ uno::UNO_QUERY_THROW);
+ const uno::Reference<ucb::XContent> xContent(
+ xTDDCF->createDocumentContent(xModel) );
+ OSL_ENSURE(xContent.is(), "GetDMA: cannot create DocumentContent");
+ if (!xContent.is())
+ {
+ return 0;
+ }
+ uri = xContent->getIdentifier()->getContentIdentifier();
+ OSL_ENSURE(uri.getLength(), "GetDMA: empty uri?");
+ if (uri.getLength() && !uri.endsWithAsciiL("/", 1))
+ {
+ uri = uri + ::rtl::OUString::createFromAscii("/");
+ }
+
+ m_xDocumentMetadata = new ::sfx2::DocumentMetadataAccess(
+ xContext, *m_pObjectShell, uri);
+ }
+ return m_xDocumentMetadata;
+ }
+
+ uno::Reference<rdf::XDocumentMetadataAccess> CreateDMAUninitialized()
+ {
+ return (m_pObjectShell)
+ ? new ::sfx2::DocumentMetadataAccess(
+ ::comphelper::getProcessComponentContext(), *m_pObjectShell)
+ : 0;
+ }
};
// static member initialization.
@@ -417,9 +476,9 @@ SfxSaveGuard::~SfxSaveGuard()
//________________________________________________________________________________________________________
DBG_NAME(sfx2_SfxBaseModel)
SfxBaseModel::SfxBaseModel( SfxObjectShell *pObjectShell )
-: IMPL_SfxBaseModel_MutexContainer()
+: BaseMutex()
, m_pData( new IMPL_SfxBaseModel_DataContainer( m_aMutex, pObjectShell ) )
-, m_bSupportEmbeddedScripts( pObjectShell && pObjectShell->pImp ? !pObjectShell->pImp->m_bNoBasicCapabilities : false )
+, m_bSupportEmbeddedScripts( pObjectShell && pObjectShell->Get_Impl() ? !pObjectShell->Get_Impl()->m_bNoBasicCapabilities : false )
{
DBG_CTOR(sfx2_SfxBaseModel,NULL);
if ( pObjectShell != NULL )
@@ -686,10 +745,9 @@ void SAL_CALL SfxBaseModel::dispose() throw(::com::sun::star::uno::RuntimeExcept
m_pData->m_xDocumentInfo = 0;
}
- if ( m_pData->m_xDocumentProperties.is() )
- {
- m_pData->m_xDocumentProperties = 0;
- }
+ m_pData->m_xDocumentProperties.clear();
+
+ m_pData->m_xDocumentMetadata.clear();
EndListening( *m_pData->m_pObjectShell );
@@ -3829,3 +3887,325 @@ css::uno::Reference< css::frame::XController2 > SAL_CALL SfxBaseModel::createVie
{
return css::uno::Reference< css::frame::XController2 >();
}
+
+//=============================================================================
+// RDF DocumentMetadataAccess
+
+// ::com::sun::star::rdf::XRepositorySupplier:
+uno::Reference< rdf::XRepository > SAL_CALL
+SfxBaseModel::getRDFRepository() throw (uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( impl_isDisposed() )
+ throw lang::DisposedException();
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->getRDFRepository();
+}
+
+// ::com::sun::star::rdf::XNode:
+::rtl::OUString SAL_CALL
+SfxBaseModel::getStringValue() throw (uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( impl_isDisposed() )
+ throw lang::DisposedException();
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->getStringValue();
+}
+
+// ::com::sun::star::rdf::XURI:
+::rtl::OUString SAL_CALL
+SfxBaseModel::getNamespace() throw (uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( impl_isDisposed() )
+ throw lang::DisposedException();
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->getNamespace();
+}
+
+::rtl::OUString SAL_CALL
+SfxBaseModel::getLocalName() throw (uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( impl_isDisposed() )
+ throw lang::DisposedException();
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->getLocalName();
+}
+
+// ::com::sun::star::rdf::XDocumentMetadataAccess:
+uno::Reference< rdf::XMetadatable > SAL_CALL
+SfxBaseModel::getElementByMetadataReference(
+ const ::com::sun::star::beans::StringPair & i_rReference)
+throw (uno::RuntimeException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( impl_isDisposed() )
+ throw lang::DisposedException();
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->getElementByMetadataReference(i_rReference);
+}
+
+uno::Reference< rdf::XMetadatable > SAL_CALL
+SfxBaseModel::getElementByURI(const uno::Reference< rdf::XURI > & i_xURI)
+throw (uno::RuntimeException, lang::IllegalArgumentException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( impl_isDisposed() )
+ throw lang::DisposedException();
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->getElementByURI(i_xURI);
+}
+
+uno::Sequence< uno::Reference< rdf::XURI > > SAL_CALL
+SfxBaseModel::getMetadataGraphsWithType(
+ const uno::Reference<rdf::XURI> & i_xType)
+throw (uno::RuntimeException, lang::IllegalArgumentException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( impl_isDisposed() )
+ throw lang::DisposedException();
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->getMetadataGraphsWithType(i_xType);
+}
+
+uno::Reference<rdf::XURI> SAL_CALL
+SfxBaseModel::addMetadataFile(const ::rtl::OUString & i_rFileName,
+ const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ container::ElementExistException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( impl_isDisposed() )
+ throw lang::DisposedException();
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->addMetadataFile(i_rFileName, i_rTypes);
+}
+
+uno::Reference<rdf::XURI> SAL_CALL
+SfxBaseModel::importMetadataFile(::sal_Int16 i_Format,
+ const uno::Reference< io::XInputStream > & i_xInStream,
+ const ::rtl::OUString & i_rFileName,
+ const uno::Reference< rdf::XURI > & i_xBaseURI,
+ const uno::Sequence < uno::Reference< rdf::XURI > > & i_rTypes)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ datatransfer::UnsupportedFlavorException,
+ container::ElementExistException, rdf::ParseException, io::IOException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( impl_isDisposed() )
+ throw lang::DisposedException();
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->importMetadataFile(i_Format,
+ i_xInStream, i_rFileName, i_xBaseURI, i_rTypes);
+}
+
+void SAL_CALL
+SfxBaseModel::removeMetadataFile(
+ const uno::Reference< rdf::XURI > & i_xGraphName)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ container::NoSuchElementException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( impl_isDisposed() )
+ throw lang::DisposedException();
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->removeMetadataFile(i_xGraphName);
+}
+
+void SAL_CALL
+SfxBaseModel::addContentOrStylesFile(const ::rtl::OUString & i_rFileName)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ container::ElementExistException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( impl_isDisposed() )
+ throw lang::DisposedException();
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->addContentOrStylesFile(i_rFileName);
+}
+
+void SAL_CALL
+SfxBaseModel::removeContentOrStylesFile(const ::rtl::OUString & i_rFileName)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ container::NoSuchElementException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( impl_isDisposed() )
+ throw lang::DisposedException();
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->removeContentOrStylesFile(i_rFileName);
+}
+
+void SAL_CALL
+SfxBaseModel::loadMetadataFromStorage(
+ uno::Reference< embed::XStorage > const & i_xStorage,
+ uno::Reference<rdf::XURI> const & i_xBaseURI,
+ uno::Reference<task::XInteractionHandler> const & i_xHandler)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ lang::WrappedTargetException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( impl_isDisposed() )
+ throw lang::DisposedException();
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
+ m_pData->CreateDMAUninitialized());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ try {
+ xDMA->loadMetadataFromStorage(i_xStorage, i_xBaseURI, i_xHandler);
+ } catch (lang::IllegalArgumentException &) {
+ throw; // not initialized
+ } catch (uno::Exception &) {
+ // UGLY: if it's a RuntimeException, we can't be sure DMA is initialzed
+ m_pData->m_xDocumentMetadata = xDMA;
+ throw;
+ }
+ m_pData->m_xDocumentMetadata = xDMA;
+
+}
+
+void SAL_CALL
+SfxBaseModel::storeMetadataToStorage(
+ uno::Reference< embed::XStorage > const & i_xStorage)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ lang::WrappedTargetException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( impl_isDisposed() )
+ throw lang::DisposedException();
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->storeMetadataToStorage(i_xStorage);
+}
+
+void SAL_CALL
+SfxBaseModel::loadMetadataFromMedium(
+ const uno::Sequence< beans::PropertyValue > & i_rMedium)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ lang::WrappedTargetException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( impl_isDisposed() )
+ throw lang::DisposedException();
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
+ m_pData->CreateDMAUninitialized());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ try {
+ xDMA->loadMetadataFromMedium(i_rMedium);
+ } catch (lang::IllegalArgumentException &) {
+ throw; // not initialized
+ } catch (uno::Exception &) {
+ // UGLY: if it's a RuntimeException, we can't be sure DMA is initialzed
+ m_pData->m_xDocumentMetadata = xDMA;
+ throw;
+ }
+ m_pData->m_xDocumentMetadata = xDMA;
+}
+
+void SAL_CALL
+SfxBaseModel::storeMetadataToMedium(
+ const uno::Sequence< beans::PropertyValue > & i_rMedium)
+throw (uno::RuntimeException, lang::IllegalArgumentException,
+ lang::WrappedTargetException)
+{
+ ::vos::OGuard aGuard( Application::GetSolarMutex() );
+ if ( impl_isDisposed() )
+ throw lang::DisposedException();
+
+ const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(m_pData->GetDMA());
+ if (!xDMA.is()) {
+ throw uno::RuntimeException( ::rtl::OUString::createFromAscii(
+ "model has no document metadata"), *this );
+ }
+
+ return xDMA->storeMetadataToMedium(i_rMedium);
+}
+