summaryrefslogtreecommitdiff
path: root/ucb
diff options
context:
space:
mode:
authorJens-Heiner Rechtien <hr@openoffice.org>2004-04-14 12:42:54 +0000
committerJens-Heiner Rechtien <hr@openoffice.org>2004-04-14 12:42:54 +0000
commit226915f8623ec78b9c7acf6eed7b1f837dfbb24e (patch)
tree6d44314a06a06e48fcd28a255e863f93a4dc0c83 /ucb
parentc69992c896cbdd136bf16a5950d1d672ff3a0a24 (diff)
INTEGRATION: CWS unopkg1 (1.1.2); FILE ADDED
2004/03/15 17:04:14 kso 1.1.2.5: #112920# - Moved TransientDocumentsDocumentContentFactory to modele css.frame. Issue number: Submitted by: Reviewed by: 2004/03/12 17:27:54 kso 1.1.2.4: #i26370# - Added support for property 'DocumentModel' Issue number: i26370 Submitted by: Reviewed by: 2004/02/23 15:59:50 kso 1.1.2.3: #112920# - Added support for encrypted streams. Issue number: Submitted by: Reviewed by: 2004/01/27 17:23:33 kso 1.1.2.2: #112920# - Speaking Title property value for document contents. - Use 'RuntimeUID' document property as document id, if available - New interface at provider for creating document contents directly from document model. 2004/01/20 15:17:32 kso 1.1.2.1: #112920# TDOC UCP: Initial revision.
Diffstat (limited to 'ucb')
-rw-r--r--ucb/source/ucp/tdoc/tdoc_provider.cxx515
1 files changed, 515 insertions, 0 deletions
diff --git a/ucb/source/ucp/tdoc/tdoc_provider.cxx b/ucb/source/ucp/tdoc/tdoc_provider.cxx
new file mode 100644
index 000000000000..f013b407bf2e
--- /dev/null
+++ b/ucb/source/ucp/tdoc/tdoc_provider.cxx
@@ -0,0 +1,515 @@
+/*************************************************************************
+ *
+ * $RCSfile: tdoc_provider.cxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: hr $ $Date: 2004-04-14 13:42:54 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): Kai Sommerfeld ( kso@sun.com )
+ *
+ *
+ ************************************************************************/
+
+/**************************************************************************
+ TODO
+ **************************************************************************
+
+ *************************************************************************/
+
+#include "rtl/ustrbuf.hxx"
+
+#include "com/sun/star/container/XNameAccess.hpp"
+#include "com/sun/star/embed/XStorage.hpp"
+
+#include "ucbhelper/contentidentifier.hxx"
+
+#include "tdoc_provider.hxx"
+#include "tdoc_content.hxx"
+#include "tdoc_uri.hxx"
+#include "tdoc_docmgr.hxx"
+#include "tdoc_storage.hxx"
+
+using namespace com::sun;
+using namespace com::sun::star;
+
+using namespace tdoc_ucp;
+
+//=========================================================================
+//=========================================================================
+//
+// ContentProvider Implementation.
+//
+//=========================================================================
+//=========================================================================
+
+ContentProvider::ContentProvider(
+ const uno::Reference< lang::XMultiServiceFactory >& xSMgr )
+: ::ucb::ContentProviderImplHelper( xSMgr ),
+ m_xDocsMgr( new OfficeDocumentsManager( xSMgr, this ) ),
+ m_xStgElemFac( new StorageElementFactory( xSMgr, m_xDocsMgr ) )
+{
+}
+
+//=========================================================================
+// virtual
+ContentProvider::~ContentProvider()
+{
+ if ( m_xDocsMgr.is() )
+ m_xDocsMgr->destroy();
+}
+
+//=========================================================================
+//
+// XInterface methods.
+//
+//=========================================================================
+
+XINTERFACE_IMPL_4( ContentProvider,
+ lang::XTypeProvider,
+ lang::XServiceInfo,
+ star::ucb::XContentProvider,
+ frame::XTransientDocumentsDocumentContentFactory );
+
+//=========================================================================
+//
+// XTypeProvider methods.
+//
+//=========================================================================
+
+XTYPEPROVIDER_IMPL_4( ContentProvider,
+ lang::XTypeProvider,
+ lang::XServiceInfo,
+ star::ucb::XContentProvider,
+ frame::XTransientDocumentsDocumentContentFactory );
+
+//=========================================================================
+//
+// XServiceInfo methods.
+//
+//=========================================================================
+
+XSERVICEINFO_IMPL_1(
+ ContentProvider,
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.comp.ucb.TransientDocumentsContentProvider" ) ),
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
+ TDOC_CONTENT_PROVIDER_SERVICE_NAME ) ) );
+
+//=========================================================================
+//
+// Service factory implementation.
+//
+//=========================================================================
+
+ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );
+
+//=========================================================================
+//
+// XContentProvider methods.
+//
+//=========================================================================
+
+// virtual
+uno::Reference< star::ucb::XContent > SAL_CALL
+ContentProvider::queryContent(
+ const uno::Reference< star::ucb::XContentIdentifier >& Identifier )
+ throw( star::ucb::IllegalIdentifierException, uno::RuntimeException )
+{
+ Uri aUri( Identifier->getContentIdentifier() );
+ if ( !aUri.isValid() )
+ throw star::ucb::IllegalIdentifierException(
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid URL!" ) ),
+ Identifier );
+
+ // Normalize URI.
+ uno::Reference< star::ucb::XContentIdentifier > xCanonicId
+ = new ::ucb::ContentIdentifier( m_xSMgr, aUri.getUri() );
+
+ vos::OGuard aGuard( m_aMutex );
+
+ // Check, if a content with given id already exists...
+ uno::Reference< star::ucb::XContent > xContent
+ = queryExistingContent( xCanonicId ).getBodyPtr();
+
+ if ( !xContent.is() )
+ {
+ // Create a new content.
+ xContent = Content::create( m_xSMgr, this, xCanonicId );
+ }
+
+ return xContent;
+}
+
+//=========================================================================
+//
+// XTransientDocumentsDocumentContentFactory methods.
+//
+//=========================================================================
+
+// virtual
+uno::Reference< star::ucb::XContent > SAL_CALL
+ContentProvider::createDocumentContent(
+ const uno::Reference< frame::XModel >& Model )
+ throw ( lang::IllegalArgumentException, uno::RuntimeException )
+{
+ // model -> id -> content identifier -> queryContent
+ if ( m_xDocsMgr.is() )
+ {
+ rtl::OUString aDocId = m_xDocsMgr->queryDocumentId( Model );
+ if ( aDocId.getLength() > 0 )
+ {
+ rtl::OUStringBuffer aBuffer;
+ aBuffer.appendAscii( TDOC_URL_SCHEME ":/" );
+ aBuffer.append( aDocId );
+
+ uno::Reference< star::ucb::XContentIdentifier > xId
+ = new ::ucb::ContentIdentifier(
+ m_xSMgr, aBuffer.makeStringAndClear() );
+
+ vos::OGuard aGuard( m_aMutex );
+
+ // Check, if a content with given id already exists...
+ uno::Reference< star::ucb::XContent > xContent
+ = queryExistingContent( xId ).getBodyPtr();
+
+ if ( !xContent.is() )
+ {
+ // Create a new content.
+ xContent = Content::create( m_xSMgr, this, xId );
+ }
+
+ if ( xContent.is() )
+ return xContent;
+
+ // no content.
+ throw lang::IllegalArgumentException(
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
+ "Illegal Content Identifier!" ) ),
+ static_cast< cppu::OWeakObject * >( this ),
+ 1 );
+ }
+ else
+ {
+ throw lang::IllegalArgumentException(
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
+ "Unable to obtain document id from model!" ) ),
+ static_cast< cppu::OWeakObject * >( this ),
+ 1 );
+ }
+ }
+ else
+ {
+ throw lang::IllegalArgumentException(
+ rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
+ "No Document Manager!" ) ),
+ static_cast< cppu::OWeakObject * >( this ),
+ 1 );
+ }
+}
+
+//=========================================================================
+//
+// interface OfficeDocumentsCloseListener
+//
+//=========================================================================
+
+// virtual
+void ContentProvider::notifyDocumentClosed( const rtl::OUString & rDocId )
+{
+ vos::OGuard aGuard( getContentListMutex() );
+
+ ::ucb::ContentRefList aAllContents;
+ queryExistingContents( aAllContents );
+
+ ::ucb::ContentRefList::const_iterator it = aAllContents.begin();
+ ::ucb::ContentRefList::const_iterator end = aAllContents.end();
+
+ // Notify all content objects related to the closed doc.
+
+ while ( it != end )
+ {
+ const rtl::OUString aURL
+ = (*it)->getIdentifier()->getContentIdentifier();
+ sal_Int32 nLen = TDOC_URL_SCHEME_LENGTH + 2; // url-scheme + :/
+
+ if ( aURL.match( rDocId, nLen ) )
+ {
+ // Inform content.
+ rtl::Reference< Content > xContent
+ = static_cast< Content * >( (*it).getBodyPtr() );
+
+ xContent->notifyDocumentClosure();
+ }
+ ++it;
+ }
+}
+
+//=========================================================================
+//
+// Non-UNO
+//
+//=========================================================================
+
+uno::Reference< embed::XStorage >
+ContentProvider::queryStorage( const rtl::OUString & rUri,
+ StorageAccessMode eMode ) const
+{
+ if ( m_xStgElemFac.is() )
+ {
+ try
+ {
+ return m_xStgElemFac->createStorage( rUri, eMode );
+ }
+ catch ( embed::InvalidStorageException const & )
+ {
+ OSL_ENSURE( false, "Caught InvalidStorageException!" );
+ }
+ catch ( lang::IllegalArgumentException const & )
+ {
+ OSL_ENSURE( false, "Caught IllegalArgumentException!" );
+ }
+ catch ( io::IOException const & )
+ {
+ OSL_ENSURE( false, "Caught IOException!" );
+ }
+ catch ( embed::StorageWTException const & )
+ {
+ OSL_ENSURE( false, "Caught embed::StorageWTException!" );
+ }
+ }
+ return uno::Reference< embed::XStorage >();
+}
+
+//=========================================================================
+uno::Reference< io::XInputStream >
+ContentProvider::queryInputStream( const rtl::OUString & rUri,
+ const rtl::OUString & rPassword ) const
+ throw ( packages::WrongPasswordException )
+{
+ if ( m_xStgElemFac.is() )
+ {
+ try
+ {
+ return m_xStgElemFac->createInputStream( rUri, rPassword );
+ }
+ catch ( embed::InvalidStorageException const & )
+ {
+ OSL_ENSURE( false, "Caught InvalidStorageException!" );
+ }
+ catch ( lang::IllegalArgumentException const & )
+ {
+ OSL_ENSURE( false, "Caught IllegalArgumentException!" );
+ }
+ catch ( io::IOException const & )
+ {
+ OSL_ENSURE( false, "Caught IOException!" );
+ }
+ catch ( embed::StorageWTException const & )
+ {
+ OSL_ENSURE( false, "Caught embed::StorageWTException!" );
+ }
+/*
+ catch ( packages::WrongPasswordException const & )
+ {
+ // the key provided is wrong; rethrow; to be handled by caller.
+ throw;
+ }
+*/
+ }
+ return uno::Reference< io::XInputStream >();
+}
+
+//=========================================================================
+uno::Reference< io::XOutputStream >
+ContentProvider::queryOutputStream( const rtl::OUString & rUri,
+ const rtl::OUString & rPassword ) const
+ throw ( packages::WrongPasswordException )
+{
+ if ( m_xStgElemFac.is() )
+ {
+ try
+ {
+ return m_xStgElemFac->createOutputStream( rUri, rPassword );
+ }
+ catch ( embed::InvalidStorageException const & )
+ {
+ OSL_ENSURE( false, "Caught InvalidStorageException!" );
+ }
+ catch ( lang::IllegalArgumentException const & )
+ {
+ OSL_ENSURE( false, "Caught IllegalArgumentException!" );
+ }
+ catch ( io::IOException const & )
+ {
+ OSL_ENSURE( false, "Caught IOException!" );
+ }
+ catch ( embed::StorageWTException const & )
+ {
+ OSL_ENSURE( false, "Caught embed::StorageWTException!" );
+ }
+/*
+ catch ( packages::WrongPasswordException const & )
+ {
+ // the key provided is wrong; rethrow; to be handled by caller.
+ throw;
+ }
+*/
+ }
+ return uno::Reference< io::XOutputStream >();
+}
+
+//=========================================================================
+bool ContentProvider::queryNamesOfChildren(
+ const rtl::OUString & rUri, uno::Sequence< rtl::OUString > & rNames ) const
+{
+ Uri aUri( rUri );
+ if ( aUri.isRoot() )
+ {
+ // special handling for root, which has no storage, but children.
+ if ( m_xDocsMgr.is() )
+ {
+ rNames = m_xDocsMgr->queryDocuments();
+ return true;
+ }
+ }
+ else
+ {
+ if ( m_xStgElemFac.is() )
+ {
+ try
+ {
+ uno::Reference< embed::XStorage > xStorage
+ = m_xStgElemFac->createStorage( rUri, READ );
+
+ OSL_ENSURE( xStorage.is(), "Got no Storage!" );
+
+ if ( xStorage.is() )
+ {
+ uno::Reference< container::XNameAccess > xNA(
+ xStorage, uno::UNO_QUERY );
+
+ OSL_ENSURE( xNA.is(), "Got no css.container.XNameAccess!" );
+ if ( xNA.is() )
+ {
+ rNames = xNA->getElementNames();
+ return true;
+ }
+ }
+ }
+ catch ( embed::InvalidStorageException const & )
+ {
+ OSL_ENSURE( false, "Caught InvalidStorageException!" );
+ }
+ catch ( lang::IllegalArgumentException const & )
+ {
+ OSL_ENSURE( false, "Caught IllegalArgumentException!" );
+ }
+ catch ( io::IOException const & )
+ {
+ OSL_ENSURE( false, "Caught IOException!" );
+ }
+ catch ( embed::StorageWTException const & )
+ {
+ OSL_ENSURE( false, "Caught embed::StorageWTException!" );
+ }
+ }
+ }
+ return false;
+}
+
+//=========================================================================
+rtl::OUString
+ContentProvider::queryStorageTitle( const rtl::OUString & rUri ) const
+{
+ rtl::OUString aTitle;
+
+ Uri aUri( rUri );
+ if ( aUri.isRoot() )
+ {
+ // always empty.
+ aTitle = rtl::OUString();
+ }
+ else if ( aUri.isDocument() )
+ {
+ // for documents, title shall not be derived from URL. It shall
+ // be somethimg more 'speaking' than just the document UID.
+ if ( m_xDocsMgr.is() )
+ aTitle = m_xDocsMgr->queryStorageTitle( aUri.getDocumentId() );
+ }
+ else
+ {
+ // derive title from URL
+ aTitle = aUri.getDecodedName();
+ }
+
+ OSL_ENSURE( ( aTitle.getLength() > 0 ) || aUri.isRoot(),
+ "ContentProvider::queryStorageTitle - empty title!" );
+ return aTitle;
+}
+
+//=========================================================================
+uno::Reference< frame::XModel >
+ContentProvider::queryDocumentModel( const rtl::OUString & rUri ) const
+{
+ uno::Reference< frame::XModel > xModel;
+
+ if ( m_xDocsMgr.is() )
+ {
+ Uri aUri( rUri );
+ xModel = m_xDocsMgr->queryDocumentModel( aUri.getDocumentId() );
+ }
+
+ OSL_ENSURE( xModel.is(),
+ "ContentProvider::queryDocumentModel - no model!" );
+ return xModel;
+}
+