1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
|
/*************************************************************************
*
* $RCSfile: FileAccess.cxx,v $
*
* $Revision: 1.19 $
*
* last change: $Author: rt $ $Date: 2003-04-23 16:55:13 $
*
* 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): _______________________________________
*
*
************************************************************************/
#include <osl/mutex.hxx>
#include <osl/diagnose.h>
#include <uno/mapping.hxx>
#include <cppuhelper/factory.hxx>
#include <cppuhelper/implbase1.hxx>
#include <tools/ref.hxx>
#include <tools/urlobj.hxx>
#include <ucbhelper/content.hxx>
#include <unotools/streamwrap.hxx>
#include <tools/stream.hxx>
#include <com/sun/star/beans/Property.hpp>
#include <com/sun/star/io/XActiveDataSink.hpp>
#include <com/sun/star/io/XActiveDataSource.hpp>
#include <com/sun/star/io/XActiveDataStreamer.hpp>
#include <com/sun/star/sdbc/XResultSet.hpp>
#include <com/sun/star/ucb/CommandFailedException.hpp>
#include <com/sun/star/ucb/ContentInfo.hpp>
#include <com/sun/star/ucb/ContentInfoAttribute.hpp>
#include <com/sun/star/ucb/InsertCommandArgument.hpp>
#include <com/sun/star/ucb/InteractiveIOException.hpp>
#include <com/sun/star/ucb/NameClash.hpp>
#include <com/sun/star/ucb/NameClashException.hpp>
#include <com/sun/star/ucb/OpenCommandArgument2.hpp>
#include <com/sun/star/ucb/OpenMode.hpp>
#include <com/sun/star/ucb/XCommandEnvironment.hpp>
#include <com/sun/star/ucb/XContentAccess.hpp>
#include <com/sun/star/ucb/XContentCreator.hpp>
#include <com/sun/star/ucb/XSimpleFileAccess3.hpp>
#define IMPLEMENTATION_NAME "com.sun.star.comp.ucb.SimpleFileAccess"
#define SERVICE_NAME "com.sun.star.ucb.SimpleFileAccess"
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::io;
using namespace ::com::sun::star::ucb;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::task;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::registry;
namespace io_FileAccess
{
//===========================================================================
// Implementation XSimpleFileAccess
typedef cppu::WeakImplHelper1< XSimpleFileAccess3 > FileAccessHelper;
class OCommandEnvironment;
class OFileAccess : public FileAccessHelper
{
Reference< XCommandEnvironment > mxEnvironment;
OCommandEnvironment* mpEnvironment;
void transferImpl( const rtl::OUString& rSource, const rtl::OUString& rDest, sal_Bool bMoveData )
throw(CommandAbortedException, Exception, RuntimeException);
public:
OFileAccess() : mpEnvironment( NULL ) {}
// Methods
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
virtual void SAL_CALL setInteractionHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ) throw(::com::sun::star::uno::RuntimeException);
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);
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);
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);
};
//===========================================================================
// Implementation XActiveDataSink
typedef cppu::WeakImplHelper1< XActiveDataSink > ActiveDataSinkHelper;
class OActiveDataSink : public ActiveDataSinkHelper
{
Reference< XInputStream > mxStream;
public:
// Methods
virtual void SAL_CALL setInputStream( const Reference< XInputStream >& aStream )
throw(RuntimeException);
virtual Reference< XInputStream > SAL_CALL getInputStream( )
throw(RuntimeException);
};
void OActiveDataSink::setInputStream( const Reference< XInputStream >& aStream )
throw(RuntimeException)
{
mxStream = aStream;
}
Reference< XInputStream > OActiveDataSink::getInputStream()
throw(RuntimeException)
{
return mxStream;
}
//===========================================================================
// Implementation XActiveDataSource
typedef cppu::WeakImplHelper1< XActiveDataSource > ActiveDataSourceHelper;
class OActiveDataSource : public ActiveDataSourceHelper
{
Reference< XOutputStream > mxStream;
public:
// Methods
virtual void SAL_CALL setOutputStream( const Reference< XOutputStream >& aStream )
throw(RuntimeException);
virtual Reference< XOutputStream > SAL_CALL getOutputStream()
throw(RuntimeException);
};
void OActiveDataSource::setOutputStream( const Reference< XOutputStream >& aStream )
throw(RuntimeException)
{
mxStream = aStream;
}
Reference< XOutputStream > OActiveDataSource::getOutputStream()
throw(RuntimeException)
{
return mxStream;
}
//===========================================================================
// Implementation XActiveDataStreamer
typedef cppu::WeakImplHelper1< XActiveDataStreamer > ActiveDataStreamerHelper;
class OActiveDataStreamer : public ActiveDataStreamerHelper
{
Reference< XStream > mxStream;
public:
// Methods
virtual void SAL_CALL setStream( const Reference< XStream >& aStream )
throw(RuntimeException);
virtual Reference< XStream > SAL_CALL getStream()
throw(RuntimeException);
};
void OActiveDataStreamer::setStream( const Reference< XStream >& aStream )
throw(RuntimeException)
{
mxStream = aStream;
}
Reference< XStream > OActiveDataStreamer::getStream()
throw(RuntimeException)
{
return mxStream;
}
//===========================================================================
// Implementation XCommandEnvironment
typedef cppu::WeakImplHelper1< XCommandEnvironment > CommandEnvironmentHelper;
class OCommandEnvironment : public CommandEnvironmentHelper
{
Reference< XInteractionHandler > mxInteraction;
public:
void setHandler( Reference< XInteractionHandler > xInteraction_ )
{
mxInteraction = xInteraction_;
}
// Methods
virtual Reference< XInteractionHandler > SAL_CALL getInteractionHandler()
throw(RuntimeException);
virtual Reference< XProgressHandler > SAL_CALL getProgressHandler()
throw(RuntimeException);
};
Reference< XInteractionHandler > OCommandEnvironment::getInteractionHandler()
throw(RuntimeException)
{
return mxInteraction;
}
Reference< XProgressHandler > OCommandEnvironment::getProgressHandler()
throw(RuntimeException)
{
Reference< XProgressHandler > xRet;
return xRet;
}
//===========================================================================
void OFileAccess::transferImpl( const rtl::OUString& rSource, const rtl::OUString& rDest, sal_Bool bMoveData )
throw(CommandAbortedException, Exception, RuntimeException)
{
// SfxContentHelper::Transfer_Impl
INetURLObject aSourceObj( rSource, INET_PROT_FILE );
INetURLObject aDestObj( rDest, INET_PROT_FILE );
String aName = aDestObj.getName( INetURLObject::LAST_SEGMENT, true,
INetURLObject::DECODE_WITH_CHARSET );
aDestObj.removeSegment();
aDestObj.setFinalSlash();
ucb::Content aDestPath( aDestObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment );
ucb::Content aSrc( aSourceObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment );
try
{
aDestPath.transferContent( aSrc,
bMoveData
? ucb::InsertOperation_MOVE
: ucb::InsertOperation_COPY,
aName,
::com::sun::star::ucb::NameClash::OVERWRITE );
}
catch ( ::com::sun::star::ucb::CommandFailedException const & )
{
// Interaction Handler already handled the error that has occured...
}
}
void OFileAccess::copy( const rtl::OUString& SourceURL, const rtl::OUString& DestURL )
throw(CommandAbortedException, Exception, RuntimeException)
{
transferImpl( SourceURL, DestURL, sal_False );
}
void OFileAccess::move( const rtl::OUString& SourceURL, const rtl::OUString& DestURL )
throw(CommandAbortedException, Exception, RuntimeException)
{
transferImpl( SourceURL, DestURL, sal_True );
}
void OFileAccess::kill( const rtl::OUString& FileURL )
throw(CommandAbortedException, Exception, RuntimeException)
{
// SfxContentHelper::Kill
INetURLObject aDeleteObj( FileURL, INET_PROT_FILE );
ucb::Content aCnt( aDeleteObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment );
try
{
aCnt.executeCommand( rtl::OUString::createFromAscii( "delete" ), makeAny( sal_Bool( sal_True ) ) );
}
catch ( ::com::sun::star::ucb::CommandFailedException const & )
{
// Interaction Handler already handled the error that has occured...
}
}
sal_Bool OFileAccess::isFolder( const rtl::OUString& FileURL )
throw(CommandAbortedException, Exception, RuntimeException)
{
sal_Bool bRet = sal_False;
try
{
INetURLObject aURLObj( FileURL, INET_PROT_FILE );
ucb::Content aCnt( aURLObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment );
bRet = aCnt.isFolder();
}
catch (Exception &) {}
return bRet;
}
sal_Bool OFileAccess::isReadOnly( const rtl::OUString& FileURL )
throw(CommandAbortedException, Exception, RuntimeException)
{
INetURLObject aURLObj( FileURL, INET_PROT_FILE );
ucb::Content aCnt( aURLObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment );
Any aRetAny = aCnt.getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ) );
sal_Bool bRet = sal_False;
aRetAny >>= bRet;
return bRet;
}
void OFileAccess::setReadOnly( const rtl::OUString& FileURL, sal_Bool bReadOnly )
throw(CommandAbortedException, Exception, RuntimeException)
{
INetURLObject aURLObj( FileURL, INET_PROT_FILE );
ucb::Content aCnt( aURLObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment );
Any aAny;
aAny <<= bReadOnly;
aCnt.setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ), aAny );
}
void OFileAccess::createFolder( const rtl::OUString& NewFolderURL )
throw(CommandAbortedException, Exception, RuntimeException)
{
// Does the folder already exist?
if( !NewFolderURL.getLength() || isFolder( NewFolderURL ) )
return;
// SfxContentHelper::MakeFolder
INetURLObject aURL( NewFolderURL, INET_PROT_FILE );
String aNewFolderURLStr = aURL.GetMainURL( INetURLObject::NO_DECODE );
String aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
if ( aTitle.Len() )
{
aURL.removeSegment();
// Does the base folder exist? Otherwise create it first
String aBaseFolderURLStr = aURL.GetMainURL( INetURLObject::NO_DECODE );
if( !isFolder( aBaseFolderURLStr ) )
{
createFolder( aBaseFolderURLStr );
}
}
ucb::Content aCnt( aURL.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment );
Reference< XContentCreator > xCreator = Reference< XContentCreator >( aCnt.get(), UNO_QUERY );
if ( !xCreator.is() )
return;
Sequence< ContentInfo > aInfo = xCreator->queryCreatableContentsInfo();
sal_Int32 nCount = aInfo.getLength();
if ( nCount == 0 )
return;
for ( sal_Int32 i = 0; i < nCount; ++i )
{
// Simply look for the first KIND_FOLDER...
const ContentInfo & rCurr = aInfo[i];
if ( rCurr.Attributes & ContentInfoAttribute::KIND_FOLDER )
{
// 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( aTitle ) );
ucb::Content aNew;
try
{
if ( !aCnt.insertNewContent( rCurr.Type, aNames, aValues, aNew ) )
continue;
}
catch ( ::com::sun::star::ucb::CommandFailedException const & )
{
// Interaction Handler already handled the error that has occured...
continue;
}
}
}
}
sal_Int32 OFileAccess::getSize( const rtl::OUString& FileURL )
throw(CommandAbortedException, Exception, RuntimeException)
{
// SfxContentHelper::GetSize
sal_Int32 nSize = 0;
sal_Int64 nTemp = 0;
INetURLObject aObj( FileURL, INET_PROT_FILE );
ucb::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment );
aCnt.getPropertyValue( rtl::OUString::createFromAscii( "Size" ) ) >>= nTemp;
nSize = (sal_Int32)nTemp;
return nSize;
}
rtl::OUString OFileAccess::getContentType( const rtl::OUString& FileURL )
throw(CommandAbortedException, Exception, RuntimeException)
{
INetURLObject aObj( FileURL, INET_PROT_FILE );
ucb::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment );
Reference< XContent > xContent = aCnt.get();
rtl::OUString aTypeStr = xContent->getContentType();
return aTypeStr;
}
DateTime OFileAccess::getDateTimeModified( const rtl::OUString& FileURL )
throw(CommandAbortedException, Exception, RuntimeException)
{
INetURLObject aFileObj( FileURL, INET_PROT_FILE );
DateTime aDateTime;
Reference< XCommandEnvironment > aCmdEnv;
ucb::Content aYoung( aFileObj.GetMainURL( INetURLObject::NO_DECODE ), aCmdEnv );
aYoung.getPropertyValue( rtl::OUString::createFromAscii( "DateModified" ) ) >>= aDateTime;
return aDateTime;
}
DECLARE_LIST( StringList_Impl, rtl::OUString* )
Sequence< rtl::OUString > OFileAccess::getFolderContents( const rtl::OUString& FolderURL, sal_Bool bIncludeFolders )
throw(CommandAbortedException, Exception, RuntimeException)
{
// SfxContentHelper::GetFolderContents
StringList_Impl* pFiles = NULL;
INetURLObject aFolderObj( FolderURL, INET_PROT_FILE );
ucb::Content aCnt( aFolderObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment );
Reference< XResultSet > xResultSet;
Sequence< rtl::OUString > aProps(0);
//Sequence< rtl::OUString > aProps(1);
//rtl::OUString* pProps = aProps.getArray();
//pProps[0] == rtl::OUString::createFromAscii( "Url" );
ucb::ResultSetInclude eInclude = bIncludeFolders ? ucb::INCLUDE_FOLDERS_AND_DOCUMENTS : ucb::INCLUDE_DOCUMENTS_ONLY;
try
{
xResultSet = aCnt.createCursor( aProps, eInclude );
}
catch ( ::com::sun::star::ucb::CommandFailedException const & )
{
// Interaction Handler already handled the error that has occured...
}
if ( xResultSet.is() )
{
pFiles = new StringList_Impl;
Reference< com::sun::star::ucb::XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
while ( xResultSet->next() )
{
rtl::OUString aId = xContentAccess->queryContentIdentifierString();
INetURLObject aURL( aId, INET_PROT_FILE );
rtl::OUString* pFile = new rtl::OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
pFiles->Insert( pFile, LIST_APPEND );
}
}
if ( pFiles )
{
ULONG nCount = pFiles->Count();
Sequence < rtl::OUString > aRet( nCount );
rtl::OUString* pRet = aRet.getArray();
for ( USHORT i = 0; i < nCount; ++i )
{
rtl::OUString* pFile = pFiles->GetObject(i);
pRet[i] = *( pFile );
delete pFile;
}
delete pFiles;
return aRet;
}
else
return Sequence < rtl::OUString > ();
}
sal_Bool OFileAccess::exists( const rtl::OUString& FileURL )
throw(CommandAbortedException, Exception, RuntimeException)
{
sal_Bool bRet = sal_False;
try
{
bRet = isFolder( FileURL );
if( !bRet )
{
Reference< XInputStream > xStream = openFileRead( FileURL );
bRet = xStream.is();
if( bRet )
xStream->closeInput();
}
}
catch (Exception &) {}
return bRet;
}
Reference< XInputStream > OFileAccess::openFileRead( const rtl::OUString& FileURL )
throw(CommandAbortedException, Exception, RuntimeException)
{
Reference< XInputStream > xRet;
INetURLObject aObj( FileURL, INET_PROT_FILE );
ucb::Content aCnt( aObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment );
Reference< XActiveDataSink > xSink = (XActiveDataSink*)(new OActiveDataSink());
try
{
sal_Bool bRet = aCnt.openStream( xSink );
if( bRet )
xRet = xSink->getInputStream();
}
catch ( ::com::sun::star::ucb::CommandFailedException const & )
{
// Interaction Handler already handled the error that has occured...
}
return xRet;
}
Reference< XOutputStream > OFileAccess::openFileWrite( const rtl::OUString& FileURL )
throw(CommandAbortedException, Exception, RuntimeException)
{
Reference< XOutputStream > xRet;
Reference< XStream > xStream = OFileAccess::openFileReadWrite( FileURL );
if( xStream.is() )
xRet = xStream->getOutputStream();
return xRet;
}
Reference< XStream > OFileAccess::openFileReadWrite( const rtl::OUString& FileURL )
throw(CommandAbortedException, Exception, RuntimeException)
{
Reference< XActiveDataStreamer > xSink = (XActiveDataStreamer*)new OActiveDataStreamer();
Reference< XInterface > xSinkIface = Reference< XInterface >::query( xSink );
OpenCommandArgument2 aArg;
aArg.Mode = OpenMode::DOCUMENT;
aArg.Priority = 0; // unused
aArg.Sink = xSink;
aArg.Properties = Sequence< Property >( 0 ); // unused
Any aCmdArg;
aCmdArg <<= aArg;
INetURLObject aFileObj( FileURL, INET_PROT_FILE );
ucb::Content aCnt( aFileObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment );
// Be silent...
Reference< XInteractionHandler > xIH;
if ( mpEnvironment )
{
xIH = mpEnvironment->getInteractionHandler();
mpEnvironment->setHandler( 0 );
}
try
{
aCnt.executeCommand( rtl::OUString::createFromAscii( "open" ), aCmdArg );
}
catch ( InteractiveIOException const & e )
{
if ( xIH.is() )
mpEnvironment->setHandler( xIH );
if ( e.Code == IOErrorCode_NOT_EXISTING )
{
// Create file...
SvMemoryStream aStream(0,0);
::utl::OInputStreamWrapper* pInput = new ::utl::OInputStreamWrapper( aStream );
Reference< XInputStream > xInput( pInput );
InsertCommandArgument aInsertArg;
aInsertArg.Data = xInput;
aInsertArg.ReplaceExisting = sal_False;
aCmdArg <<= aInsertArg;
aCnt.executeCommand( rtl::OUString::createFromAscii( "insert" ), aCmdArg );
// Retry...
return openFileReadWrite( FileURL );
}
throw;
}
if ( xIH.is() )
mpEnvironment->setHandler( xIH );
Reference< XStream > xRet = xSink->getStream();
return xRet;
}
void OFileAccess::setInteractionHandler( const Reference< XInteractionHandler >& Handler )
throw(RuntimeException)
{
if( !mpEnvironment )
{
mpEnvironment = new OCommandEnvironment();
mxEnvironment = (XCommandEnvironment*)mpEnvironment;
}
mpEnvironment->setHandler( Handler );
}
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 );
try
{
aCnt.writeStream( data, sal_True /* bReplaceExisting */ );
}
catch ( ::com::sun::star::ucb::CommandFailedException const & )
{
// Interaction Handler already handled the error that has occured...
}
}
sal_Bool OFileAccess::isHidden( const ::rtl::OUString& FileURL )
throw(CommandAbortedException, Exception, RuntimeException)
{
INetURLObject aURLObj( FileURL, INET_PROT_FILE );
ucb::Content aCnt( aURLObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment );
Any aRetAny = aCnt.getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsHidden" ) ) );
sal_Bool bRet = sal_False;
aRetAny >>= bRet;
return bRet;
}
void OFileAccess::setHidden( const ::rtl::OUString& FileURL, sal_Bool bHidden )
throw(CommandAbortedException, Exception, RuntimeException)
{
INetURLObject aURLObj( FileURL, INET_PROT_FILE );
ucb::Content aCnt( aURLObj.GetMainURL( INetURLObject::NO_DECODE ), mxEnvironment );
Any aAny;
aAny <<= 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 );
}
Sequence< rtl::OUString > FileAccess_getSupportedServiceNames()
{
static Sequence < rtl::OUString > *pNames = 0;
if( ! pNames )
{
osl::MutexGuard guard( osl::Mutex::getGlobalMutex() );
if( !pNames )
{
static Sequence< rtl::OUString > seqNames(1);
seqNames.getArray()[0] = rtl::OUString::createFromAscii( SERVICE_NAME );
pNames = &seqNames;
}
}
return *pNames;
}
}
//==================================================================================================
// Component exports
extern "C"
{
//==================================================================================================
void SAL_CALL component_getImplementationEnvironment(
const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
{
*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
}
//==================================================================================================
sal_Bool SAL_CALL component_writeInfo(
void * pServiceManager, void * pRegistryKey )
{
if (pRegistryKey)
{
try
{
Reference< XRegistryKey > xNewKey(
reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey(
rtl::OUString::createFromAscii("/" IMPLEMENTATION_NAME "/UNO/SERVICES" ) ) );
const Sequence< rtl::OUString > & rSNL = io_FileAccess::FileAccess_getSupportedServiceNames();
const rtl::OUString * pArray = rSNL.getConstArray();
for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
xNewKey->createKey( pArray[nPos] );
return sal_True;
}
catch (InvalidRegistryException &)
{
OSL_ENSURE( sal_False, "### InvalidRegistryException!" );
}
}
return sal_False;
}
//==================================================================================================
void * SAL_CALL component_getFactory(
const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
{
void * pRet = 0;
if (pServiceManager && rtl_str_compare( pImplName, IMPLEMENTATION_NAME ) == 0)
{
Reference< XSingleServiceFactory > xFactory( cppu::createSingleFactory(
reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
rtl::OUString::createFromAscii( pImplName ),
io_FileAccess::FileAccess_CreateInstance,
io_FileAccess::FileAccess_getSupportedServiceNames() ) );
if (xFactory.is())
{
xFactory->acquire();
pRet = xFactory.get();
}
}
return pRet;
}
}
|