merge the formfield patch from ooo-build
[ooovba.git] / package / qa / ofopxmlstorages / TestHelper.java
blobabad297dfc007b54fe2e6cfdb583262da375fa0b
1 package complex.ofopxmlstorages;
3 import com.sun.star.uno.UnoRuntime;
4 import com.sun.star.uno.XInterface;
5 import com.sun.star.uno.AnyConverter;
7 import com.sun.star.lang.*;
8 import com.sun.star.embed.*;
9 import com.sun.star.packages.*;
10 import com.sun.star.io.*;
11 import com.sun.star.beans.*;
13 import share.LogWriter;
15 public class TestHelper {
17 LogWriter m_aLogWriter;
18 String m_sTestPrefix;
20 public TestHelper( LogWriter aLogWriter, String sTestPrefix )
22 m_aLogWriter = aLogWriter;
23 m_sTestPrefix = sTestPrefix;
26 public boolean WriteBytesToStream( XStream xStream,
27 String sStreamName,
28 String sMediaType,
29 boolean bCompressed,
30 byte[] pBytes,
31 StringPair[][] aRelations )
33 // get output stream of substream
34 XOutputStream xOutput = xStream.getOutputStream();
35 if ( xOutput == null )
37 Error( "Can't get XOutputStream implementation from substream '" + sStreamName + "'!" );
38 return false;
41 // get XTrucate implementation from output stream
42 XTruncate xTruncate = (XTruncate) UnoRuntime.queryInterface( XTruncate.class, xOutput );
43 if ( xTruncate == null )
45 Error( "Can't get XTruncate implementation from substream '" + sStreamName + "'!" );
46 return false;
49 // write requested byte sequence
50 try
52 xTruncate.truncate();
53 xOutput.writeBytes( pBytes );
55 catch( Exception e )
57 Error( "Can't write to stream '" + sStreamName + "', exception: " + e );
58 return false;
61 // get access to the XPropertySet interface
62 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStream );
63 if ( xPropSet == null )
65 Error( "Can't get XPropertySet implementation from substream '" + sStreamName + "'!" );
66 return false;
69 // set properties to the stream
70 try
72 xPropSet.setPropertyValue( "MediaType", sMediaType );
73 xPropSet.setPropertyValue( "Compressed", new Boolean( bCompressed ) );
75 catch( Exception e )
77 Error( "Can't set properties to substream '" + sStreamName + "', exception: " + e );
78 return false;
81 // check size property of the stream
82 try
84 int nSize = AnyConverter.toInt( xPropSet.getPropertyValue( "Size" ) );
85 if ( nSize != pBytes.length )
87 Error( "The 'Size' property of substream '" + sStreamName + "' contains wrong value!" );
88 return false;
91 catch( Exception e )
93 Error( "Can't get 'Size' property from substream '" + sStreamName + "', exception: " + e );
94 return false;
97 // get access to the relationship information
98 XRelationshipAccess xRelAccess = (XRelationshipAccess) UnoRuntime.queryInterface( XRelationshipAccess.class, xStream );
99 if ( xRelAccess == null )
101 Error( "Can't get XRelationshipAccess implementation from substream '" + sStreamName + "'!" );
102 return false;
105 // set the relationship information
108 xRelAccess.insertRelationships( aRelations, false );
110 catch( Exception e )
112 Error( "Can't set relationships to substream '" + sStreamName + "', exception: " + e );
113 return false;
116 // free the stream resources, garbage collector may remove the object too late
117 if ( !disposeStream( xStream, sStreamName ) )
118 return false;
120 return true;
123 public boolean WriteBytesToSubstream( XStorage xStorage,
124 String sStreamName,
125 String sMediaType,
126 boolean bCompressed,
127 byte[] pBytes,
128 StringPair[][] aRelations )
130 // open substream element
131 XStream xSubStream = null;
134 Object oSubStream = xStorage.openStreamElement( sStreamName, ElementModes.WRITE );
135 xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
136 if ( xSubStream == null )
138 Error( "Can't create substream '" + sStreamName + "'!" );
139 return false;
142 catch( Exception e )
144 Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" );
145 return false;
148 return WriteBytesToStream( xSubStream, sStreamName, sMediaType, bCompressed, pBytes, aRelations );
151 public boolean setStorageTypeAndCheckProps( XStorage xStorage,
152 boolean bIsRoot,
153 int nMode,
154 StringPair[][] aRelations )
156 boolean bOk = false;
158 // get access to the XPropertySet interface
159 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStorage );
160 if ( xPropSet != null )
164 // get "IsRoot" and "OpenMode" properties and control there values
165 boolean bPropIsRoot = AnyConverter.toBoolean( xPropSet.getPropertyValue( "IsRoot" ) );
166 int nPropMode = AnyConverter.toInt( xPropSet.getPropertyValue( "OpenMode" ) );
168 bOk = true;
169 if ( bPropIsRoot != bIsRoot )
171 Error( "'IsRoot' property contains wrong value!" );
172 bOk = false;
175 if ( ( bIsRoot
176 && ( nPropMode | ElementModes.READ ) != ( nMode | ElementModes.READ ) )
177 || ( !bIsRoot && ( nPropMode & nMode ) != nMode ) )
179 Error( "'OpenMode' property contains wrong value, expected " + nMode + ", in reality " + nPropMode + "!" );
180 bOk = false;
183 catch( Exception e )
185 Error( "Can't control properties of substorage, exception: " + e );
188 else
190 Error( "Can't get XPropertySet implementation from storage!" );
193 // get access to the relationship information
194 XRelationshipAccess xRelAccess = (XRelationshipAccess) UnoRuntime.queryInterface( XRelationshipAccess.class, xStorage );
196 if ( xRelAccess == null )
198 Error( "Can't get XRelationshipAccess implementation from the storage!" );
199 return false;
202 // set the relationship information
205 xRelAccess.insertRelationships( aRelations, false );
207 catch( Exception e )
209 Error( "Can't set relationships to the storage, exception: " + e );
210 return false;
214 return bOk;
217 public boolean checkRelations( StringPair[][] aStorRels, StringPair[][] aTestRels )
219 // Message( "StorageRels:" );
220 // PrintRelations( aStorRels );
221 // Message( "TestRels:" );
222 // PrintRelations( aTestRels );
224 if ( aStorRels.length != aTestRels.length )
226 Error( "The provided relations sequence has different size than the storage's one!" );
227 return false;
230 for ( int nStorInd = 0; nStorInd < aStorRels.length; nStorInd++ )
232 int nStorIDInd = -1;
233 for ( int nStorTagInd = 0; nStorTagInd < aStorRels[nStorInd].length; nStorTagInd++ )
235 if ( aStorRels[nStorInd][nStorTagInd].First.equals( "Id" ) )
237 nStorIDInd = nStorTagInd;
238 break;
242 if ( nStorIDInd == -1 )
244 Error( "One of the storage relations entries has no ID!" );
245 return false;
248 for ( int nInd = 0; nInd < aTestRels.length; nInd++ )
250 int nIDInd = -1;
251 for ( int nTagInd = 0; nTagInd < aTestRels[nInd].length; nTagInd++ )
253 if ( aTestRels[nInd][nTagInd].First.equals( "Id" ) )
255 nIDInd = nTagInd;
256 break;
260 if ( nIDInd == -1 )
262 Error( "One of the test hardcoded entries has no ID, num = " + nInd + ", length = " + aTestRels[nInd].length + ", global length = " + aTestRels.length + "!" );
263 return false;
266 if ( aStorRels[nStorInd][nStorIDInd].Second.equals( aTestRels[nInd][nIDInd].Second ) )
268 boolean[] pRelCheckMark = new boolean[ aTestRels[nInd].length ];
269 for ( int nCheckInd = 0; nCheckInd < pRelCheckMark.length; nCheckInd++ )
271 pRelCheckMark[nCheckInd] = false;
274 for ( int nStorTagInd = 0; nStorTagInd < aStorRels[nStorInd].length; nStorTagInd++ )
276 boolean bFound = false;
277 for ( int nTagInd = 0; nTagInd < aTestRels[nInd].length; nTagInd++ )
279 if ( aTestRels[nInd][nTagInd].First.equals( aStorRels[nStorInd][nStorTagInd].First ) )
281 if ( !aTestRels[nInd][nTagInd].Second.equals( aStorRels[nStorInd][nStorTagInd].Second ) )
283 Error( "Test rel. num. " + nInd + " has different tag \"" + aTestRels[nInd][nTagInd].First + "\" value!" );
284 return false;
287 bFound = true;
288 pRelCheckMark[nTagInd] = true;
289 break;
293 if ( !bFound )
295 Error( "Stor rel. num. " + nStorInd + " has unexpected tag \"" + aStorRels[nStorInd][nStorTagInd].First + "\", ID = \"" + aStorRels[nStorInd][nStorIDInd].Second + "\"!" );
296 return false;
300 for ( int nCheckInd = 0; nCheckInd < pRelCheckMark.length; nCheckInd++ )
302 if ( !pRelCheckMark[nCheckInd] && !aTestRels[nInd][nCheckInd].Second.equals( "" ) )
304 Error( "Test rel. num. " + nInd + " has unexpected tag \"" + aTestRels[nInd][nCheckInd].First + "\" with nonempty value!" );
305 return false;
309 break;
314 return true;
317 public boolean checkStorageProperties( XStorage xStorage,
318 boolean bIsRoot,
319 int nMode,
320 StringPair[][] aRelations )
322 boolean bOk = false;
324 // get access to the XPropertySet interface
325 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStorage );
326 if ( xPropSet != null )
330 // get "IsRoot" and "OpenMode" properties and control there values
331 boolean bPropIsRoot = AnyConverter.toBoolean( xPropSet.getPropertyValue( "IsRoot" ) );
332 int nPropMode = AnyConverter.toInt( xPropSet.getPropertyValue( "OpenMode" ) );
334 bOk = true;
335 if ( bPropIsRoot != bIsRoot )
337 Error( "'IsRoot' property contains wrong value!" );
338 bOk = false;
341 if ( ( bIsRoot
342 && ( nPropMode | ElementModes.READ ) != ( nMode | ElementModes.READ ) )
343 || ( !bIsRoot && ( nPropMode & nMode ) != nMode ) )
345 Error( "'OpenMode' property contains wrong value, expected " + nMode + ", in reality " + nPropMode + "!" );
346 bOk = false;
349 catch( Exception e )
351 Error( "Can't get properties of substorage, exception: " + e );
354 else
356 Error( "Can't get XPropertySet implementation from storage!" );
359 // get access to the relationship information
360 XRelationshipAccess xRelAccess = (XRelationshipAccess) UnoRuntime.queryInterface( XRelationshipAccess.class, xStorage );
362 if ( xRelAccess == null )
364 Error( "Can't get XRelationshipAccess implementation from the checked storage!" );
365 return false;
368 // get the relationship information
369 StringPair[][] aStorRels;
372 aStorRels = xRelAccess.getAllRelationships();
374 catch( Exception e )
376 Error( "Can't get relationships of the checked storage, exception: " + e );
377 return false;
380 if ( !checkRelations( aStorRels, aRelations ) )
382 Error( "StorageRelationsChecking has failed!" );
383 return false;
386 return bOk;
389 public boolean InternalCheckStream( XStream xStream,
390 String sName,
391 String sMediaType,
392 byte[] pBytes,
393 StringPair[][] aRelations )
395 // get input stream of substream
396 XInputStream xInput = xStream.getInputStream();
397 if ( xInput == null )
399 Error( "Can't get XInputStream implementation from substream '" + sName + "'!" );
400 return false;
403 byte pContents[][] = new byte[1][]; // ???
405 // read contents
408 xInput.readBytes( pContents, pBytes.length + 1 );
410 catch( Exception e )
412 Error( "Can't read from stream '" + sName + "', exception: " + e );
413 return false;
416 // check size of stream data
417 if ( pContents.length == 0 )
419 Error( "SubStream '" + sName + "' reading produced disaster!" );
420 return false;
423 if ( pBytes.length != pContents[0].length )
425 Error( "SubStream '" + sName + "' contains wrong amount of data! (" + pContents[0].length + "/" + pBytes.length + ")" );
426 return false;
429 // check stream data
430 for ( int ind = 0; ind < pBytes.length; ind++ )
432 if ( pBytes[ind] != pContents[0][ind] )
434 Error( "SubStream '" + sName + "' contains wrong data! ( byte num. "
435 + ind + " should be" + pBytes[ind] + " but it is " + pContents[0][ind] + ")" );
436 return false;
440 // check properties
441 boolean bOk = false;
443 // get access to the XPropertySet interface
444 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStream );
445 if ( xPropSet != null )
449 // get "MediaType" and "Size" properties and control there values
450 String sPropMediaType = AnyConverter.toString( xPropSet.getPropertyValue( "MediaType" ) );
451 int nPropSize = AnyConverter.toInt( xPropSet.getPropertyValue( "Size" ) );
453 bOk = true;
454 if ( !sPropMediaType.equals( sMediaType ) )
456 Error( "'MediaType' property contains wrong value for stream '" + sName + "',\nexpected: '"
457 + sMediaType + "', set: '" + sPropMediaType + "'!" );
458 bOk = false;
461 if ( nPropSize != pBytes.length )
463 Error( "'Size' property contains wrong value for stream'" + sName + "'!" );
464 bOk = false;
467 catch( Exception e )
469 Error( "Can't get properties of substream '" + sName + "', exception: " + e );
472 else
474 Error( "Can't get XPropertySet implementation from stream '" + sName + "'!" );
478 // get access to the relationship information
479 XRelationshipAccess xRelAccess = (XRelationshipAccess) UnoRuntime.queryInterface( XRelationshipAccess.class, xStream );
481 if ( xRelAccess == null )
483 Error( "Can't get XRelationshipAccess implementation from the stream\"" + sName + "\"!" );
484 return false;
487 // get the relationship information
488 StringPair[][] aStorRels;
491 aStorRels = xRelAccess.getAllRelationships();
493 catch( Exception e )
495 Error( "Can't get relationships of the substream '" + sName + "', exception: " + e );
496 return false;
499 if ( !checkRelations( aStorRels, aRelations ) )
501 Error( "Stream '" + sName + "' RelationsChecking has failed!" );
502 return false;
505 return bOk;
508 public boolean checkStream( XStorage xParentStorage,
509 String sName,
510 String sMediaType,
511 byte[] pBytes,
512 StringPair[][] aRelations )
514 // open substream element first
515 XStream xSubStream = null;
518 Object oSubStream = xParentStorage.openStreamElement( sName, ElementModes.READ );
519 xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
520 if ( xSubStream == null )
522 Error( "Can't open substream '" + sName + "'!" );
523 return false;
526 catch( Exception e )
528 Error( "Can't open substream '" + sName + "', exception : " + e + "!" );
529 return false;
532 boolean bResult = InternalCheckStream( xSubStream, sName, sMediaType, pBytes, aRelations );
534 // free the stream resources, garbage collector may remove the object too late
535 if ( !disposeStream( xSubStream, sName ) )
536 return false;
538 return bResult;
541 public boolean copyStorage( XStorage xSourceStorage, XStorage xDestStorage )
543 // copy xSourceStorage to xDestStorage
546 xSourceStorage.copyToStorage( xDestStorage );
548 catch( Exception e )
550 Error( "Storage copying failed, exception: " + e );
551 return false;
554 return true;
557 public boolean commitStorage( XStorage xStorage )
559 // XTransactedObject must be supported by storages
560 XTransactedObject xTransact = (XTransactedObject) UnoRuntime.queryInterface( XTransactedObject.class, xStorage );
561 if ( xTransact == null )
563 Error( "Storage doesn't implement transacted access!" );
564 return false;
569 xTransact.commit();
571 catch( Exception e )
573 Error( "Storage commit failed, exception:" + e );
574 return false;
577 return true;
580 public boolean disposeStream( XStream xStream, String sStreamName )
582 XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xStream );
583 if ( xComponent == null )
585 Error( "Can't get XComponent implementation from substream '" + sStreamName + "'!" );
586 return false;
591 xComponent.dispose();
593 catch( Exception e )
595 Error( "Substream '" + sStreamName + "' disposing throws exception: " + e );
596 return false;
599 return true;
602 public boolean disposeStorage( XStorage xStorage )
604 // dispose the storage
605 XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xStorage );
606 if ( xComponent == null )
608 Error( "Can't retrieve XComponent implementation from storage!" );
609 return false;
614 xComponent.dispose();
616 catch( Exception e )
618 Error( "Storage disposing failed!" );
619 return false;
622 return true;
625 public XInputStream getInputStream( XStream xStream )
627 XInputStream xInTemp = null;
630 xInTemp = xStream.getInputStream();
631 if ( xInTemp == null )
632 Error( "Can't get the input part of a stream!" );
634 catch ( Exception e )
636 Error( "Can't get the input part of a stream, exception :" + e );
639 return xInTemp;
642 public boolean closeOutput( XStream xStream )
644 XOutputStream xOutTemp = null;
647 xOutTemp = xStream.getOutputStream();
648 if ( xOutTemp == null )
650 Error( "Can't get the output part of a stream!" );
651 return false;
654 catch ( Exception e )
656 Error( "Can't get the output part of a stream, exception :" + e );
657 return false;
662 xOutTemp.closeOutput();
664 catch ( Exception e )
666 Error( "Can't close output part of a stream, exception :" + e );
667 return false;
670 return true;
673 public XStorage openSubStorage( XStorage xStorage, String sName, int nMode )
675 // open existing substorage
678 Object oSubStorage = xStorage.openStorageElement( sName, nMode );
679 XStorage xSubStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oSubStorage );
680 return xSubStorage;
682 catch( Exception e )
684 Error( "Can't open substorage '" + sName + "', exception: " + e );
687 return null;
690 public XStream CreateTempFileStream( XMultiServiceFactory xMSF )
692 // try to get temporary file representation
693 XStream xTempFileStream = null;
696 Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" );
697 xTempFileStream = (XStream)UnoRuntime.queryInterface( XStream.class, oTempFile );
699 catch( Exception e )
702 if ( xTempFileStream == null )
703 Error( "Can't create temporary file!" );
705 return xTempFileStream;
708 public String CreateTempFile( XMultiServiceFactory xMSF )
710 String sResult = null;
712 // try to get temporary file representation
713 XPropertySet xTempFileProps = null;
716 Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" );
717 xTempFileProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, oTempFile );
719 catch( Exception e )
722 if ( xTempFileProps != null )
726 xTempFileProps.setPropertyValue( "RemoveFile", new Boolean( false ) );
727 sResult = AnyConverter.toString( xTempFileProps.getPropertyValue( "Uri" ) );
729 catch( Exception e )
731 Error( "Can't control TempFile properties, exception: " + e );
734 else
736 Error( "Can't create temporary file representation!" );
739 // close temporary file explicitly
742 XStream xStream = (XStream)UnoRuntime.queryInterface( XStream.class, xTempFileProps );
743 if ( xStream != null )
745 XOutputStream xOut = xStream.getOutputStream();
746 if ( xOut != null )
747 xOut.closeOutput();
749 XInputStream xIn = xStream.getInputStream();
750 if ( xIn != null )
751 xIn.closeInput();
753 else
754 Error( "Can't close TempFile!" );
756 catch( Exception e )
758 Error( "Can't close TempFile, exception: " + e );
761 return sResult;
764 public boolean copyElementTo( XStorage xSource, String sName, XStorage xDest )
766 // copy element with name sName from xSource to xDest
769 xSource.copyElementTo( sName, xDest, sName );
771 catch( Exception e )
773 Error( "Element copying failed, exception: " + e );
774 return false;
777 return true;
780 public boolean copyElementTo( XStorage xSource, String sName, XStorage xDest, String sTargetName )
782 // copy element with name sName from xSource to xDest
785 xSource.copyElementTo( sName, xDest, sTargetName );
787 catch( Exception e )
789 Error( "Element copying failed, exception: " + e );
790 return false;
793 return true;
796 public boolean moveElementTo( XStorage xSource, String sName, XStorage xDest )
798 // move element with name sName from xSource to xDest
801 xSource.moveElementTo( sName, xDest, sName );
803 catch( Exception e )
805 Error( "Element moving failed, exception: " + e );
806 return false;
809 return true;
812 public boolean renameElement( XStorage xStorage, String sOldName, String sNewName )
814 // rename element with name sOldName to sNewName
817 xStorage.renameElement( sOldName, sNewName );
819 catch( Exception e )
821 Error( "Element renaming failed, exception: " + e );
822 return false;
825 return true;
828 public boolean removeElement( XStorage xStorage, String sName )
830 // remove element with name sName
833 xStorage.removeElement( sName );
835 catch( Exception e )
837 Error( "Element removing failed, exception: " + e );
838 return false;
841 return true;
844 public XStream OpenStream( XStorage xStorage,
845 String sStreamName,
846 int nMode )
848 // open substream element
849 XStream xSubStream = null;
852 Object oSubStream = xStorage.openStreamElement( sStreamName, nMode );
853 xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
854 if ( xSubStream == null )
855 Error( "Can't create substream '" + sStreamName + "'!" );
857 catch( Exception e )
859 Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" );
862 return xSubStream;
865 public boolean cantOpenStorage( XStorage xStorage, String sName )
867 // try to open an opened substorage, open call must fail
870 Object oDummyStorage = xStorage.openStorageElement( sName, ElementModes.READ );
871 Error( "The trying to reopen opened substorage '" + sName + "' must fail!" );
873 catch( Exception e )
875 return true;
878 return false;
881 public boolean cantOpenStream( XStorage xStorage, String sName, int nMode )
883 // try to open the substream with specified mode must fail
886 Object oDummyStream = xStorage.openStreamElement( sName, nMode );
887 Error( "The trying to open substoream '" + sName + "' must fail!" );
889 catch( Exception e )
891 return true;
894 return false;
897 public XStorage createStorageFromURL(
898 XSingleServiceFactory xFactory,
899 String aURL,
900 int nMode )
902 XStorage xResult = null;
906 PropertyValue[] aAddArgs = new PropertyValue[1];
907 aAddArgs[0] = new PropertyValue();
908 aAddArgs[0].Name = "StorageFormat";
909 aAddArgs[0].Value = "OFOPXMLFormat";
911 Object pArgs[] = new Object[3];
912 pArgs[0] = (Object) aURL;
913 pArgs[1] = new Integer( nMode );
914 pArgs[2] = (Object) aAddArgs;
916 Object oTempStorage = xFactory.createInstanceWithArguments( pArgs );
917 xResult = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
919 catch( Exception e )
921 Error( "Can't create storage from URL, exception: " + e );
922 return null;
925 if ( xResult == null )
926 Error( "Can't create storage from URL!" );
928 return xResult;
931 public XStorage createStorageFromStream(
932 XSingleServiceFactory xFactory,
933 XStream xStream,
934 int nMode )
936 XStorage xResult = null;
940 PropertyValue[] aAddArgs = new PropertyValue[1];
941 aAddArgs[0] = new PropertyValue();
942 aAddArgs[0].Name = "StorageFormat";
943 aAddArgs[0].Value = "OFOPXMLFormat";
945 Object pArgs[] = new Object[3];
946 pArgs[0] = (Object) xStream;
947 pArgs[1] = new Integer( nMode );
948 pArgs[2] = (Object) aAddArgs;
950 Object oTempStorage = xFactory.createInstanceWithArguments( pArgs );
951 xResult = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
953 catch( Exception e )
955 Error( "Can't create storage from stream, exception: " + e );
956 return null;
959 if ( xResult == null )
960 Error( "Can't create storage from stream!" );
962 return xResult;
965 public XStorage createStorageFromInputStream(
966 XSingleServiceFactory xFactory,
967 XInputStream xInStream )
969 XStorage xResult = null;
973 PropertyValue[] aAddArgs = new PropertyValue[1];
974 aAddArgs[0] = new PropertyValue();
975 aAddArgs[0].Name = "StorageFormat";
976 aAddArgs[0].Value = "OFOPXMLFormat";
978 Object pArgs[] = new Object[3];
979 pArgs[0] = (Object) xInStream;
980 pArgs[1] = new Integer( ElementModes.READ );
981 pArgs[2] = (Object) aAddArgs;
983 Object oTempStorage = xFactory.createInstanceWithArguments( pArgs );
984 xResult = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
986 catch( Exception e )
988 Error( "Can't create storage from input stream, exception: " + e );
989 return null;
992 if ( xResult == null )
993 Error( "Can't create storage from input stream!" );
995 return xResult;
998 public XStorage createTempStorage( XMultiServiceFactory xMSF, XSingleServiceFactory xFactory )
1000 // create a temporary storage
1001 XStorage xResult = null;
1002 XStream xStream = CreateTempFileStream( xMSF );
1003 if ( xStream == null )
1005 Error( "Can't create temp file stream!" );
1006 return null;
1011 xResult = createStorageFromStream( xFactory, xStream, ElementModes.WRITE );
1013 catch( Exception e )
1015 Error( "Can't create temp storage, exception: " + e );
1018 return xResult;
1021 public XStorage cloneStorage( XMultiServiceFactory xMSF, XSingleServiceFactory xFactory, XStorage xStorage )
1023 // create a copy of a last commited version of specified storage
1024 XStorage xResult = null;
1027 xResult = createTempStorage( xMSF, xFactory );
1028 if ( xResult != null )
1029 xStorage.copyLastCommitTo( xResult );
1031 catch( Exception e )
1033 Error( "Can't clone storage, exception: " + e );
1034 return null;
1037 return xResult;
1040 public XStorage cloneSubStorage( XMultiServiceFactory xMSF, XSingleServiceFactory xFactory, XStorage xStorage, String sName )
1042 // create a copy of a last commited version of specified substorage
1043 XStorage xResult = null;
1046 xResult = createTempStorage( xMSF, xFactory );
1047 if ( xResult != null )
1048 xStorage.copyStorageElementLastCommitTo( sName, xResult );
1050 catch( Exception e )
1052 Error( "Can't clone substorage '" + sName + "', exception: " + e );
1053 return null;
1056 return xResult;
1059 public XStream cloneSubStream( XStorage xStorage, String sName )
1061 // clone existing substream
1064 XStream xStream = xStorage.cloneStreamElement( sName );
1065 return xStream;
1067 catch( Exception e )
1069 Error( "Can't clone substream '" + sName + "', exception: " + e );
1072 return null;
1075 public void Error( String sError )
1077 m_aLogWriter.println( m_sTestPrefix + "Error: " + sError );
1080 public void Message( String sMessage )
1082 m_aLogWriter.println( m_sTestPrefix + sMessage );
1085 public void PrintRelations( StringPair[][] aRels )
1087 m_aLogWriter.println( "========" );
1088 for ( int nInd1 = 0; nInd1 < aRels.length; nInd1++ )
1090 for ( int nInd2 = 0; nInd2 < aRels[nInd1].length; nInd2++ )
1092 m_aLogWriter.println( "\"" + aRels[nInd1][nInd2].First + "\" = \"" + aRels[nInd1][nInd2].Second + "\", " );
1094 m_aLogWriter.println( "========" );