Hi Mikhail,

Mikhail Voytenko wrote:
Hi Giuseppe,

The document is working with the storage, that means that some parts of the storage are just locked by other components. This is why for example the substorages related to the embedded objects can not be opened. They are already opened by related components for editing and thus are locked.

Please try the following solution to open the substorage:
...
XStorage xAnotherSubStore;
try
{
xAnotherSubStore = xThePackage.openStorageElement(aObjName[i], ElementModes.READ);
}
catch ( com.sun.star.io.IOException )
{
   // the substorage might be locked, get the last commited version of it
xAnotherSubStore = xStorageFactory.createInstance(); // should create an empty temporary storage xThePackage.copyStorageElementLastCommitTo( aObjName[i], xAnotherSubStore );
}

Hope that helps.

helped, thanks.

I guess that if I can open the substorage, I can open the contained streams as well.

BeppeC.

using this approach, it is a bug if it is not so. The folder can be handled as a usual substorage in those cases.


The document analyzed is the same in both the simplified code snippets below, but it's available in full through an anonymous accessible svn repository, if needed.

In this first example, I can access the whole document storage, creating a storage object starting from the document URL.

<code>

XComponentContext _xCompCtx)
...
    // try from url
Object oObj = _xMCF.createInstanceWithContext("com.sun.star.embed.StorageFactory", _xCompCtx); XSingleServiceFactory xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface(XSingleServiceFactory.class,oObj);

    Object args[]=new Object[2];
    args[0] = aTheDocURL;
    args[1] = ElementModes.READ;

Object oMyStorage = xStorageFactory.createInstanceWithArguments(args);

        XStorage xThePackage;
xThePackage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oMyStorage );
 ....
    String sElementName = "";

    sElementName = "ObjectReplacements";
XStorage xSubStore = xThePackage.openStorageElement(sElementName, ElementModes.READ);

// the following function accesses recursively a substorage
    fillElementList(xSubStore, aElements,sElementName+"/", do_recurse);
    xSubStore.dispose();
....           //Object folders
    String aObjectName = new String("Object ");
    String[] aObjName = xThePackage.getElementNames();
    for(int i = 0; i < aObjName.length; i++) {
        sElementName = aObjName[i];
if((aObjName[i].indexOf(aObjectName) != -1) && xThePackage.isStorageElement(aObjName[i])) { XStorage xAnotherSubStore = xThePackage.openStorageElement(aObjName[i], ElementModes.READ); fillElementList(xAnotherSubStore, aElements,aObjName[i]+"/", true);
            xAnotherSubStore.dispose();
        }
    }
</code>

With the above code I got the following correct package structure, without runtime error:

  layout-cache
  content.xml
  styles.xml
  meta.xml
  settings.xml
  Pictures/10000000000001280000007642983D08.jpg
  ObjectReplacements/Object 1
  ObjectReplacements/Object 2
  ObjectReplacements/Object 3
  ObjectReplacements/Object 4
  ObjectReplacements/Object 5
  ObjectReplacements/Object 6
  Object 1/content.xml
  Object 1/styles.xml
  Object 1/settings.xml
  Object 2/content.xml
  Object 2/styles.xml
  Object 2/settings.xml
  Object 3/content.xml
  Object 3/styles.xml
  Object 3/settings.xml
  Object 4/content.xml
  Object 4/styles.xml
  Object 4/settings.xml
  Object 5/content.xml
  Object 5/styles.xml
  Object 5/settings.xml
  Object 6/content.xml
  Object 6/styles.xml
  Object 6/settings.xml

In the second example I'll use the XStorageBaseDocument to retrieve the document storage, here it goes.

<code>
// the xModel variable below is the XModel I got in a
// synchronous job when instantiated
// at the load finished event (OnLoad event)

    XStorage xStorage = null;
    XStorageBasedDocument xDocStorage =
(XStorageBasedDocument)UnoRuntime.queryInterface( XStorageBasedDocument.class, xModel );

    xStorage = xDocStorage.getDocumentStorage();
....
                           sElementName = "ObjectReplacements";
XStorage xSubStore = xStorage.openStorageElement(sElementName, ElementModes.READ);

//same function as above
    fillElementList(xSubStore, aElements,sElementName+"/", true);
    xSubStore.dispose();
....
// now the code is the same as above               //Object folders
    String aObjectName = new String("Object ");
    String[] aObjName = xStorage.getElementNames();
    for(int i = 0; i < aObjName.length; i++) {
        sElementName = aObjName[i];
if((aObjName[i].indexOf(aObjectName) != -1) && xStorage.isStorageElement(aObjName[i])) {

// the followin line rises an exception, while it shouldn't
// com.sun.star.io.IOException, see below
XStorage xAnotherSubStore = xStorage.openStorageElement(aObjName[i], ElementModes.READ); fillElementList(xAnotherSubStore, aElements,aObjName[i]+"/", true);
            xAnotherSubStore.dispose();
        }
    }

</code>

With the above code I got the following (wrong!) document package structure:

This package contains the following elements:
  layout-cache
  content.xml
  styles.xml
  meta.xml
  settings.xml
  Pictures/10000000000001280000007642983D08.jpg
  ObjectReplacements/Object 1
  ObjectReplacements/Object 2
  ObjectReplacements/Object 3
  ObjectReplacements/Object 4
  ObjectReplacements/Object 5
  ObjectReplacements/Object 6

As it can be seen, the "Object 1", "Object 2" elements, where the OLE objects are actually stored, are missing.

Besides I got the following exception:

<log>

it.plio.ext.xades.ooo.pack.DigitalSignatureHelper createElemeList "Object 1" missing
com.sun.star.io.IOException:
com.sun.star.bridges.jni_uno.JNI_proxy.dispatch_call(Native Method) com.sun.star.bridges.jni_uno.JNI_proxy.invoke(JNI_proxy.java:178)
$Proxy30.openStorageElement(Unknown Source)

the next line is the one indicated in the above code

it.plio.ext.xades.ooo.pack.DigitalSignatureHelper.makeTheElementList(DigitalSignatureHelper.java:186) it.plio.ext.xades.ooo.pack.DigitalSignatureHelper.verifyDocumentSignature(DigitalSignatureHelper.java:231) it.plio.ext.xades.jobs.sync.SyncJob.initThisDocumentURLData(SyncJob.java:699) it.plio.ext.xades.jobs.sync.SyncJob.execute(SyncJob.java:457)

</log>

I'm afraid it's not something simple to explain...

Thanks, anyway.


--
Kind Regards,
Giuseppe Castagno
Acca Esse http://www.acca-esse.eu
giuseppe.castagno at acca-esse.eu
beppec56 at openoffice.org

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org

Reply via email to