Ejemplo n.º 1
0
  public boolean WriteBytesToEncrStreamH(
      XStorage xStorage,
      String sStreamPath,
      String sMediaType,
      boolean bCompressed,
      byte[] pBytes,
      String sPass,
      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.openEncryptedStreamElementByHierarchicalName(
              sStreamPath, ElementModes.WRITE, sPass);
      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;
  }
Ejemplo n.º 2
0
  public boolean commitStorage(XStorage xStorage) {
    // XTransactedObject must be supported by storages
    XTransactedObject xTransact = UnoRuntime.queryInterface(XTransactedObject.class, xStorage);
    if (xTransact == null) {
      Error("Storage doesn't implement transacted access!");
      return false;
    }

    try {
      xTransact.commit();
    } catch (Exception e) {
      Error("Storage commit failed, exception:" + e);
      return false;
    }

    return true;
  }
Ejemplo n.º 3
0
  public int ChangeStreamPassH(
      XStorage xStorage, String sPath, String sOldPass, String sNewPass, boolean bCommit) {
    // open substream element
    XHierarchicalStorageAccess xHStorage =
        (XHierarchicalStorageAccess)
            UnoRuntime.queryInterface(XHierarchicalStorageAccess.class, xStorage);
    if (xHStorage == null) {
      Error("The storage does not support hierarchical access!");
      return 0;
    }

    XStream xSubStream = null;
    try {
      Object oSubStream =
          xHStorage.openEncryptedStreamElementByHierarchicalName(
              sPath, ElementModes.WRITE, sOldPass);
      xSubStream = (XStream) UnoRuntime.queryInterface(XStream.class, oSubStream);
      if (xSubStream == null) {
        Error("Can't open encrypted substream '" + sPath + "'!");
        return 0;
      }
    } catch (Exception e) {
      Error("Can't open encrypted substream '" + sPath + "', exception : " + e + "!");
      return 0;
    }

    // change the password for the stream
    XEncryptionProtectedSource xStreamEncryption =
        (XEncryptionProtectedSource)
            UnoRuntime.queryInterface(XEncryptionProtectedSource.class, xSubStream);

    if (xStreamEncryption == null) {
      Message(
          "Optional interface XEncryptionProtectedSource is not implemented, feature can not be tested!");
      return -1;
    }

    try {
      xStreamEncryption.setEncryptionPassword(sNewPass);
    } catch (Exception e) {
      Error("Can't change encryption key of the substream '" + sPath + "', exception:" + e);
      return 0;
    }

    XTransactedObject xTransact =
        (XTransactedObject) UnoRuntime.queryInterface(XTransactedObject.class, xSubStream);
    if (xTransact == null) {
      Error("Substream '" + sPath + "', stream opened for writing must be transacted!");
      return 0;
    }

    if (bCommit) {
      try {
        xTransact.commit();
      } catch (Exception e) {
        Error(
            "Can't commit storage after substream '" + sPath + "' change, exception : " + e + "!");
        return 0;
      }
    }

    // free the stream resources, garbage collector may remove the object too late
    if (!disposeStream(xSubStream, sPath)) return 0;

    return 1;
  }
Ejemplo n.º 4
0
  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;
  }