18be892b1SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 38be892b1SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 48be892b1SAndrew Rist * or more contributor license agreements. See the NOTICE file 58be892b1SAndrew Rist * distributed with this work for additional information 68be892b1SAndrew Rist * regarding copyright ownership. The ASF licenses this file 78be892b1SAndrew Rist * to you under the Apache License, Version 2.0 (the 88be892b1SAndrew Rist * "License"); you may not use this file except in compliance 98be892b1SAndrew Rist * with the License. You may obtain a copy of the License at 108be892b1SAndrew Rist * 118be892b1SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 128be892b1SAndrew Rist * 138be892b1SAndrew Rist * Unless required by applicable law or agreed to in writing, 148be892b1SAndrew Rist * software distributed under the License is distributed on an 158be892b1SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 168be892b1SAndrew Rist * KIND, either express or implied. See the License for the 178be892b1SAndrew Rist * specific language governing permissions and limitations 188be892b1SAndrew Rist * under the License. 198be892b1SAndrew Rist * 208be892b1SAndrew Rist *************************************************************/ 218be892b1SAndrew Rist 228be892b1SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include <osl/mutex.hxx> 25cdf0e10cSrcweir #include <osl/diagnose.h> 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <uno/mapping.hxx> 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 30cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <tools/ref.hxx> 33cdf0e10cSrcweir #include <tools/urlobj.hxx> 34cdf0e10cSrcweir #include <ucbhelper/content.hxx> 35cdf0e10cSrcweir #include <unotools/streamwrap.hxx> 36cdf0e10cSrcweir #include <tools/stream.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include <com/sun/star/beans/Property.hpp> 39cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 40cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp> 41cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp> 42cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp> 43cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataStreamer.hpp> 44cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp> 45cdf0e10cSrcweir #include <com/sun/star/ucb/CommandFailedException.hpp> 46cdf0e10cSrcweir #include <com/sun/star/ucb/ContentInfo.hpp> 47cdf0e10cSrcweir #include <com/sun/star/ucb/ContentInfoAttribute.hpp> 48cdf0e10cSrcweir #include <com/sun/star/ucb/InsertCommandArgument.hpp> 49cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveIOException.hpp> 50cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp> 51cdf0e10cSrcweir #include <com/sun/star/ucb/NameClashException.hpp> 52cdf0e10cSrcweir #include <com/sun/star/ucb/OpenCommandArgument2.hpp> 53cdf0e10cSrcweir #include <com/sun/star/ucb/OpenMode.hpp> 54cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp> 55cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp> 56cdf0e10cSrcweir #include <com/sun/star/ucb/XContentAccess.hpp> 57cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess3.hpp> 58cdf0e10cSrcweir #include <com/sun/star/util/XMacroExpander.hpp> 59cdf0e10cSrcweir 60cdf0e10cSrcweir #define IMPLEMENTATION_NAME "com.sun.star.comp.ucb.SimpleFileAccess" 61cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.ucb.SimpleFileAccess" 62cdf0e10cSrcweir 63cdf0e10cSrcweir using namespace ::com::sun::star::uno; 64cdf0e10cSrcweir using namespace ::com::sun::star::lang; 65cdf0e10cSrcweir using namespace ::com::sun::star::io; 66cdf0e10cSrcweir using namespace ::com::sun::star::ucb; 67cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 68cdf0e10cSrcweir using namespace ::com::sun::star::task; 69cdf0e10cSrcweir using namespace ::com::sun::star::util; 70cdf0e10cSrcweir using namespace ::com::sun::star::beans; 71cdf0e10cSrcweir using namespace ::com::sun::star::registry; 72cdf0e10cSrcweir using namespace ::com::sun::star::container; 73cdf0e10cSrcweir 74cdf0e10cSrcweir namespace io_FileAccess 75cdf0e10cSrcweir { 76cdf0e10cSrcweir 77cdf0e10cSrcweir 78cdf0e10cSrcweir //=========================================================================== 79cdf0e10cSrcweir // Implementation XSimpleFileAccess 80cdf0e10cSrcweir 81cdf0e10cSrcweir typedef cppu::WeakImplHelper1< XSimpleFileAccess3 > FileAccessHelper; 82cdf0e10cSrcweir class OCommandEnvironment; 83cdf0e10cSrcweir 84cdf0e10cSrcweir class OFileAccess : public FileAccessHelper 85cdf0e10cSrcweir { 86cdf0e10cSrcweir Reference< XMultiServiceFactory > mxSMgr; 87cdf0e10cSrcweir Reference< XCommandEnvironment > mxEnvironment; 88cdf0e10cSrcweir OCommandEnvironment* mpEnvironment; 89cdf0e10cSrcweir 90cdf0e10cSrcweir void transferImpl( const rtl::OUString& rSource, const rtl::OUString& rDest, sal_Bool bMoveData ) 91cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException); 92cdf0e10cSrcweir bool createNewFile( const rtl::OUString & rParentURL, 93cdf0e10cSrcweir const rtl::OUString & rTitle, 94cdf0e10cSrcweir const Reference< XInputStream >& data ) 95cdf0e10cSrcweir throw ( Exception ); 96cdf0e10cSrcweir 97cdf0e10cSrcweir public: 98cdf0e10cSrcweir OFileAccess( const Reference< XMultiServiceFactory > & xSMgr ) 99cdf0e10cSrcweir : mxSMgr( xSMgr), mpEnvironment( NULL ) {} 100cdf0e10cSrcweir 101cdf0e10cSrcweir // Methods 102cdf0e10cSrcweir virtual void SAL_CALL copy( const ::rtl::OUString& SourceURL, const ::rtl::OUString& DestURL ) throw(::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 103cdf0e10cSrcweir virtual void SAL_CALL move( const ::rtl::OUString& SourceURL, const ::rtl::OUString& DestURL ) throw(::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 104cdf0e10cSrcweir virtual void SAL_CALL kill( const ::rtl::OUString& FileURL ) throw(::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 105cdf0e10cSrcweir virtual sal_Bool SAL_CALL isFolder( const ::rtl::OUString& FileURL ) throw(::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 106cdf0e10cSrcweir virtual sal_Bool SAL_CALL isReadOnly( const ::rtl::OUString& FileURL ) throw(::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 107cdf0e10cSrcweir virtual void SAL_CALL setReadOnly( const ::rtl::OUString& FileURL, sal_Bool bReadOnly ) throw(::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 108cdf0e10cSrcweir virtual void SAL_CALL createFolder( const ::rtl::OUString& NewFolderURL ) throw(::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 109cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getSize( const ::rtl::OUString& FileURL ) throw(::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 110cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getContentType( const ::rtl::OUString& FileURL ) throw(::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 111cdf0e10cSrcweir virtual ::com::sun::star::util::DateTime SAL_CALL getDateTimeModified( const ::rtl::OUString& FileURL ) throw(::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 112cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getFolderContents( const ::rtl::OUString& FolderURL, sal_Bool bIncludeFolders ) throw(::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 113cdf0e10cSrcweir virtual sal_Bool SAL_CALL exists( const ::rtl::OUString& FileURL ) throw(::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 114cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL openFileRead( const ::rtl::OUString& FileURL ) throw(::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 115cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL openFileWrite( const ::rtl::OUString& FileURL ) throw(::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 116cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL openFileReadWrite( const ::rtl::OUString& FileURL ) throw(::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 117cdf0e10cSrcweir virtual void SAL_CALL setInteractionHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ) throw(::com::sun::star::uno::RuntimeException); 118cdf0e10cSrcweir virtual void SAL_CALL writeFile( const ::rtl::OUString& FileURL, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& data ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 119cdf0e10cSrcweir virtual sal_Bool SAL_CALL isHidden( const ::rtl::OUString& FileURL ) throw(::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 120cdf0e10cSrcweir virtual void SAL_CALL setHidden( const ::rtl::OUString& FileURL, sal_Bool bHidden ) throw(::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 121cdf0e10cSrcweir }; 122cdf0e10cSrcweir 123cdf0e10cSrcweir 124cdf0e10cSrcweir //=========================================================================== 125cdf0e10cSrcweir // Implementation XActiveDataSink 126cdf0e10cSrcweir 127cdf0e10cSrcweir typedef cppu::WeakImplHelper1< XActiveDataSink > ActiveDataSinkHelper; 128cdf0e10cSrcweir 129cdf0e10cSrcweir class OActiveDataSink : public ActiveDataSinkHelper 130cdf0e10cSrcweir { 131cdf0e10cSrcweir Reference< XInputStream > mxStream; 132cdf0e10cSrcweir 133cdf0e10cSrcweir public: 134cdf0e10cSrcweir 135cdf0e10cSrcweir // Methods 136cdf0e10cSrcweir virtual void SAL_CALL setInputStream( const Reference< XInputStream >& aStream ) 137cdf0e10cSrcweir throw(RuntimeException); 138cdf0e10cSrcweir virtual Reference< XInputStream > SAL_CALL getInputStream( ) 139cdf0e10cSrcweir throw(RuntimeException); 140cdf0e10cSrcweir }; 141cdf0e10cSrcweir 142cdf0e10cSrcweir void OActiveDataSink::setInputStream( const Reference< XInputStream >& aStream ) 143cdf0e10cSrcweir throw(RuntimeException) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir mxStream = aStream; 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir Reference< XInputStream > OActiveDataSink::getInputStream() 149cdf0e10cSrcweir throw(RuntimeException) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir return mxStream; 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir 155cdf0e10cSrcweir //=========================================================================== 156cdf0e10cSrcweir // Implementation XActiveDataSource 157cdf0e10cSrcweir 158cdf0e10cSrcweir typedef cppu::WeakImplHelper1< XActiveDataSource > ActiveDataSourceHelper; 159cdf0e10cSrcweir 160cdf0e10cSrcweir class OActiveDataSource : public ActiveDataSourceHelper 161cdf0e10cSrcweir { 162cdf0e10cSrcweir Reference< XOutputStream > mxStream; 163cdf0e10cSrcweir 164cdf0e10cSrcweir public: 165cdf0e10cSrcweir 166cdf0e10cSrcweir // Methods 167cdf0e10cSrcweir virtual void SAL_CALL setOutputStream( const Reference< XOutputStream >& aStream ) 168cdf0e10cSrcweir throw(RuntimeException); 169cdf0e10cSrcweir virtual Reference< XOutputStream > SAL_CALL getOutputStream() 170cdf0e10cSrcweir throw(RuntimeException); 171cdf0e10cSrcweir }; 172cdf0e10cSrcweir 173cdf0e10cSrcweir void OActiveDataSource::setOutputStream( const Reference< XOutputStream >& aStream ) 174cdf0e10cSrcweir throw(RuntimeException) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir mxStream = aStream; 177cdf0e10cSrcweir } 178cdf0e10cSrcweir 179cdf0e10cSrcweir Reference< XOutputStream > OActiveDataSource::getOutputStream() 180cdf0e10cSrcweir throw(RuntimeException) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir return mxStream; 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir 186cdf0e10cSrcweir //=========================================================================== 187cdf0e10cSrcweir // Implementation XActiveDataStreamer 188cdf0e10cSrcweir 189cdf0e10cSrcweir typedef cppu::WeakImplHelper1< XActiveDataStreamer > ActiveDataStreamerHelper; 190cdf0e10cSrcweir 191cdf0e10cSrcweir class OActiveDataStreamer : public ActiveDataStreamerHelper 192cdf0e10cSrcweir { 193cdf0e10cSrcweir Reference< XStream > mxStream; 194cdf0e10cSrcweir 195cdf0e10cSrcweir public: 196cdf0e10cSrcweir 197cdf0e10cSrcweir // Methods 198cdf0e10cSrcweir virtual void SAL_CALL setStream( const Reference< XStream >& aStream ) 199cdf0e10cSrcweir throw(RuntimeException); 200cdf0e10cSrcweir virtual Reference< XStream > SAL_CALL getStream() 201cdf0e10cSrcweir throw(RuntimeException); 202cdf0e10cSrcweir }; 203cdf0e10cSrcweir 204cdf0e10cSrcweir void OActiveDataStreamer::setStream( const Reference< XStream >& aStream ) 205cdf0e10cSrcweir throw(RuntimeException) 206cdf0e10cSrcweir { 207cdf0e10cSrcweir mxStream = aStream; 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir Reference< XStream > OActiveDataStreamer::getStream() 211cdf0e10cSrcweir throw(RuntimeException) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir return mxStream; 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir 217cdf0e10cSrcweir 218cdf0e10cSrcweir //=========================================================================== 219cdf0e10cSrcweir // Implementation XCommandEnvironment 220cdf0e10cSrcweir 221cdf0e10cSrcweir typedef cppu::WeakImplHelper1< XCommandEnvironment > CommandEnvironmentHelper; 222cdf0e10cSrcweir 223cdf0e10cSrcweir class OCommandEnvironment : public CommandEnvironmentHelper 224cdf0e10cSrcweir { 225cdf0e10cSrcweir Reference< XInteractionHandler > mxInteraction; 226cdf0e10cSrcweir 227cdf0e10cSrcweir public: 228cdf0e10cSrcweir void setHandler( Reference< XInteractionHandler > xInteraction_ ) 229cdf0e10cSrcweir { 230cdf0e10cSrcweir mxInteraction = xInteraction_; 231cdf0e10cSrcweir } 232cdf0e10cSrcweir 233cdf0e10cSrcweir // Methods 234cdf0e10cSrcweir virtual Reference< XInteractionHandler > SAL_CALL getInteractionHandler() 235cdf0e10cSrcweir throw(RuntimeException); 236cdf0e10cSrcweir virtual Reference< XProgressHandler > SAL_CALL getProgressHandler() 237cdf0e10cSrcweir throw(RuntimeException); 238cdf0e10cSrcweir }; 239cdf0e10cSrcweir 240cdf0e10cSrcweir Reference< XInteractionHandler > OCommandEnvironment::getInteractionHandler() 241cdf0e10cSrcweir throw(RuntimeException) 242cdf0e10cSrcweir { 243cdf0e10cSrcweir return mxInteraction; 244cdf0e10cSrcweir } 245cdf0e10cSrcweir 246cdf0e10cSrcweir Reference< XProgressHandler > OCommandEnvironment::getProgressHandler() 247cdf0e10cSrcweir throw(RuntimeException) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir Reference< XProgressHandler > xRet; 250cdf0e10cSrcweir return xRet; 251cdf0e10cSrcweir } 252cdf0e10cSrcweir 253cdf0e10cSrcweir //=========================================================================== 254cdf0e10cSrcweir 255cdf0e10cSrcweir void OFileAccess::transferImpl( const rtl::OUString& rSource, 256cdf0e10cSrcweir const rtl::OUString& rDest, 257cdf0e10cSrcweir sal_Bool bMoveData ) 258cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException) 259cdf0e10cSrcweir { 260cdf0e10cSrcweir // SfxContentHelper::Transfer_Impl 261cdf0e10cSrcweir INetURLObject aSourceObj( rSource, INET_PROT_FILE ); 262cdf0e10cSrcweir INetURLObject aDestObj( rDest, INET_PROT_FILE ); 263cdf0e10cSrcweir String aName = aDestObj.getName( 264cdf0e10cSrcweir INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); 265cdf0e10cSrcweir String aDestURL; 266cdf0e10cSrcweir String aSourceURL = aSourceObj.GetMainURL( INetURLObject::NO_DECODE ); 267cdf0e10cSrcweir if ( aDestObj.removeSegment() ) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir // hierarchical URL. 270cdf0e10cSrcweir 271cdf0e10cSrcweir aDestObj.setFinalSlash(); 272cdf0e10cSrcweir aDestURL = aDestObj.GetMainURL( INetURLObject::NO_DECODE ); 273cdf0e10cSrcweir } 274cdf0e10cSrcweir else 275cdf0e10cSrcweir { 276cdf0e10cSrcweir // non-hierachical URL 277cdf0e10cSrcweir 278cdf0e10cSrcweir // #i29648# 279cdf0e10cSrcweir // 280cdf0e10cSrcweir #if 0 281*07a3d7f1SPedro Giffuni // Note: A hierarchical UCB content implements interface XChild, which 282cdf0e10cSrcweir // has a method getParent(). Unfortunately this does not always help 283cdf0e10cSrcweir // here, because it is not guaranteed that a content object for a 284cdf0e10cSrcweir // non-existing resource can be created. Thus, it will happen that an 285cdf0e10cSrcweir // exception is thrown when trying to create a UCB content for the 286cdf0e10cSrcweir // destination URL. 287cdf0e10cSrcweir 288cdf0e10cSrcweir try 289cdf0e10cSrcweir { 290cdf0e10cSrcweir ucbhelper::Content aFullDest( 291cdf0e10cSrcweir aDestObj.GetMainURL( 292cdf0e10cSrcweir INetURLObject::NO_DECODE ), mxEnvironment ); 293cdf0e10cSrcweir 294cdf0e10cSrcweir Reference< XChild > xChild( aFullDest.get(), UNO_QUERY_THROW ); 295cdf0e10cSrcweir Reference< com::sun::star::ucb::XContent > 296cdf0e10cSrcweir xParent( xChild->getParent(), UNO_QUERY_THROW ); 297cdf0e10cSrcweir ucbhelper::Content aParent( xParent, mxEnvironment ); 298cdf0e10cSrcweir 299cdf0e10cSrcweir aDestURL = aParent.getURL(); 300cdf0e10cSrcweir 301cdf0e10cSrcweir rtl::OUString aNameTmp; 302cdf0e10cSrcweir aFullDest.getPropertyValue( 303cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ) ) 304cdf0e10cSrcweir >>= aNameTmp; 305cdf0e10cSrcweir aName = aNameTmp; 306cdf0e10cSrcweir } 307cdf0e10cSrcweir catch ( Exception const & ) 308cdf0e10cSrcweir { 309cdf0e10cSrcweir throw RuntimeException( 310cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 311cdf0e10cSrcweir "OFileAccess::transferrImpl - Unable to " 312cdf0e10cSrcweir "obtain destination folder URL!" ) ), 313cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 314cdf0e10cSrcweir } 315cdf0e10cSrcweir #else 316cdf0e10cSrcweir if ( aDestObj.GetProtocol() == INET_PROT_VND_SUN_STAR_EXPAND ) 317cdf0e10cSrcweir { 318cdf0e10cSrcweir // Hack: Expand destination URL using Macro Expander and try again 319cdf0e10cSrcweir // with the hopefully hierarchical expanded URL... 320cdf0e10cSrcweir 321cdf0e10cSrcweir try 322cdf0e10cSrcweir { 323cdf0e10cSrcweir Reference< XComponentContext > xCtx; 324cdf0e10cSrcweir Reference< XPropertySet > xPropSet( mxSMgr, UNO_QUERY_THROW ); 325cdf0e10cSrcweir if ( xPropSet.is() ) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir xPropSet->getPropertyValue( 328cdf0e10cSrcweir rtl::OUString( 329cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) ) 330cdf0e10cSrcweir >>= xCtx; 331cdf0e10cSrcweir } 332cdf0e10cSrcweir 333cdf0e10cSrcweir Reference< XMacroExpander > xExpander; 334cdf0e10cSrcweir 335cdf0e10cSrcweir xCtx->getValueByName( 336cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 337cdf0e10cSrcweir "/singletons/com.sun.star.util.theMacroExpander" ) ) ) 338cdf0e10cSrcweir >>= xExpander; 339cdf0e10cSrcweir 340cdf0e10cSrcweir OSL_ENSURE( xExpander.is(), 341cdf0e10cSrcweir "Unable to obtain macro expander singleton!" ); 342cdf0e10cSrcweir 343cdf0e10cSrcweir aDestURL = xExpander->expandMacros( 344cdf0e10cSrcweir aDestObj.GetURLPath( INetURLObject::DECODE_WITH_CHARSET ) ); 345cdf0e10cSrcweir } 346cdf0e10cSrcweir catch ( Exception const & ) 347cdf0e10cSrcweir { 348cdf0e10cSrcweir throw RuntimeException( 349cdf0e10cSrcweir rtl::OUString( 350cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 351cdf0e10cSrcweir "OFileAccess::transferrImpl - Unable to obtain " 352cdf0e10cSrcweir "destination folder URL!" ) ), 353cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 354cdf0e10cSrcweir } 355cdf0e10cSrcweir 356cdf0e10cSrcweir transferImpl( rSource, aDestURL, bMoveData ); 357cdf0e10cSrcweir return; 358cdf0e10cSrcweir } 359cdf0e10cSrcweir 360cdf0e10cSrcweir throw RuntimeException( 361cdf0e10cSrcweir rtl::OUString( 362cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 363cdf0e10cSrcweir "OFileAccess::transferrImpl - Unable to obtain " 364cdf0e10cSrcweir "destination folder URL!" ) ), 365cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 366cdf0e10cSrcweir #endif 367cdf0e10cSrcweir } 368cdf0e10cSrcweir 369cdf0e10cSrcweir ucbhelper::Content aDestPath( aDestURL, mxEnvironment ); 370cdf0e10cSrcweir ucbhelper::Content aSrc ( aSourceURL, mxEnvironment ); 371cdf0e10cSrcweir 372cdf0e10cSrcweir try 373cdf0e10cSrcweir { 374cdf0e10cSrcweir aDestPath.transferContent( aSrc, 375cdf0e10cSrcweir bMoveData 376cdf0e10cSrcweir ? ucbhelper::InsertOperation_MOVE 377cdf0e10cSrcweir : ucbhelper::InsertOperation_COPY, 378cdf0e10cSrcweir aName, 379cdf0e10cSrcweir ::com::sun::star::ucb::NameClash::OVERWRITE ); 380cdf0e10cSrcweir } 381cdf0e10cSrcweir catch ( ::com::sun::star::ucb::CommandFailedException const & ) 382cdf0e10cSrcweir { 383*07a3d7f1SPedro Giffuni // Interaction Handler already handled the error that has occurred... 384cdf0e10cSrcweir } 385cdf0e10cSrcweir } 386cdf0e10cSrcweir 387cdf0e10cSrcweir void OFileAccess::copy( const rtl::OUString& SourceURL, const rtl::OUString& DestURL ) 388cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException) 389cdf0e10cSrcweir { 390cdf0e10cSrcweir transferImpl( SourceURL, DestURL, sal_False ); 391cdf0e10cSrcweir } 392cdf0e10cSrcweir 393cdf0e10cSrcweir void OFileAccess::move( const rtl::OUString& SourceURL, const rtl::OUString& DestURL ) 394cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir transferImpl( SourceURL, DestURL, sal_True ); 397cdf0e10cSrcweir } 398cdf0e10cSrcweir 399cdf0e10cSrcweir void OFileAccess::kill( const rtl::OUString& FileURL ) 400cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException) 401cdf0e10cSrcweir { 402cdf0e10cSrcweir // SfxContentHelper::Kill 403cdf0e10cSrcweir INetURLObject aDeleteObj( FileURL, INET_PROT_FILE ); 404cdf0e10cSrcweir ucbhelper::Content aCnt( aDeleteObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment ); 405cdf0e10cSrcweir try 406cdf0e10cSrcweir { 407cdf0e10cSrcweir aCnt.executeCommand( rtl::OUString::createFromAscii( "delete" ), makeAny( sal_Bool( sal_True ) ) ); 408cdf0e10cSrcweir } 409cdf0e10cSrcweir catch ( ::com::sun::star::ucb::CommandFailedException const & ) 410cdf0e10cSrcweir { 411*07a3d7f1SPedro Giffuni // Interaction Handler already handled the error that has occurred... 412cdf0e10cSrcweir } 413cdf0e10cSrcweir } 414cdf0e10cSrcweir 415cdf0e10cSrcweir sal_Bool OFileAccess::isFolder( const rtl::OUString& FileURL ) 416cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException) 417cdf0e10cSrcweir { 418cdf0e10cSrcweir sal_Bool bRet = sal_False; 419cdf0e10cSrcweir try 420cdf0e10cSrcweir { 421cdf0e10cSrcweir INetURLObject aURLObj( FileURL, INET_PROT_FILE ); 422cdf0e10cSrcweir ucbhelper::Content aCnt( aURLObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment ); 423cdf0e10cSrcweir bRet = aCnt.isFolder(); 424cdf0e10cSrcweir } 425cdf0e10cSrcweir catch (Exception &) {} 426cdf0e10cSrcweir return bRet; 427cdf0e10cSrcweir } 428cdf0e10cSrcweir 429cdf0e10cSrcweir sal_Bool OFileAccess::isReadOnly( const rtl::OUString& FileURL ) 430cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException) 431cdf0e10cSrcweir { 432cdf0e10cSrcweir INetURLObject aURLObj( FileURL, INET_PROT_FILE ); 433cdf0e10cSrcweir ucbhelper::Content aCnt( aURLObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment ); 434cdf0e10cSrcweir Any aRetAny = aCnt.getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ) ); 435cdf0e10cSrcweir sal_Bool bRet = sal_False; 436cdf0e10cSrcweir aRetAny >>= bRet; 437cdf0e10cSrcweir return bRet; 438cdf0e10cSrcweir } 439cdf0e10cSrcweir 440cdf0e10cSrcweir void OFileAccess::setReadOnly( const rtl::OUString& FileURL, sal_Bool bReadOnly ) 441cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException) 442cdf0e10cSrcweir { 443cdf0e10cSrcweir INetURLObject aURLObj( FileURL, INET_PROT_FILE ); 444cdf0e10cSrcweir ucbhelper::Content aCnt( aURLObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment ); 445cdf0e10cSrcweir Any aAny; 446cdf0e10cSrcweir aAny <<= bReadOnly; 447cdf0e10cSrcweir aCnt.setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ), aAny ); 448cdf0e10cSrcweir } 449cdf0e10cSrcweir 450cdf0e10cSrcweir void OFileAccess::createFolder( const rtl::OUString& NewFolderURL ) 451cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException) 452cdf0e10cSrcweir { 453cdf0e10cSrcweir // Does the folder already exist? 454cdf0e10cSrcweir if( !NewFolderURL.getLength() || isFolder( NewFolderURL ) ) 455cdf0e10cSrcweir return; 456cdf0e10cSrcweir 457cdf0e10cSrcweir // SfxContentHelper::MakeFolder 458cdf0e10cSrcweir INetURLObject aURL( NewFolderURL, INET_PROT_FILE ); 459cdf0e10cSrcweir String aNewFolderURLStr = aURL.GetMainURL( INetURLObject::NO_DECODE ); 460cdf0e10cSrcweir String aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); 461cdf0e10cSrcweir if ( aTitle.Len() ) 462cdf0e10cSrcweir { 463cdf0e10cSrcweir aURL.removeSegment(); 464cdf0e10cSrcweir 465cdf0e10cSrcweir // Does the base folder exist? Otherwise create it first 466cdf0e10cSrcweir String aBaseFolderURLStr = aURL.GetMainURL( INetURLObject::NO_DECODE ); 467cdf0e10cSrcweir if( !isFolder( aBaseFolderURLStr ) ) 468cdf0e10cSrcweir { 469cdf0e10cSrcweir createFolder( aBaseFolderURLStr ); 470cdf0e10cSrcweir } 471cdf0e10cSrcweir } 472cdf0e10cSrcweir 473cdf0e10cSrcweir ucbhelper::Content aCnt( aURL.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment ); 474cdf0e10cSrcweir 475cdf0e10cSrcweir Sequence< ContentInfo > aInfo = aCnt.queryCreatableContentsInfo(); 476cdf0e10cSrcweir sal_Int32 nCount = aInfo.getLength(); 477cdf0e10cSrcweir if ( nCount == 0 ) 478cdf0e10cSrcweir return; 479cdf0e10cSrcweir 480cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nCount; ++i ) 481cdf0e10cSrcweir { 482cdf0e10cSrcweir // Simply look for the first KIND_FOLDER... 483cdf0e10cSrcweir const ContentInfo & rCurr = aInfo[i]; 484cdf0e10cSrcweir if ( rCurr.Attributes & ContentInfoAttribute::KIND_FOLDER ) 485cdf0e10cSrcweir { 486cdf0e10cSrcweir // Make sure the only required bootstrap property is "Title", 487cdf0e10cSrcweir const Sequence< Property > & rProps = rCurr.Properties; 488cdf0e10cSrcweir if ( rProps.getLength() != 1 ) 489cdf0e10cSrcweir continue; 490cdf0e10cSrcweir 491cdf0e10cSrcweir if ( !rProps[ 0 ].Name.equalsAsciiL( 492cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "Title" ) ) ) 493cdf0e10cSrcweir continue; 494cdf0e10cSrcweir 495cdf0e10cSrcweir Sequence<rtl::OUString> aNames(1); 496cdf0e10cSrcweir rtl::OUString* pNames = aNames.getArray(); 497cdf0e10cSrcweir pNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ); 498cdf0e10cSrcweir Sequence< Any > aValues(1); 499cdf0e10cSrcweir Any* pValues = aValues.getArray(); 500cdf0e10cSrcweir pValues[0] = makeAny( rtl::OUString( aTitle ) ); 501cdf0e10cSrcweir 502cdf0e10cSrcweir ucbhelper::Content aNew; 503cdf0e10cSrcweir try 504cdf0e10cSrcweir { 505cdf0e10cSrcweir if ( !aCnt.insertNewContent( rCurr.Type, aNames, aValues, aNew ) ) 506cdf0e10cSrcweir continue; 507cdf0e10cSrcweir 508cdf0e10cSrcweir // Success. We're done. 509cdf0e10cSrcweir return; 510cdf0e10cSrcweir } 511cdf0e10cSrcweir catch ( ::com::sun::star::ucb::CommandFailedException const & ) 512cdf0e10cSrcweir { 513*07a3d7f1SPedro Giffuni // Interaction Handler already handled the error that has occurred... 514cdf0e10cSrcweir continue; 515cdf0e10cSrcweir } 516cdf0e10cSrcweir } 517cdf0e10cSrcweir } 518cdf0e10cSrcweir } 519cdf0e10cSrcweir 520cdf0e10cSrcweir sal_Int32 OFileAccess::getSize( const rtl::OUString& FileURL ) 521cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException) 522cdf0e10cSrcweir { 523cdf0e10cSrcweir // SfxContentHelper::GetSize 524cdf0e10cSrcweir sal_Int32 nSize = 0; 525cdf0e10cSrcweir sal_Int64 nTemp = 0; 526cdf0e10cSrcweir INetURLObject aObj( FileURL, INET_PROT_FILE ); 527cdf0e10cSrcweir ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment ); 528cdf0e10cSrcweir aCnt.getPropertyValue( rtl::OUString::createFromAscii( "Size" ) ) >>= nTemp; 529cdf0e10cSrcweir nSize = (sal_Int32)nTemp; 530cdf0e10cSrcweir return nSize; 531cdf0e10cSrcweir } 532cdf0e10cSrcweir 533cdf0e10cSrcweir rtl::OUString OFileAccess::getContentType( const rtl::OUString& FileURL ) 534cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException) 535cdf0e10cSrcweir { 536cdf0e10cSrcweir INetURLObject aObj( FileURL, INET_PROT_FILE ); 537cdf0e10cSrcweir ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment ); 538cdf0e10cSrcweir 539cdf0e10cSrcweir Reference< XContent > xContent = aCnt.get(); 540cdf0e10cSrcweir rtl::OUString aTypeStr = xContent->getContentType(); 541cdf0e10cSrcweir return aTypeStr; 542cdf0e10cSrcweir } 543cdf0e10cSrcweir 544cdf0e10cSrcweir DateTime OFileAccess::getDateTimeModified( const rtl::OUString& FileURL ) 545cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException) 546cdf0e10cSrcweir { 547cdf0e10cSrcweir INetURLObject aFileObj( FileURL, INET_PROT_FILE ); 548cdf0e10cSrcweir DateTime aDateTime; 549cdf0e10cSrcweir 550cdf0e10cSrcweir Reference< XCommandEnvironment > aCmdEnv; 551cdf0e10cSrcweir ucbhelper::Content aYoung( aFileObj.GetMainURL( INetURLObject::NO_DECODE ), aCmdEnv ); 552cdf0e10cSrcweir aYoung.getPropertyValue( rtl::OUString::createFromAscii( "DateModified" ) ) >>= aDateTime; 553cdf0e10cSrcweir return aDateTime; 554cdf0e10cSrcweir } 555cdf0e10cSrcweir 556cdf0e10cSrcweir 557cdf0e10cSrcweir DECLARE_LIST( StringList_Impl, rtl::OUString* ) 558cdf0e10cSrcweir 559cdf0e10cSrcweir Sequence< rtl::OUString > OFileAccess::getFolderContents( const rtl::OUString& FolderURL, sal_Bool bIncludeFolders ) 560cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException) 561cdf0e10cSrcweir { 562cdf0e10cSrcweir // SfxContentHelper::GetFolderContents 563cdf0e10cSrcweir 564cdf0e10cSrcweir StringList_Impl* pFiles = NULL; 565cdf0e10cSrcweir INetURLObject aFolderObj( FolderURL, INET_PROT_FILE ); 566cdf0e10cSrcweir 567cdf0e10cSrcweir ucbhelper::Content aCnt( aFolderObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment ); 568cdf0e10cSrcweir Reference< XResultSet > xResultSet; 569cdf0e10cSrcweir Sequence< rtl::OUString > aProps(0); 570cdf0e10cSrcweir //Sequence< rtl::OUString > aProps(1); 571cdf0e10cSrcweir //rtl::OUString* pProps = aProps.getArray(); 572cdf0e10cSrcweir //pProps[0] == rtl::OUString::createFromAscii( "Url" ); 573cdf0e10cSrcweir 574cdf0e10cSrcweir ucbhelper::ResultSetInclude eInclude = bIncludeFolders ? ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS : ucbhelper::INCLUDE_DOCUMENTS_ONLY; 575cdf0e10cSrcweir 576cdf0e10cSrcweir try 577cdf0e10cSrcweir { 578cdf0e10cSrcweir xResultSet = aCnt.createCursor( aProps, eInclude ); 579cdf0e10cSrcweir } 580cdf0e10cSrcweir catch ( ::com::sun::star::ucb::CommandFailedException const & ) 581cdf0e10cSrcweir { 582*07a3d7f1SPedro Giffuni // Interaction Handler already handled the error that has occurred... 583cdf0e10cSrcweir } 584cdf0e10cSrcweir 585cdf0e10cSrcweir if ( xResultSet.is() ) 586cdf0e10cSrcweir { 587cdf0e10cSrcweir pFiles = new StringList_Impl; 588cdf0e10cSrcweir Reference< com::sun::star::ucb::XContentAccess > xContentAccess( xResultSet, UNO_QUERY ); 589cdf0e10cSrcweir 590cdf0e10cSrcweir while ( xResultSet->next() ) 591cdf0e10cSrcweir { 592cdf0e10cSrcweir rtl::OUString aId = xContentAccess->queryContentIdentifierString(); 593cdf0e10cSrcweir INetURLObject aURL( aId, INET_PROT_FILE ); 594cdf0e10cSrcweir rtl::OUString* pFile = new rtl::OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ) ); 595cdf0e10cSrcweir pFiles->Insert( pFile, LIST_APPEND ); 596cdf0e10cSrcweir } 597cdf0e10cSrcweir } 598cdf0e10cSrcweir 599cdf0e10cSrcweir if ( pFiles ) 600cdf0e10cSrcweir { 601cdf0e10cSrcweir sal_uIntPtr nCount = pFiles->Count(); 602cdf0e10cSrcweir Sequence < rtl::OUString > aRet( nCount ); 603cdf0e10cSrcweir rtl::OUString* pRet = aRet.getArray(); 604cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nCount; ++i ) 605cdf0e10cSrcweir { 606cdf0e10cSrcweir rtl::OUString* pFile = pFiles->GetObject(i); 607cdf0e10cSrcweir pRet[i] = *( pFile ); 608cdf0e10cSrcweir delete pFile; 609cdf0e10cSrcweir } 610cdf0e10cSrcweir delete pFiles; 611cdf0e10cSrcweir return aRet; 612cdf0e10cSrcweir } 613cdf0e10cSrcweir else 614cdf0e10cSrcweir return Sequence < rtl::OUString > (); 615cdf0e10cSrcweir } 616cdf0e10cSrcweir 617cdf0e10cSrcweir sal_Bool OFileAccess::exists( const rtl::OUString& FileURL ) 618cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException) 619cdf0e10cSrcweir { 620cdf0e10cSrcweir sal_Bool bRet = sal_False; 621cdf0e10cSrcweir try 622cdf0e10cSrcweir { 623cdf0e10cSrcweir bRet = isFolder( FileURL ); 624cdf0e10cSrcweir if( !bRet ) 625cdf0e10cSrcweir { 626cdf0e10cSrcweir Reference< XInputStream > xStream = openFileRead( FileURL ); 627cdf0e10cSrcweir bRet = xStream.is(); 628cdf0e10cSrcweir if( bRet ) 629cdf0e10cSrcweir xStream->closeInput(); 630cdf0e10cSrcweir } 631cdf0e10cSrcweir } 632cdf0e10cSrcweir catch (Exception &) {} 633cdf0e10cSrcweir return bRet; 634cdf0e10cSrcweir } 635cdf0e10cSrcweir 636cdf0e10cSrcweir Reference< XInputStream > OFileAccess::openFileRead( const rtl::OUString& FileURL ) 637cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException) 638cdf0e10cSrcweir { 639cdf0e10cSrcweir Reference< XInputStream > xRet; 640cdf0e10cSrcweir INetURLObject aObj( FileURL, INET_PROT_FILE ); 641cdf0e10cSrcweir ucbhelper::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment ); 642cdf0e10cSrcweir 643cdf0e10cSrcweir Reference< XActiveDataSink > xSink = (XActiveDataSink*)(new OActiveDataSink()); 644cdf0e10cSrcweir 645cdf0e10cSrcweir try 646cdf0e10cSrcweir { 647cdf0e10cSrcweir sal_Bool bRet = aCnt.openStream( xSink ); 648cdf0e10cSrcweir if( bRet ) 649cdf0e10cSrcweir xRet = xSink->getInputStream(); 650cdf0e10cSrcweir } 651cdf0e10cSrcweir catch ( ::com::sun::star::ucb::CommandFailedException const & ) 652cdf0e10cSrcweir { 653*07a3d7f1SPedro Giffuni // Interaction Handler already handled the error that has occurred... 654cdf0e10cSrcweir } 655cdf0e10cSrcweir 656cdf0e10cSrcweir return xRet; 657cdf0e10cSrcweir } 658cdf0e10cSrcweir 659cdf0e10cSrcweir Reference< XOutputStream > OFileAccess::openFileWrite( const rtl::OUString& FileURL ) 660cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException) 661cdf0e10cSrcweir { 662cdf0e10cSrcweir Reference< XOutputStream > xRet; 663cdf0e10cSrcweir Reference< XStream > xStream = OFileAccess::openFileReadWrite( FileURL ); 664cdf0e10cSrcweir if( xStream.is() ) 665cdf0e10cSrcweir xRet = xStream->getOutputStream(); 666cdf0e10cSrcweir return xRet; 667cdf0e10cSrcweir } 668cdf0e10cSrcweir 669cdf0e10cSrcweir Reference< XStream > OFileAccess::openFileReadWrite( const rtl::OUString& FileURL ) 670cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException) 671cdf0e10cSrcweir { 672cdf0e10cSrcweir Reference< XActiveDataStreamer > xSink = (XActiveDataStreamer*)new OActiveDataStreamer(); 673cdf0e10cSrcweir Reference< XInterface > xSinkIface = Reference< XInterface >::query( xSink ); 674cdf0e10cSrcweir 675cdf0e10cSrcweir OpenCommandArgument2 aArg; 676cdf0e10cSrcweir aArg.Mode = OpenMode::DOCUMENT; 677cdf0e10cSrcweir aArg.Priority = 0; // unused 678cdf0e10cSrcweir aArg.Sink = xSink; 679cdf0e10cSrcweir aArg.Properties = Sequence< Property >( 0 ); // unused 680cdf0e10cSrcweir 681cdf0e10cSrcweir Any aCmdArg; 682cdf0e10cSrcweir aCmdArg <<= aArg; 683cdf0e10cSrcweir 684cdf0e10cSrcweir INetURLObject aFileObj( FileURL, INET_PROT_FILE ); 685cdf0e10cSrcweir ucbhelper::Content aCnt( aFileObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment ); 686cdf0e10cSrcweir 687cdf0e10cSrcweir // Be silent... 688cdf0e10cSrcweir Reference< XInteractionHandler > xIH; 689cdf0e10cSrcweir if ( mpEnvironment ) 690cdf0e10cSrcweir { 691cdf0e10cSrcweir xIH = mpEnvironment->getInteractionHandler(); 692cdf0e10cSrcweir mpEnvironment->setHandler( 0 ); 693cdf0e10cSrcweir } 694cdf0e10cSrcweir 695cdf0e10cSrcweir try 696cdf0e10cSrcweir { 697cdf0e10cSrcweir aCnt.executeCommand( rtl::OUString::createFromAscii( "open" ), aCmdArg ); 698cdf0e10cSrcweir } 699cdf0e10cSrcweir catch ( InteractiveIOException const & e ) 700cdf0e10cSrcweir { 701cdf0e10cSrcweir if ( xIH.is() ) 702cdf0e10cSrcweir mpEnvironment->setHandler( xIH ); 703cdf0e10cSrcweir 704cdf0e10cSrcweir if ( e.Code == IOErrorCode_NOT_EXISTING ) 705cdf0e10cSrcweir { 706cdf0e10cSrcweir // Create file... 707cdf0e10cSrcweir SvMemoryStream aStream(0,0); 708cdf0e10cSrcweir ::utl::OInputStreamWrapper* pInput = new ::utl::OInputStreamWrapper( aStream ); 709cdf0e10cSrcweir Reference< XInputStream > xInput( pInput ); 710cdf0e10cSrcweir InsertCommandArgument aInsertArg; 711cdf0e10cSrcweir aInsertArg.Data = xInput; 712cdf0e10cSrcweir aInsertArg.ReplaceExisting = sal_False; 713cdf0e10cSrcweir 714cdf0e10cSrcweir aCmdArg <<= aInsertArg; 715cdf0e10cSrcweir aCnt.executeCommand( rtl::OUString::createFromAscii( "insert" ), aCmdArg ); 716cdf0e10cSrcweir 717cdf0e10cSrcweir // Retry... 718cdf0e10cSrcweir return openFileReadWrite( FileURL ); 719cdf0e10cSrcweir } 720cdf0e10cSrcweir 721cdf0e10cSrcweir throw; 722cdf0e10cSrcweir } 723cdf0e10cSrcweir 724cdf0e10cSrcweir if ( xIH.is() ) 725cdf0e10cSrcweir mpEnvironment->setHandler( xIH ); 726cdf0e10cSrcweir 727cdf0e10cSrcweir Reference< XStream > xRet = xSink->getStream(); 728cdf0e10cSrcweir return xRet; 729cdf0e10cSrcweir } 730cdf0e10cSrcweir 731cdf0e10cSrcweir void OFileAccess::setInteractionHandler( const Reference< XInteractionHandler >& Handler ) 732cdf0e10cSrcweir throw(RuntimeException) 733cdf0e10cSrcweir { 734cdf0e10cSrcweir if( !mpEnvironment ) 735cdf0e10cSrcweir { 736cdf0e10cSrcweir mpEnvironment = new OCommandEnvironment(); 737cdf0e10cSrcweir mxEnvironment = (XCommandEnvironment*)mpEnvironment; 738cdf0e10cSrcweir } 739cdf0e10cSrcweir mpEnvironment->setHandler( Handler ); 740cdf0e10cSrcweir } 741cdf0e10cSrcweir 742cdf0e10cSrcweir bool OFileAccess::createNewFile( const rtl::OUString & rParentURL, 743cdf0e10cSrcweir const rtl::OUString & rTitle, 744cdf0e10cSrcweir const Reference< XInputStream >& data ) 745cdf0e10cSrcweir throw ( Exception ) 746cdf0e10cSrcweir { 747cdf0e10cSrcweir ucbhelper::Content aParentCnt( rParentURL, mxEnvironment ); 748cdf0e10cSrcweir 749cdf0e10cSrcweir Sequence< ContentInfo > aInfo = aParentCnt.queryCreatableContentsInfo(); 750cdf0e10cSrcweir sal_Int32 nCount = aInfo.getLength(); 751cdf0e10cSrcweir if ( nCount == 0 ) 752cdf0e10cSrcweir return false; 753cdf0e10cSrcweir 754cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nCount; ++i ) 755cdf0e10cSrcweir { 756cdf0e10cSrcweir const ContentInfo & rCurr = aInfo[i]; 757cdf0e10cSrcweir if ( ( rCurr.Attributes 758cdf0e10cSrcweir & ContentInfoAttribute::KIND_DOCUMENT ) && 759cdf0e10cSrcweir ( rCurr.Attributes 760cdf0e10cSrcweir & ContentInfoAttribute::INSERT_WITH_INPUTSTREAM ) ) 761cdf0e10cSrcweir { 762cdf0e10cSrcweir // Make sure the only required bootstrap property is 763cdf0e10cSrcweir // "Title", 764cdf0e10cSrcweir const Sequence< Property > & rProps = rCurr.Properties; 765cdf0e10cSrcweir if ( rProps.getLength() != 1 ) 766cdf0e10cSrcweir continue; 767cdf0e10cSrcweir 768cdf0e10cSrcweir if ( !rProps[ 0 ].Name.equalsAsciiL( 769cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "Title" ) ) ) 770cdf0e10cSrcweir continue; 771cdf0e10cSrcweir 772cdf0e10cSrcweir Sequence<rtl::OUString> aNames(1); 773cdf0e10cSrcweir rtl::OUString* pNames = aNames.getArray(); 774cdf0e10cSrcweir pNames[0] = rtl::OUString( 775cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "Title" ) ); 776cdf0e10cSrcweir Sequence< Any > aValues(1); 777cdf0e10cSrcweir Any* pValues = aValues.getArray(); 778cdf0e10cSrcweir pValues[0] = makeAny( rtl::OUString( rTitle ) ); 779cdf0e10cSrcweir 780cdf0e10cSrcweir try 781cdf0e10cSrcweir { 782cdf0e10cSrcweir ucbhelper::Content aNew; 783cdf0e10cSrcweir if ( aParentCnt.insertNewContent( 784cdf0e10cSrcweir rCurr.Type, aNames, aValues, data, aNew ) ) 785cdf0e10cSrcweir return true; // success. 786cdf0e10cSrcweir else 787cdf0e10cSrcweir continue; 788cdf0e10cSrcweir } 789cdf0e10cSrcweir catch ( CommandFailedException const & ) 790cdf0e10cSrcweir { 791cdf0e10cSrcweir // Interaction Handler already handled the 792*07a3d7f1SPedro Giffuni // error that has occurred... 793cdf0e10cSrcweir continue; 794cdf0e10cSrcweir } 795cdf0e10cSrcweir } 796cdf0e10cSrcweir } 797cdf0e10cSrcweir 798cdf0e10cSrcweir return false; 799cdf0e10cSrcweir } 800cdf0e10cSrcweir 801cdf0e10cSrcweir void SAL_CALL OFileAccess::writeFile( const rtl::OUString& FileURL, 802cdf0e10cSrcweir const Reference< XInputStream >& data ) 803cdf0e10cSrcweir throw ( Exception, RuntimeException ) 804cdf0e10cSrcweir { 805cdf0e10cSrcweir INetURLObject aURL( FileURL, INET_PROT_FILE ); 806cdf0e10cSrcweir try 807cdf0e10cSrcweir { 808cdf0e10cSrcweir ucbhelper::Content aCnt( 809cdf0e10cSrcweir aURL.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment ); 810cdf0e10cSrcweir 811cdf0e10cSrcweir try 812cdf0e10cSrcweir { 813cdf0e10cSrcweir aCnt.writeStream( data, sal_True /* bReplaceExisting */ ); 814cdf0e10cSrcweir } 815cdf0e10cSrcweir catch ( CommandFailedException const & ) 816cdf0e10cSrcweir { 817*07a3d7f1SPedro Giffuni // Interaction Handler already handled the error that has occurred... 818cdf0e10cSrcweir } 819cdf0e10cSrcweir } 820cdf0e10cSrcweir catch ( ContentCreationException const & e ) 821cdf0e10cSrcweir { 822cdf0e10cSrcweir // Most probably file does not exist. Try to create. 823cdf0e10cSrcweir if ( e.eError == ContentCreationError_CONTENT_CREATION_FAILED ) 824cdf0e10cSrcweir { 825cdf0e10cSrcweir INetURLObject aParentURLObj( aURL ); 826cdf0e10cSrcweir if ( aParentURLObj.removeSegment() ) 827cdf0e10cSrcweir { 828cdf0e10cSrcweir String aParentURL 829cdf0e10cSrcweir = aParentURLObj.GetMainURL( INetURLObject::NO_DECODE ); 830cdf0e10cSrcweir 831cdf0e10cSrcweir // ensure all parent folders exist. 832cdf0e10cSrcweir createFolder( aParentURL ); 833cdf0e10cSrcweir 834cdf0e10cSrcweir // create the new file... 835cdf0e10cSrcweir String aTitle 836cdf0e10cSrcweir = aURL.getName( INetURLObject::LAST_SEGMENT, 837cdf0e10cSrcweir true, 838cdf0e10cSrcweir INetURLObject::DECODE_WITH_CHARSET ); 839cdf0e10cSrcweir if ( createNewFile( aParentURL, aTitle, data ) ) 840cdf0e10cSrcweir { 841cdf0e10cSrcweir // success 842cdf0e10cSrcweir return; 843cdf0e10cSrcweir } 844cdf0e10cSrcweir } 845cdf0e10cSrcweir } 846cdf0e10cSrcweir 847cdf0e10cSrcweir throw; 848cdf0e10cSrcweir } 849cdf0e10cSrcweir } 850cdf0e10cSrcweir 851cdf0e10cSrcweir sal_Bool OFileAccess::isHidden( const ::rtl::OUString& FileURL ) 852cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException) 853cdf0e10cSrcweir { 854cdf0e10cSrcweir INetURLObject aURLObj( FileURL, INET_PROT_FILE ); 855cdf0e10cSrcweir ucbhelper::Content aCnt( aURLObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment ); 856cdf0e10cSrcweir Any aRetAny = aCnt.getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsHidden" ) ) ); 857cdf0e10cSrcweir sal_Bool bRet = sal_False; 858cdf0e10cSrcweir aRetAny >>= bRet; 859cdf0e10cSrcweir return bRet; 860cdf0e10cSrcweir } 861cdf0e10cSrcweir 862cdf0e10cSrcweir void OFileAccess::setHidden( const ::rtl::OUString& FileURL, sal_Bool bHidden ) 863cdf0e10cSrcweir throw(CommandAbortedException, Exception, RuntimeException) 864cdf0e10cSrcweir { 865cdf0e10cSrcweir INetURLObject aURLObj( FileURL, INET_PROT_FILE ); 866cdf0e10cSrcweir ucbhelper::Content aCnt( aURLObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment ); 867cdf0e10cSrcweir Any aAny; 868cdf0e10cSrcweir aAny <<= bHidden; 869cdf0e10cSrcweir aCnt.setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsHidden" ) ), aAny ); 870cdf0e10cSrcweir } 871cdf0e10cSrcweir 872cdf0e10cSrcweir //================================================================================================== 873cdf0e10cSrcweir //================================================================================================== 874cdf0e10cSrcweir //================================================================================================== 875cdf0e10cSrcweir 876cdf0e10cSrcweir Reference< XInterface > SAL_CALL FileAccess_CreateInstance( const Reference< XMultiServiceFactory > & xSMgr ) 877cdf0e10cSrcweir { 878cdf0e10cSrcweir return Reference < XInterface >( ( cppu::OWeakObject * ) new OFileAccess( xSMgr ) ); 879cdf0e10cSrcweir } 880cdf0e10cSrcweir 881cdf0e10cSrcweir 882cdf0e10cSrcweir Sequence< rtl::OUString > FileAccess_getSupportedServiceNames() 883cdf0e10cSrcweir { 884cdf0e10cSrcweir static Sequence < rtl::OUString > *pNames = 0; 885cdf0e10cSrcweir if( ! pNames ) 886cdf0e10cSrcweir { 887cdf0e10cSrcweir osl::MutexGuard guard( osl::Mutex::getGlobalMutex() ); 888cdf0e10cSrcweir if( !pNames ) 889cdf0e10cSrcweir { 890cdf0e10cSrcweir static Sequence< rtl::OUString > seqNames(1); 891cdf0e10cSrcweir seqNames.getArray()[0] = rtl::OUString::createFromAscii( SERVICE_NAME ); 892cdf0e10cSrcweir pNames = &seqNames; 893cdf0e10cSrcweir } 894cdf0e10cSrcweir } 895cdf0e10cSrcweir return *pNames; 896cdf0e10cSrcweir } 897cdf0e10cSrcweir 898cdf0e10cSrcweir 899cdf0e10cSrcweir } 900cdf0e10cSrcweir 901cdf0e10cSrcweir //================================================================================================== 902cdf0e10cSrcweir // Component exports 903cdf0e10cSrcweir 904cdf0e10cSrcweir extern "C" 905cdf0e10cSrcweir { 906cdf0e10cSrcweir //================================================================================================== 907cdf0e10cSrcweir void SAL_CALL component_getImplementationEnvironment( 908cdf0e10cSrcweir const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ ) 909cdf0e10cSrcweir { 910cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 911cdf0e10cSrcweir } 912cdf0e10cSrcweir //================================================================================================== 913cdf0e10cSrcweir void * SAL_CALL component_getFactory( 914cdf0e10cSrcweir const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) 915cdf0e10cSrcweir { 916cdf0e10cSrcweir void * pRet = 0; 917cdf0e10cSrcweir 918cdf0e10cSrcweir if (pServiceManager && rtl_str_compare( pImplName, IMPLEMENTATION_NAME ) == 0) 919cdf0e10cSrcweir { 920cdf0e10cSrcweir Reference< XSingleServiceFactory > xFactory( cppu::createSingleFactory( 921cdf0e10cSrcweir reinterpret_cast< XMultiServiceFactory * >( pServiceManager ), 922cdf0e10cSrcweir rtl::OUString::createFromAscii( pImplName ), 923cdf0e10cSrcweir io_FileAccess::FileAccess_CreateInstance, 924cdf0e10cSrcweir io_FileAccess::FileAccess_getSupportedServiceNames() ) ); 925cdf0e10cSrcweir 926cdf0e10cSrcweir if (xFactory.is()) 927cdf0e10cSrcweir { 928cdf0e10cSrcweir xFactory->acquire(); 929cdf0e10cSrcweir pRet = xFactory.get(); 930cdf0e10cSrcweir } 931cdf0e10cSrcweir } 932cdf0e10cSrcweir 933cdf0e10cSrcweir return pRet; 934cdf0e10cSrcweir } 935cdf0e10cSrcweir } 936cdf0e10cSrcweir 937cdf0e10cSrcweir 938