1*ae15d43aSAndrew Rist /************************************************************** 2*ae15d43aSAndrew Rist * 3*ae15d43aSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ae15d43aSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ae15d43aSAndrew Rist * distributed with this work for additional information 6*ae15d43aSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ae15d43aSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ae15d43aSAndrew Rist * "License"); you may not use this file except in compliance 9*ae15d43aSAndrew Rist * with the License. You may obtain a copy of the License at 10*ae15d43aSAndrew Rist * 11*ae15d43aSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ae15d43aSAndrew Rist * 13*ae15d43aSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ae15d43aSAndrew Rist * software distributed under the License is distributed on an 15*ae15d43aSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ae15d43aSAndrew Rist * KIND, either express or implied. See the License for the 17*ae15d43aSAndrew Rist * specific language governing permissions and limitations 18*ae15d43aSAndrew Rist * under the License. 19*ae15d43aSAndrew Rist * 20*ae15d43aSAndrew Rist *************************************************************/ 21*ae15d43aSAndrew Rist 22cdf0e10cSrcweir package storagetesting; 23cdf0e10cSrcweir 24cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 25cdf0e10cSrcweir import com.sun.star.uno.XInterface; 26cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 27cdf0e10cSrcweir 28cdf0e10cSrcweir import com.sun.star.lang.*; 29cdf0e10cSrcweir import com.sun.star.embed.*; 30cdf0e10cSrcweir import com.sun.star.packages.*; 31cdf0e10cSrcweir import com.sun.star.io.*; 32cdf0e10cSrcweir import com.sun.star.beans.*; 33cdf0e10cSrcweir 34cdf0e10cSrcweir public class TestHelper { 35cdf0e10cSrcweir 36cdf0e10cSrcweir String m_sTestPrefix; 37cdf0e10cSrcweir TestHelper( String sTestPrefix )38cdf0e10cSrcweir public TestHelper( String sTestPrefix ) 39cdf0e10cSrcweir { 40cdf0e10cSrcweir m_sTestPrefix = sTestPrefix; 41cdf0e10cSrcweir } 42cdf0e10cSrcweir WriteBytesToStream( XStream xStream, String sStreamName, String sMediaType, boolean bCompressed, byte[] pBytes )43cdf0e10cSrcweir public boolean WriteBytesToStream( XStream xStream, 44cdf0e10cSrcweir String sStreamName, 45cdf0e10cSrcweir String sMediaType, 46cdf0e10cSrcweir boolean bCompressed, 47cdf0e10cSrcweir byte[] pBytes ) 48cdf0e10cSrcweir { 49cdf0e10cSrcweir // get output stream of substream 50cdf0e10cSrcweir XOutputStream xOutput = xStream.getOutputStream(); 51cdf0e10cSrcweir if ( xOutput == null ) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir Error( "Can't get XOutputStream implementation from substream '" + sStreamName + "'!" ); 54cdf0e10cSrcweir return false; 55cdf0e10cSrcweir } 56cdf0e10cSrcweir 57cdf0e10cSrcweir // get XTrucate implementation from output stream 58cdf0e10cSrcweir XTruncate xTruncate = (XTruncate) UnoRuntime.queryInterface( XTruncate.class, xOutput ); 59cdf0e10cSrcweir if ( xTruncate == null ) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir Error( "Can't get XTruncate implementation from substream '" + sStreamName + "'!" ); 62cdf0e10cSrcweir return false; 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir // write requested byte sequence 66cdf0e10cSrcweir try 67cdf0e10cSrcweir { 68cdf0e10cSrcweir xTruncate.truncate(); 69cdf0e10cSrcweir xOutput.writeBytes( pBytes ); 70cdf0e10cSrcweir } 71cdf0e10cSrcweir catch( Exception e ) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir Error( "Can't write to stream '" + sStreamName + "', exception: " + e ); 74cdf0e10cSrcweir return false; 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir // get access to the XPropertySet interface 78cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStream ); 79cdf0e10cSrcweir if ( xPropSet == null ) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir Error( "Can't get XPropertySet implementation from substream '" + sStreamName + "'!" ); 82cdf0e10cSrcweir return false; 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir // set properties to the stream 86cdf0e10cSrcweir try 87cdf0e10cSrcweir { 88cdf0e10cSrcweir xPropSet.setPropertyValue( "MediaType", sMediaType ); 89cdf0e10cSrcweir xPropSet.setPropertyValue( "Compressed", new Boolean( bCompressed ) ); 90cdf0e10cSrcweir } 91cdf0e10cSrcweir catch( Exception e ) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir Error( "Can't set properties to substream '" + sStreamName + "', exception: " + e ); 94cdf0e10cSrcweir return false; 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir // check size property of the stream 98cdf0e10cSrcweir try 99cdf0e10cSrcweir { 100cdf0e10cSrcweir int nSize = AnyConverter.toInt( xPropSet.getPropertyValue( "Size" ) ); 101cdf0e10cSrcweir if ( nSize != pBytes.length ) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir Error( "The 'Size' property of substream '" + sStreamName + "' contains wrong value!" ); 104cdf0e10cSrcweir return false; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir } 107cdf0e10cSrcweir catch( Exception e ) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir Error( "Can't get 'Size' property from substream '" + sStreamName + "', exception: " + e ); 110cdf0e10cSrcweir return false; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir // free the stream resources, garbage collector may remove the object too late 114cdf0e10cSrcweir XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xStream ); 115cdf0e10cSrcweir if ( xComponent == null ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir Error( "Can't get XComponent implementation from substream '" + sStreamName + "'!" ); 118cdf0e10cSrcweir return false; 119cdf0e10cSrcweir } 120cdf0e10cSrcweir xComponent.dispose(); 121cdf0e10cSrcweir 122cdf0e10cSrcweir return true; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir WriteBytesToSubstream( XStorage xStorage, String sStreamName, String sMediaType, boolean bCompressed, byte[] pBytes )126cdf0e10cSrcweir public boolean WriteBytesToSubstream( XStorage xStorage, 127cdf0e10cSrcweir String sStreamName, 128cdf0e10cSrcweir String sMediaType, 129cdf0e10cSrcweir boolean bCompressed, 130cdf0e10cSrcweir byte[] pBytes ) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir // open substream element 133cdf0e10cSrcweir XStream xSubStream = null; 134cdf0e10cSrcweir try 135cdf0e10cSrcweir { 136cdf0e10cSrcweir Object oSubStream = xStorage.openStreamElement( sStreamName, ElementModes.ELEMENT_WRITE ); 137cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 138cdf0e10cSrcweir if ( xSubStream == null ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "'!" ); 141cdf0e10cSrcweir return false; 142cdf0e10cSrcweir } 143cdf0e10cSrcweir } 144cdf0e10cSrcweir catch( Exception e ) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" ); 147cdf0e10cSrcweir return false; 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir return WriteBytesToStream( xSubStream, sStreamName, sMediaType, bCompressed, pBytes ); 151cdf0e10cSrcweir } 152cdf0e10cSrcweir WriteBytesToEncrSubstream( XStorage xStorage, String sStreamName, String sMediaType, boolean bCompressed, byte[] pBytes, byte[] pPass )153cdf0e10cSrcweir public boolean WriteBytesToEncrSubstream( XStorage xStorage, 154cdf0e10cSrcweir String sStreamName, 155cdf0e10cSrcweir String sMediaType, 156cdf0e10cSrcweir boolean bCompressed, 157cdf0e10cSrcweir byte[] pBytes, 158cdf0e10cSrcweir byte[] pPass ) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir // open substream element 161cdf0e10cSrcweir XStream xSubStream = null; 162cdf0e10cSrcweir try 163cdf0e10cSrcweir { 164cdf0e10cSrcweir Object oSubStream = xStorage.openEncryptedStreamElement( sStreamName, ElementModes.ELEMENT_WRITE, pPass ); 165cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 166cdf0e10cSrcweir if ( xSubStream == null ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "'!" ); 169cdf0e10cSrcweir return false; 170cdf0e10cSrcweir } 171cdf0e10cSrcweir } 172cdf0e10cSrcweir catch( Exception e ) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" ); 175cdf0e10cSrcweir return false; 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir return WriteBytesToStream( xSubStream, sStreamName, sMediaType, bCompressed, pBytes ); 179cdf0e10cSrcweir } 180cdf0e10cSrcweir WBToSubstrOfEncr( XStorage xStorage, String sStreamName, String sMediaType, boolean bCompressed, byte[] pBytes, boolean bEncrypted )181cdf0e10cSrcweir public boolean WBToSubstrOfEncr( XStorage xStorage, 182cdf0e10cSrcweir String sStreamName, 183cdf0e10cSrcweir String sMediaType, 184cdf0e10cSrcweir boolean bCompressed, 185cdf0e10cSrcweir byte[] pBytes, 186cdf0e10cSrcweir boolean bEncrypted ) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir // open substream element 189cdf0e10cSrcweir XStream xSubStream = null; 190cdf0e10cSrcweir try 191cdf0e10cSrcweir { 192cdf0e10cSrcweir Object oSubStream = xStorage.openStreamElement( sStreamName, ElementModes.ELEMENT_WRITE ); 193cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 194cdf0e10cSrcweir if ( xSubStream == null ) 195cdf0e10cSrcweir { 196cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "'!" ); 197cdf0e10cSrcweir return false; 198cdf0e10cSrcweir } 199cdf0e10cSrcweir } 200cdf0e10cSrcweir catch( Exception e ) 201cdf0e10cSrcweir { 202cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" ); 203cdf0e10cSrcweir return false; 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir // get access to the XPropertySet interface 207cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xSubStream ); 208cdf0e10cSrcweir if ( xPropSet == null ) 209cdf0e10cSrcweir { 210cdf0e10cSrcweir Error( "Can't get XPropertySet implementation from substream '" + sStreamName + "'!" ); 211cdf0e10cSrcweir return false; 212cdf0e10cSrcweir } 213cdf0e10cSrcweir 214cdf0e10cSrcweir // set properties to the stream 215cdf0e10cSrcweir try 216cdf0e10cSrcweir { 217cdf0e10cSrcweir xPropSet.setPropertyValue( "Encrypted", new Boolean( bEncrypted ) ); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir catch( Exception e ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir Error( "Can't set 'Encrypted' property to substream '" + sStreamName + "', exception: " + e ); 222cdf0e10cSrcweir return false; 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225cdf0e10cSrcweir return WriteBytesToStream( xSubStream, sStreamName, sMediaType, bCompressed, pBytes ); 226cdf0e10cSrcweir } 227cdf0e10cSrcweir ChangeStreamPass( XStorage xStorage, String sStreamName, byte[] pOldPass, byte[] pNewPass )228cdf0e10cSrcweir public int ChangeStreamPass( XStorage xStorage, 229cdf0e10cSrcweir String sStreamName, 230cdf0e10cSrcweir byte[] pOldPass, 231cdf0e10cSrcweir byte[] pNewPass ) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir // open substream element 234cdf0e10cSrcweir XStream xSubStream = null; 235cdf0e10cSrcweir try 236cdf0e10cSrcweir { 237cdf0e10cSrcweir Object oSubStream = xStorage.openEncryptedStreamElement( sStreamName, ElementModes.ELEMENT_WRITE, pOldPass ); 238cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 239cdf0e10cSrcweir if ( xSubStream == null ) 240cdf0e10cSrcweir { 241cdf0e10cSrcweir Error( "Can't open substream '" + sStreamName + "'!" ); 242cdf0e10cSrcweir return 0; 243cdf0e10cSrcweir } 244cdf0e10cSrcweir } 245cdf0e10cSrcweir catch( Exception e ) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir Error( "Can't open substream '" + sStreamName + "', exception : " + e + "!" ); 248cdf0e10cSrcweir return 0; 249cdf0e10cSrcweir } 250cdf0e10cSrcweir 251cdf0e10cSrcweir 252cdf0e10cSrcweir // change the password for the stream 253cdf0e10cSrcweir XEncryptionProtectedSource xStreamEncryption = 254cdf0e10cSrcweir (XEncryptionProtectedSource) UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xSubStream ); 255cdf0e10cSrcweir 256cdf0e10cSrcweir if ( xStreamEncryption == null ) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir Message( "Optional interface XEncryptionProtectedSource is not implemented, feature can not be tested!" ); 259cdf0e10cSrcweir return -1; 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 262cdf0e10cSrcweir try { 263cdf0e10cSrcweir xStreamEncryption.setEncryptionKey( pNewPass ); 264cdf0e10cSrcweir } 265cdf0e10cSrcweir catch( Exception e ) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir Error( "Can't change encryption key of the substream '" + sStreamName + "', exception:" + e ); 268cdf0e10cSrcweir return 0; 269cdf0e10cSrcweir } 270cdf0e10cSrcweir 271cdf0e10cSrcweir // free the stream resources, garbage collector may remove the object too late 272cdf0e10cSrcweir XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xSubStream ); 273cdf0e10cSrcweir if ( xComponent == null ) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir Error( "Can't get XComponent implementation from substream '" + sStreamName + "'!" ); 276cdf0e10cSrcweir return 0; 277cdf0e10cSrcweir } 278cdf0e10cSrcweir xComponent.dispose(); 279cdf0e10cSrcweir 280cdf0e10cSrcweir return 1; 281cdf0e10cSrcweir } 282cdf0e10cSrcweir setStorageTypeAndCheckProps( XStorage xStorage, String sMediaType, boolean bIsRoot, int nMode )283cdf0e10cSrcweir public boolean setStorageTypeAndCheckProps( XStorage xStorage, String sMediaType, boolean bIsRoot, int nMode ) 284cdf0e10cSrcweir { 285cdf0e10cSrcweir boolean bOk = false; 286cdf0e10cSrcweir 287cdf0e10cSrcweir // get access to the XPropertySet interface 288cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStorage ); 289cdf0e10cSrcweir if ( xPropSet != null ) 290cdf0e10cSrcweir { 291cdf0e10cSrcweir try 292cdf0e10cSrcweir { 293cdf0e10cSrcweir // set "MediaType" property to the stream 294cdf0e10cSrcweir xPropSet.setPropertyValue( "MediaType", sMediaType ); 295cdf0e10cSrcweir 296cdf0e10cSrcweir // get "IsRoot" and "OpenMode" properties and control there values 297cdf0e10cSrcweir boolean bPropIsRoot = AnyConverter.toBoolean( xPropSet.getPropertyValue( "IsRoot" ) ); 298cdf0e10cSrcweir int nPropMode = AnyConverter.toInt( xPropSet.getPropertyValue( "OpenMode" ) ); 299cdf0e10cSrcweir 300cdf0e10cSrcweir bOk = true; 301cdf0e10cSrcweir if ( bPropIsRoot != bIsRoot ) 302cdf0e10cSrcweir { 303cdf0e10cSrcweir Error( "'IsRoot' property contains wrong value!" ); 304cdf0e10cSrcweir bOk = false; 305cdf0e10cSrcweir } 306cdf0e10cSrcweir 307cdf0e10cSrcweir if ( ( bIsRoot && ( nPropMode | ElementModes.ELEMENT_READ ) != ( nMode | ElementModes.ELEMENT_READ ) ) 308cdf0e10cSrcweir || ( !bIsRoot && ( nPropMode & nMode ) != nMode ) ) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir Error( "'OpenMode' property contains wrong value!" ); 311cdf0e10cSrcweir bOk = false; 312cdf0e10cSrcweir } 313cdf0e10cSrcweir } 314cdf0e10cSrcweir catch( Exception e ) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir Error( "Can't control properties of substorage, exception: " + e ); 317cdf0e10cSrcweir } 318cdf0e10cSrcweir } 319cdf0e10cSrcweir else 320cdf0e10cSrcweir { 321cdf0e10cSrcweir Error( "Can't get XPropertySet implementation from storage!" ); 322cdf0e10cSrcweir } 323cdf0e10cSrcweir 324cdf0e10cSrcweir return bOk; 325cdf0e10cSrcweir } 326cdf0e10cSrcweir checkStorageProperties( XStorage xStorage, String sMediaType, boolean bIsRoot, int nMode )327cdf0e10cSrcweir public boolean checkStorageProperties( XStorage xStorage, String sMediaType, boolean bIsRoot, int nMode ) 328cdf0e10cSrcweir { 329cdf0e10cSrcweir boolean bOk = false; 330cdf0e10cSrcweir 331cdf0e10cSrcweir // get access to the XPropertySet interface 332cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStorage ); 333cdf0e10cSrcweir if ( xPropSet != null ) 334cdf0e10cSrcweir { 335cdf0e10cSrcweir try 336cdf0e10cSrcweir { 337cdf0e10cSrcweir // get "MediaType", "IsRoot" and "OpenMode" properties and control there values 338cdf0e10cSrcweir String sPropMediaType = AnyConverter.toString( xPropSet.getPropertyValue( "MediaType" ) ); 339cdf0e10cSrcweir boolean bPropIsRoot = AnyConverter.toBoolean( xPropSet.getPropertyValue( "IsRoot" ) ); 340cdf0e10cSrcweir int nPropMode = AnyConverter.toInt( xPropSet.getPropertyValue( "OpenMode" ) ); 341cdf0e10cSrcweir 342cdf0e10cSrcweir bOk = true; 343cdf0e10cSrcweir if ( !sPropMediaType.equals( sMediaType ) ) 344cdf0e10cSrcweir { 345cdf0e10cSrcweir Error( "'MediaType' property contains wrong value, expected '" 346cdf0e10cSrcweir + sMediaType + "', set '" + sPropMediaType + "' !" ); 347cdf0e10cSrcweir bOk = false; 348cdf0e10cSrcweir } 349cdf0e10cSrcweir 350cdf0e10cSrcweir if ( bPropIsRoot != bIsRoot ) 351cdf0e10cSrcweir { 352cdf0e10cSrcweir Error( "'IsRoot' property contains wrong value!" ); 353cdf0e10cSrcweir bOk = false; 354cdf0e10cSrcweir } 355cdf0e10cSrcweir 356cdf0e10cSrcweir if ( ( bIsRoot && ( nPropMode | ElementModes.ELEMENT_READ ) != ( nMode | ElementModes.ELEMENT_READ ) ) 357cdf0e10cSrcweir || ( !bIsRoot && ( nPropMode & nMode ) != nMode ) ) 358cdf0e10cSrcweir { 359cdf0e10cSrcweir Error( "'OpenMode' property contains wrong value!" ); 360cdf0e10cSrcweir bOk = false; 361cdf0e10cSrcweir } 362cdf0e10cSrcweir } 363cdf0e10cSrcweir catch( Exception e ) 364cdf0e10cSrcweir { 365cdf0e10cSrcweir Error( "Can't get properties of substorage, exception: " + e ); 366cdf0e10cSrcweir } 367cdf0e10cSrcweir } 368cdf0e10cSrcweir else 369cdf0e10cSrcweir { 370cdf0e10cSrcweir Error( "Can't get XPropertySet implementation from storage!" ); 371cdf0e10cSrcweir } 372cdf0e10cSrcweir 373cdf0e10cSrcweir return bOk; 374cdf0e10cSrcweir } 375cdf0e10cSrcweir InternalCheckStream( XStream xStream, String sName, String sMediaType, byte[] pBytes )376cdf0e10cSrcweir public boolean InternalCheckStream( XStream xStream, 377cdf0e10cSrcweir String sName, 378cdf0e10cSrcweir String sMediaType, 379cdf0e10cSrcweir byte[] pBytes ) 380cdf0e10cSrcweir { 381cdf0e10cSrcweir // get input stream of substream 382cdf0e10cSrcweir XInputStream xInput = xStream.getInputStream(); 383cdf0e10cSrcweir if ( xInput == null ) 384cdf0e10cSrcweir { 385cdf0e10cSrcweir Error( "Can't get XInputStream implementation from substream '" + sName + "'!" ); 386cdf0e10cSrcweir return false; 387cdf0e10cSrcweir } 388cdf0e10cSrcweir 389cdf0e10cSrcweir byte pContents[][] = new byte[1][]; // ??? 390cdf0e10cSrcweir 391cdf0e10cSrcweir // read contents 392cdf0e10cSrcweir try 393cdf0e10cSrcweir { 394cdf0e10cSrcweir xInput.readBytes( pContents, pBytes.length + 1 ); 395cdf0e10cSrcweir } 396cdf0e10cSrcweir catch( Exception e ) 397cdf0e10cSrcweir { 398cdf0e10cSrcweir Error( "Can't read from stream '" + sName + "', exception: " + e ); 399cdf0e10cSrcweir return false; 400cdf0e10cSrcweir } 401cdf0e10cSrcweir 402cdf0e10cSrcweir // check size of stream data 403cdf0e10cSrcweir if ( pContents.length == 0 ) 404cdf0e10cSrcweir { 405cdf0e10cSrcweir Error( "SubStream '" + sName + "' reading produced disaster!" ); 406cdf0e10cSrcweir return false; 407cdf0e10cSrcweir } 408cdf0e10cSrcweir 409cdf0e10cSrcweir if ( pBytes.length != pContents[0].length ) 410cdf0e10cSrcweir { 411cdf0e10cSrcweir Error( "SubStream '" + sName + "' contains wrong amount of data! (" + pContents[0].length + "/" + pBytes.length + ")" ); 412cdf0e10cSrcweir return false; 413cdf0e10cSrcweir } 414cdf0e10cSrcweir 415cdf0e10cSrcweir // check stream data 416cdf0e10cSrcweir for ( int ind = 0; ind < pBytes.length; ind++ ) 417cdf0e10cSrcweir { 418cdf0e10cSrcweir if ( pBytes[ind] != pContents[0][ind] ) 419cdf0e10cSrcweir { 420cdf0e10cSrcweir Error( "SubStream '" + sName + "' contains wrong data!" ); 421cdf0e10cSrcweir return false; 422cdf0e10cSrcweir } 423cdf0e10cSrcweir } 424cdf0e10cSrcweir 425cdf0e10cSrcweir 426cdf0e10cSrcweir // check properties 427cdf0e10cSrcweir boolean bOk = false; 428cdf0e10cSrcweir 429cdf0e10cSrcweir // get access to the XPropertySet interface 430cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStream ); 431cdf0e10cSrcweir if ( xPropSet != null ) 432cdf0e10cSrcweir { 433cdf0e10cSrcweir try 434cdf0e10cSrcweir { 435cdf0e10cSrcweir // get "MediaType" and "Size" properties and control there values 436cdf0e10cSrcweir String sPropMediaType = AnyConverter.toString( xPropSet.getPropertyValue( "MediaType" ) ); 437cdf0e10cSrcweir int nPropSize = AnyConverter.toInt( xPropSet.getPropertyValue( "Size" ) ); 438cdf0e10cSrcweir 439cdf0e10cSrcweir bOk = true; 440cdf0e10cSrcweir if ( !sPropMediaType.equals( sMediaType ) ) 441cdf0e10cSrcweir { 442cdf0e10cSrcweir Error( "'MediaType' property contains wrong value for stream '" + sName + "',\nexpected: '" 443cdf0e10cSrcweir + sMediaType + "', set: '" + sPropMediaType + "'!" ); 444cdf0e10cSrcweir bOk = false; 445cdf0e10cSrcweir } 446cdf0e10cSrcweir 447cdf0e10cSrcweir if ( nPropSize != pBytes.length ) 448cdf0e10cSrcweir { 449cdf0e10cSrcweir Error( "'Size' property contains wrong value for stream'" + sName + "'!" ); 450cdf0e10cSrcweir bOk = false; 451cdf0e10cSrcweir } 452cdf0e10cSrcweir } 453cdf0e10cSrcweir catch( Exception e ) 454cdf0e10cSrcweir { 455cdf0e10cSrcweir Error( "Can't get properties of substream '" + sName + "', exception: " + e ); 456cdf0e10cSrcweir } 457cdf0e10cSrcweir } 458cdf0e10cSrcweir else 459cdf0e10cSrcweir { 460cdf0e10cSrcweir Error( "Can't get XPropertySet implementation from stream '" + sName + "'!" ); 461cdf0e10cSrcweir } 462cdf0e10cSrcweir 463cdf0e10cSrcweir return bOk; 464cdf0e10cSrcweir } 465cdf0e10cSrcweir checkStream( XStorage xParentStorage, String sName, String sMediaType, byte[] pBytes )466cdf0e10cSrcweir public boolean checkStream( XStorage xParentStorage, 467cdf0e10cSrcweir String sName, 468cdf0e10cSrcweir String sMediaType, 469cdf0e10cSrcweir byte[] pBytes ) 470cdf0e10cSrcweir { 471cdf0e10cSrcweir // open substream element first 472cdf0e10cSrcweir XStream xSubStream = null; 473cdf0e10cSrcweir try 474cdf0e10cSrcweir { 475cdf0e10cSrcweir Object oSubStream = xParentStorage.openStreamElement( sName, ElementModes.ELEMENT_READ ); 476cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 477cdf0e10cSrcweir if ( xSubStream == null ) 478cdf0e10cSrcweir { 479cdf0e10cSrcweir Error( "Can't open substream '" + sName + "'!" ); 480cdf0e10cSrcweir return false; 481cdf0e10cSrcweir } 482cdf0e10cSrcweir } 483cdf0e10cSrcweir catch( Exception e ) 484cdf0e10cSrcweir { 485cdf0e10cSrcweir Error( "Can't open substream '" + sName + "', exception : " + e + "!" ); 486cdf0e10cSrcweir return false; 487cdf0e10cSrcweir } 488cdf0e10cSrcweir 489cdf0e10cSrcweir return InternalCheckStream( xSubStream, sName, sMediaType, pBytes ); 490cdf0e10cSrcweir } 491cdf0e10cSrcweir checkEncrStream( XStorage xParentStorage, String sName, String sMediaType, byte[] pBytes, byte[] pPass )492cdf0e10cSrcweir public boolean checkEncrStream( XStorage xParentStorage, 493cdf0e10cSrcweir String sName, 494cdf0e10cSrcweir String sMediaType, 495cdf0e10cSrcweir byte[] pBytes, 496cdf0e10cSrcweir byte[] pPass ) 497cdf0e10cSrcweir { 498cdf0e10cSrcweir // Important: a common password for any of parent storage should not be set or 499cdf0e10cSrcweir // should be different from pPass 500cdf0e10cSrcweir 501cdf0e10cSrcweir if ( pPass.length == 0 ) 502cdf0e10cSrcweir { 503cdf0e10cSrcweir Error( "Wrong password is used in the test!" ); 504cdf0e10cSrcweir return false; 505cdf0e10cSrcweir } 506cdf0e10cSrcweir 507cdf0e10cSrcweir try 508cdf0e10cSrcweir { 509cdf0e10cSrcweir Object oSubStream = xParentStorage.openStreamElement( sName, ElementModes.ELEMENT_READ ); 510cdf0e10cSrcweir Error( "Encrypted stream '" + sName + "' was opened without password!" ); 511cdf0e10cSrcweir return false; 512cdf0e10cSrcweir } 513cdf0e10cSrcweir catch( WrongPasswordException wpe ) 514cdf0e10cSrcweir {} 515cdf0e10cSrcweir catch( Exception e ) 516cdf0e10cSrcweir { 517cdf0e10cSrcweir Error( "Unexpected exception in case of opening of encrypted stream '" + sName + "' without password: " + e + "!" ); 518cdf0e10cSrcweir return false; 519cdf0e10cSrcweir } 520cdf0e10cSrcweir 521cdf0e10cSrcweir byte pWrongPass[] = { 1, 1 }; 522cdf0e10cSrcweir pWrongPass[0] += pPass[0]; 523cdf0e10cSrcweir try 524cdf0e10cSrcweir { 525cdf0e10cSrcweir Object oSubStream = xParentStorage.openEncryptedStreamElement( sName, ElementModes.ELEMENT_READ, pWrongPass ); 526cdf0e10cSrcweir Error( "Encrypted stream '" + sName + "' was opened with wrong password!" ); 527cdf0e10cSrcweir return false; 528cdf0e10cSrcweir } 529cdf0e10cSrcweir catch( WrongPasswordException wpe ) 530cdf0e10cSrcweir {} 531cdf0e10cSrcweir catch( Exception e ) 532cdf0e10cSrcweir { 533cdf0e10cSrcweir Error( "Unexpected exception in case of opening of encrypted stream '" + sName + "' with wrong password: " + e + "!" ); 534cdf0e10cSrcweir return false; 535cdf0e10cSrcweir } 536cdf0e10cSrcweir 537cdf0e10cSrcweir XStream xSubStream = null; 538cdf0e10cSrcweir try 539cdf0e10cSrcweir { 540cdf0e10cSrcweir Object oSubStream = xParentStorage.openEncryptedStreamElement( sName, ElementModes.ELEMENT_READ, pPass ); 541cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 542cdf0e10cSrcweir if ( xSubStream == null ) 543cdf0e10cSrcweir { 544cdf0e10cSrcweir Error( "Can't open encrypted substream '" + sName + "'!" ); 545cdf0e10cSrcweir return false; 546cdf0e10cSrcweir } 547cdf0e10cSrcweir } 548cdf0e10cSrcweir catch( Exception e ) 549cdf0e10cSrcweir { 550cdf0e10cSrcweir Error( "Can't open encrypted substream '" + sName + "', exception : " + e + "!" ); 551cdf0e10cSrcweir return false; 552cdf0e10cSrcweir } 553cdf0e10cSrcweir 554cdf0e10cSrcweir return InternalCheckStream( xSubStream, sName, sMediaType, pBytes ); 555cdf0e10cSrcweir } 556cdf0e10cSrcweir copyStorage( XStorage xSourceStorage, XStorage xDestStorage )557cdf0e10cSrcweir public boolean copyStorage( XStorage xSourceStorage, XStorage xDestStorage ) 558cdf0e10cSrcweir { 559cdf0e10cSrcweir // copy xSourceStorage to xDestStorage 560cdf0e10cSrcweir try 561cdf0e10cSrcweir { 562cdf0e10cSrcweir xSourceStorage.copyToStorage( xDestStorage ); 563cdf0e10cSrcweir } 564cdf0e10cSrcweir catch( Exception e ) 565cdf0e10cSrcweir { 566cdf0e10cSrcweir Error( "Storage copying failed, exception: " + e ); 567cdf0e10cSrcweir return false; 568cdf0e10cSrcweir } 569cdf0e10cSrcweir 570cdf0e10cSrcweir return true; 571cdf0e10cSrcweir } 572cdf0e10cSrcweir commitStorage( XStorage xStorage )573cdf0e10cSrcweir public boolean commitStorage( XStorage xStorage ) 574cdf0e10cSrcweir { 575cdf0e10cSrcweir // XTransactedObject must be supported by storages 576cdf0e10cSrcweir XTransactedObject xTransact = (XTransactedObject) UnoRuntime.queryInterface( XTransactedObject.class, xStorage ); 577cdf0e10cSrcweir if ( xTransact == null ) 578cdf0e10cSrcweir { 579cdf0e10cSrcweir Error( "Storage doesn't implement transacted access!" ); 580cdf0e10cSrcweir return false; 581cdf0e10cSrcweir } 582cdf0e10cSrcweir 583cdf0e10cSrcweir try 584cdf0e10cSrcweir { 585cdf0e10cSrcweir xTransact.commit(); 586cdf0e10cSrcweir } 587cdf0e10cSrcweir catch( Exception e ) 588cdf0e10cSrcweir { 589cdf0e10cSrcweir Error( "Storage commit failed, exception:" + e ); 590cdf0e10cSrcweir return false; 591cdf0e10cSrcweir } 592cdf0e10cSrcweir 593cdf0e10cSrcweir return true; 594cdf0e10cSrcweir } 595cdf0e10cSrcweir disposeStorage( XStorage xStorage )596cdf0e10cSrcweir public boolean disposeStorage( XStorage xStorage ) 597cdf0e10cSrcweir { 598cdf0e10cSrcweir // dispose the storage 599cdf0e10cSrcweir XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xStorage ); 600cdf0e10cSrcweir if ( xComponent == null ) 601cdf0e10cSrcweir { 602cdf0e10cSrcweir Error( "Can't retrieve XComponent implementation from storage!" ); 603cdf0e10cSrcweir return false; 604cdf0e10cSrcweir } 605cdf0e10cSrcweir 606cdf0e10cSrcweir try 607cdf0e10cSrcweir { 608cdf0e10cSrcweir xComponent.dispose(); 609cdf0e10cSrcweir } 610cdf0e10cSrcweir catch( Exception e ) 611cdf0e10cSrcweir { 612cdf0e10cSrcweir Error( "Storage disposing failed!" ); 613cdf0e10cSrcweir return false; 614cdf0e10cSrcweir } 615cdf0e10cSrcweir 616cdf0e10cSrcweir return true; 617cdf0e10cSrcweir } 618cdf0e10cSrcweir getInputStream( XStream xStream )619cdf0e10cSrcweir public XInputStream getInputStream( XStream xStream ) 620cdf0e10cSrcweir { 621cdf0e10cSrcweir XInputStream xInTemp = null; 622cdf0e10cSrcweir try 623cdf0e10cSrcweir { 624cdf0e10cSrcweir xInTemp = xStream.getInputStream(); 625cdf0e10cSrcweir if ( xInTemp == null ) 626cdf0e10cSrcweir Error( "Can't get the input part of a stream!" ); 627cdf0e10cSrcweir } 628cdf0e10cSrcweir catch ( Exception e ) 629cdf0e10cSrcweir { 630cdf0e10cSrcweir Error( "Can't get the input part of a stream, exception :" + e ); 631cdf0e10cSrcweir } 632cdf0e10cSrcweir 633cdf0e10cSrcweir return xInTemp; 634cdf0e10cSrcweir } 635cdf0e10cSrcweir closeOutput( XStream xStream )636cdf0e10cSrcweir public boolean closeOutput( XStream xStream ) 637cdf0e10cSrcweir { 638cdf0e10cSrcweir XOutputStream xOutTemp = null; 639cdf0e10cSrcweir try 640cdf0e10cSrcweir { 641cdf0e10cSrcweir xOutTemp = xStream.getOutputStream(); 642cdf0e10cSrcweir if ( xOutTemp == null ) 643cdf0e10cSrcweir { 644cdf0e10cSrcweir Error( "Can't get the output part of a stream!" ); 645cdf0e10cSrcweir return false; 646cdf0e10cSrcweir } 647cdf0e10cSrcweir } 648cdf0e10cSrcweir catch ( Exception e ) 649cdf0e10cSrcweir { 650cdf0e10cSrcweir Error( "Can't get the output part of a stream, exception :" + e ); 651cdf0e10cSrcweir return false; 652cdf0e10cSrcweir } 653cdf0e10cSrcweir 654cdf0e10cSrcweir try 655cdf0e10cSrcweir { 656cdf0e10cSrcweir xOutTemp.closeOutput(); 657cdf0e10cSrcweir } 658cdf0e10cSrcweir catch ( Exception e ) 659cdf0e10cSrcweir { 660cdf0e10cSrcweir Error( "Can't close output part of a stream, exception :" + e ); 661cdf0e10cSrcweir return false; 662cdf0e10cSrcweir } 663cdf0e10cSrcweir 664cdf0e10cSrcweir return true; 665cdf0e10cSrcweir } 666cdf0e10cSrcweir openSubStorage( XStorage xStorage, String sName, int nMode )667cdf0e10cSrcweir public XStorage openSubStorage( XStorage xStorage, String sName, int nMode ) 668cdf0e10cSrcweir { 669cdf0e10cSrcweir // open existing substorage 670cdf0e10cSrcweir try 671cdf0e10cSrcweir { 672cdf0e10cSrcweir Object oSubStorage = xStorage.openStorageElement( sName, nMode ); 673cdf0e10cSrcweir XStorage xSubStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oSubStorage ); 674cdf0e10cSrcweir return xSubStorage; 675cdf0e10cSrcweir } 676cdf0e10cSrcweir catch( Exception e ) 677cdf0e10cSrcweir { 678cdf0e10cSrcweir Error( "Can't open substorage '" + sName + "', exception: " + e ); 679cdf0e10cSrcweir } 680cdf0e10cSrcweir 681cdf0e10cSrcweir return null; 682cdf0e10cSrcweir } 683cdf0e10cSrcweir CreateTempFileStream( XMultiServiceFactory xMSF )684cdf0e10cSrcweir public XStream CreateTempFileStream( XMultiServiceFactory xMSF ) 685cdf0e10cSrcweir { 686cdf0e10cSrcweir // try to get temporary file representation 687cdf0e10cSrcweir XStream xTempFileStream = null; 688cdf0e10cSrcweir try 689cdf0e10cSrcweir { 690cdf0e10cSrcweir Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" ); 691cdf0e10cSrcweir xTempFileStream = (XStream)UnoRuntime.queryInterface( XStream.class, oTempFile ); 692cdf0e10cSrcweir } 693cdf0e10cSrcweir catch( Exception e ) 694cdf0e10cSrcweir {} 695cdf0e10cSrcweir 696cdf0e10cSrcweir if ( xTempFileStream == null ) 697cdf0e10cSrcweir Error( "Can't create temporary file!" ); 698cdf0e10cSrcweir 699cdf0e10cSrcweir return xTempFileStream; 700cdf0e10cSrcweir } 701cdf0e10cSrcweir CreateTempFile( XMultiServiceFactory xMSF )702cdf0e10cSrcweir public String CreateTempFile( XMultiServiceFactory xMSF ) 703cdf0e10cSrcweir { 704cdf0e10cSrcweir String sResult = null; 705cdf0e10cSrcweir 706cdf0e10cSrcweir // try to get temporary file representation 707cdf0e10cSrcweir XPropertySet xTempFileProps = null; 708cdf0e10cSrcweir try 709cdf0e10cSrcweir { 710cdf0e10cSrcweir Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" ); 711cdf0e10cSrcweir xTempFileProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, oTempFile ); 712cdf0e10cSrcweir } 713cdf0e10cSrcweir catch( Exception e ) 714cdf0e10cSrcweir {} 715cdf0e10cSrcweir 716cdf0e10cSrcweir if ( xTempFileProps != null ) 717cdf0e10cSrcweir { 718cdf0e10cSrcweir try 719cdf0e10cSrcweir { 720cdf0e10cSrcweir xTempFileProps.setPropertyValue( "RemoveFile", new Boolean( false ) ); 721cdf0e10cSrcweir sResult = AnyConverter.toString( xTempFileProps.getPropertyValue( "Uri" ) ); 722cdf0e10cSrcweir } 723cdf0e10cSrcweir catch( Exception e ) 724cdf0e10cSrcweir { 725cdf0e10cSrcweir Error( "Can't control TempFile properties, exception: " + e ); 726cdf0e10cSrcweir } 727cdf0e10cSrcweir } 728cdf0e10cSrcweir else 729cdf0e10cSrcweir { 730cdf0e10cSrcweir Error( "Can't create temporary file representation!" ); 731cdf0e10cSrcweir } 732cdf0e10cSrcweir 733cdf0e10cSrcweir // close temporary file explicitly 734cdf0e10cSrcweir try 735cdf0e10cSrcweir { 736cdf0e10cSrcweir XStream xStream = (XStream)UnoRuntime.queryInterface( XStream.class, xTempFileProps ); 737cdf0e10cSrcweir if ( xStream != null ) 738cdf0e10cSrcweir { 739cdf0e10cSrcweir XOutputStream xOut = xStream.getOutputStream(); 740cdf0e10cSrcweir if ( xOut != null ) 741cdf0e10cSrcweir xOut.closeOutput(); 742cdf0e10cSrcweir 743cdf0e10cSrcweir XInputStream xIn = xStream.getInputStream(); 744cdf0e10cSrcweir if ( xIn != null ) 745cdf0e10cSrcweir xIn.closeInput(); 746cdf0e10cSrcweir } 747cdf0e10cSrcweir else 748cdf0e10cSrcweir Error( "Can't close TempFile!" ); 749cdf0e10cSrcweir } 750cdf0e10cSrcweir catch( Exception e ) 751cdf0e10cSrcweir { 752cdf0e10cSrcweir Error( "Can't close TempFile, exception: " + e ); 753cdf0e10cSrcweir } 754cdf0e10cSrcweir 755cdf0e10cSrcweir return sResult; 756cdf0e10cSrcweir } 757cdf0e10cSrcweir copyElementTo( XStorage xSource, String sName, XStorage xDest )758cdf0e10cSrcweir public boolean copyElementTo( XStorage xSource, String sName, XStorage xDest ) 759cdf0e10cSrcweir { 760cdf0e10cSrcweir // copy element with name sName from xSource to xDest 761cdf0e10cSrcweir try 762cdf0e10cSrcweir { 763cdf0e10cSrcweir xSource.copyElementTo( sName, xDest, sName ); 764cdf0e10cSrcweir } 765cdf0e10cSrcweir catch( Exception e ) 766cdf0e10cSrcweir { 767cdf0e10cSrcweir Error( "Element copying failed, exception: " + e ); 768cdf0e10cSrcweir return false; 769cdf0e10cSrcweir } 770cdf0e10cSrcweir 771cdf0e10cSrcweir return true; 772cdf0e10cSrcweir } 773cdf0e10cSrcweir moveElementTo( XStorage xSource, String sName, XStorage xDest )774cdf0e10cSrcweir public boolean moveElementTo( XStorage xSource, String sName, XStorage xDest ) 775cdf0e10cSrcweir { 776cdf0e10cSrcweir // move element with name sName from xSource to xDest 777cdf0e10cSrcweir try 778cdf0e10cSrcweir { 779cdf0e10cSrcweir xSource.moveElementTo( sName, xDest, sName ); 780cdf0e10cSrcweir } 781cdf0e10cSrcweir catch( Exception e ) 782cdf0e10cSrcweir { 783cdf0e10cSrcweir Error( "Element moving failed, exception: " + e ); 784cdf0e10cSrcweir return false; 785cdf0e10cSrcweir } 786cdf0e10cSrcweir 787cdf0e10cSrcweir return true; 788cdf0e10cSrcweir } 789cdf0e10cSrcweir renameElement( XStorage xStorage, String sOldName, String sNewName )790cdf0e10cSrcweir public boolean renameElement( XStorage xStorage, String sOldName, String sNewName ) 791cdf0e10cSrcweir { 792cdf0e10cSrcweir // rename element with name sOldName to sNewName 793cdf0e10cSrcweir try 794cdf0e10cSrcweir { 795cdf0e10cSrcweir xStorage.renameElement( sOldName, sNewName ); 796cdf0e10cSrcweir } 797cdf0e10cSrcweir catch( Exception e ) 798cdf0e10cSrcweir { 799cdf0e10cSrcweir Error( "Element renaming failed, exception: " + e ); 800cdf0e10cSrcweir return false; 801cdf0e10cSrcweir } 802cdf0e10cSrcweir 803cdf0e10cSrcweir return true; 804cdf0e10cSrcweir } 805cdf0e10cSrcweir removeElement( XStorage xStorage, String sName )806cdf0e10cSrcweir public boolean removeElement( XStorage xStorage, String sName ) 807cdf0e10cSrcweir { 808cdf0e10cSrcweir // remove element with name sName 809cdf0e10cSrcweir try 810cdf0e10cSrcweir { 811cdf0e10cSrcweir xStorage.removeElement( sName ); 812cdf0e10cSrcweir } 813cdf0e10cSrcweir catch( Exception e ) 814cdf0e10cSrcweir { 815cdf0e10cSrcweir Error( "Element removing failed, exception: " + e ); 816cdf0e10cSrcweir return false; 817cdf0e10cSrcweir } 818cdf0e10cSrcweir 819cdf0e10cSrcweir return true; 820cdf0e10cSrcweir } 821cdf0e10cSrcweir OpenStream( XStorage xStorage, String sStreamName, int nMode )822cdf0e10cSrcweir public XStream OpenStream( XStorage xStorage, 823cdf0e10cSrcweir String sStreamName, 824cdf0e10cSrcweir int nMode ) 825cdf0e10cSrcweir { 826cdf0e10cSrcweir // open substream element 827cdf0e10cSrcweir XStream xSubStream = null; 828cdf0e10cSrcweir try 829cdf0e10cSrcweir { 830cdf0e10cSrcweir Object oSubStream = xStorage.openStreamElement( sStreamName, nMode ); 831cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 832cdf0e10cSrcweir if ( xSubStream == null ) 833cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "'!" ); 834cdf0e10cSrcweir } 835cdf0e10cSrcweir catch( Exception e ) 836cdf0e10cSrcweir { 837cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" ); 838cdf0e10cSrcweir } 839cdf0e10cSrcweir 840cdf0e10cSrcweir return xSubStream; 841cdf0e10cSrcweir } 842cdf0e10cSrcweir cantOpenStorage( XStorage xStorage, String sName )843cdf0e10cSrcweir public boolean cantOpenStorage( XStorage xStorage, String sName ) 844cdf0e10cSrcweir { 845cdf0e10cSrcweir // try to open an opened substorage, open call must fail 846cdf0e10cSrcweir try 847cdf0e10cSrcweir { 848cdf0e10cSrcweir Object oDummyStorage = xStorage.openStorageElement( sName, ElementModes.ELEMENT_READ ); 849cdf0e10cSrcweir Error( "The trying to reopen opened substorage '" + sName + "' must fail!" ); 850cdf0e10cSrcweir } 851cdf0e10cSrcweir catch( Exception e ) 852cdf0e10cSrcweir { 853cdf0e10cSrcweir return true; 854cdf0e10cSrcweir } 855cdf0e10cSrcweir 856cdf0e10cSrcweir return false; 857cdf0e10cSrcweir } 858cdf0e10cSrcweir cantOpenStream( XStorage xStorage, String sName, int nMode )859cdf0e10cSrcweir public boolean cantOpenStream( XStorage xStorage, String sName, int nMode ) 860cdf0e10cSrcweir { 861cdf0e10cSrcweir // try to open the substream with specified mode must fail 862cdf0e10cSrcweir try 863cdf0e10cSrcweir { 864cdf0e10cSrcweir Object oDummyStream = xStorage.openStreamElement( sName, nMode ); 865cdf0e10cSrcweir Error( "The trying to open substoream '" + sName + "' must fail!" ); 866cdf0e10cSrcweir } 867cdf0e10cSrcweir catch( Exception e ) 868cdf0e10cSrcweir { 869cdf0e10cSrcweir return true; 870cdf0e10cSrcweir } 871cdf0e10cSrcweir 872cdf0e10cSrcweir return false; 873cdf0e10cSrcweir } 874cdf0e10cSrcweir Error( String sError )875cdf0e10cSrcweir public void Error( String sError ) 876cdf0e10cSrcweir { 877cdf0e10cSrcweir System.out.println( m_sTestPrefix + "Error: " + sError ); 878cdf0e10cSrcweir } 879cdf0e10cSrcweir Message( String sError )880cdf0e10cSrcweir public void Message( String sError ) 881cdf0e10cSrcweir { 882cdf0e10cSrcweir System.out.println( m_sTestPrefix + sError ); 883cdf0e10cSrcweir } 884cdf0e10cSrcweir } 885cdf0e10cSrcweir 886