Kaydet (Commit) 0d6b24a7 authored tarafından Rüdiger Timm's avatar Rüdiger Timm

INTEGRATION: CWS tdoc3 (1.7.24); FILE MERGED

2004/11/03 15:48:28 kso 1.7.24.2: #i36025# - streams cannot longer be created as children of document root
           storage (but folders can). Document would throw those away
           on saving.
Issue number:
Submitted by:
Reviewed by:
2004/11/02 13:56:07 kso 1.7.24.1: #i36025# - Adapted to final Storage API.
Issue number:
Submitted by:
Reviewed by:
üst bc371774
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: tdoc_content.cxx,v $ * $RCSfile: tdoc_content.cxx,v $
* *
* $Revision: 1.7 $ * $Revision: 1.8 $
* *
* last change: $Author: hr $ $Date: 2004-07-23 13:50:50 $ * last change: $Author: rt $ $Date: 2004-11-09 15:33:15 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -63,13 +63,8 @@ ...@@ -63,13 +63,8 @@
TODO TODO
************************************************************************** **************************************************************************
- support for encrypted streams needed?
- Content::storeData: remove dummyfile workaround for creation of new folders
*************************************************************************/ *************************************************************************/
#define STORAGE_CREATION_WORKAROUND 1
#include "osl/diagnose.h" #include "osl/diagnose.h"
#include "osl/doublecheckedlocking.h" #include "osl/doublecheckedlocking.h"
#include "rtl/ustrbuf.hxx" #include "rtl/ustrbuf.hxx"
...@@ -555,6 +550,27 @@ uno::Any SAL_CALL Content::execute( ...@@ -555,6 +550,27 @@ uno::Any SAL_CALL Content::execute(
// Unreachable // Unreachable
} }
#ifdef NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT
if ( eType == STREAM )
{
Uri aUri( m_xIdentifier->getContentIdentifier() );
Uri aParentUri( aUri.getParentUri() );
if ( aParentUri.isDocument() )
{
ucbhelper::cancelCommandExecution(
uno::makeAny( star::ucb::UnsupportedCommandException(
rtl::OUString(
RTL_CONSTASCII_USTRINGPARAM(
"insert command not supported by "
"streams that are direct children "
"of document root!" ) ),
static_cast< cppu::OWeakObject * >(
this ) ) ),
Environment );
// Unreachable
}
}
#endif
star::ucb::InsertCommandArgument aArg; star::ucb::InsertCommandArgument aArg;
if ( !( aCommand.Argument >>= aArg ) ) if ( !( aCommand.Argument >>= aArg ) )
{ {
...@@ -716,24 +732,45 @@ Content::queryCreatableContentsInfo() ...@@ -716,24 +732,45 @@ Content::queryCreatableContentsInfo()
getCppuType( static_cast< const rtl::OUString * >( 0 ) ), getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
beans::PropertyAttribute::BOUND ); beans::PropertyAttribute::BOUND );
uno::Sequence< star::ucb::ContentInfo > aSeq( 2 ); #ifdef NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT
if ( m_aProps.getType() == DOCUMENT )
// Folder. {
aSeq.getArray()[ 0 ].Type // streams cannot be created as direct children of document root
= rtl::OUString::createFromAscii( TDOC_FOLDER_CONTENT_TYPE ); uno::Sequence< star::ucb::ContentInfo > aSeq( 1 );
aSeq.getArray()[ 0 ].Attributes
= star::ucb::ContentInfoAttribute::KIND_FOLDER;
aSeq.getArray()[ 0 ].Properties = aProps;
// Stream. // Folder.
aSeq.getArray()[ 1 ].Type aSeq.getArray()[ 0 ].Type
= rtl::OUString::createFromAscii( TDOC_STREAM_CONTENT_TYPE ); = rtl::OUString::createFromAscii( TDOC_FOLDER_CONTENT_TYPE );
aSeq.getArray()[ 1 ].Attributes aSeq.getArray()[ 0 ].Attributes
= star::ucb::ContentInfoAttribute::INSERT_WITH_INPUTSTREAM = star::ucb::ContentInfoAttribute::KIND_FOLDER;
| star::ucb::ContentInfoAttribute::KIND_DOCUMENT; aSeq.getArray()[ 0 ].Properties = aProps;
aSeq.getArray()[ 1 ].Properties = aProps;
return aSeq; return aSeq;
}
else
{
#endif
uno::Sequence< star::ucb::ContentInfo > aSeq( 2 );
// Folder.
aSeq.getArray()[ 0 ].Type
= rtl::OUString::createFromAscii( TDOC_FOLDER_CONTENT_TYPE );
aSeq.getArray()[ 0 ].Attributes
= star::ucb::ContentInfoAttribute::KIND_FOLDER;
aSeq.getArray()[ 0 ].Properties = aProps;
// Stream.
aSeq.getArray()[ 1 ].Type
= rtl::OUString::createFromAscii( TDOC_STREAM_CONTENT_TYPE );
aSeq.getArray()[ 1 ].Attributes
= star::ucb::ContentInfoAttribute::INSERT_WITH_INPUTSTREAM
| star::ucb::ContentInfoAttribute::KIND_DOCUMENT;
aSeq.getArray()[ 1 ].Properties = aProps;
return aSeq;
#ifdef NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT
}
#endif
} }
else else
{ {
...@@ -762,6 +799,16 @@ Content::createNewContent( const star::ucb::ContentInfo& Info ) ...@@ -762,6 +799,16 @@ Content::createNewContent( const star::ucb::ContentInfo& Info )
Info.Type.equalsAsciiL( Info.Type.equalsAsciiL(
RTL_CONSTASCII_STRINGPARAM( TDOC_FOLDER_CONTENT_TYPE ) ); RTL_CONSTASCII_STRINGPARAM( TDOC_FOLDER_CONTENT_TYPE ) );
#ifdef NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT
// streams cannot be created as direct children of document root
if ( !bCreateFolder && ( m_aProps.getType() == DOCUMENT ) )
{
OSL_ENSURE( sal_False,
"Content::createNewContent - streams cannot be "
"created as direct children of document root!" );
return uno::Reference< star::ucb::XContent >();
}
#endif
if ( !bCreateFolder && if ( !bCreateFolder &&
!Info.Type.equalsAsciiL( !Info.Type.equalsAsciiL(
RTL_CONSTASCII_STRINGPARAM( TDOC_STREAM_CONTENT_TYPE ) ) ) RTL_CONSTASCII_STRINGPARAM( TDOC_STREAM_CONTENT_TYPE ) ) )
...@@ -1679,6 +1726,18 @@ void Content::insert( const uno::Reference< io::XInputStream >& xData, ...@@ -1679,6 +1726,18 @@ void Content::insert( const uno::Reference< io::XInputStream >& xData,
Uri aUri( m_xIdentifier->getContentIdentifier() ); Uri aUri( m_xIdentifier->getContentIdentifier() );
#ifdef NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT
#if OSL_DEBUG_LEVEL > 0
if ( eType == STREAM )
{
Uri aParentUri( aUri.getParentUri() );
OSL_ENSURE( !aParentUri.isDocument(),
"insert command not supported by streams that are direct "
"children of document root!" );
}
#endif
#endif
// Check, if all required properties were set. // Check, if all required properties were set.
if ( eType == FOLDER ) if ( eType == FOLDER )
{ {
...@@ -2015,7 +2074,7 @@ void Content::transfer( ...@@ -2015,7 +2074,7 @@ void Content::transfer(
if ( !aScheme.equalsAsciiL( if ( !aScheme.equalsAsciiL(
RTL_CONSTASCII_STRINGPARAM( TDOC_URL_SCHEME ":/" ) ) ) RTL_CONSTASCII_STRINGPARAM( TDOC_URL_SCHEME ":/" ) ) )
{ {
// Invaild scheme. // Invalid scheme.
ucbhelper::cancelCommandExecution( ucbhelper::cancelCommandExecution(
uno::makeAny( star::ucb::InteractiveBadTransferURLException( uno::makeAny( star::ucb::InteractiveBadTransferURLException(
rtl::OUString(), rtl::OUString(),
...@@ -2083,6 +2142,63 @@ void Content::transfer( ...@@ -2083,6 +2142,63 @@ void Content::transfer(
} }
} }
#ifdef NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT
if ( m_aProps.getType() == DOCUMENT )
{
bool bOK = false;
uno::Reference< embed::XStorage > xStorage
= m_pProvider->queryStorage(
aSourceUri.getParentUri(), READ_WRITE_NOCREATE );
if ( xStorage.is() )
{
try
{
if ( xStorage->isStreamElement( aSourceUri.getDecodedName() ) )
{
ucbhelper::cancelCommandExecution(
uno::makeAny( lang::IllegalArgumentException(
rtl::OUString::createFromAscii(
"Invalid source URI! "
"Streams cannot be created as "
"children of document root!" ),
static_cast< cppu::OWeakObject * >(
this ),
-1 ) ),
xEnv );
// Unreachable
}
bOK = true;
}
catch ( container::NoSuchElementException const & )
{
// handled below.
}
catch ( lang::IllegalArgumentException const & )
{
// handled below.
}
catch ( embed::InvalidStorageException const & )
{
// handled below.
}
}
if ( !bOK )
{
ucbhelper::cancelCommandExecution(
uno::makeAny( lang::IllegalArgumentException(
rtl::OUString::createFromAscii(
"Invalid source URI! "
"Unabale to determine source type!" ),
static_cast< cppu::OWeakObject * >( this ),
-1 ) ),
xEnv );
// Unreachable
}
}
#endif
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// Copy data. // Copy data.
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
...@@ -2392,16 +2508,6 @@ bool Content::loadData( ContentProvider* pProvider, ...@@ -2392,16 +2508,6 @@ bool Content::loadData( ContentProvider* pProvider,
} }
//========================================================================= //=========================================================================
#ifdef STORAGE_CREATION_WORKAROUND
static uno::Reference< io::XOutputStream > lcl_getTruncatedOutputStream(
const rtl::OUString & rUri,
ContentProvider * pProvider,
const uno::Reference< star::ucb::XCommandEnvironment > & xEnv )
throw ( star::ucb::CommandFailedException,
task::DocumentPasswordRequest );
#endif /* STORAGE_CREATION_WORKAROUND */
bool Content::storeData( const uno::Reference< io::XInputStream >& xData, bool Content::storeData( const uno::Reference< io::XInputStream >& xData,
const uno::Reference< const uno::Reference<
star::ucb::XCommandEnvironment >& xEnv ) star::ucb::XCommandEnvironment >& xEnv )
...@@ -2466,33 +2572,6 @@ bool Content::storeData( const uno::Reference< io::XInputStream >& xData, ...@@ -2466,33 +2572,6 @@ bool Content::storeData( const uno::Reference< io::XInputStream >& xData,
return false; return false;
} }
#ifdef STORAGE_CREATION_WORKAROUND
// @@@ workaround(!) - current Storage API implementation does not
// support empty substorages (<-- MAV). Final solution will do.
// As a workaround we currently put a dummy file into the newly
// created substorage.
uno::Reference< io::XOutputStream > xOut;
if ( m_eState == TRANSIENT )
{
rtl::OUStringBuffer aDummyStreamUri( aUri.getUri() );
if ( aUri.getUri()[ aUri.getUri().getLength() - 1 ]
!= sal_Unicode( '/' ) )
aDummyStreamUri.appendAscii( "/" );
aDummyStreamUri.appendAscii(
"this_is_a_dummy_stream_just_there_as_a_workaround_for_a_"
"temporary_limitation_of_the_storage_api_implementation" );
// May throw CommandFailedException, DocumentPasswordRequest!
xOut = lcl_getTruncatedOutputStream(
aDummyStreamUri.makeStringAndClear(), m_pProvider, xEnv );
OSL_ENSURE( xOut.is(), "No target data stream!" );
closeOutputStream( xOut );
}
#endif /* STORAGE_CREATION_WORKAROUND */
if ( !commitStorage( xStorage ) ) if ( !commitStorage( xStorage ) )
return false; return false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment