Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / package / qa / ofopxmlstorages / TestHelper.java
blobb7f7a44d9846abaf934d366821cec889bb7af75d
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package complex.ofopxmlstorages;
21 import com.sun.star.uno.UnoRuntime;
22 import com.sun.star.uno.XInterface;
23 import com.sun.star.uno.AnyConverter;
25 import com.sun.star.lang.*;
26 import com.sun.star.embed.*;
27 import com.sun.star.packages.*;
28 import com.sun.star.io.*;
29 import com.sun.star.beans.*;
31 import share.LogWriter;
33 public class TestHelper {
35 LogWriter m_aLogWriter;
36 String m_sTestPrefix;
38 public TestHelper( LogWriter aLogWriter, String sTestPrefix )
40 m_aLogWriter = aLogWriter;
41 m_sTestPrefix = sTestPrefix;
44 public boolean WriteBytesToStream( XStream xStream,
45 String sStreamName,
46 String sMediaType,
47 boolean bCompressed,
48 byte[] pBytes,
49 StringPair[][] aRelations )
51 // get output stream of substream
52 XOutputStream xOutput = xStream.getOutputStream();
53 if ( xOutput == null )
55 Error( "Can't get XOutputStream implementation from substream '" + sStreamName + "'!" );
56 return false;
59 // get XTrucate implementation from output stream
60 XTruncate xTruncate = (XTruncate) UnoRuntime.queryInterface( XTruncate.class, xOutput );
61 if ( xTruncate == null )
63 Error( "Can't get XTruncate implementation from substream '" + sStreamName + "'!" );
64 return false;
67 // write requested byte sequence
68 try
70 xTruncate.truncate();
71 xOutput.writeBytes( pBytes );
73 catch( Exception e )
75 Error( "Can't write to stream '" + sStreamName + "', exception: " + e );
76 return false;
79 // get access to the XPropertySet interface
80 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStream );
81 if ( xPropSet == null )
83 Error( "Can't get XPropertySet implementation from substream '" + sStreamName + "'!" );
84 return false;
87 // set properties to the stream
88 try
90 xPropSet.setPropertyValue( "MediaType", sMediaType );
91 xPropSet.setPropertyValue( "Compressed", Boolean.valueOf( bCompressed ) );
93 catch( Exception e )
95 Error( "Can't set properties to substream '" + sStreamName + "', exception: " + e );
96 return false;
99 // check size property of the stream
102 long nSize = AnyConverter.toLong( xPropSet.getPropertyValue( "Size" ) );
103 if ( nSize != pBytes.length )
105 Error( "The 'Size' property of substream '" + sStreamName + "' contains wrong value!" );
106 return false;
109 catch( Exception e )
111 Error( "Can't get 'Size' property from substream '" + sStreamName + "', exception: " + e );
112 return false;
115 // get access to the relationship information
116 XRelationshipAccess xRelAccess = (XRelationshipAccess) UnoRuntime.queryInterface( XRelationshipAccess.class, xStream );
117 if ( xRelAccess == null )
119 Error( "Can't get XRelationshipAccess implementation from substream '" + sStreamName + "'!" );
120 return false;
123 // set the relationship information
126 xRelAccess.insertRelationships( aRelations, false );
128 catch( Exception e )
130 Error( "Can't set relationships to substream '" + sStreamName + "', exception: " + e );
131 return false;
134 // free the stream resources, garbage collector may remove the object too late
135 if ( !disposeStream( xStream, sStreamName ) )
136 return false;
138 return true;
141 public boolean WriteBytesToSubstream( XStorage xStorage,
142 String sStreamName,
143 String sMediaType,
144 boolean bCompressed,
145 byte[] pBytes,
146 StringPair[][] aRelations )
148 // open substream element
149 XStream xSubStream = null;
152 Object oSubStream = xStorage.openStreamElement( sStreamName, ElementModes.WRITE );
153 xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
154 if ( xSubStream == null )
156 Error( "Can't create substream '" + sStreamName + "'!" );
157 return false;
160 catch( Exception e )
162 Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" );
163 return false;
166 return WriteBytesToStream( xSubStream, sStreamName, sMediaType, bCompressed, pBytes, aRelations );
169 public boolean setStorageTypeAndCheckProps( XStorage xStorage,
170 boolean bIsRoot,
171 int nMode,
172 StringPair[][] aRelations )
174 boolean bOk = false;
176 // get access to the XPropertySet interface
177 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStorage );
178 if ( xPropSet != null )
182 // get "IsRoot" and "OpenMode" properties and control there values
183 boolean bPropIsRoot = AnyConverter.toBoolean( xPropSet.getPropertyValue( "IsRoot" ) );
184 int nPropMode = AnyConverter.toInt( xPropSet.getPropertyValue( "OpenMode" ) );
186 bOk = true;
187 if ( bPropIsRoot != bIsRoot )
189 Error( "'IsRoot' property contains wrong value!" );
190 bOk = false;
193 if ( ( bIsRoot
194 && ( nPropMode | ElementModes.READ ) != ( nMode | ElementModes.READ ) )
195 || ( !bIsRoot && ( nPropMode & nMode ) != nMode ) )
197 Error( "'OpenMode' property contains wrong value, expected " + nMode + ", in reality " + nPropMode + "!" );
198 bOk = false;
201 catch( Exception e )
203 Error( "Can't control properties of substorage, exception: " + e );
206 else
208 Error( "Can't get XPropertySet implementation from storage!" );
211 // get access to the relationship information
212 XRelationshipAccess xRelAccess = (XRelationshipAccess) UnoRuntime.queryInterface( XRelationshipAccess.class, xStorage );
214 if ( xRelAccess == null )
216 Error( "Can't get XRelationshipAccess implementation from the storage!" );
217 return false;
220 // set the relationship information
223 xRelAccess.insertRelationships( aRelations, false );
225 catch( Exception e )
227 Error( "Can't set relationships to the storage, exception: " + e );
228 return false;
232 return bOk;
235 public boolean checkRelations( StringPair[][] aStorRels, StringPair[][] aTestRels )
237 if ( aStorRels.length != aTestRels.length )
239 Error( "The provided relations sequence has different size than the storage's one!" );
240 return false;
243 for ( int nStorInd = 0; nStorInd < aStorRels.length; nStorInd++ )
245 int nStorIDInd = -1;
246 for ( int nStorTagInd = 0; nStorTagInd < aStorRels[nStorInd].length; nStorTagInd++ )
248 if ( aStorRels[nStorInd][nStorTagInd].First.equals( "Id" ) )
250 nStorIDInd = nStorTagInd;
251 break;
255 if ( nStorIDInd == -1 )
257 Error( "One of the storage relations entries has no ID!" );
258 return false;
261 for ( int nInd = 0; nInd < aTestRels.length; nInd++ )
263 int nIDInd = -1;
264 for ( int nTagInd = 0; nTagInd < aTestRels[nInd].length; nTagInd++ )
266 if ( aTestRels[nInd][nTagInd].First.equals( "Id" ) )
268 nIDInd = nTagInd;
269 break;
273 if ( nIDInd == -1 )
275 Error( "One of the test hardcoded entries has no ID, num = " + nInd + ", length = " + aTestRels[nInd].length + ", global length = " + aTestRels.length + "!" );
276 return false;
279 if ( aStorRels[nStorInd][nStorIDInd].Second.equals( aTestRels[nInd][nIDInd].Second ) )
281 boolean[] pRelCheckMark = new boolean[ aTestRels[nInd].length ];
282 for ( int nCheckInd = 0; nCheckInd < pRelCheckMark.length; nCheckInd++ )
284 pRelCheckMark[nCheckInd] = false;
287 for ( int nStorTagInd = 0; nStorTagInd < aStorRels[nStorInd].length; nStorTagInd++ )
289 boolean bFound = false;
290 for ( int nTagInd = 0; nTagInd < aTestRels[nInd].length; nTagInd++ )
292 if ( aTestRels[nInd][nTagInd].First.equals( aStorRels[nStorInd][nStorTagInd].First ) )
294 if ( !aTestRels[nInd][nTagInd].Second.equals( aStorRels[nStorInd][nStorTagInd].Second ) )
296 Error( "Test rel. num. " + nInd + " has different tag \"" + aTestRels[nInd][nTagInd].First + "\" value!" );
297 return false;
300 bFound = true;
301 pRelCheckMark[nTagInd] = true;
302 break;
306 if ( !bFound )
308 Error( "Stor rel. num. " + nStorInd + " has unexpected tag \"" + aStorRels[nStorInd][nStorTagInd].First + "\", ID = \"" + aStorRels[nStorInd][nStorIDInd].Second + "\"!" );
309 return false;
313 for ( int nCheckInd = 0; nCheckInd < pRelCheckMark.length; nCheckInd++ )
315 if ( !pRelCheckMark[nCheckInd] && !aTestRels[nInd][nCheckInd].Second.equals( "" ) )
317 Error( "Test rel. num. " + nInd + " has unexpected tag \"" + aTestRels[nInd][nCheckInd].First + "\" with nonempty value!" );
318 return false;
322 break;
327 return true;
330 public boolean checkStorageProperties( XStorage xStorage,
331 boolean bIsRoot,
332 int nMode,
333 StringPair[][] aRelations )
335 boolean bOk = false;
337 // get access to the XPropertySet interface
338 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStorage );
339 if ( xPropSet != null )
343 // get "IsRoot" and "OpenMode" properties and control there values
344 boolean bPropIsRoot = AnyConverter.toBoolean( xPropSet.getPropertyValue( "IsRoot" ) );
345 int nPropMode = AnyConverter.toInt( xPropSet.getPropertyValue( "OpenMode" ) );
347 bOk = true;
348 if ( bPropIsRoot != bIsRoot )
350 Error( "'IsRoot' property contains wrong value!" );
351 bOk = false;
354 if ( ( bIsRoot
355 && ( nPropMode | ElementModes.READ ) != ( nMode | ElementModes.READ ) )
356 || ( !bIsRoot && ( nPropMode & nMode ) != nMode ) )
358 Error( "'OpenMode' property contains wrong value, expected " + nMode + ", in reality " + nPropMode + "!" );
359 bOk = false;
362 catch( Exception e )
364 Error( "Can't get properties of substorage, exception: " + e );
367 else
369 Error( "Can't get XPropertySet implementation from storage!" );
372 // get access to the relationship information
373 XRelationshipAccess xRelAccess = (XRelationshipAccess) UnoRuntime.queryInterface( XRelationshipAccess.class, xStorage );
375 if ( xRelAccess == null )
377 Error( "Can't get XRelationshipAccess implementation from the checked storage!" );
378 return false;
381 // get the relationship information
382 StringPair[][] aStorRels;
385 aStorRels = xRelAccess.getAllRelationships();
387 catch( Exception e )
389 Error( "Can't get relationships of the checked storage, exception: " + e );
390 return false;
393 if ( !checkRelations( aStorRels, aRelations ) )
395 Error( "StorageRelationsChecking has failed!" );
396 return false;
399 return bOk;
402 public boolean InternalCheckStream( XStream xStream,
403 String sName,
404 String sMediaType,
405 byte[] pBytes,
406 StringPair[][] aRelations )
408 // get input stream of substream
409 XInputStream xInput = xStream.getInputStream();
410 if ( xInput == null )
412 Error( "Can't get XInputStream implementation from substream '" + sName + "'!" );
413 return false;
416 byte pContents[][] = new byte[1][]; // ???
418 // read contents
421 xInput.readBytes( pContents, pBytes.length + 1 );
423 catch( Exception e )
425 Error( "Can't read from stream '" + sName + "', exception: " + e );
426 return false;
429 // check size of stream data
430 if ( pContents.length == 0 )
432 Error( "SubStream '" + sName + "' reading produced disaster!" );
433 return false;
436 if ( pBytes.length != pContents[0].length )
438 Error( "SubStream '" + sName + "' contains wrong amount of data! (" + pContents[0].length + "/" + pBytes.length + ")" );
439 return false;
442 // check stream data
443 for ( int ind = 0; ind < pBytes.length; ind++ )
445 if ( pBytes[ind] != pContents[0][ind] )
447 Error( "SubStream '" + sName + "' contains wrong data! ( byte num. "
448 + ind + " should be" + pBytes[ind] + " but it is " + pContents[0][ind] + ")" );
449 return false;
453 // check properties
454 boolean bOk = false;
456 // get access to the XPropertySet interface
457 XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStream );
458 if ( xPropSet != null )
462 // get "MediaType" and "Size" properties and control there values
463 String sPropMediaType = AnyConverter.toString( xPropSet.getPropertyValue( "MediaType" ) );
464 long nPropSize = AnyConverter.toLong( xPropSet.getPropertyValue( "Size" ) );
466 bOk = true;
467 if ( !sPropMediaType.equals( sMediaType ) )
469 Error( "'MediaType' property contains wrong value for stream '" + sName + "',\nexpected: '"
470 + sMediaType + "', set: '" + sPropMediaType + "'!" );
471 bOk = false;
474 if ( nPropSize != pBytes.length )
476 Error( "'Size' property contains wrong value for stream'" + sName + "'!" );
477 bOk = false;
480 catch( Exception e )
482 Error( "Can't get properties of substream '" + sName + "', exception: " + e );
485 else
487 Error( "Can't get XPropertySet implementation from stream '" + sName + "'!" );
491 // get access to the relationship information
492 XRelationshipAccess xRelAccess = (XRelationshipAccess) UnoRuntime.queryInterface( XRelationshipAccess.class, xStream );
494 if ( xRelAccess == null )
496 Error( "Can't get XRelationshipAccess implementation from the stream\"" + sName + "\"!" );
497 return false;
500 // get the relationship information
501 StringPair[][] aStorRels;
504 aStorRels = xRelAccess.getAllRelationships();
506 catch( Exception e )
508 Error( "Can't get relationships of the substream '" + sName + "', exception: " + e );
509 return false;
512 if ( !checkRelations( aStorRels, aRelations ) )
514 Error( "Stream '" + sName + "' RelationsChecking has failed!" );
515 return false;
518 return bOk;
521 public boolean checkStream( XStorage xParentStorage,
522 String sName,
523 String sMediaType,
524 byte[] pBytes,
525 StringPair[][] aRelations )
527 // open substream element first
528 XStream xSubStream = null;
531 Object oSubStream = xParentStorage.openStreamElement( sName, ElementModes.READ );
532 xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
533 if ( xSubStream == null )
535 Error( "Can't open substream '" + sName + "'!" );
536 return false;
539 catch( Exception e )
541 Error( "Can't open substream '" + sName + "', exception : " + e + "!" );
542 return false;
545 boolean bResult = InternalCheckStream( xSubStream, sName, sMediaType, pBytes, aRelations );
547 // free the stream resources, garbage collector may remove the object too late
548 if ( !disposeStream( xSubStream, sName ) )
549 return false;
551 return bResult;
554 public boolean copyStorage( XStorage xSourceStorage, XStorage xDestStorage )
556 // copy xSourceStorage to xDestStorage
559 xSourceStorage.copyToStorage( xDestStorage );
561 catch( Exception e )
563 Error( "Storage copying failed, exception: " + e );
564 return false;
567 return true;
570 public boolean commitStorage( XStorage xStorage )
572 // XTransactedObject must be supported by storages
573 XTransactedObject xTransact = (XTransactedObject) UnoRuntime.queryInterface( XTransactedObject.class, xStorage );
574 if ( xTransact == null )
576 Error( "Storage doesn't implement transacted access!" );
577 return false;
582 xTransact.commit();
584 catch( Exception e )
586 Error( "Storage commit failed, exception:" + e );
587 return false;
590 return true;
593 public boolean disposeStream( XStream xStream, String sStreamName )
595 XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xStream );
596 if ( xComponent == null )
598 Error( "Can't get XComponent implementation from substream '" + sStreamName + "'!" );
599 return false;
604 xComponent.dispose();
606 catch( Exception e )
608 Error( "Substream '" + sStreamName + "' disposing throws exception: " + e );
609 return false;
612 return true;
615 public boolean disposeStorage( XStorage xStorage )
617 // dispose the storage
618 XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xStorage );
619 if ( xComponent == null )
621 Error( "Can't retrieve XComponent implementation from storage!" );
622 return false;
627 xComponent.dispose();
629 catch( Exception e )
631 Error( "Storage disposing failed!" );
632 return false;
635 return true;
638 public XInputStream getInputStream( XStream xStream )
640 XInputStream xInTemp = null;
643 xInTemp = xStream.getInputStream();
644 if ( xInTemp == null )
645 Error( "Can't get the input part of a stream!" );
647 catch ( Exception e )
649 Error( "Can't get the input part of a stream, exception :" + e );
652 return xInTemp;
655 public boolean closeOutput( XStream xStream )
657 XOutputStream xOutTemp = null;
660 xOutTemp = xStream.getOutputStream();
661 if ( xOutTemp == null )
663 Error( "Can't get the output part of a stream!" );
664 return false;
667 catch ( Exception e )
669 Error( "Can't get the output part of a stream, exception :" + e );
670 return false;
675 xOutTemp.closeOutput();
677 catch ( Exception e )
679 Error( "Can't close output part of a stream, exception :" + e );
680 return false;
683 return true;
686 public XStorage openSubStorage( XStorage xStorage, String sName, int nMode )
688 // open existing substorage
691 Object oSubStorage = xStorage.openStorageElement( sName, nMode );
692 XStorage xSubStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oSubStorage );
693 return xSubStorage;
695 catch( Exception e )
697 Error( "Can't open substorage '" + sName + "', exception: " + e );
700 return null;
703 public XStream CreateTempFileStream( XMultiServiceFactory xMSF )
705 // try to get temporary file representation
706 XStream xTempFileStream = null;
709 Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" );
710 xTempFileStream = (XStream)UnoRuntime.queryInterface( XStream.class, oTempFile );
712 catch( Exception e )
715 if ( xTempFileStream == null )
716 Error( "Can't create temporary file!" );
718 return xTempFileStream;
721 public String CreateTempFile( XMultiServiceFactory xMSF )
723 String sResult = null;
725 // try to get temporary file representation
726 XPropertySet xTempFileProps = null;
729 Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" );
730 xTempFileProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, oTempFile );
732 catch( Exception e )
735 if ( xTempFileProps != null )
739 xTempFileProps.setPropertyValue( "RemoveFile", Boolean.FALSE );
740 sResult = AnyConverter.toString( xTempFileProps.getPropertyValue( "Uri" ) );
742 catch( Exception e )
744 Error( "Can't control TempFile properties, exception: " + e );
747 else
749 Error( "Can't create temporary file representation!" );
752 // close temporary file explicitly
755 XStream xStream = (XStream)UnoRuntime.queryInterface( XStream.class, xTempFileProps );
756 if ( xStream != null )
758 XOutputStream xOut = xStream.getOutputStream();
759 if ( xOut != null )
760 xOut.closeOutput();
762 XInputStream xIn = xStream.getInputStream();
763 if ( xIn != null )
764 xIn.closeInput();
766 else
767 Error( "Can't close TempFile!" );
769 catch( Exception e )
771 Error( "Can't close TempFile, exception: " + e );
774 return sResult;
777 public boolean copyElementTo( XStorage xSource, String sName, XStorage xDest )
779 // copy element with name sName from xSource to xDest
782 xSource.copyElementTo( sName, xDest, sName );
784 catch( Exception e )
786 Error( "Element copying failed, exception: " + e );
787 return false;
790 return true;
793 public boolean copyElementTo( XStorage xSource, String sName, XStorage xDest, String sTargetName )
795 // copy element with name sName from xSource to xDest
798 xSource.copyElementTo( sName, xDest, sTargetName );
800 catch( Exception e )
802 Error( "Element copying failed, exception: " + e );
803 return false;
806 return true;
809 public boolean moveElementTo( XStorage xSource, String sName, XStorage xDest )
811 // move element with name sName from xSource to xDest
814 xSource.moveElementTo( sName, xDest, sName );
816 catch( Exception e )
818 Error( "Element moving failed, exception: " + e );
819 return false;
822 return true;
825 public boolean renameElement( XStorage xStorage, String sOldName, String sNewName )
827 // rename element with name sOldName to sNewName
830 xStorage.renameElement( sOldName, sNewName );
832 catch( Exception e )
834 Error( "Element renaming failed, exception: " + e );
835 return false;
838 return true;
841 public boolean removeElement( XStorage xStorage, String sName )
843 // remove element with name sName
846 xStorage.removeElement( sName );
848 catch( Exception e )
850 Error( "Element removing failed, exception: " + e );
851 return false;
854 return true;
857 public XStream OpenStream( XStorage xStorage,
858 String sStreamName,
859 int nMode )
861 // open substream element
862 XStream xSubStream = null;
865 Object oSubStream = xStorage.openStreamElement( sStreamName, nMode );
866 xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream );
867 if ( xSubStream == null )
868 Error( "Can't create substream '" + sStreamName + "'!" );
870 catch( Exception e )
872 Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" );
875 return xSubStream;
878 public boolean cantOpenStorage( XStorage xStorage, String sName )
880 // try to open an opened substorage, open call must fail
883 Object oDummyStorage = xStorage.openStorageElement( sName, ElementModes.READ );
884 Error( "The trying to reopen opened substorage '" + sName + "' must fail!" );
886 catch( Exception e )
888 return true;
891 return false;
894 public boolean cantOpenStream( XStorage xStorage, String sName, int nMode )
896 // try to open the substream with specified mode must fail
899 Object oDummyStream = xStorage.openStreamElement( sName, nMode );
900 Error( "The trying to open substoream '" + sName + "' must fail!" );
902 catch( Exception e )
904 return true;
907 return false;
910 public XStorage createStorageFromURL(
911 XSingleServiceFactory xFactory,
912 String aURL,
913 int nMode )
915 XStorage xResult = null;
919 PropertyValue[] aAddArgs = new PropertyValue[1];
920 aAddArgs[0] = new PropertyValue();
921 aAddArgs[0].Name = "StorageFormat";
922 aAddArgs[0].Value = "OFOPXMLFormat";
924 Object pArgs[] = new Object[3];
925 pArgs[0] = (Object) aURL;
926 pArgs[1] = Integer.valueOf( nMode );
927 pArgs[2] = (Object) aAddArgs;
929 Object oTempStorage = xFactory.createInstanceWithArguments( pArgs );
930 xResult = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
932 catch( Exception e )
934 Error( "Can't create storage from URL, exception: " + e );
935 return null;
938 if ( xResult == null )
939 Error( "Can't create storage from URL!" );
941 return xResult;
944 public XStorage createStorageFromStream(
945 XSingleServiceFactory xFactory,
946 XStream xStream,
947 int nMode )
949 XStorage xResult = null;
953 PropertyValue[] aAddArgs = new PropertyValue[1];
954 aAddArgs[0] = new PropertyValue();
955 aAddArgs[0].Name = "StorageFormat";
956 aAddArgs[0].Value = "OFOPXMLFormat";
958 Object pArgs[] = new Object[3];
959 pArgs[0] = (Object) xStream;
960 pArgs[1] = Integer.valueOf( nMode );
961 pArgs[2] = (Object) aAddArgs;
963 Object oTempStorage = xFactory.createInstanceWithArguments( pArgs );
964 xResult = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
966 catch( Exception e )
968 Error( "Can't create storage from stream, exception: " + e );
969 return null;
972 if ( xResult == null )
973 Error( "Can't create storage from stream!" );
975 return xResult;
978 public XStorage createStorageFromInputStream(
979 XSingleServiceFactory xFactory,
980 XInputStream xInStream )
982 XStorage xResult = null;
986 PropertyValue[] aAddArgs = new PropertyValue[1];
987 aAddArgs[0] = new PropertyValue();
988 aAddArgs[0].Name = "StorageFormat";
989 aAddArgs[0].Value = "OFOPXMLFormat";
991 Object pArgs[] = new Object[3];
992 pArgs[0] = (Object) xInStream;
993 pArgs[1] = Integer.valueOf( ElementModes.READ );
994 pArgs[2] = (Object) aAddArgs;
996 Object oTempStorage = xFactory.createInstanceWithArguments( pArgs );
997 xResult = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage );
999 catch( Exception e )
1001 Error( "Can't create storage from input stream, exception: " + e );
1002 return null;
1005 if ( xResult == null )
1006 Error( "Can't create storage from input stream!" );
1008 return xResult;
1011 public XStorage createTempStorage( XMultiServiceFactory xMSF, XSingleServiceFactory xFactory )
1013 // create a temporary storage
1014 XStorage xResult = null;
1015 XStream xStream = CreateTempFileStream( xMSF );
1016 if ( xStream == null )
1018 Error( "Can't create temp file stream!" );
1019 return null;
1024 xResult = createStorageFromStream( xFactory, xStream, ElementModes.WRITE );
1026 catch( Exception e )
1028 Error( "Can't create temp storage, exception: " + e );
1031 return xResult;
1034 public XStorage cloneStorage( XMultiServiceFactory xMSF, XSingleServiceFactory xFactory, XStorage xStorage )
1036 // create a copy of a last committed version of specified storage
1037 XStorage xResult = null;
1040 xResult = createTempStorage( xMSF, xFactory );
1041 if ( xResult != null )
1042 xStorage.copyLastCommitTo( xResult );
1044 catch( Exception e )
1046 Error( "Can't clone storage, exception: " + e );
1047 return null;
1050 return xResult;
1053 public XStorage cloneSubStorage( XMultiServiceFactory xMSF, XSingleServiceFactory xFactory, XStorage xStorage, String sName )
1055 // create a copy of a last committed version of specified substorage
1056 XStorage xResult = null;
1059 xResult = createTempStorage( xMSF, xFactory );
1060 if ( xResult != null )
1061 xStorage.copyStorageElementLastCommitTo( sName, xResult );
1063 catch( Exception e )
1065 Error( "Can't clone substorage '" + sName + "', exception: " + e );
1066 return null;
1069 return xResult;
1072 public XStream cloneSubStream( XStorage xStorage, String sName )
1074 // clone existing substream
1077 XStream xStream = xStorage.cloneStreamElement( sName );
1078 return xStream;
1080 catch( Exception e )
1082 Error( "Can't clone substream '" + sName + "', exception: " + e );
1085 return null;
1088 public void Error( String sError )
1090 m_aLogWriter.println( m_sTestPrefix + "Error: " + sError );
1093 public void Message( String sMessage )
1095 m_aLogWriter.println( m_sTestPrefix + sMessage );
1098 public void PrintRelations( StringPair[][] aRels )
1100 m_aLogWriter.println( "========" );
1101 for ( int nInd1 = 0; nInd1 < aRels.length; nInd1++ )
1103 for ( int nInd2 = 0; nInd2 < aRels[nInd1].length; nInd2++ )
1105 m_aLogWriter.println( "\"" + aRels[nInd1][nInd2].First + "\" = \"" + aRels[nInd1][nInd2].Second + "\", " );
1107 m_aLogWriter.println( "========" );