1*a740f2aaSAndrew Rist /************************************************************** 2*a740f2aaSAndrew Rist * 3*a740f2aaSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*a740f2aaSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*a740f2aaSAndrew Rist * distributed with this work for additional information 6*a740f2aaSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*a740f2aaSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*a740f2aaSAndrew Rist * "License"); you may not use this file except in compliance 9*a740f2aaSAndrew Rist * with the License. You may obtain a copy of the License at 10*a740f2aaSAndrew Rist * 11*a740f2aaSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*a740f2aaSAndrew Rist * 13*a740f2aaSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*a740f2aaSAndrew Rist * software distributed under the License is distributed on an 15*a740f2aaSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*a740f2aaSAndrew Rist * KIND, either express or implied. See the License for the 17*a740f2aaSAndrew Rist * specific language governing permissions and limitations 18*a740f2aaSAndrew Rist * under the License. 19*a740f2aaSAndrew Rist * 20*a740f2aaSAndrew Rist *************************************************************/ 21*a740f2aaSAndrew Rist 22cdf0e10cSrcweir package complex.storages; 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 import share.LogWriter; 35cdf0e10cSrcweir 36cdf0e10cSrcweir public class TestHelper { 37cdf0e10cSrcweir 38cdf0e10cSrcweir LogWriter m_aLogWriter; 39cdf0e10cSrcweir String m_sTestPrefix; 40cdf0e10cSrcweir 41cdf0e10cSrcweir public TestHelper( LogWriter aLogWriter, String sTestPrefix ) 42cdf0e10cSrcweir { 43cdf0e10cSrcweir m_aLogWriter = aLogWriter; 44cdf0e10cSrcweir m_sTestPrefix = sTestPrefix; 45cdf0e10cSrcweir } 46cdf0e10cSrcweir 47cdf0e10cSrcweir public boolean WriteBytesToStream( XStream xStream, 48cdf0e10cSrcweir String sStreamName, 49cdf0e10cSrcweir String sMediaType, 50cdf0e10cSrcweir boolean bCompressed, 51cdf0e10cSrcweir byte[] pBytes ) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir // get output stream of substream 54cdf0e10cSrcweir XOutputStream xOutput = xStream.getOutputStream(); 55cdf0e10cSrcweir if ( xOutput == null ) 56cdf0e10cSrcweir { 57cdf0e10cSrcweir Error( "Can't get XOutputStream implementation from substream '" + sStreamName + "'!" ); 58cdf0e10cSrcweir return false; 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir // get XTrucate implementation from output stream 62cdf0e10cSrcweir XTruncate xTruncate = (XTruncate) UnoRuntime.queryInterface( XTruncate.class, xOutput ); 63cdf0e10cSrcweir if ( xTruncate == null ) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir Error( "Can't get XTruncate implementation from substream '" + sStreamName + "'!" ); 66cdf0e10cSrcweir return false; 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir // write requested byte sequence 70cdf0e10cSrcweir try 71cdf0e10cSrcweir { 72cdf0e10cSrcweir xTruncate.truncate(); 73cdf0e10cSrcweir xOutput.writeBytes( pBytes ); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir catch( Exception e ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir Error( "Can't write to stream '" + sStreamName + "', exception: " + e ); 78cdf0e10cSrcweir return false; 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir // get access to the XPropertySet interface 82cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStream ); 83cdf0e10cSrcweir if ( xPropSet == null ) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir Error( "Can't get XPropertySet implementation from substream '" + sStreamName + "'!" ); 86cdf0e10cSrcweir return false; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir // set properties to the stream 90cdf0e10cSrcweir try 91cdf0e10cSrcweir { 92cdf0e10cSrcweir xPropSet.setPropertyValue( "MediaType", sMediaType ); 93cdf0e10cSrcweir xPropSet.setPropertyValue( "Compressed", new Boolean( bCompressed ) ); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir catch( Exception e ) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir Error( "Can't set properties to substream '" + sStreamName + "', exception: " + e ); 98cdf0e10cSrcweir return false; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir // check size property of the stream 102cdf0e10cSrcweir try 103cdf0e10cSrcweir { 104cdf0e10cSrcweir int nSize = AnyConverter.toInt( xPropSet.getPropertyValue( "Size" ) ); 105cdf0e10cSrcweir if ( nSize != pBytes.length ) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir Error( "The 'Size' property of substream '" + sStreamName + "' contains wrong value!" ); 108cdf0e10cSrcweir return false; 109cdf0e10cSrcweir } 110cdf0e10cSrcweir } 111cdf0e10cSrcweir catch( Exception e ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir Error( "Can't get 'Size' property from substream '" + sStreamName + "', exception: " + e ); 114cdf0e10cSrcweir return false; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir return true; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir public boolean WriteBytesToSubstreamDefaultCompressed( XStorage xStorage, 121cdf0e10cSrcweir String sStreamName, 122cdf0e10cSrcweir String sMediaType, 123cdf0e10cSrcweir byte[] pBytes ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir // open substream element 126cdf0e10cSrcweir XStream xSubStream = null; 127cdf0e10cSrcweir try 128cdf0e10cSrcweir { 129cdf0e10cSrcweir Object oSubStream = xStorage.openStreamElement( sStreamName, ElementModes.WRITE ); 130cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 131cdf0e10cSrcweir if ( xSubStream == null ) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "'!" ); 134cdf0e10cSrcweir return false; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir } 137cdf0e10cSrcweir catch( Exception e ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" ); 140cdf0e10cSrcweir return false; 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir // get output stream of substream 144cdf0e10cSrcweir XOutputStream xOutput = xSubStream.getOutputStream(); 145cdf0e10cSrcweir if ( xOutput == null ) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir Error( "Can't get XOutputStream implementation from substream '" + sStreamName + "'!" ); 148cdf0e10cSrcweir return false; 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir // get XTrucate implementation from output stream 152cdf0e10cSrcweir XTruncate xTruncate = (XTruncate) UnoRuntime.queryInterface( XTruncate.class, xOutput ); 153cdf0e10cSrcweir if ( xTruncate == null ) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir Error( "Can't get XTruncate implementation from substream '" + sStreamName + "'!" ); 156cdf0e10cSrcweir return false; 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir // write requested byte sequence 160cdf0e10cSrcweir try 161cdf0e10cSrcweir { 162cdf0e10cSrcweir xTruncate.truncate(); 163cdf0e10cSrcweir xOutput.writeBytes( pBytes ); 164cdf0e10cSrcweir } 165cdf0e10cSrcweir catch( Exception e ) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir Error( "Can't write to stream '" + sStreamName + "', exception: " + e ); 168cdf0e10cSrcweir return false; 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir // get access to the XPropertySet interface 172cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xSubStream ); 173cdf0e10cSrcweir if ( xPropSet == null ) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir Error( "Can't get XPropertySet implementation from substream '" + sStreamName + "'!" ); 176cdf0e10cSrcweir return false; 177cdf0e10cSrcweir } 178cdf0e10cSrcweir 179cdf0e10cSrcweir // set properties to the stream 180cdf0e10cSrcweir // do not set the compressed property 181cdf0e10cSrcweir try 182cdf0e10cSrcweir { 183cdf0e10cSrcweir xPropSet.setPropertyValue( "MediaType", sMediaType ); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir catch( Exception e ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir Error( "Can't set properties to substream '" + sStreamName + "', exception: " + e ); 188cdf0e10cSrcweir return false; 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir // check size property of the stream 192cdf0e10cSrcweir try 193cdf0e10cSrcweir { 194cdf0e10cSrcweir int nSize = AnyConverter.toInt( xPropSet.getPropertyValue( "Size" ) ); 195cdf0e10cSrcweir if ( nSize != pBytes.length ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir Error( "The 'Size' property of substream '" + sStreamName + "' contains wrong value!" ); 198cdf0e10cSrcweir return false; 199cdf0e10cSrcweir } 200cdf0e10cSrcweir } 201cdf0e10cSrcweir catch( Exception e ) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir Error( "Can't get 'Size' property from substream '" + sStreamName + "', exception: " + e ); 204cdf0e10cSrcweir return false; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir // free the stream resources, garbage collector may remove the object too late 208cdf0e10cSrcweir if ( !disposeStream( xSubStream, sStreamName ) ) 209cdf0e10cSrcweir return false; 210cdf0e10cSrcweir 211cdf0e10cSrcweir return true; 212cdf0e10cSrcweir } 213cdf0e10cSrcweir 214cdf0e10cSrcweir public boolean WriteBytesToSubstream( XStorage xStorage, 215cdf0e10cSrcweir String sStreamName, 216cdf0e10cSrcweir String sMediaType, 217cdf0e10cSrcweir boolean bCompressed, 218cdf0e10cSrcweir byte[] pBytes ) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir // open substream element 221cdf0e10cSrcweir XStream xSubStream = null; 222cdf0e10cSrcweir try 223cdf0e10cSrcweir { 224cdf0e10cSrcweir Object oSubStream = xStorage.openStreamElement( sStreamName, ElementModes.WRITE ); 225cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 226cdf0e10cSrcweir if ( xSubStream == null ) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "'!" ); 229cdf0e10cSrcweir return false; 230cdf0e10cSrcweir } 231cdf0e10cSrcweir } 232cdf0e10cSrcweir catch( Exception e ) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" ); 235cdf0e10cSrcweir return false; 236cdf0e10cSrcweir } 237cdf0e10cSrcweir 238cdf0e10cSrcweir if ( !WriteBytesToStream( xSubStream, sStreamName, sMediaType, bCompressed, pBytes ) ) 239cdf0e10cSrcweir return false; 240cdf0e10cSrcweir 241cdf0e10cSrcweir // free the stream resources, garbage collector may remove the object too late 242cdf0e10cSrcweir if ( !disposeStream( xSubStream, sStreamName ) ) 243cdf0e10cSrcweir return false; 244cdf0e10cSrcweir 245cdf0e10cSrcweir return true; 246cdf0e10cSrcweir } 247cdf0e10cSrcweir 248cdf0e10cSrcweir public boolean WriteBytesToEncrSubstream( XStorage xStorage, 249cdf0e10cSrcweir String sStreamName, 250cdf0e10cSrcweir String sMediaType, 251cdf0e10cSrcweir boolean bCompressed, 252cdf0e10cSrcweir byte[] pBytes, 253cdf0e10cSrcweir String sPass ) 254cdf0e10cSrcweir { 255cdf0e10cSrcweir // open substream element 256cdf0e10cSrcweir XStream xSubStream = null; 257cdf0e10cSrcweir try 258cdf0e10cSrcweir { 259cdf0e10cSrcweir Object oSubStream = xStorage.openEncryptedStreamElement( sStreamName, ElementModes.WRITE, sPass ); 260cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 261cdf0e10cSrcweir if ( xSubStream == null ) 262cdf0e10cSrcweir { 263cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "'!" ); 264cdf0e10cSrcweir return false; 265cdf0e10cSrcweir } 266cdf0e10cSrcweir } 267cdf0e10cSrcweir catch( Exception e ) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" ); 270cdf0e10cSrcweir return false; 271cdf0e10cSrcweir } 272cdf0e10cSrcweir 273cdf0e10cSrcweir if ( !WriteBytesToStream( xSubStream, sStreamName, sMediaType, bCompressed, pBytes ) ) 274cdf0e10cSrcweir return false; 275cdf0e10cSrcweir 276cdf0e10cSrcweir // free the stream resources, garbage collector may remove the object too late 277cdf0e10cSrcweir if ( !disposeStream( xSubStream, sStreamName ) ) 278cdf0e10cSrcweir return false; 279cdf0e10cSrcweir 280cdf0e10cSrcweir return true; 281cdf0e10cSrcweir } 282cdf0e10cSrcweir 283cdf0e10cSrcweir public boolean WBToSubstrOfEncr( XStorage xStorage, 284cdf0e10cSrcweir String sStreamName, 285cdf0e10cSrcweir String sMediaType, 286cdf0e10cSrcweir boolean bCompressed, 287cdf0e10cSrcweir byte[] pBytes, 288cdf0e10cSrcweir boolean bEncrypted ) 289cdf0e10cSrcweir { 290cdf0e10cSrcweir // open substream element 291cdf0e10cSrcweir XStream xSubStream = null; 292cdf0e10cSrcweir try 293cdf0e10cSrcweir { 294cdf0e10cSrcweir Object oSubStream = xStorage.openStreamElement( sStreamName, ElementModes.WRITE ); 295cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 296cdf0e10cSrcweir if ( xSubStream == null ) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "'!" ); 299cdf0e10cSrcweir return false; 300cdf0e10cSrcweir } 301cdf0e10cSrcweir } 302cdf0e10cSrcweir catch( Exception e ) 303cdf0e10cSrcweir { 304cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" ); 305cdf0e10cSrcweir return false; 306cdf0e10cSrcweir } 307cdf0e10cSrcweir 308cdf0e10cSrcweir // get access to the XPropertySet interface 309cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xSubStream ); 310cdf0e10cSrcweir if ( xPropSet == null ) 311cdf0e10cSrcweir { 312cdf0e10cSrcweir Error( "Can't get XPropertySet implementation from substream '" + sStreamName + "'!" ); 313cdf0e10cSrcweir return false; 314cdf0e10cSrcweir } 315cdf0e10cSrcweir 316cdf0e10cSrcweir // set properties to the stream 317cdf0e10cSrcweir try 318cdf0e10cSrcweir { 319cdf0e10cSrcweir xPropSet.setPropertyValue( "UseCommonStoragePasswordEncryption", new Boolean( bEncrypted ) ); 320cdf0e10cSrcweir } 321cdf0e10cSrcweir catch( Exception e ) 322cdf0e10cSrcweir { 323cdf0e10cSrcweir Error( "Can't set 'UseCommonStoragePasswordEncryption' property to substream '" + sStreamName + "', exception: " + e ); 324cdf0e10cSrcweir return false; 325cdf0e10cSrcweir } 326cdf0e10cSrcweir 327cdf0e10cSrcweir if ( !WriteBytesToStream( xSubStream, sStreamName, sMediaType, bCompressed, pBytes ) ) 328cdf0e10cSrcweir return false; 329cdf0e10cSrcweir 330cdf0e10cSrcweir // free the stream resources, garbage collector may remove the object too late 331cdf0e10cSrcweir if ( !disposeStream( xSubStream, sStreamName ) ) 332cdf0e10cSrcweir return false; 333cdf0e10cSrcweir 334cdf0e10cSrcweir return true; 335cdf0e10cSrcweir } 336cdf0e10cSrcweir 337cdf0e10cSrcweir public boolean WriteBytesToStreamH( XStorage xStorage, 338cdf0e10cSrcweir String sStreamPath, 339cdf0e10cSrcweir String sMediaType, 340cdf0e10cSrcweir boolean bCompressed, 341cdf0e10cSrcweir byte[] pBytes, 342cdf0e10cSrcweir boolean bCommit ) 343cdf0e10cSrcweir { 344cdf0e10cSrcweir // open substream element 345cdf0e10cSrcweir XStream xSubStream = null; 346cdf0e10cSrcweir try 347cdf0e10cSrcweir { 348cdf0e10cSrcweir XHierarchicalStorageAccess xHStorage = 349cdf0e10cSrcweir (XHierarchicalStorageAccess) UnoRuntime.queryInterface( XHierarchicalStorageAccess.class, xStorage ); 350cdf0e10cSrcweir if ( xHStorage == null ) 351cdf0e10cSrcweir { 352cdf0e10cSrcweir Error( "The storage does not support hierarchical access!" ); 353cdf0e10cSrcweir return false; 354cdf0e10cSrcweir } 355cdf0e10cSrcweir 356cdf0e10cSrcweir Object oSubStream = xHStorage.openStreamElementByHierarchicalName( sStreamPath, ElementModes.WRITE ); 357cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 358cdf0e10cSrcweir if ( xSubStream == null ) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir Error( "Can't create substream '" + sStreamPath + "'!" ); 361cdf0e10cSrcweir return false; 362cdf0e10cSrcweir } 363cdf0e10cSrcweir } 364cdf0e10cSrcweir catch( Exception e ) 365cdf0e10cSrcweir { 366cdf0e10cSrcweir Error( "Can't create substream '" + sStreamPath + "', exception : " + e + "!" ); 367cdf0e10cSrcweir return false; 368cdf0e10cSrcweir } 369cdf0e10cSrcweir 370cdf0e10cSrcweir if ( !WriteBytesToStream( xSubStream, sStreamPath, sMediaType, bCompressed, pBytes ) ) 371cdf0e10cSrcweir return false; 372cdf0e10cSrcweir 373cdf0e10cSrcweir XTransactedObject xTransact = 374cdf0e10cSrcweir (XTransactedObject) UnoRuntime.queryInterface( XTransactedObject.class, xSubStream ); 375cdf0e10cSrcweir if ( xTransact == null ) 376cdf0e10cSrcweir { 377cdf0e10cSrcweir Error( "Substream '" + sStreamPath + "', stream opened for writing must be transacted!" ); 378cdf0e10cSrcweir return false; 379cdf0e10cSrcweir } 380cdf0e10cSrcweir 381cdf0e10cSrcweir if ( bCommit ) 382cdf0e10cSrcweir { 383cdf0e10cSrcweir try { 384cdf0e10cSrcweir xTransact.commit(); 385cdf0e10cSrcweir } catch( Exception e ) 386cdf0e10cSrcweir { 387cdf0e10cSrcweir Error( "Can't commit storage after substream '" + sStreamPath + "' change, exception : " + e + "!" ); 388cdf0e10cSrcweir return false; 389cdf0e10cSrcweir } 390cdf0e10cSrcweir } 391cdf0e10cSrcweir 392cdf0e10cSrcweir // free the stream resources, garbage collector may remove the object too late 393cdf0e10cSrcweir if ( !disposeStream( xSubStream, sStreamPath ) ) 394cdf0e10cSrcweir return false; 395cdf0e10cSrcweir 396cdf0e10cSrcweir return true; 397cdf0e10cSrcweir } 398cdf0e10cSrcweir 399cdf0e10cSrcweir public boolean WriteBytesToEncrStreamH( XStorage xStorage, 400cdf0e10cSrcweir String sStreamPath, 401cdf0e10cSrcweir String sMediaType, 402cdf0e10cSrcweir boolean bCompressed, 403cdf0e10cSrcweir byte[] pBytes, 404cdf0e10cSrcweir String sPass, 405cdf0e10cSrcweir boolean bCommit ) 406cdf0e10cSrcweir { 407cdf0e10cSrcweir // open substream element 408cdf0e10cSrcweir XStream xSubStream = null; 409cdf0e10cSrcweir try 410cdf0e10cSrcweir { 411cdf0e10cSrcweir XHierarchicalStorageAccess xHStorage = 412cdf0e10cSrcweir (XHierarchicalStorageAccess) UnoRuntime.queryInterface( XHierarchicalStorageAccess.class, xStorage ); 413cdf0e10cSrcweir if ( xHStorage == null ) 414cdf0e10cSrcweir { 415cdf0e10cSrcweir Error( "The storage does not support hierarchical access!" ); 416cdf0e10cSrcweir return false; 417cdf0e10cSrcweir } 418cdf0e10cSrcweir 419cdf0e10cSrcweir Object oSubStream = xHStorage.openEncryptedStreamElementByHierarchicalName( sStreamPath, 420cdf0e10cSrcweir ElementModes.WRITE, 421cdf0e10cSrcweir sPass ); 422cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 423cdf0e10cSrcweir if ( xSubStream == null ) 424cdf0e10cSrcweir { 425cdf0e10cSrcweir Error( "Can't create substream '" + sStreamPath + "'!" ); 426cdf0e10cSrcweir return false; 427cdf0e10cSrcweir } 428cdf0e10cSrcweir } 429cdf0e10cSrcweir catch( Exception e ) 430cdf0e10cSrcweir { 431cdf0e10cSrcweir Error( "Can't create substream '" + sStreamPath + "', exception : " + e + "!" ); 432cdf0e10cSrcweir return false; 433cdf0e10cSrcweir } 434cdf0e10cSrcweir 435cdf0e10cSrcweir if ( !WriteBytesToStream( xSubStream, sStreamPath, sMediaType, bCompressed, pBytes ) ) 436cdf0e10cSrcweir return false; 437cdf0e10cSrcweir 438cdf0e10cSrcweir XTransactedObject xTransact = 439cdf0e10cSrcweir (XTransactedObject) UnoRuntime.queryInterface( XTransactedObject.class, xSubStream ); 440cdf0e10cSrcweir if ( xTransact == null ) 441cdf0e10cSrcweir { 442cdf0e10cSrcweir Error( "Substream '" + sStreamPath + "', stream opened for writing must be transacted!" ); 443cdf0e10cSrcweir return false; 444cdf0e10cSrcweir } 445cdf0e10cSrcweir 446cdf0e10cSrcweir if ( bCommit ) 447cdf0e10cSrcweir { 448cdf0e10cSrcweir try { 449cdf0e10cSrcweir xTransact.commit(); 450cdf0e10cSrcweir } catch( Exception e ) 451cdf0e10cSrcweir { 452cdf0e10cSrcweir Error( "Can't commit storage after substream '" + sStreamPath + "' change, exception : " + e + "!" ); 453cdf0e10cSrcweir return false; 454cdf0e10cSrcweir } 455cdf0e10cSrcweir } 456cdf0e10cSrcweir 457cdf0e10cSrcweir // free the stream resources, garbage collector may remove the object too late 458cdf0e10cSrcweir if ( !disposeStream( xSubStream, sStreamPath ) ) 459cdf0e10cSrcweir return false; 460cdf0e10cSrcweir 461cdf0e10cSrcweir return true; 462cdf0e10cSrcweir } 463cdf0e10cSrcweir 464cdf0e10cSrcweir public boolean WBToSubstrOfEncrH( XStorage xStorage, 465cdf0e10cSrcweir String sStreamPath, 466cdf0e10cSrcweir String sMediaType, 467cdf0e10cSrcweir boolean bCompressed, 468cdf0e10cSrcweir byte[] pBytes, 469cdf0e10cSrcweir boolean bEncrypted, 470cdf0e10cSrcweir boolean bCommit ) 471cdf0e10cSrcweir { 472cdf0e10cSrcweir // open substream element 473cdf0e10cSrcweir XStream xSubStream = null; 474cdf0e10cSrcweir try 475cdf0e10cSrcweir { 476cdf0e10cSrcweir XHierarchicalStorageAccess xHStorage = 477cdf0e10cSrcweir (XHierarchicalStorageAccess) UnoRuntime.queryInterface( XHierarchicalStorageAccess.class, xStorage ); 478cdf0e10cSrcweir if ( xHStorage == null ) 479cdf0e10cSrcweir { 480cdf0e10cSrcweir Error( "The storage does not support hierarchical access!" ); 481cdf0e10cSrcweir return false; 482cdf0e10cSrcweir } 483cdf0e10cSrcweir 484cdf0e10cSrcweir Object oSubStream = xHStorage.openStreamElementByHierarchicalName( sStreamPath, ElementModes.WRITE ); 485cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 486cdf0e10cSrcweir if ( xSubStream == null ) 487cdf0e10cSrcweir { 488cdf0e10cSrcweir Error( "Can't create substream '" + sStreamPath + "'!" ); 489cdf0e10cSrcweir return false; 490cdf0e10cSrcweir } 491cdf0e10cSrcweir } 492cdf0e10cSrcweir catch( Exception e ) 493cdf0e10cSrcweir { 494cdf0e10cSrcweir Error( "Can't create substream '" + sStreamPath + "', exception : " + e + "!" ); 495cdf0e10cSrcweir return false; 496cdf0e10cSrcweir } 497cdf0e10cSrcweir 498cdf0e10cSrcweir // get access to the XPropertySet interface 499cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xSubStream ); 500cdf0e10cSrcweir if ( xPropSet == null ) 501cdf0e10cSrcweir { 502cdf0e10cSrcweir Error( "Can't get XPropertySet implementation from substream '" + sStreamPath + "'!" ); 503cdf0e10cSrcweir return false; 504cdf0e10cSrcweir } 505cdf0e10cSrcweir 506cdf0e10cSrcweir // set properties to the stream 507cdf0e10cSrcweir try 508cdf0e10cSrcweir { 509cdf0e10cSrcweir xPropSet.setPropertyValue( "UseCommonStoragePasswordEncryption", new Boolean( bEncrypted ) ); 510cdf0e10cSrcweir } 511cdf0e10cSrcweir catch( Exception e ) 512cdf0e10cSrcweir { 513cdf0e10cSrcweir Error( "Can't set 'UseCommonStoragePasswordEncryption' property to substream '" + sStreamPath + "', exception: " + e ); 514cdf0e10cSrcweir return false; 515cdf0e10cSrcweir } 516cdf0e10cSrcweir 517cdf0e10cSrcweir if ( !WriteBytesToStream( xSubStream, sStreamPath, sMediaType, bCompressed, pBytes ) ) 518cdf0e10cSrcweir return false; 519cdf0e10cSrcweir 520cdf0e10cSrcweir XTransactedObject xTransact = 521cdf0e10cSrcweir (XTransactedObject) UnoRuntime.queryInterface( XTransactedObject.class, xSubStream ); 522cdf0e10cSrcweir if ( xTransact == null ) 523cdf0e10cSrcweir { 524cdf0e10cSrcweir Error( "Substream '" + sStreamPath + "', stream opened for writing must be transacted!" ); 525cdf0e10cSrcweir return false; 526cdf0e10cSrcweir } 527cdf0e10cSrcweir 528cdf0e10cSrcweir if ( bCommit ) 529cdf0e10cSrcweir { 530cdf0e10cSrcweir try { 531cdf0e10cSrcweir xTransact.commit(); 532cdf0e10cSrcweir } catch( Exception e ) 533cdf0e10cSrcweir { 534cdf0e10cSrcweir Error( "Can't commit storage after substream '" + sStreamPath + "' change, exception : " + e + "!" ); 535cdf0e10cSrcweir return false; 536cdf0e10cSrcweir } 537cdf0e10cSrcweir } 538cdf0e10cSrcweir 539cdf0e10cSrcweir // free the stream resources, garbage collector may remove the object too late 540cdf0e10cSrcweir if ( !disposeStream( xSubStream, sStreamPath ) ) 541cdf0e10cSrcweir return false; 542cdf0e10cSrcweir 543cdf0e10cSrcweir return true; 544cdf0e10cSrcweir } 545cdf0e10cSrcweir 546cdf0e10cSrcweir public int ChangeStreamPass( XStorage xStorage, 547cdf0e10cSrcweir String sStreamName, 548cdf0e10cSrcweir String sOldPass, 549cdf0e10cSrcweir String sNewPass ) 550cdf0e10cSrcweir { 551cdf0e10cSrcweir // open substream element 552cdf0e10cSrcweir XStream xSubStream = null; 553cdf0e10cSrcweir try 554cdf0e10cSrcweir { 555cdf0e10cSrcweir Object oSubStream = xStorage.openEncryptedStreamElement( sStreamName, ElementModes.WRITE, sOldPass ); 556cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 557cdf0e10cSrcweir if ( xSubStream == null ) 558cdf0e10cSrcweir { 559cdf0e10cSrcweir Error( "Can't open substream '" + sStreamName + "'!" ); 560cdf0e10cSrcweir return 0; 561cdf0e10cSrcweir } 562cdf0e10cSrcweir } 563cdf0e10cSrcweir catch( Exception e ) 564cdf0e10cSrcweir { 565cdf0e10cSrcweir Error( "Can't open substream '" + sStreamName + "', exception : " + e + "!" ); 566cdf0e10cSrcweir return 0; 567cdf0e10cSrcweir } 568cdf0e10cSrcweir 569cdf0e10cSrcweir 570cdf0e10cSrcweir // change the password for the stream 571cdf0e10cSrcweir XEncryptionProtectedSource xStreamEncryption = 572cdf0e10cSrcweir (XEncryptionProtectedSource) UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xSubStream ); 573cdf0e10cSrcweir 574cdf0e10cSrcweir if ( xStreamEncryption == null ) 575cdf0e10cSrcweir { 576cdf0e10cSrcweir Message( "Optional interface XEncryptionProtectedSource is not implemented, feature can not be tested!" ); 577cdf0e10cSrcweir return -1; 578cdf0e10cSrcweir } 579cdf0e10cSrcweir 580cdf0e10cSrcweir try { 581cdf0e10cSrcweir xStreamEncryption.setEncryptionPassword( sNewPass ); 582cdf0e10cSrcweir } 583cdf0e10cSrcweir catch( Exception e ) 584cdf0e10cSrcweir { 585cdf0e10cSrcweir Error( "Can't change encryption key of the substream '" + sStreamName + "', exception:" + e ); 586cdf0e10cSrcweir return 0; 587cdf0e10cSrcweir } 588cdf0e10cSrcweir 589cdf0e10cSrcweir // free the stream resources, garbage collector may remove the object too late 590cdf0e10cSrcweir if ( !disposeStream( xSubStream, sStreamName ) ) 591cdf0e10cSrcweir return 0; 592cdf0e10cSrcweir 593cdf0e10cSrcweir return 1; 594cdf0e10cSrcweir } 595cdf0e10cSrcweir 596cdf0e10cSrcweir public int ChangeStreamPassH( XStorage xStorage, 597cdf0e10cSrcweir String sPath, 598cdf0e10cSrcweir String sOldPass, 599cdf0e10cSrcweir String sNewPass, 600cdf0e10cSrcweir boolean bCommit ) 601cdf0e10cSrcweir { 602cdf0e10cSrcweir // open substream element 603cdf0e10cSrcweir XHierarchicalStorageAccess xHStorage = 604cdf0e10cSrcweir (XHierarchicalStorageAccess) UnoRuntime.queryInterface( XHierarchicalStorageAccess.class, xStorage ); 605cdf0e10cSrcweir if ( xHStorage == null ) 606cdf0e10cSrcweir { 607cdf0e10cSrcweir Error( "The storage does not support hierarchical access!" ); 608cdf0e10cSrcweir return 0; 609cdf0e10cSrcweir } 610cdf0e10cSrcweir 611cdf0e10cSrcweir XStream xSubStream = null; 612cdf0e10cSrcweir try 613cdf0e10cSrcweir { 614cdf0e10cSrcweir Object oSubStream = xHStorage.openEncryptedStreamElementByHierarchicalName( sPath, ElementModes.WRITE, sOldPass ); 615cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 616cdf0e10cSrcweir if ( xSubStream == null ) 617cdf0e10cSrcweir { 618cdf0e10cSrcweir Error( "Can't open encrypted substream '" + sPath + "'!" ); 619cdf0e10cSrcweir return 0; 620cdf0e10cSrcweir } 621cdf0e10cSrcweir } 622cdf0e10cSrcweir catch( Exception e ) 623cdf0e10cSrcweir { 624cdf0e10cSrcweir Error( "Can't open encrypted substream '" + sPath + "', exception : " + e + "!" ); 625cdf0e10cSrcweir return 0; 626cdf0e10cSrcweir } 627cdf0e10cSrcweir 628cdf0e10cSrcweir // change the password for the stream 629cdf0e10cSrcweir XEncryptionProtectedSource xStreamEncryption = 630cdf0e10cSrcweir (XEncryptionProtectedSource) UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xSubStream ); 631cdf0e10cSrcweir 632cdf0e10cSrcweir if ( xStreamEncryption == null ) 633cdf0e10cSrcweir { 634cdf0e10cSrcweir Message( "Optional interface XEncryptionProtectedSource is not implemented, feature can not be tested!" ); 635cdf0e10cSrcweir return -1; 636cdf0e10cSrcweir } 637cdf0e10cSrcweir 638cdf0e10cSrcweir try { 639cdf0e10cSrcweir xStreamEncryption.setEncryptionPassword( sNewPass ); 640cdf0e10cSrcweir } 641cdf0e10cSrcweir catch( Exception e ) 642cdf0e10cSrcweir { 643cdf0e10cSrcweir Error( "Can't change encryption key of the substream '" + sPath + "', exception:" + e ); 644cdf0e10cSrcweir return 0; 645cdf0e10cSrcweir } 646cdf0e10cSrcweir 647cdf0e10cSrcweir XTransactedObject xTransact = 648cdf0e10cSrcweir (XTransactedObject) UnoRuntime.queryInterface( XTransactedObject.class, xSubStream ); 649cdf0e10cSrcweir if ( xTransact == null ) 650cdf0e10cSrcweir { 651cdf0e10cSrcweir Error( "Substream '" + sPath + "', stream opened for writing must be transacted!" ); 652cdf0e10cSrcweir return 0; 653cdf0e10cSrcweir } 654cdf0e10cSrcweir 655cdf0e10cSrcweir if ( bCommit ) 656cdf0e10cSrcweir { 657cdf0e10cSrcweir try { 658cdf0e10cSrcweir xTransact.commit(); 659cdf0e10cSrcweir } catch( Exception e ) 660cdf0e10cSrcweir { 661cdf0e10cSrcweir Error( "Can't commit storage after substream '" + sPath + "' change, exception : " + e + "!" ); 662cdf0e10cSrcweir return 0; 663cdf0e10cSrcweir } 664cdf0e10cSrcweir } 665cdf0e10cSrcweir 666cdf0e10cSrcweir // free the stream resources, garbage collector may remove the object too late 667cdf0e10cSrcweir if ( !disposeStream( xSubStream, sPath ) ) 668cdf0e10cSrcweir return 0; 669cdf0e10cSrcweir 670cdf0e10cSrcweir return 1; 671cdf0e10cSrcweir } 672cdf0e10cSrcweir 673cdf0e10cSrcweir public boolean setStorageTypeAndCheckProps( XStorage xStorage, String sMediaType, boolean bIsRoot, int nMode ) 674cdf0e10cSrcweir { 675cdf0e10cSrcweir boolean bOk = false; 676cdf0e10cSrcweir 677cdf0e10cSrcweir // get access to the XPropertySet interface 678cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStorage ); 679cdf0e10cSrcweir if ( xPropSet != null ) 680cdf0e10cSrcweir { 681cdf0e10cSrcweir try 682cdf0e10cSrcweir { 683cdf0e10cSrcweir // set "MediaType" property to the stream 684cdf0e10cSrcweir xPropSet.setPropertyValue( "MediaType", sMediaType ); 685cdf0e10cSrcweir 686cdf0e10cSrcweir // get "IsRoot" and "OpenMode" properties and control there values 687cdf0e10cSrcweir boolean bPropIsRoot = AnyConverter.toBoolean( xPropSet.getPropertyValue( "IsRoot" ) ); 688cdf0e10cSrcweir int nPropMode = AnyConverter.toInt( xPropSet.getPropertyValue( "OpenMode" ) ); 689cdf0e10cSrcweir 690cdf0e10cSrcweir bOk = true; 691cdf0e10cSrcweir if ( bPropIsRoot != bIsRoot ) 692cdf0e10cSrcweir { 693cdf0e10cSrcweir Error( "'IsRoot' property contains wrong value!" ); 694cdf0e10cSrcweir bOk = false; 695cdf0e10cSrcweir } 696cdf0e10cSrcweir 697cdf0e10cSrcweir if ( ( bIsRoot 698cdf0e10cSrcweir && ( nPropMode | ElementModes.READ ) != ( nMode | ElementModes.READ ) ) 699cdf0e10cSrcweir || ( !bIsRoot && ( nPropMode & nMode ) != nMode ) ) 700cdf0e10cSrcweir { 701cdf0e10cSrcweir Error( "'OpenMode' property contains wrong value, expected " + nMode + ", in reality " + nPropMode + "!" ); 702cdf0e10cSrcweir bOk = false; 703cdf0e10cSrcweir } 704cdf0e10cSrcweir } 705cdf0e10cSrcweir catch( Exception e ) 706cdf0e10cSrcweir { 707cdf0e10cSrcweir Error( "Can't control properties of substorage, exception: " + e ); 708cdf0e10cSrcweir } 709cdf0e10cSrcweir } 710cdf0e10cSrcweir else 711cdf0e10cSrcweir { 712cdf0e10cSrcweir Error( "Can't get XPropertySet implementation from storage!" ); 713cdf0e10cSrcweir } 714cdf0e10cSrcweir 715cdf0e10cSrcweir return bOk; 716cdf0e10cSrcweir } 717cdf0e10cSrcweir 718cdf0e10cSrcweir public boolean checkStorageProperties( XStorage xStorage, String sMediaType, boolean bIsRoot, int nMode ) 719cdf0e10cSrcweir { 720cdf0e10cSrcweir boolean bOk = false; 721cdf0e10cSrcweir 722cdf0e10cSrcweir // get access to the XPropertySet interface 723cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStorage ); 724cdf0e10cSrcweir if ( xPropSet != null ) 725cdf0e10cSrcweir { 726cdf0e10cSrcweir try 727cdf0e10cSrcweir { 728cdf0e10cSrcweir // get "MediaType", "IsRoot" and "OpenMode" properties and control there values 729cdf0e10cSrcweir String sPropMediaType = AnyConverter.toString( xPropSet.getPropertyValue( "MediaType" ) ); 730cdf0e10cSrcweir boolean bPropIsRoot = AnyConverter.toBoolean( xPropSet.getPropertyValue( "IsRoot" ) ); 731cdf0e10cSrcweir int nPropMode = AnyConverter.toInt( xPropSet.getPropertyValue( "OpenMode" ) ); 732cdf0e10cSrcweir 733cdf0e10cSrcweir bOk = true; 734cdf0e10cSrcweir if ( !sPropMediaType.equals( sMediaType ) ) 735cdf0e10cSrcweir { 736cdf0e10cSrcweir Error( "'MediaType' property contains wrong value, expected '" 737cdf0e10cSrcweir + sMediaType + "', set '" + sPropMediaType + "' !" ); 738cdf0e10cSrcweir bOk = false; 739cdf0e10cSrcweir } 740cdf0e10cSrcweir 741cdf0e10cSrcweir if ( bPropIsRoot != bIsRoot ) 742cdf0e10cSrcweir { 743cdf0e10cSrcweir Error( "'IsRoot' property contains wrong value!" ); 744cdf0e10cSrcweir bOk = false; 745cdf0e10cSrcweir } 746cdf0e10cSrcweir 747cdf0e10cSrcweir if ( ( bIsRoot 748cdf0e10cSrcweir && ( nPropMode | ElementModes.READ ) != ( nMode | ElementModes.READ ) ) 749cdf0e10cSrcweir || ( !bIsRoot && ( nPropMode & nMode ) != nMode ) ) 750cdf0e10cSrcweir { 751cdf0e10cSrcweir Error( "'OpenMode' property contains wrong value, expected " + nMode + ", in reality " + nPropMode + "!" ); 752cdf0e10cSrcweir bOk = false; 753cdf0e10cSrcweir } 754cdf0e10cSrcweir } 755cdf0e10cSrcweir catch( Exception e ) 756cdf0e10cSrcweir { 757cdf0e10cSrcweir Error( "Can't get properties of substorage, exception: " + e ); 758cdf0e10cSrcweir } 759cdf0e10cSrcweir } 760cdf0e10cSrcweir else 761cdf0e10cSrcweir { 762cdf0e10cSrcweir Error( "Can't get XPropertySet implementation from storage!" ); 763cdf0e10cSrcweir } 764cdf0e10cSrcweir 765cdf0e10cSrcweir return bOk; 766cdf0e10cSrcweir } 767cdf0e10cSrcweir 768cdf0e10cSrcweir public boolean InternalCheckStream( XStream xStream, 769cdf0e10cSrcweir String sName, 770cdf0e10cSrcweir String sMediaType, 771cdf0e10cSrcweir boolean bCompressed, 772cdf0e10cSrcweir byte[] pBytes, 773cdf0e10cSrcweir boolean bCheckCompressed ) 774cdf0e10cSrcweir { 775cdf0e10cSrcweir // get input stream of substream 776cdf0e10cSrcweir XInputStream xInput = xStream.getInputStream(); 777cdf0e10cSrcweir if ( xInput == null ) 778cdf0e10cSrcweir { 779cdf0e10cSrcweir Error( "Can't get XInputStream implementation from substream '" + sName + "'!" ); 780cdf0e10cSrcweir return false; 781cdf0e10cSrcweir } 782cdf0e10cSrcweir 783cdf0e10cSrcweir byte pContents[][] = new byte[1][]; // ??? 784cdf0e10cSrcweir 785cdf0e10cSrcweir // read contents 786cdf0e10cSrcweir try 787cdf0e10cSrcweir { 788cdf0e10cSrcweir xInput.readBytes( pContents, pBytes.length + 1 ); 789cdf0e10cSrcweir } 790cdf0e10cSrcweir catch( Exception e ) 791cdf0e10cSrcweir { 792cdf0e10cSrcweir Error( "Can't read from stream '" + sName + "', exception: " + e ); 793cdf0e10cSrcweir return false; 794cdf0e10cSrcweir } 795cdf0e10cSrcweir 796cdf0e10cSrcweir // check size of stream data 797cdf0e10cSrcweir if ( pContents.length == 0 ) 798cdf0e10cSrcweir { 799cdf0e10cSrcweir Error( "SubStream '" + sName + "' reading produced disaster!" ); 800cdf0e10cSrcweir return false; 801cdf0e10cSrcweir } 802cdf0e10cSrcweir 803cdf0e10cSrcweir if ( pBytes.length != pContents[0].length ) 804cdf0e10cSrcweir { 805cdf0e10cSrcweir Error( "SubStream '" + sName + "' contains wrong amount of data! (" + pContents[0].length + "/" + pBytes.length + ")" ); 806cdf0e10cSrcweir return false; 807cdf0e10cSrcweir } 808cdf0e10cSrcweir 809cdf0e10cSrcweir // check stream data 810cdf0e10cSrcweir for ( int ind = 0; ind < pBytes.length; ind++ ) 811cdf0e10cSrcweir { 812cdf0e10cSrcweir if ( pBytes[ind] != pContents[0][ind] ) 813cdf0e10cSrcweir { 814cdf0e10cSrcweir Error( "SubStream '" + sName + "' contains wrong data! ( byte num. " 815cdf0e10cSrcweir + ind + " should be " + pBytes[ind] + " but it is " + pContents[0][ind] + ")" ); 816cdf0e10cSrcweir return false; 817cdf0e10cSrcweir } 818cdf0e10cSrcweir } 819cdf0e10cSrcweir 820cdf0e10cSrcweir // check properties 821cdf0e10cSrcweir boolean bOk = false; 822cdf0e10cSrcweir 823cdf0e10cSrcweir // get access to the XPropertySet interface 824cdf0e10cSrcweir XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStream ); 825cdf0e10cSrcweir if ( xPropSet != null ) 826cdf0e10cSrcweir { 827cdf0e10cSrcweir try 828cdf0e10cSrcweir { 829cdf0e10cSrcweir // get "MediaType" and "Size" properties and control there values 830cdf0e10cSrcweir String sPropMediaType = AnyConverter.toString( xPropSet.getPropertyValue( "MediaType" ) ); 831cdf0e10cSrcweir int nPropSize = AnyConverter.toInt( xPropSet.getPropertyValue( "Size" ) ); 832cdf0e10cSrcweir boolean bPropCompress = AnyConverter.toBoolean( xPropSet.getPropertyValue( "Compressed" ) ); 833cdf0e10cSrcweir 834cdf0e10cSrcweir bOk = true; 835cdf0e10cSrcweir if ( !sPropMediaType.equals( sMediaType ) ) 836cdf0e10cSrcweir { 837cdf0e10cSrcweir Error( "'MediaType' property contains wrong value for stream '" + sName + "',\nexpected: '" 838cdf0e10cSrcweir + sMediaType + "', set: '" + sPropMediaType + "'!" ); 839cdf0e10cSrcweir bOk = false; 840cdf0e10cSrcweir } 841cdf0e10cSrcweir 842cdf0e10cSrcweir if ( nPropSize != pBytes.length ) 843cdf0e10cSrcweir { 844cdf0e10cSrcweir Error( "'Size' property contains wrong value for stream'" + sName + "'!" ); 845cdf0e10cSrcweir bOk = false; 846cdf0e10cSrcweir } 847cdf0e10cSrcweir 848cdf0e10cSrcweir if ( bCheckCompressed && bPropCompress != bCompressed ) 849cdf0e10cSrcweir { 850cdf0e10cSrcweir Error( "'Compressed' property contains wrong value for stream'" + sName + "'!" ); 851cdf0e10cSrcweir bOk = false; 852cdf0e10cSrcweir } 853cdf0e10cSrcweir } 854cdf0e10cSrcweir catch( Exception e ) 855cdf0e10cSrcweir { 856cdf0e10cSrcweir Error( "Can't get properties of substream '" + sName + "', exception: " + e ); 857cdf0e10cSrcweir } 858cdf0e10cSrcweir } 859cdf0e10cSrcweir else 860cdf0e10cSrcweir { 861cdf0e10cSrcweir Error( "Can't get XPropertySet implementation from stream '" + sName + "'!" ); 862cdf0e10cSrcweir } 863cdf0e10cSrcweir 864cdf0e10cSrcweir return bOk; 865cdf0e10cSrcweir } 866cdf0e10cSrcweir 867cdf0e10cSrcweir public boolean checkStream( XStorage xParentStorage, 868cdf0e10cSrcweir String sName, 869cdf0e10cSrcweir String sMediaType, 870cdf0e10cSrcweir boolean bCompressed, 871cdf0e10cSrcweir byte[] pBytes ) 872cdf0e10cSrcweir { 873cdf0e10cSrcweir // open substream element first 874cdf0e10cSrcweir XStream xSubStream = null; 875cdf0e10cSrcweir try 876cdf0e10cSrcweir { 877cdf0e10cSrcweir Object oSubStream = xParentStorage.openStreamElement( sName, ElementModes.READ ); 878cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 879cdf0e10cSrcweir if ( xSubStream == null ) 880cdf0e10cSrcweir { 881cdf0e10cSrcweir Error( "Can't open substream '" + sName + "'!" ); 882cdf0e10cSrcweir return false; 883cdf0e10cSrcweir } 884cdf0e10cSrcweir } 885cdf0e10cSrcweir catch( Exception e ) 886cdf0e10cSrcweir { 887cdf0e10cSrcweir Error( "Can't open substream '" + sName + "', exception : " + e + "!" ); 888cdf0e10cSrcweir return false; 889cdf0e10cSrcweir } 890cdf0e10cSrcweir 891cdf0e10cSrcweir boolean bResult = InternalCheckStream( xSubStream, sName, sMediaType, bCompressed, pBytes, true ); 892cdf0e10cSrcweir 893cdf0e10cSrcweir // free the stream resources, garbage collector may remove the object too late 894cdf0e10cSrcweir if ( !disposeStream( xSubStream, sName ) ) 895cdf0e10cSrcweir return false; 896cdf0e10cSrcweir 897cdf0e10cSrcweir return bResult; 898cdf0e10cSrcweir } 899cdf0e10cSrcweir 900cdf0e10cSrcweir public boolean checkEncrStream( XStorage xParentStorage, 901cdf0e10cSrcweir String sName, 902cdf0e10cSrcweir String sMediaType, 903cdf0e10cSrcweir byte[] pBytes, 904cdf0e10cSrcweir String sPass ) 905cdf0e10cSrcweir { 906cdf0e10cSrcweir // Important: a common password for any of parent storage should not be set or 907cdf0e10cSrcweir // should be different from sPass 908cdf0e10cSrcweir 909cdf0e10cSrcweir try 910cdf0e10cSrcweir { 911cdf0e10cSrcweir Object oSubStream = xParentStorage.openStreamElement( sName, ElementModes.READ ); 912cdf0e10cSrcweir Error( "Encrypted stream '" + sName + "' was opened without password!" ); 913cdf0e10cSrcweir return false; 914cdf0e10cSrcweir } 915cdf0e10cSrcweir catch( WrongPasswordException wpe ) 916cdf0e10cSrcweir {} 917cdf0e10cSrcweir catch( Exception e ) 918cdf0e10cSrcweir { 919cdf0e10cSrcweir Error( "Unexpected exception in case of opening of encrypted stream '" + sName + "' without password: " + e + "!" ); 920cdf0e10cSrcweir return false; 921cdf0e10cSrcweir } 922cdf0e10cSrcweir 923cdf0e10cSrcweir String sWrongPass = "11"; 924cdf0e10cSrcweir sWrongPass += sPass; 925cdf0e10cSrcweir try 926cdf0e10cSrcweir { 927cdf0e10cSrcweir Object oSubStream = xParentStorage.openEncryptedStreamElement( sName, ElementModes.READ, sWrongPass ); 928cdf0e10cSrcweir Error( "Encrypted stream '" + sName + "' was opened with wrong password!" ); 929cdf0e10cSrcweir return false; 930cdf0e10cSrcweir } 931cdf0e10cSrcweir catch( WrongPasswordException wpe ) 932cdf0e10cSrcweir {} 933cdf0e10cSrcweir catch( Exception e ) 934cdf0e10cSrcweir { 935cdf0e10cSrcweir Error( "Unexpected exception in case of opening of encrypted stream '" + sName + "' with wrong password: " + e + "!" ); 936cdf0e10cSrcweir return false; 937cdf0e10cSrcweir } 938cdf0e10cSrcweir 939cdf0e10cSrcweir XStream xSubStream = null; 940cdf0e10cSrcweir try 941cdf0e10cSrcweir { 942cdf0e10cSrcweir Object oSubStream = xParentStorage.openEncryptedStreamElement( sName, ElementModes.READ, sPass ); 943cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 944cdf0e10cSrcweir if ( xSubStream == null ) 945cdf0e10cSrcweir { 946cdf0e10cSrcweir Error( "Can't open encrypted substream '" + sName + "'!" ); 947cdf0e10cSrcweir return false; 948cdf0e10cSrcweir } 949cdf0e10cSrcweir } 950cdf0e10cSrcweir catch( Exception e ) 951cdf0e10cSrcweir { 952cdf0e10cSrcweir Error( "Can't open encrypted substream '" + sName + "', exception : " + e + "!" ); 953cdf0e10cSrcweir return false; 954cdf0e10cSrcweir } 955cdf0e10cSrcweir 956cdf0e10cSrcweir // encrypted streams will be compressed always, so after the storing this property is always true, 957cdf0e10cSrcweir // although before the storing it can be set to false ( it is not always clear whether a stream is encrypted 958cdf0e10cSrcweir // before the storing ) 959cdf0e10cSrcweir boolean bResult = InternalCheckStream( xSubStream, sName, sMediaType, true, pBytes, false ); 960cdf0e10cSrcweir 961cdf0e10cSrcweir // free the stream resources, garbage collector may remove the object too late 962cdf0e10cSrcweir if ( !disposeStream( xSubStream, sName ) ) 963cdf0e10cSrcweir return false; 964cdf0e10cSrcweir 965cdf0e10cSrcweir return bResult; 966cdf0e10cSrcweir } 967cdf0e10cSrcweir 968cdf0e10cSrcweir public boolean checkStreamH( XStorage xParentStorage, 969cdf0e10cSrcweir String sPath, 970cdf0e10cSrcweir String sMediaType, 971cdf0e10cSrcweir boolean bCompressed, 972cdf0e10cSrcweir byte[] pBytes ) 973cdf0e10cSrcweir { 974cdf0e10cSrcweir // open substream element first 975cdf0e10cSrcweir XStream xSubStream = null; 976cdf0e10cSrcweir try 977cdf0e10cSrcweir { 978cdf0e10cSrcweir XHierarchicalStorageAccess xHStorage = 979cdf0e10cSrcweir (XHierarchicalStorageAccess) UnoRuntime.queryInterface( XHierarchicalStorageAccess.class, xParentStorage ); 980cdf0e10cSrcweir if ( xHStorage == null ) 981cdf0e10cSrcweir { 982cdf0e10cSrcweir Error( "The storage does not support hierarchical access!" ); 983cdf0e10cSrcweir return false; 984cdf0e10cSrcweir } 985cdf0e10cSrcweir 986cdf0e10cSrcweir Object oSubStream = xHStorage.openStreamElementByHierarchicalName( sPath, ElementModes.READ ); 987cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 988cdf0e10cSrcweir if ( xSubStream == null ) 989cdf0e10cSrcweir { 990cdf0e10cSrcweir Error( "Can't open substream '" + sPath + "'!" ); 991cdf0e10cSrcweir return false; 992cdf0e10cSrcweir } 993cdf0e10cSrcweir } 994cdf0e10cSrcweir catch( Exception e ) 995cdf0e10cSrcweir { 996cdf0e10cSrcweir Error( "Can't open substream '" + sPath + "', exception : " + e + "!" ); 997cdf0e10cSrcweir return false; 998cdf0e10cSrcweir } 999cdf0e10cSrcweir 1000cdf0e10cSrcweir boolean bResult = InternalCheckStream( xSubStream, sPath, sMediaType, bCompressed, pBytes, true ); 1001cdf0e10cSrcweir 1002cdf0e10cSrcweir // free the stream resources, garbage collector may remove the object too late 1003cdf0e10cSrcweir if ( !disposeStream( xSubStream, sPath ) ) 1004cdf0e10cSrcweir return false; 1005cdf0e10cSrcweir 1006cdf0e10cSrcweir return bResult; 1007cdf0e10cSrcweir } 1008cdf0e10cSrcweir 1009cdf0e10cSrcweir public boolean checkEncrStreamH( XStorage xParentStorage, 1010cdf0e10cSrcweir String sPath, 1011cdf0e10cSrcweir String sMediaType, 1012cdf0e10cSrcweir byte[] pBytes, 1013cdf0e10cSrcweir String sPass ) 1014cdf0e10cSrcweir { 1015cdf0e10cSrcweir // Important: a common password for any of parent storage should not be set or 1016cdf0e10cSrcweir // should be different from sPass 1017cdf0e10cSrcweir XHierarchicalStorageAccess xHStorage = 1018cdf0e10cSrcweir (XHierarchicalStorageAccess) UnoRuntime.queryInterface( XHierarchicalStorageAccess.class, xParentStorage ); 1019cdf0e10cSrcweir if ( xHStorage == null ) 1020cdf0e10cSrcweir { 1021cdf0e10cSrcweir Error( "The storage does not support hierarchical access!" ); 1022cdf0e10cSrcweir return false; 1023cdf0e10cSrcweir } 1024cdf0e10cSrcweir 1025cdf0e10cSrcweir try 1026cdf0e10cSrcweir { 1027cdf0e10cSrcweir Object oSubStream = xHStorage.openStreamElementByHierarchicalName( sPath, ElementModes.READ ); 1028cdf0e10cSrcweir XStream xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 1029cdf0e10cSrcweir Error( "Encrypted substream '" + sPath + "' was opened without password!" ); 1030cdf0e10cSrcweir return false; 1031cdf0e10cSrcweir } 1032cdf0e10cSrcweir catch( WrongPasswordException wpe ) 1033cdf0e10cSrcweir {} 1034cdf0e10cSrcweir catch( Exception e ) 1035cdf0e10cSrcweir { 1036cdf0e10cSrcweir Error( "Unexpected exception in case of opening of encrypted stream '" + sPath + "' without password: " + e + "!" ); 1037cdf0e10cSrcweir return false; 1038cdf0e10cSrcweir } 1039cdf0e10cSrcweir 1040cdf0e10cSrcweir String sWrongPass = "11"; 1041cdf0e10cSrcweir sWrongPass += sPass; 1042cdf0e10cSrcweir try 1043cdf0e10cSrcweir { 1044cdf0e10cSrcweir Object oSubStream = xHStorage.openEncryptedStreamElementByHierarchicalName( sPath, ElementModes.READ, sWrongPass ); 1045cdf0e10cSrcweir XStream xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 1046cdf0e10cSrcweir Error( "Encrypted substream '" + sPath + "' was opened with wrong password!" ); 1047cdf0e10cSrcweir return false; 1048cdf0e10cSrcweir } 1049cdf0e10cSrcweir catch( WrongPasswordException wpe ) 1050cdf0e10cSrcweir {} 1051cdf0e10cSrcweir catch( Exception e ) 1052cdf0e10cSrcweir { 1053cdf0e10cSrcweir Error( "Unexpected exception in case of opening of encrypted stream '" + sPath + "' with wrong password: " + e + "!" ); 1054cdf0e10cSrcweir return false; 1055cdf0e10cSrcweir } 1056cdf0e10cSrcweir 1057cdf0e10cSrcweir XStream xSubStream = null; 1058cdf0e10cSrcweir try 1059cdf0e10cSrcweir { 1060cdf0e10cSrcweir Object oSubStream = xHStorage.openEncryptedStreamElementByHierarchicalName( sPath, ElementModes.READ, sPass ); 1061cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 1062cdf0e10cSrcweir if ( xSubStream == null ) 1063cdf0e10cSrcweir { 1064cdf0e10cSrcweir Error( "Can't open encrypted substream '" + sPath + "'!" ); 1065cdf0e10cSrcweir return false; 1066cdf0e10cSrcweir } 1067cdf0e10cSrcweir } 1068cdf0e10cSrcweir catch( Exception e ) 1069cdf0e10cSrcweir { 1070cdf0e10cSrcweir Error( "Can't open encrypted substream '" + sPath + "', exception : " + e + "!" ); 1071cdf0e10cSrcweir return false; 1072cdf0e10cSrcweir } 1073cdf0e10cSrcweir 1074cdf0e10cSrcweir // encrypted streams will be compressed always, so after the storing this property is always true, 1075cdf0e10cSrcweir // although before the storing it can be set to false ( it is not always clear whether a stream is encrypted 1076cdf0e10cSrcweir // before the storing ) 1077cdf0e10cSrcweir boolean bResult = InternalCheckStream( xSubStream, sPath, sMediaType, true, pBytes, false ); 1078cdf0e10cSrcweir 1079cdf0e10cSrcweir // free the stream resources, garbage collector may remove the object too late 1080cdf0e10cSrcweir if ( !disposeStream( xSubStream, sPath ) ) 1081cdf0e10cSrcweir return false; 1082cdf0e10cSrcweir 1083cdf0e10cSrcweir return bResult; 1084cdf0e10cSrcweir } 1085cdf0e10cSrcweir 1086cdf0e10cSrcweir public boolean copyStorage( XStorage xSourceStorage, XStorage xDestStorage ) 1087cdf0e10cSrcweir { 1088cdf0e10cSrcweir // copy xSourceStorage to xDestStorage 1089cdf0e10cSrcweir try 1090cdf0e10cSrcweir { 1091cdf0e10cSrcweir xSourceStorage.copyToStorage( xDestStorage ); 1092cdf0e10cSrcweir } 1093cdf0e10cSrcweir catch( Exception e ) 1094cdf0e10cSrcweir { 1095cdf0e10cSrcweir Error( "Storage copying failed, exception: " + e ); 1096cdf0e10cSrcweir return false; 1097cdf0e10cSrcweir } 1098cdf0e10cSrcweir 1099cdf0e10cSrcweir return true; 1100cdf0e10cSrcweir } 1101cdf0e10cSrcweir 1102cdf0e10cSrcweir public boolean commitStorage( XStorage xStorage ) 1103cdf0e10cSrcweir { 1104cdf0e10cSrcweir // XTransactedObject must be supported by storages 1105cdf0e10cSrcweir XTransactedObject xTransact = (XTransactedObject) UnoRuntime.queryInterface( XTransactedObject.class, xStorage ); 1106cdf0e10cSrcweir if ( xTransact == null ) 1107cdf0e10cSrcweir { 1108cdf0e10cSrcweir Error( "Storage doesn't implement transacted access!" ); 1109cdf0e10cSrcweir return false; 1110cdf0e10cSrcweir } 1111cdf0e10cSrcweir 1112cdf0e10cSrcweir try 1113cdf0e10cSrcweir { 1114cdf0e10cSrcweir xTransact.commit(); 1115cdf0e10cSrcweir } 1116cdf0e10cSrcweir catch( Exception e ) 1117cdf0e10cSrcweir { 1118cdf0e10cSrcweir Error( "Storage commit failed, exception:" + e ); 1119cdf0e10cSrcweir return false; 1120cdf0e10cSrcweir } 1121cdf0e10cSrcweir 1122cdf0e10cSrcweir return true; 1123cdf0e10cSrcweir } 1124cdf0e10cSrcweir 1125cdf0e10cSrcweir public boolean disposeStream( XStream xStream, String sStreamName ) 1126cdf0e10cSrcweir { 1127cdf0e10cSrcweir XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xStream ); 1128cdf0e10cSrcweir if ( xComponent == null ) 1129cdf0e10cSrcweir { 1130cdf0e10cSrcweir Error( "Can't get XComponent implementation from substream '" + sStreamName + "'!" ); 1131cdf0e10cSrcweir return false; 1132cdf0e10cSrcweir } 1133cdf0e10cSrcweir 1134cdf0e10cSrcweir try 1135cdf0e10cSrcweir { 1136cdf0e10cSrcweir xComponent.dispose(); 1137cdf0e10cSrcweir } 1138cdf0e10cSrcweir catch( Exception e ) 1139cdf0e10cSrcweir { 1140cdf0e10cSrcweir Error( "Substream '" + sStreamName + "' disposing throws exception: " + e ); 1141cdf0e10cSrcweir return false; 1142cdf0e10cSrcweir } 1143cdf0e10cSrcweir 1144cdf0e10cSrcweir return true; 1145cdf0e10cSrcweir } 1146cdf0e10cSrcweir 1147cdf0e10cSrcweir public boolean disposeStorage( XStorage xStorage ) 1148cdf0e10cSrcweir { 1149cdf0e10cSrcweir // dispose the storage 1150cdf0e10cSrcweir XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xStorage ); 1151cdf0e10cSrcweir if ( xComponent == null ) 1152cdf0e10cSrcweir { 1153cdf0e10cSrcweir Error( "Can't retrieve XComponent implementation from storage!" ); 1154cdf0e10cSrcweir return false; 1155cdf0e10cSrcweir } 1156cdf0e10cSrcweir 1157cdf0e10cSrcweir try 1158cdf0e10cSrcweir { 1159cdf0e10cSrcweir xComponent.dispose(); 1160cdf0e10cSrcweir } 1161cdf0e10cSrcweir catch( Exception e ) 1162cdf0e10cSrcweir { 1163cdf0e10cSrcweir Error( "Storage disposing failed!" ); 1164cdf0e10cSrcweir return false; 1165cdf0e10cSrcweir } 1166cdf0e10cSrcweir 1167cdf0e10cSrcweir return true; 1168cdf0e10cSrcweir } 1169cdf0e10cSrcweir 1170cdf0e10cSrcweir public XInputStream getInputStream( XStream xStream ) 1171cdf0e10cSrcweir { 1172cdf0e10cSrcweir XInputStream xInTemp = null; 1173cdf0e10cSrcweir try 1174cdf0e10cSrcweir { 1175cdf0e10cSrcweir xInTemp = xStream.getInputStream(); 1176cdf0e10cSrcweir if ( xInTemp == null ) 1177cdf0e10cSrcweir Error( "Can't get the input part of a stream!" ); 1178cdf0e10cSrcweir } 1179cdf0e10cSrcweir catch ( Exception e ) 1180cdf0e10cSrcweir { 1181cdf0e10cSrcweir Error( "Can't get the input part of a stream, exception :" + e ); 1182cdf0e10cSrcweir } 1183cdf0e10cSrcweir 1184cdf0e10cSrcweir return xInTemp; 1185cdf0e10cSrcweir } 1186cdf0e10cSrcweir 1187cdf0e10cSrcweir public boolean closeOutput( XStream xStream ) 1188cdf0e10cSrcweir { 1189cdf0e10cSrcweir XOutputStream xOutTemp = null; 1190cdf0e10cSrcweir try 1191cdf0e10cSrcweir { 1192cdf0e10cSrcweir xOutTemp = xStream.getOutputStream(); 1193cdf0e10cSrcweir if ( xOutTemp == null ) 1194cdf0e10cSrcweir { 1195cdf0e10cSrcweir Error( "Can't get the output part of a stream!" ); 1196cdf0e10cSrcweir return false; 1197cdf0e10cSrcweir } 1198cdf0e10cSrcweir } 1199cdf0e10cSrcweir catch ( Exception e ) 1200cdf0e10cSrcweir { 1201cdf0e10cSrcweir Error( "Can't get the output part of a stream, exception :" + e ); 1202cdf0e10cSrcweir return false; 1203cdf0e10cSrcweir } 1204cdf0e10cSrcweir 1205cdf0e10cSrcweir try 1206cdf0e10cSrcweir { 1207cdf0e10cSrcweir xOutTemp.closeOutput(); 1208cdf0e10cSrcweir } 1209cdf0e10cSrcweir catch ( Exception e ) 1210cdf0e10cSrcweir { 1211cdf0e10cSrcweir Error( "Can't close output part of a stream, exception :" + e ); 1212cdf0e10cSrcweir return false; 1213cdf0e10cSrcweir } 1214cdf0e10cSrcweir 1215cdf0e10cSrcweir return true; 1216cdf0e10cSrcweir } 1217cdf0e10cSrcweir 1218cdf0e10cSrcweir public XStorage openSubStorage( XStorage xStorage, String sName, int nMode ) 1219cdf0e10cSrcweir { 1220cdf0e10cSrcweir // open existing substorage 1221cdf0e10cSrcweir try 1222cdf0e10cSrcweir { 1223cdf0e10cSrcweir Object oSubStorage = xStorage.openStorageElement( sName, nMode ); 1224cdf0e10cSrcweir XStorage xSubStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oSubStorage ); 1225cdf0e10cSrcweir return xSubStorage; 1226cdf0e10cSrcweir } 1227cdf0e10cSrcweir catch( Exception e ) 1228cdf0e10cSrcweir { 1229cdf0e10cSrcweir Error( "Can't open substorage '" + sName + "', exception: " + e ); 1230cdf0e10cSrcweir } 1231cdf0e10cSrcweir 1232cdf0e10cSrcweir return null; 1233cdf0e10cSrcweir } 1234cdf0e10cSrcweir 1235cdf0e10cSrcweir public XStream CreateTempFileStream( XMultiServiceFactory xMSF ) 1236cdf0e10cSrcweir { 1237cdf0e10cSrcweir // try to get temporary file representation 1238cdf0e10cSrcweir XStream xTempFileStream = null; 1239cdf0e10cSrcweir try 1240cdf0e10cSrcweir { 1241cdf0e10cSrcweir Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" ); 1242cdf0e10cSrcweir xTempFileStream = (XStream)UnoRuntime.queryInterface( XStream.class, oTempFile ); 1243cdf0e10cSrcweir } 1244cdf0e10cSrcweir catch( Exception e ) 1245cdf0e10cSrcweir {} 1246cdf0e10cSrcweir 1247cdf0e10cSrcweir if ( xTempFileStream == null ) 1248cdf0e10cSrcweir Error( "Can't create temporary file!" ); 1249cdf0e10cSrcweir 1250cdf0e10cSrcweir return xTempFileStream; 1251cdf0e10cSrcweir } 1252cdf0e10cSrcweir 1253cdf0e10cSrcweir public String CreateTempFile( XMultiServiceFactory xMSF ) 1254cdf0e10cSrcweir { 1255cdf0e10cSrcweir String sResult = null; 1256cdf0e10cSrcweir 1257cdf0e10cSrcweir // try to get temporary file representation 1258cdf0e10cSrcweir XPropertySet xTempFileProps = null; 1259cdf0e10cSrcweir try 1260cdf0e10cSrcweir { 1261cdf0e10cSrcweir Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" ); 1262cdf0e10cSrcweir xTempFileProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, oTempFile ); 1263cdf0e10cSrcweir } 1264cdf0e10cSrcweir catch( Exception e ) 1265cdf0e10cSrcweir {} 1266cdf0e10cSrcweir 1267cdf0e10cSrcweir if ( xTempFileProps != null ) 1268cdf0e10cSrcweir { 1269cdf0e10cSrcweir try 1270cdf0e10cSrcweir { 1271cdf0e10cSrcweir xTempFileProps.setPropertyValue( "RemoveFile", new Boolean( false ) ); 1272cdf0e10cSrcweir sResult = AnyConverter.toString( xTempFileProps.getPropertyValue( "Uri" ) ); 1273cdf0e10cSrcweir } 1274cdf0e10cSrcweir catch( Exception e ) 1275cdf0e10cSrcweir { 1276cdf0e10cSrcweir Error( "Can't control TempFile properties, exception: " + e ); 1277cdf0e10cSrcweir } 1278cdf0e10cSrcweir } 1279cdf0e10cSrcweir else 1280cdf0e10cSrcweir { 1281cdf0e10cSrcweir Error( "Can't create temporary file representation!" ); 1282cdf0e10cSrcweir } 1283cdf0e10cSrcweir 1284cdf0e10cSrcweir // close temporary file explicitly 1285cdf0e10cSrcweir try 1286cdf0e10cSrcweir { 1287cdf0e10cSrcweir XStream xStream = (XStream)UnoRuntime.queryInterface( XStream.class, xTempFileProps ); 1288cdf0e10cSrcweir if ( xStream != null ) 1289cdf0e10cSrcweir { 1290cdf0e10cSrcweir XOutputStream xOut = xStream.getOutputStream(); 1291cdf0e10cSrcweir if ( xOut != null ) 1292cdf0e10cSrcweir xOut.closeOutput(); 1293cdf0e10cSrcweir 1294cdf0e10cSrcweir XInputStream xIn = xStream.getInputStream(); 1295cdf0e10cSrcweir if ( xIn != null ) 1296cdf0e10cSrcweir xIn.closeInput(); 1297cdf0e10cSrcweir } 1298cdf0e10cSrcweir else 1299cdf0e10cSrcweir Error( "Can't close TempFile!" ); 1300cdf0e10cSrcweir } 1301cdf0e10cSrcweir catch( Exception e ) 1302cdf0e10cSrcweir { 1303cdf0e10cSrcweir Error( "Can't close TempFile, exception: " + e ); 1304cdf0e10cSrcweir } 1305cdf0e10cSrcweir 1306cdf0e10cSrcweir return sResult; 1307cdf0e10cSrcweir } 1308cdf0e10cSrcweir 1309cdf0e10cSrcweir public boolean copyElementTo( XStorage xSource, String sName, XStorage xDest ) 1310cdf0e10cSrcweir { 1311cdf0e10cSrcweir // copy element with name sName from xSource to xDest 1312cdf0e10cSrcweir try 1313cdf0e10cSrcweir { 1314cdf0e10cSrcweir xSource.copyElementTo( sName, xDest, sName ); 1315cdf0e10cSrcweir } 1316cdf0e10cSrcweir catch( Exception e ) 1317cdf0e10cSrcweir { 1318cdf0e10cSrcweir Error( "Element copying failed, exception: " + e ); 1319cdf0e10cSrcweir return false; 1320cdf0e10cSrcweir } 1321cdf0e10cSrcweir 1322cdf0e10cSrcweir return true; 1323cdf0e10cSrcweir } 1324cdf0e10cSrcweir 1325cdf0e10cSrcweir public boolean copyElementTo( XStorage xSource, String sName, XStorage xDest, String sTargetName ) 1326cdf0e10cSrcweir { 1327cdf0e10cSrcweir // copy element with name sName from xSource to xDest 1328cdf0e10cSrcweir try 1329cdf0e10cSrcweir { 1330cdf0e10cSrcweir xSource.copyElementTo( sName, xDest, sTargetName ); 1331cdf0e10cSrcweir } 1332cdf0e10cSrcweir catch( Exception e ) 1333cdf0e10cSrcweir { 1334cdf0e10cSrcweir Error( "Element copying failed, exception: " + e ); 1335cdf0e10cSrcweir return false; 1336cdf0e10cSrcweir } 1337cdf0e10cSrcweir 1338cdf0e10cSrcweir return true; 1339cdf0e10cSrcweir } 1340cdf0e10cSrcweir 1341cdf0e10cSrcweir public boolean moveElementTo( XStorage xSource, String sName, XStorage xDest ) 1342cdf0e10cSrcweir { 1343cdf0e10cSrcweir // move element with name sName from xSource to xDest 1344cdf0e10cSrcweir try 1345cdf0e10cSrcweir { 1346cdf0e10cSrcweir xSource.moveElementTo( sName, xDest, sName ); 1347cdf0e10cSrcweir } 1348cdf0e10cSrcweir catch( Exception e ) 1349cdf0e10cSrcweir { 1350cdf0e10cSrcweir Error( "Element moving failed, exception: " + e ); 1351cdf0e10cSrcweir return false; 1352cdf0e10cSrcweir } 1353cdf0e10cSrcweir 1354cdf0e10cSrcweir return true; 1355cdf0e10cSrcweir } 1356cdf0e10cSrcweir 1357cdf0e10cSrcweir public boolean renameElement( XStorage xStorage, String sOldName, String sNewName ) 1358cdf0e10cSrcweir { 1359cdf0e10cSrcweir // rename element with name sOldName to sNewName 1360cdf0e10cSrcweir try 1361cdf0e10cSrcweir { 1362cdf0e10cSrcweir xStorage.renameElement( sOldName, sNewName ); 1363cdf0e10cSrcweir } 1364cdf0e10cSrcweir catch( Exception e ) 1365cdf0e10cSrcweir { 1366cdf0e10cSrcweir Error( "Element renaming failed, exception: " + e ); 1367cdf0e10cSrcweir return false; 1368cdf0e10cSrcweir } 1369cdf0e10cSrcweir 1370cdf0e10cSrcweir return true; 1371cdf0e10cSrcweir } 1372cdf0e10cSrcweir 1373cdf0e10cSrcweir public boolean removeElement( XStorage xStorage, String sName ) 1374cdf0e10cSrcweir { 1375cdf0e10cSrcweir // remove element with name sName 1376cdf0e10cSrcweir try 1377cdf0e10cSrcweir { 1378cdf0e10cSrcweir xStorage.removeElement( sName ); 1379cdf0e10cSrcweir } 1380cdf0e10cSrcweir catch( Exception e ) 1381cdf0e10cSrcweir { 1382cdf0e10cSrcweir Error( "Element removing failed, exception: " + e ); 1383cdf0e10cSrcweir return false; 1384cdf0e10cSrcweir } 1385cdf0e10cSrcweir 1386cdf0e10cSrcweir return true; 1387cdf0e10cSrcweir } 1388cdf0e10cSrcweir 1389cdf0e10cSrcweir public XStream OpenStream( XStorage xStorage, 1390cdf0e10cSrcweir String sStreamName, 1391cdf0e10cSrcweir int nMode ) 1392cdf0e10cSrcweir { 1393cdf0e10cSrcweir // open substream element 1394cdf0e10cSrcweir XStream xSubStream = null; 1395cdf0e10cSrcweir try 1396cdf0e10cSrcweir { 1397cdf0e10cSrcweir Object oSubStream = xStorage.openStreamElement( sStreamName, nMode ); 1398cdf0e10cSrcweir xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); 1399cdf0e10cSrcweir if ( xSubStream == null ) 1400cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "'!" ); 1401cdf0e10cSrcweir } 1402cdf0e10cSrcweir catch( Exception e ) 1403cdf0e10cSrcweir { 1404cdf0e10cSrcweir Error( "Can't create substream '" + sStreamName + "', exception : " + e + "!" ); 1405cdf0e10cSrcweir } 1406cdf0e10cSrcweir 1407cdf0e10cSrcweir return xSubStream; 1408cdf0e10cSrcweir } 1409cdf0e10cSrcweir 1410cdf0e10cSrcweir public boolean compareRawMethodsOnEncrStream( XStorage xStorage, String sStreamName ) 1411cdf0e10cSrcweir { 1412cdf0e10cSrcweir 1413cdf0e10cSrcweir XStorageRawAccess xRawStorage; 1414cdf0e10cSrcweir try 1415cdf0e10cSrcweir { 1416cdf0e10cSrcweir xRawStorage = (XStorageRawAccess) UnoRuntime.queryInterface( XStorageRawAccess.class, xStorage ); 1417cdf0e10cSrcweir } 1418cdf0e10cSrcweir catch( Exception e ) 1419cdf0e10cSrcweir { 1420cdf0e10cSrcweir Error( "Can't get raw access to the storage, exception : " + e + "!" ); 1421cdf0e10cSrcweir return false; 1422cdf0e10cSrcweir } 1423cdf0e10cSrcweir 1424cdf0e10cSrcweir if ( xRawStorage == null ) 1425cdf0e10cSrcweir { 1426cdf0e10cSrcweir Error( "Can't get raw access to the storage!" ); 1427cdf0e10cSrcweir return false; 1428cdf0e10cSrcweir } 1429cdf0e10cSrcweir 1430cdf0e10cSrcweir XInputStream xHeadRawStream = null; 1431cdf0e10cSrcweir try 1432cdf0e10cSrcweir { 1433cdf0e10cSrcweir xHeadRawStream = xRawStorage.getRawEncrStreamElement( sStreamName ); 1434cdf0e10cSrcweir } 1435cdf0e10cSrcweir catch( Exception e ) 1436cdf0e10cSrcweir { 1437cdf0e10cSrcweir Error( "Can't open encrypted stream '" + sStreamName + "' in raw mode with header, exception : " + e + "!" ); 1438cdf0e10cSrcweir } 1439cdf0e10cSrcweir 1440cdf0e10cSrcweir XInputStream xPlainRawStream = null; 1441cdf0e10cSrcweir try 1442cdf0e10cSrcweir { 1443cdf0e10cSrcweir xPlainRawStream = xRawStorage.getPlainRawStreamElement( sStreamName ); 1444cdf0e10cSrcweir } 1445cdf0e10cSrcweir catch( Exception e ) 1446cdf0e10cSrcweir { 1447cdf0e10cSrcweir Error( "Can't open encrypted stream '" + sStreamName + "' in raw mode with header, exception : " + e + "!" ); 1448cdf0e10cSrcweir } 1449cdf0e10cSrcweir 1450cdf0e10cSrcweir if ( xHeadRawStream == null || xPlainRawStream == null ) 1451cdf0e10cSrcweir { 1452cdf0e10cSrcweir Error( "Can't open encrypted stream '" + sStreamName + "' in raw modes!" ); 1453cdf0e10cSrcweir return false; 1454cdf0e10cSrcweir } 1455cdf0e10cSrcweir 1456cdf0e10cSrcweir try 1457cdf0e10cSrcweir { 1458cdf0e10cSrcweir byte pData[][] = new byte[1][38]; 1459cdf0e10cSrcweir if ( xHeadRawStream.readBytes( pData, 38 ) != 38 ) 1460cdf0e10cSrcweir { 1461cdf0e10cSrcweir Error( "Can't read header of encrypted stream '" + sStreamName + "' raw representations!" ); 1462cdf0e10cSrcweir return false; 1463cdf0e10cSrcweir } 1464cdf0e10cSrcweir 1465cdf0e10cSrcweir if ( pData[0][0] != 0x4d || pData[0][1] != 0x4d || pData[0][2] != 0x02 || pData[0][3] != 0x05 ) 1466cdf0e10cSrcweir { 1467cdf0e10cSrcweir Error( "No signature in the header of encrypted stream '" + sStreamName + "' raw representations!" ); 1468cdf0e10cSrcweir return false; 1469cdf0e10cSrcweir } 1470cdf0e10cSrcweir 1471cdf0e10cSrcweir int nVariableHeaderLength = 1472cdf0e10cSrcweir ( pData[0][30] + pData[0][31] * 0x100 ) // salt length 1473cdf0e10cSrcweir + ( pData[0][32] + pData[0][33] * 0x100 ) // iv length 1474cdf0e10cSrcweir + ( pData[0][34] + pData[0][35] * 0x100 ) // digest length 1475cdf0e10cSrcweir + ( pData[0][36] + pData[0][37] * 0x100 ); // mediatype length 1476cdf0e10cSrcweir 1477cdf0e10cSrcweir xHeadRawStream.skipBytes( nVariableHeaderLength ); 1478cdf0e10cSrcweir 1479cdf0e10cSrcweir byte pRawData1[][] = new byte[1][32000]; 1480cdf0e10cSrcweir byte pRawData2[][] = new byte[1][32000]; 1481cdf0e10cSrcweir int nRead1 = 0; 1482cdf0e10cSrcweir int nRead2 = 0; 1483cdf0e10cSrcweir 1484cdf0e10cSrcweir do 1485cdf0e10cSrcweir { 1486cdf0e10cSrcweir nRead1 = xHeadRawStream.readBytes( pRawData1, 32000 ); 1487cdf0e10cSrcweir nRead2 = xPlainRawStream.readBytes( pRawData2, 32000 ); 1488cdf0e10cSrcweir 1489cdf0e10cSrcweir if ( nRead1 != nRead2 ) 1490cdf0e10cSrcweir { 1491cdf0e10cSrcweir Error( "The encrypted stream '" + sStreamName + "' raw representations have different size! nRead1 - nRead2 = " + ( new Integer( nRead1 - nRead2 ) ).toString() ); 1492cdf0e10cSrcweir return false; 1493cdf0e10cSrcweir } 1494cdf0e10cSrcweir 1495cdf0e10cSrcweir for ( int nInd = 0; nInd < nRead1; nInd++ ) 1496cdf0e10cSrcweir if ( pRawData1[0][nInd] != pRawData2[0][nInd] ) 1497cdf0e10cSrcweir { 1498cdf0e10cSrcweir Error( "The encrypted stream '" + sStreamName + "' raw representations have different data!" ); 1499cdf0e10cSrcweir return false; 1500cdf0e10cSrcweir } 1501cdf0e10cSrcweir } 1502cdf0e10cSrcweir while( nRead1 == 32000 ); 1503cdf0e10cSrcweir } 1504cdf0e10cSrcweir catch ( Exception e ) 1505cdf0e10cSrcweir { 1506cdf0e10cSrcweir Error( "Can't compare stream '" + sStreamName + "' raw representations, exception : " + e + "!" ); 1507cdf0e10cSrcweir return false; 1508cdf0e10cSrcweir } 1509cdf0e10cSrcweir 1510cdf0e10cSrcweir return true; 1511cdf0e10cSrcweir } 1512cdf0e10cSrcweir 1513cdf0e10cSrcweir public boolean cantOpenStorage( XStorage xStorage, String sName ) 1514cdf0e10cSrcweir { 1515cdf0e10cSrcweir // try to open an opened substorage, open call must fail 1516cdf0e10cSrcweir try 1517cdf0e10cSrcweir { 1518cdf0e10cSrcweir Object oDummyStorage = xStorage.openStorageElement( sName, ElementModes.READ ); 1519cdf0e10cSrcweir Error( "The trying to reopen opened substorage '" + sName + "' must fail!" ); 1520cdf0e10cSrcweir } 1521cdf0e10cSrcweir catch( Exception e ) 1522cdf0e10cSrcweir { 1523cdf0e10cSrcweir return true; 1524cdf0e10cSrcweir } 1525cdf0e10cSrcweir 1526cdf0e10cSrcweir return false; 1527cdf0e10cSrcweir } 1528cdf0e10cSrcweir 1529cdf0e10cSrcweir public boolean cantOpenStream( XStorage xStorage, String sName, int nMode ) 1530cdf0e10cSrcweir { 1531cdf0e10cSrcweir // try to open the substream with specified mode must fail 1532cdf0e10cSrcweir try 1533cdf0e10cSrcweir { 1534cdf0e10cSrcweir Object oDummyStream = xStorage.openStreamElement( sName, nMode ); 1535cdf0e10cSrcweir Error( "The trying to open substream '" + sName + "' must fail!" ); 1536cdf0e10cSrcweir } 1537cdf0e10cSrcweir catch( Exception e ) 1538cdf0e10cSrcweir { 1539cdf0e10cSrcweir return true; 1540cdf0e10cSrcweir } 1541cdf0e10cSrcweir 1542cdf0e10cSrcweir return false; 1543cdf0e10cSrcweir } 1544cdf0e10cSrcweir 1545cdf0e10cSrcweir public boolean cantOpenStreamH( XStorage xStorage, String sPath, int nMode ) 1546cdf0e10cSrcweir { 1547cdf0e10cSrcweir // try to open the substream with specified mode must fail 1548cdf0e10cSrcweir 1549cdf0e10cSrcweir XHierarchicalStorageAccess xHStorage = 1550cdf0e10cSrcweir (XHierarchicalStorageAccess) UnoRuntime.queryInterface( XHierarchicalStorageAccess.class, xStorage ); 1551cdf0e10cSrcweir if ( xHStorage == null ) 1552cdf0e10cSrcweir { 1553cdf0e10cSrcweir Error( "The storage does not support hierarchical access!" ); 1554cdf0e10cSrcweir return false; 1555cdf0e10cSrcweir } 1556cdf0e10cSrcweir 1557cdf0e10cSrcweir try 1558cdf0e10cSrcweir { 1559cdf0e10cSrcweir Object oDummyStream = xHStorage.openStreamElementByHierarchicalName( sPath, nMode ); 1560cdf0e10cSrcweir Error( "The trying to open substream '" + sPath + "' must fail!" ); 1561cdf0e10cSrcweir } 1562cdf0e10cSrcweir catch( Exception e ) 1563cdf0e10cSrcweir { 1564cdf0e10cSrcweir return true; 1565cdf0e10cSrcweir } 1566cdf0e10cSrcweir 1567cdf0e10cSrcweir return false; 1568cdf0e10cSrcweir } 1569cdf0e10cSrcweir 1570cdf0e10cSrcweir public boolean cantOpenEncrStreamH( XStorage xStorage, String sPath, int nMode, String aPass ) 1571cdf0e10cSrcweir { 1572cdf0e10cSrcweir // try to open the substream with specified mode must fail 1573cdf0e10cSrcweir 1574cdf0e10cSrcweir XHierarchicalStorageAccess xHStorage = 1575cdf0e10cSrcweir (XHierarchicalStorageAccess) UnoRuntime.queryInterface( XHierarchicalStorageAccess.class, xStorage ); 1576cdf0e10cSrcweir if ( xHStorage == null ) 1577cdf0e10cSrcweir { 1578cdf0e10cSrcweir Error( "The storage does not support hierarchical access!" ); 1579cdf0e10cSrcweir return false; 1580cdf0e10cSrcweir } 1581cdf0e10cSrcweir 1582cdf0e10cSrcweir try 1583cdf0e10cSrcweir { 1584cdf0e10cSrcweir Object oDummyStream = xHStorage.openEncryptedStreamElementByHierarchicalName( sPath, nMode, aPass ); 1585cdf0e10cSrcweir Error( "The trying to open substream '" + sPath + "' must fail!" ); 1586cdf0e10cSrcweir } 1587cdf0e10cSrcweir catch( WrongPasswordException wpe ) 1588cdf0e10cSrcweir { 1589cdf0e10cSrcweir Error( "The substream '" + sPath + "' must not exist!" ); 1590cdf0e10cSrcweir return false; 1591cdf0e10cSrcweir } 1592cdf0e10cSrcweir catch( Exception e ) 1593cdf0e10cSrcweir { 1594cdf0e10cSrcweir return true; 1595cdf0e10cSrcweir } 1596cdf0e10cSrcweir 1597cdf0e10cSrcweir return false; 1598cdf0e10cSrcweir } 1599cdf0e10cSrcweir 1600cdf0e10cSrcweir public XStorage cloneStorage( XSingleServiceFactory xFactory, XStorage xStorage ) 1601cdf0e10cSrcweir { 1602cdf0e10cSrcweir // create a copy of a last commited version of specified storage 1603cdf0e10cSrcweir XStorage xResult = null; 1604cdf0e10cSrcweir try 1605cdf0e10cSrcweir { 1606cdf0e10cSrcweir Object oTempStorage = xFactory.createInstance(); 1607cdf0e10cSrcweir xResult = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); 1608cdf0e10cSrcweir if ( xResult != null ) 1609cdf0e10cSrcweir xStorage.copyLastCommitTo( xResult ); 1610cdf0e10cSrcweir } 1611cdf0e10cSrcweir catch( Exception e ) 1612cdf0e10cSrcweir { 1613cdf0e10cSrcweir Error( "Can't clone storage, exception: " + e ); 1614cdf0e10cSrcweir return null; 1615cdf0e10cSrcweir } 1616cdf0e10cSrcweir 1617cdf0e10cSrcweir return xResult; 1618cdf0e10cSrcweir } 1619cdf0e10cSrcweir 1620cdf0e10cSrcweir public XStorage cloneSubStorage( XSingleServiceFactory xFactory, XStorage xStorage, String sName ) 1621cdf0e10cSrcweir { 1622cdf0e10cSrcweir // create a copy of a last commited version of specified substorage 1623cdf0e10cSrcweir XStorage xResult = null; 1624cdf0e10cSrcweir try 1625cdf0e10cSrcweir { 1626cdf0e10cSrcweir Object oTempStorage = xFactory.createInstance(); 1627cdf0e10cSrcweir xResult = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); 1628cdf0e10cSrcweir if ( xResult != null ) 1629cdf0e10cSrcweir xStorage.copyStorageElementLastCommitTo( sName, xResult ); 1630cdf0e10cSrcweir } 1631cdf0e10cSrcweir catch( Exception e ) 1632cdf0e10cSrcweir { 1633cdf0e10cSrcweir Error( "Can't clone substorage '" + sName + "', exception: " + e ); 1634cdf0e10cSrcweir return null; 1635cdf0e10cSrcweir } 1636cdf0e10cSrcweir 1637cdf0e10cSrcweir return xResult; 1638cdf0e10cSrcweir } 1639cdf0e10cSrcweir 1640cdf0e10cSrcweir public XStream cloneSubStream( XStorage xStorage, String sName ) 1641cdf0e10cSrcweir { 1642cdf0e10cSrcweir // clone existing substream 1643cdf0e10cSrcweir try 1644cdf0e10cSrcweir { 1645cdf0e10cSrcweir XStream xStream = xStorage.cloneStreamElement( sName ); 1646cdf0e10cSrcweir return xStream; 1647cdf0e10cSrcweir } 1648cdf0e10cSrcweir catch( Exception e ) 1649cdf0e10cSrcweir { 1650cdf0e10cSrcweir Error( "Can't clone substream '" + sName + "', exception: " + e ); 1651cdf0e10cSrcweir } 1652cdf0e10cSrcweir 1653cdf0e10cSrcweir return null; 1654cdf0e10cSrcweir } 1655cdf0e10cSrcweir 1656cdf0e10cSrcweir public XStream cloneEncrSubStream( XStorage xStorage, String sName, String sPass ) 1657cdf0e10cSrcweir { 1658cdf0e10cSrcweir // clone existing substream 1659cdf0e10cSrcweir try 1660cdf0e10cSrcweir { 1661cdf0e10cSrcweir XStream xStream = xStorage.cloneEncryptedStreamElement( sName, sPass ); 1662cdf0e10cSrcweir return xStream; 1663cdf0e10cSrcweir } 1664cdf0e10cSrcweir catch( Exception e ) 1665cdf0e10cSrcweir { 1666cdf0e10cSrcweir Error( "Can't clone encrypted substream '" + sName + "', exception: " + e ); 1667cdf0e10cSrcweir } 1668cdf0e10cSrcweir 1669cdf0e10cSrcweir return null; 1670cdf0e10cSrcweir } 1671cdf0e10cSrcweir 1672cdf0e10cSrcweir public void Error( String sError ) 1673cdf0e10cSrcweir { 1674cdf0e10cSrcweir m_aLogWriter.println( m_sTestPrefix + "Error: " + sError ); 1675cdf0e10cSrcweir } 1676cdf0e10cSrcweir 1677cdf0e10cSrcweir public void Message( String sMessage ) 1678cdf0e10cSrcweir { 1679cdf0e10cSrcweir m_aLogWriter.println( m_sTestPrefix + sMessage ); 1680cdf0e10cSrcweir } 1681cdf0e10cSrcweir } 1682cdf0e10cSrcweir 1683