public boolean checkStreamH( XStorage xParentStorage, String sPath, String sMediaType, boolean bCompressed, byte[] pBytes) { // open substream element first XStream xSubStream = null; try { XHierarchicalStorageAccess xHStorage = (XHierarchicalStorageAccess) UnoRuntime.queryInterface(XHierarchicalStorageAccess.class, xParentStorage); if (xHStorage == null) { Error("The storage does not support hierarchical access!"); return false; } Object oSubStream = xHStorage.openStreamElementByHierarchicalName(sPath, ElementModes.READ); xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream); if (xSubStream == null) { Error("Can't open substream '" + sPath + "'!"); return false; } } catch (Exception e) { Error("Can't open substream '" + sPath + "', exception : " + e + "!"); return false; } boolean bResult = InternalCheckStream(xSubStream, sPath, sMediaType, bCompressed, pBytes, true); // free the stream resources, garbage collector may remove the object too late if (!disposeStream(xSubStream, sPath)) return false; return bResult; }
public boolean WriteBytesToStreamH( XStorage xStorage, String sStreamPath, String sMediaType, boolean bCompressed, byte[] pBytes, boolean bCommit) { // open substream element XStream xSubStream = null; try { XHierarchicalStorageAccess xHStorage = (XHierarchicalStorageAccess) UnoRuntime.queryInterface(XHierarchicalStorageAccess.class, xStorage); if (xHStorage == null) { Error("The storage does not support hierarchical access!"); return false; } Object oSubStream = xHStorage.openStreamElementByHierarchicalName(sStreamPath, ElementModes.WRITE); xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream); if (xSubStream == null) { Error("Can't create substream '" + sStreamPath + "'!"); return false; } } catch (Exception e) { Error("Can't create substream '" + sStreamPath + "', exception : " + e + "!"); return false; } if (!WriteBytesToStream(xSubStream, sStreamPath, sMediaType, bCompressed, pBytes)) return false; XTransactedObject xTransact = (XTransactedObject) UnoRuntime.queryInterface(XTransactedObject.class, xSubStream); if (xTransact == null) { Error("Substream '" + sStreamPath + "', stream opened for writing must be transacted!"); return false; } if (bCommit) { try { xTransact.commit(); } catch (Exception e) { Error( "Can't commit storage after substream '" + sStreamPath + "' change, exception : " + e + "!"); return false; } } // free the stream resources, garbage collector may remove the object too late if (!disposeStream(xSubStream, sStreamPath)) return false; return true; }
public boolean cantOpenStreamH(XStorage xStorage, String sPath, int nMode) { // try to open the substream with specified mode must fail XHierarchicalStorageAccess xHStorage = (XHierarchicalStorageAccess) UnoRuntime.queryInterface(XHierarchicalStorageAccess.class, xStorage); if (xHStorage == null) { Error("The storage does not support hierarchical access!"); return false; } try { Object oDummyStream = xHStorage.openStreamElementByHierarchicalName(sPath, nMode); Error("The trying to open substream '" + sPath + "' must fail!"); } catch (Exception e) { return true; } return false; }
public boolean checkEncrStreamH( XStorage xParentStorage, String sPath, String sMediaType, byte[] pBytes, String sPass) { // Important: a common password for any of parent storage should not be set or // should be different from sPass XHierarchicalStorageAccess xHStorage = (XHierarchicalStorageAccess) UnoRuntime.queryInterface(XHierarchicalStorageAccess.class, xParentStorage); if (xHStorage == null) { Error("The storage does not support hierarchical access!"); return false; } try { Object oSubStream = xHStorage.openStreamElementByHierarchicalName(sPath, ElementModes.READ); XStream xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream); Error("Encrypted substream '" + sPath + "' was opened without password!"); return false; } catch (WrongPasswordException wpe) { } catch (Exception e) { Error( "Unexpected exception in case of opening of encrypted stream '" + sPath + "' without password: "******"!"); return false; } String sWrongPass = "******"; sWrongPass += sPass; try { Object oSubStream = xHStorage.openEncryptedStreamElementByHierarchicalName( sPath, ElementModes.READ, sWrongPass); XStream xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream); Error("Encrypted substream '" + sPath + "' was opened with wrong password!"); return false; } catch (WrongPasswordException wpe) { } catch (Exception e) { Error( "Unexpected exception in case of opening of encrypted stream '" + sPath + "' with wrong password: "******"!"); return false; } XStream xSubStream = null; try { Object oSubStream = xHStorage.openEncryptedStreamElementByHierarchicalName(sPath, ElementModes.READ, sPass); xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream); if (xSubStream == null) { Error("Can't open encrypted substream '" + sPath + "'!"); return false; } } catch (Exception e) { Error("Can't open encrypted substream '" + sPath + "', exception : " + e + "!"); return false; } // encrypted streams will be compressed always, so after the storing this property is always // true, // although before the storing it can be set to false ( it is not always clear whether a stream // is encrypted // before the storing ) boolean bResult = InternalCheckStream(xSubStream, sPath, sMediaType, true, pBytes, false); // free the stream resources, garbage collector may remove the object too late if (!disposeStream(xSubStream, sPath)) return false; return bResult; }
public boolean WBToSubstrOfEncrH( XStorage xStorage, String sStreamPath, String sMediaType, boolean bCompressed, byte[] pBytes, boolean bEncrypted, boolean bCommit) { // open substream element XStream xSubStream = null; try { XHierarchicalStorageAccess xHStorage = (XHierarchicalStorageAccess) UnoRuntime.queryInterface(XHierarchicalStorageAccess.class, xStorage); if (xHStorage == null) { Error("The storage does not support hierarchical access!"); return false; } Object oSubStream = xHStorage.openStreamElementByHierarchicalName(sStreamPath, ElementModes.WRITE); xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream); if (xSubStream == null) { Error("Can't create substream '" + sStreamPath + "'!"); return false; } } catch (Exception e) { Error("Can't create substream '" + sStreamPath + "', exception : " + e + "!"); return false; } // get access to the XPropertySet interface XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xSubStream); if (xPropSet == null) { Error("Can't get XPropertySet implementation from substream '" + sStreamPath + "'!"); return false; } // set properties to the stream try { xPropSet.setPropertyValue("UseCommonStoragePasswordEncryption", new Boolean(bEncrypted)); } catch (Exception e) { Error( "Can't set 'UseCommonStoragePasswordEncryption' property to substream '" + sStreamPath + "', exception: " + e); return false; } if (!WriteBytesToStream(xSubStream, sStreamPath, sMediaType, bCompressed, pBytes)) return false; XTransactedObject xTransact = (XTransactedObject) UnoRuntime.queryInterface(XTransactedObject.class, xSubStream); if (xTransact == null) { Error("Substream '" + sStreamPath + "', stream opened for writing must be transacted!"); return false; } if (bCommit) { try { xTransact.commit(); } catch (Exception e) { Error( "Can't commit storage after substream '" + sStreamPath + "' change, exception : " + e + "!"); return false; } } // free the stream resources, garbage collector may remove the object too late if (!disposeStream(xSubStream, sStreamPath)) return false; return true; }