/* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempStorage, "SubStream1", "MediaType1", true, pBytes, sPass ) ) returnfalse;
// open a new substorage
XStorage xTempSubStorage = m_aTestHelper.openSubStorage( xTempStorage, "SubStorage1",
ElementModes.WRITE ); if ( xTempSubStorage == null )
{
m_aTestHelper.Error( "Can't create substorage!" ); returnfalse;
}
// open a new substream, set "MediaType" and "Compressed" properties to it and write some bytes if ( !m_aTestHelper.WriteBytesToEncrSubstream( xTempSubStorage, "SubStream2", "MediaType2", false, pBytes, sPass ) ) returnfalse;
// set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempStorage, "MediaType3", true,
ElementModes.WRITE ) ) returnfalse;
// set "MediaType" property for storages and check that "IsRoot" and "OpenMode" properties are set correctly if ( !m_aTestHelper.setStorageTypeAndCheckProps( xTempSubStorage, "MediaType4", false,
ElementModes.WRITE ) ) returnfalse;
// commit substorage first if ( !m_aTestHelper.commitStorage( xTempSubStorage ) ) returnfalse;
// commit the root storage so the contents must be stored now if ( !m_aTestHelper.commitStorage( xTempStorage ) ) returnfalse;
// dispose used storage to free resources if ( !m_aTestHelper.disposeStorage( xTempStorage ) ) returnfalse;
// now reopen the storage, set the common storage key // and copy the storage
// set the common storage password
XEncryptionProtectedSource xEncr = (XEncryptionProtectedSource) UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xStep2TempStorage ); if ( xEncr == null )
{
m_aTestHelper.Error( "The storage does not support encryption access!" ); returnfalse;
} try
{
xEncr.setEncryptionPassword( sPass );
} catch( Exception e )
{
m_aTestHelper.Error( "Can not set the common storage password!" ); returnfalse;
}
// open the stream for writing and read them so that the cache is created, but do not change byte pDummyData[][] = newbyte[1][3];
XStream xTempStream1 = m_aTestHelper.OpenStream( xStep2TempStorage, "SubStream1", ElementModes.WRITE );
XStream xTempStream2 = m_aTestHelper.OpenStream( xStep2TempSubStorage, "SubStream2", ElementModes.WRITE ); if ( xTempStream1 == null || xTempStream2 == null ) returnfalse;
XInputStream xTempInStream1 = xTempStream1.getInputStream();
XInputStream xTempInStream2 = xTempStream2.getInputStream(); if ( xTempInStream1 == null || xTempInStream2 == null )
{
m_aTestHelper.Error( "No input stream is available!" ); returnfalse;
}
// create temporary storage, it will be checked later
Object oTargetStorage = m_xStorageFactory.createInstance();
XStorage xTargetStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTargetStorage ); if ( xTargetStorage == null )
{
m_aTestHelper.Error( "Can't create temporary storage representation!" ); returnfalse;
}
// copy the current storage to the target try
{
xStep2TempStorage.copyToStorage( xTargetStorage );
} catch( Exception e )
{
m_aTestHelper.Error( "Can not copy the storage with common storage password!" ); returnfalse;
}
// dispose used storage to free resources if ( !m_aTestHelper.disposeStorage( xStep2TempStorage ) ) returnfalse;
// now check all the information in the copy
if ( !m_aTestHelper.checkStorageProperties( xTargetStorage, "MediaType3", true, ElementModes.WRITE ) ) returnfalse;
// open existing substorage
XStorage xTargetSubStorage = m_aTestHelper.openSubStorage( xTargetStorage, "SubStorage1",
ElementModes.WRITE ); if ( xTargetSubStorage == null )
{
m_aTestHelper.Error( "Can't open existing substorage!" ); returnfalse;
}
if ( !m_aTestHelper.checkStorageProperties( xTargetSubStorage, "MediaType4", false, ElementModes.WRITE ) ) returnfalse;
// set the common storage password
XEncryptionProtectedSource xTargetEncr = (XEncryptionProtectedSource) UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xTargetStorage ); if ( xTargetEncr == null )
{
m_aTestHelper.Error( "The storage does not support encryption access!" ); returnfalse;
} try
{
xTargetEncr.setEncryptionPassword( sPass );
} catch( Exception e )
{
m_aTestHelper.Error( "Can not set the common storage password!" ); returnfalse;
}
// check the streams if ( !m_aTestHelper.checkStream( xTargetStorage, "SubStream1", "MediaType1", true, pBytes ) ) returnfalse; if ( !m_aTestHelper.checkStream( xTargetSubStorage, "SubStream2", "MediaType2", true, pBytes ) ) returnfalse;
// dispose used storages to free resources if ( !m_aTestHelper.disposeStorage( xTargetStorage ) ) returnfalse;
returntrue;
} catch( Exception e )
{
m_aTestHelper.Error( "Exception: " + e ); returnfalse;
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.