1*cdf0e10cSrcweir package complex.ofopxmlstorages; 2*cdf0e10cSrcweir 3*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 4*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 5*cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory; 6*cdf0e10cSrcweir 7*cdf0e10cSrcweir import com.sun.star.bridge.XUnoUrlResolver; 8*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 9*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 10*cdf0e10cSrcweir import com.sun.star.io.XStream; 11*cdf0e10cSrcweir import com.sun.star.io.XInputStream; 12*cdf0e10cSrcweir 13*cdf0e10cSrcweir import com.sun.star.embed.*; 14*cdf0e10cSrcweir import com.sun.star.beans.StringPair; 15*cdf0e10cSrcweir 16*cdf0e10cSrcweir import share.LogWriter; 17*cdf0e10cSrcweir import complex.ofopxmlstorages.TestHelper; 18*cdf0e10cSrcweir import complex.ofopxmlstorages.StorageTest; 19*cdf0e10cSrcweir 20*cdf0e10cSrcweir public class Test02 implements StorageTest { 21*cdf0e10cSrcweir 22*cdf0e10cSrcweir XMultiServiceFactory m_xMSF; 23*cdf0e10cSrcweir XSingleServiceFactory m_xStorageFactory; 24*cdf0e10cSrcweir TestHelper m_aTestHelper; 25*cdf0e10cSrcweir 26*cdf0e10cSrcweir public Test02( XMultiServiceFactory xMSF, XSingleServiceFactory xStorageFactory, LogWriter aLogWriter ) 27*cdf0e10cSrcweir { 28*cdf0e10cSrcweir m_xMSF = xMSF; 29*cdf0e10cSrcweir m_xStorageFactory = xStorageFactory; 30*cdf0e10cSrcweir m_aTestHelper = new TestHelper( aLogWriter, "Test02: " ); 31*cdf0e10cSrcweir } 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir public boolean test() 34*cdf0e10cSrcweir { 35*cdf0e10cSrcweir try 36*cdf0e10cSrcweir { 37*cdf0e10cSrcweir StringPair[][] aRelations = 38*cdf0e10cSrcweir { { new StringPair( "Id", "Num1" ) }, 39*cdf0e10cSrcweir { new StringPair( "Target", "TargetURLValue" ), new StringPair( "Id", "Num6" ) }, 40*cdf0e10cSrcweir { new StringPair( "Target", "" ), new StringPair( "Id", "Num7" ) }, 41*cdf0e10cSrcweir { new StringPair( "Id", "Num2" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, 42*cdf0e10cSrcweir { new StringPair( "Id", "Num3" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, 43*cdf0e10cSrcweir { new StringPair( "Id", "Num4" ), new StringPair( "TargetMode", "Internal" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) }, 44*cdf0e10cSrcweir { new StringPair( "Id", "Num5" ), new StringPair( "TargetMode", "" ), new StringPair( "Type", "unknown" ), new StringPair( "Target", "URL value" ) } 45*cdf0e10cSrcweir }; 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir XStream xTempFileStream = m_aTestHelper.CreateTempFileStream( m_xMSF ); 49*cdf0e10cSrcweir if ( xTempFileStream == null ) 50*cdf0e10cSrcweir return false; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir // create storage based on the temporary stream 53*cdf0e10cSrcweir XStorage xTempStorage = m_aTestHelper.createStorageFromStream( m_xStorageFactory, 54*cdf0e10cSrcweir xTempFileStream, 55*cdf0e10cSrcweir ElementModes.WRITE ); 56*cdf0e10cSrcweir if ( xTempStorage == null ) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create temporary storage representation!" ); 59*cdf0e10cSrcweir return false; 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir // open a new substorage 63*cdf0e10cSrcweir XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, 64*cdf0e10cSrcweir "SubStorage1", 65*cdf0e10cSrcweir ElementModes.WRITE ); 66*cdf0e10cSrcweir if ( xTempSubStorage == null ) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir m_aTestHelper.Error( "Can't create substorage!" ); 69*cdf0e10cSrcweir return false; 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir byte pBytes1[] = { 1, 1, 1, 1, 1 }; 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir // open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes 75*cdf0e10cSrcweir if ( !m_aTestHelper.WriteBytesToSubstream( xTempSubStorage, 76*cdf0e10cSrcweir "SubStream1", 77*cdf0e10cSrcweir "MediaType1", 78*cdf0e10cSrcweir true, 79*cdf0e10cSrcweir pBytes1, 80*cdf0e10cSrcweir aRelations ) ) 81*cdf0e10cSrcweir return false; 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly 84*cdf0e10cSrcweir if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage, 85*cdf0e10cSrcweir true, 86*cdf0e10cSrcweir ElementModes.WRITE, 87*cdf0e10cSrcweir aRelations ) ) 88*cdf0e10cSrcweir return false; 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir // set Relations for storages and check that "IsRoot" and "OpenMode" properties are set correctly 91*cdf0e10cSrcweir if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage, 92*cdf0e10cSrcweir false, 93*cdf0e10cSrcweir ElementModes.WRITE, 94*cdf0e10cSrcweir aRelations ) ) 95*cdf0e10cSrcweir return false; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir // commit substorage first 98*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) 99*cdf0e10cSrcweir return false; 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir // commit the root storage so the contents must be stored now 102*cdf0e10cSrcweir if ( !m_aTestHelper.commitStorage( xTempStorage ) ) 103*cdf0e10cSrcweir return false; 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir // dispose used storage to free resources 106*cdf0e10cSrcweir if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) 107*cdf0e10cSrcweir return false; 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir // ================================================ 111*cdf0e10cSrcweir // now check all the written information 112*cdf0e10cSrcweir // ================================================ 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir // close the output part of the temporary stream 115*cdf0e10cSrcweir // the output part must present since we already wrote to the stream 116*cdf0e10cSrcweir if ( !m_aTestHelper.closeOutput( xTempFileStream ) ) 117*cdf0e10cSrcweir return false; 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir XInputStream xTempInStream = m_aTestHelper.getInputStream( xTempFileStream ); 120*cdf0e10cSrcweir if ( xTempInStream == null ) 121*cdf0e10cSrcweir return false; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir // open input stream 125*cdf0e10cSrcweir XStorage xResultStorage = m_aTestHelper.createStorageFromInputStream( m_xStorageFactory, xTempInStream ); 126*cdf0e10cSrcweir if ( xResultStorage == null ) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir m_aTestHelper.Error( "Can't open storage based on input stream!" ); 129*cdf0e10cSrcweir return false; 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir if ( !m_aTestHelper.checkStorageProperties( xResultStorage, true, ElementModes.READ, aRelations ) ) 133*cdf0e10cSrcweir return false; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir // open existing substorage 136*cdf0e10cSrcweir XStorage xResultSubStorage = m_aTestHelper.openSubStorage( xResultStorage, 137*cdf0e10cSrcweir "SubStorage1", 138*cdf0e10cSrcweir ElementModes.READ ); 139*cdf0e10cSrcweir if ( xResultSubStorage == null ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir m_aTestHelper.Error( "Can't open existing substorage!" ); 142*cdf0e10cSrcweir return false; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, 146*cdf0e10cSrcweir false, 147*cdf0e10cSrcweir ElementModes.READ, 148*cdf0e10cSrcweir aRelations ) ) 149*cdf0e10cSrcweir return false; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir if ( !m_aTestHelper.checkStream( xResultSubStorage, "SubStream1", "MediaType1", pBytes1, aRelations ) ) 152*cdf0e10cSrcweir return false; 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir return true; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir catch( Exception e ) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir m_aTestHelper.Error( "Exception: " + e ); 159*cdf0e10cSrcweir return false; 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165