Example #1
0
  public boolean disposeStream(XStream xStream, String sStreamName) {
    XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xStream);
    if (xComponent == null) {
      Error("Can't get XComponent implementation from substream '" + sStreamName + "'!");
      return false;
    }

    try {
      xComponent.dispose();
    } catch (Exception e) {
      Error("Substream '" + sStreamName + "' disposing throws exception: " + e);
      return false;
    }

    return true;
  }
Example #2
0
  public boolean disposeStorage(XStorage xStorage) {
    // dispose the storage
    XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xStorage);
    if (xComponent == null) {
      Error("Can't retrieve XComponent implementation from storage!");
      return false;
    }

    try {
      xComponent.dispose();
    } catch (Exception e) {
      Error("Storage disposing failed!");
      return false;
    }

    return true;
  }
Example #3
0
  public int ChangeStreamPass(
      XStorage xStorage, String sStreamName, byte[] pOldPass, byte[] pNewPass) {
    // open substream element
    XStream xSubStream = null;
    try {
      Object oSubStream =
          xStorage.openEncryptedStreamElement(
              sStreamName, ElementModes.WRITE, new String(pOldPass));
      xSubStream = UnoRuntime.queryInterface(XStream.class, oSubStream);
      if (xSubStream == null) {
        Error("Can't open substream '" + sStreamName + "'!");
        return 0;
      }
    } catch (Exception e) {
      Error("Can't open substream '" + sStreamName + "', exception : " + e + "!");
      return 0;
    }

    // change the password for the stream
    XEncryptionProtectedSource xStreamEncryption =
        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(new String(pNewPass));
    } catch (Exception e) {
      Error("Can't change encryption key of the substream '" + sStreamName + "', exception:" + e);
      return 0;
    }

    // free the stream resources, garbage collector may remove the object too late
    XComponent xComponent = UnoRuntime.queryInterface(XComponent.class, xSubStream);
    if (xComponent == null) {
      Error("Can't get XComponent implementation from substream '" + sStreamName + "'!");
      return 0;
    }
    xComponent.dispose();

    return 1;
  }
Example #4
0
  public boolean WriteBytesToStream(
      XStream xStream, String sStreamName, String sMediaType, boolean bCompressed, byte[] pBytes) {
    // get output stream of substream
    XOutputStream xOutput = xStream.getOutputStream();
    if (xOutput == null) {
      Error("Can't get XOutputStream implementation from substream '" + sStreamName + "'!");
      return false;
    }

    // get XTrucate implementation from output stream
    XTruncate xTruncate = UnoRuntime.queryInterface(XTruncate.class, xOutput);
    if (xTruncate == null) {
      Error("Can't get XTruncate implementation from substream '" + sStreamName + "'!");
      return false;
    }

    // write requested byte sequence
    try {
      xTruncate.truncate();
      xOutput.writeBytes(pBytes);
    } catch (Exception e) {
      Error("Can't write to stream '" + sStreamName + "', exception: " + e);
      return false;
    }

    // get access to the XPropertySet interface
    XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xStream);
    if (xPropSet == null) {
      Error("Can't get XPropertySet implementation from substream '" + sStreamName + "'!");
      return false;
    }

    // set properties to the stream
    try {
      xPropSet.setPropertyValue("MediaType", sMediaType);
      xPropSet.setPropertyValue("Compressed", Boolean.valueOf(bCompressed));
    } catch (Exception e) {
      Error("Can't set properties to substream '" + sStreamName + "', exception: " + e);
      return false;
    }

    // check size property of the stream
    try {
      int nSize = AnyConverter.toInt(xPropSet.getPropertyValue("Size"));
      if (nSize != pBytes.length) {
        Error("The 'Size' property of substream '" + sStreamName + "' contains wrong value!");
        return false;
      }
    } catch (Exception e) {
      Error("Can't get 'Size' property from substream '" + sStreamName + "', exception: " + e);
      return false;
    }

    // free the stream resources, garbage collector may remove the object too late
    XComponent xComponent = UnoRuntime.queryInterface(XComponent.class, xStream);
    if (xComponent == null) {
      Error("Can't get XComponent implementation from substream '" + sStreamName + "'!");
      return false;
    }
    xComponent.dispose();

    return true;
  }