Hi Giuseppe,

if you want to use the OpenOffice.org UNO API for accessing ODF Packages have a look at the Package file format interfaces and services here:

http://api.openoffice.org/docs/common/ref/com/sun/star/packages/module-ix.html


If reading and manipulating the XML Streams contained in an ODF File using java tough is all you want to do you might also have a look at odf4j as an alternative lightweight approach.

http://wiki.services.openoffice.org/wiki/Odf4j

ODF4j provides a simple java API for ODF Documents that doesn´t require an OpenOffice.org installation. ODF4j is a project which is not yet finished but accessing XML Streams contained in ODF Packages is something which already works well and there are also helper classes for applying XSL-Transformations to those streams or methods to get them as W3C DOM tree, there is stuff for handling of the Manifest file etc. and some simple samples are also available.

Kind regards,
Bernd Eilers


Giuseppe Castagno wrote:
Hi all,

After I successfully opened a package (e.g. an ODT document) with Java using UCB low level APIs, I tried to read the content of one of the contained streams.

With no luck so far. Is there somewhere some example about how to do that?

After I successfully opened it with (sorry for the ugly indentation):
<Java code>

...
    XMultiServiceFactory xMSF = ....
...

Object oUCB = xMSF.createInstanceWithArguments( "com.sun.star.ucb.UniversalContentBroker", keys );
// Obtain required UCB interfaces

XContentIdentifierFactory xIdFactory = (XContentIdentifierFactory)UnoRuntime.queryInterface(XContentIdentifierFactory.class, oUCB);

XContentProvider xProvider = (XContentProvider)UnoRuntime.queryInterface(XContentProvider.class, oUCB);

...

XContentIdentifier xIdPackStream = xIdFactory.createContentIdentifier(aThePackageUrl+"/META-INF/manifest.xml");

XContent xPackStreamContent = xProvider.queryContent(xIdPackStream);
            String contentF = xPackStreamContent.getContentType();
            System.out.println("root folder type: " + contentF);
if( contentF.contentEquals("application/vnd.sun.star.pkg-stream" )) { System.out.println("Found a META-INF/metafile.xml element (the root)\n");
//now open the stream content and try to read it
                OpenCommandArgument2 aArg = new OpenCommandArgument2();
aArg.Mode = OpenMode.ALL;// FOLDER, DOCUMENTS -> simple filter
                aArg.Priority = 32768;// Ignored by most implementations

        // Fill info for the properties wanted.
                Property[] aProps = new Property[2];
                Property prop1 = new Property();
                prop1.Name = "Title";
                prop1.Handle = -1;// n/a
                aProps[0] = prop1;
                Property prop2 = new Property();
                prop2.Name = "IsFolder";
                prop2.Handle = -1;// n/a
                aProps[1] = prop2;
                XDynamicResultSet xSet;

                aArg.Properties = aProps;
Object oSet = executeCommand(xPackStreamContent, "open", aArg);
            //convert the object from Object to XDynamicResultSet
                Type aType = AnyConverter.getType(oSet);
xSet = (XDynamicResultSet) AnyConverter.toObject(new com.sun.star.uno.Type

(com.sun.star.ucb.XDynamicResultSet.class), oSet);
// now list the xSet elements
      XResultSet xResultSet = xSet.getStaticResultSet();
</code>

where executeCommand() is basically the one found here [1],

It seems the wrong approach since xResultSet throws an exception.

Any help is greatly appreciated.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to