summaryrefslogtreecommitdiff
path: root/fileaccess
diff options
context:
space:
mode:
authorOliver Bolte <obo@openoffice.org>2004-05-28 14:19:28 +0000
committerOliver Bolte <obo@openoffice.org>2004-05-28 14:19:28 +0000
commit9b1da200540d8ba0c2ff425c1292c9117909e663 (patch)
tree2bf2a0d0deb556f3cc16f74b2c735dba425319b1 /fileaccess
parent393ec1be16e7c0dac7727bdf9ef0276d4bf42be2 (diff)
INTEGRATION: CWS tdocfixes1 (1.19.56); FILE MERGED
2004/05/19 12:02:27 kso 1.19.56.1: #i29320# - Fixed OFileAccess::writeFile to create non-existing resources.
Diffstat (limited to 'fileaccess')
-rw-r--r--fileaccess/source/FileAccess.cxx127
1 files changed, 113 insertions, 14 deletions
diff --git a/fileaccess/source/FileAccess.cxx b/fileaccess/source/FileAccess.cxx
index cdcdb411fb..88011dfbad 100644
--- a/fileaccess/source/FileAccess.cxx
+++ b/fileaccess/source/FileAccess.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: FileAccess.cxx,v $
*
- * $Revision: 1.19 $
+ * $Revision: 1.20 $
*
- * last change: $Author: rt $ $Date: 2003-04-23 16:55:13 $
+ * last change: $Author: obo $ $Date: 2004-05-28 15:19:28 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -122,6 +122,10 @@ class OFileAccess : public FileAccessHelper
void transferImpl( const rtl::OUString& rSource, const rtl::OUString& rDest, sal_Bool bMoveData )
throw(CommandAbortedException, Exception, RuntimeException);
+ bool createNewFile( const rtl::OUString & rParentURL,
+ const rtl::OUString & rTitle,
+ const Reference< XInputStream >& data )
+ throw ( Exception );
public:
OFileAccess() : mpEnvironment( NULL ) {}
@@ -665,22 +669,117 @@ void OFileAccess::setInteractionHandler( const Reference< XInteractionHandler >&
mpEnvironment->setHandler( Handler );
}
+bool OFileAccess::createNewFile( const rtl::OUString & rParentURL,
+ const rtl::OUString & rTitle,
+ const Reference< XInputStream >& data )
+ throw ( Exception )
+{
+ ucb::Content aParentCnt( rParentURL, mxEnvironment );
+
+ Reference< XContentCreator > xCreator
+ = Reference< XContentCreator >( aParentCnt.get(), UNO_QUERY );
+ if ( xCreator.is() )
+ {
+ Sequence< ContentInfo > aInfo = xCreator->queryCreatableContentsInfo();
+ sal_Int32 nCount = aInfo.getLength();
+ if ( nCount == 0 )
+ return false;
+
+ for ( sal_Int32 i = 0; i < nCount; ++i )
+ {
+ const ContentInfo & rCurr = aInfo[i];
+ if ( ( rCurr.Attributes
+ & ContentInfoAttribute::KIND_DOCUMENT ) &&
+ ( rCurr.Attributes
+ & ContentInfoAttribute::INSERT_WITH_INPUTSTREAM ) )
+ {
+ // Make sure the only required bootstrap property is
+ // "Title",
+ const Sequence< Property > & rProps = rCurr.Properties;
+ if ( rProps.getLength() != 1 )
+ continue;
+
+ if ( !rProps[ 0 ].Name.equalsAsciiL(
+ RTL_CONSTASCII_STRINGPARAM( "Title" ) ) )
+ continue;
+
+ Sequence<rtl::OUString> aNames(1);
+ rtl::OUString* pNames = aNames.getArray();
+ pNames[0] = rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM( "Title" ) );
+ Sequence< Any > aValues(1);
+ Any* pValues = aValues.getArray();
+ pValues[0] = makeAny( rtl::OUString( rTitle ) );
+
+ try
+ {
+ ucb::Content aNew;
+ if ( aParentCnt.insertNewContent(
+ rCurr.Type, aNames, aValues, data, aNew ) )
+ return true; // success.
+ else
+ continue;
+ }
+ catch ( CommandFailedException const & )
+ {
+ // Interaction Handler already handled the
+ // error that has occured...
+ continue;
+ }
+ }
+ }
+ }
+
+ return false;
+}
void SAL_CALL OFileAccess::writeFile( const rtl::OUString& FileURL,
const Reference< XInputStream >& data )
throw ( Exception, RuntimeException )
{
- INetURLObject aObj( FileURL, INET_PROT_FILE );
- ucb::Content aCnt(
- aObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment );
-
+ INetURLObject aURL( FileURL, INET_PROT_FILE );
try
{
- aCnt.writeStream( data, sal_True /* bReplaceExisting */ );
+ ucb::Content aCnt(
+ aURL.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment );
+
+ try
+ {
+ aCnt.writeStream( data, sal_True /* bReplaceExisting */ );
+ }
+ catch ( CommandFailedException const & )
+ {
+ // Interaction Handler already handled the error that has occured...
+ }
}
- catch ( ::com::sun::star::ucb::CommandFailedException const & )
+ catch ( ContentCreationException const & e )
{
- // Interaction Handler already handled the error that has occured...
+ // Most probably file does not exist. Try to create.
+ if ( e.eError == ContentCreationError_CONTENT_CREATION_FAILED )
+ {
+ INetURLObject aParentURLObj( aURL );
+ if ( aParentURLObj.removeSegment() )
+ {
+ String aParentURL
+ = aParentURLObj.GetMainURL( INetURLObject::NO_DECODE );
+
+ // ensure all parent folders exist.
+ createFolder( aParentURL );
+
+ // create the new file...
+ String aTitle
+ = aURL.getName( INetURLObject::LAST_SEGMENT,
+ true,
+ INetURLObject::DECODE_WITH_CHARSET );
+ if ( createNewFile( aParentURL, aTitle, data ) )
+ {
+ // success
+ return;
+ }
+ }
+ }
+
+ throw;
}
}
@@ -695,7 +794,7 @@ sal_Bool OFileAccess::isHidden( const ::rtl::OUString& FileURL )
return bRet;
}
-void OFileAccess::setHidden( const ::rtl::OUString& FileURL, sal_Bool bHidden )
+void OFileAccess::setHidden( const ::rtl::OUString& FileURL, sal_Bool bHidden )
throw(CommandAbortedException, Exception, RuntimeException)
{
INetURLObject aURLObj( FileURL, INET_PROT_FILE );
@@ -705,6 +804,10 @@ void OFileAccess::setHidden( const ::rtl::OUString& FileURL, sal_Bool bHidden )
aCnt.setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsHidden" ) ), aAny );
}
+//==================================================================================================
+//==================================================================================================
+//==================================================================================================
+
Reference< XInterface > SAL_CALL FileAccess_CreateInstance( const Reference< XMultiServiceFactory > &)
{
return Reference < XInterface >( ( cppu::OWeakObject * ) new OFileAccess );
@@ -730,10 +833,6 @@ Sequence< rtl::OUString > FileAccess_getSupportedServiceNames()
}
-
-
-
-
//==================================================================================================
// Component exports