OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Obtaining the bytes of an embedded OLE object

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
cactuscomputing
General User
General User


Joined: 14 Apr 2008
Posts: 7

PostPosted: Mon Apr 14, 2008 7:23 am    Post subject: Obtaining the bytes of an embedded OLE object Reply with quote

Hi,

I'm attempting to retrieve from the document, the bytes that constitute any embedded OLE objects. So far I can obtain the list of object names, and for each name obtain an XembeddedObject instance. Unfortunately when I call getComponent a null is returned. To remedy this I have tried altering the state of the object, but an exception is thrown. Note that's not surprising though as no state values are returned on a call to getReachableStates. I guess I could save the document as an ODF file, and extract the ole objects from the zip file. That though seems tacky! Does anybody have any suggestions?

Fedora 7, Java 1.5, OO 2.4.

Regards
Sean

Ps Here's the code I've tried:

<code>
public void extractOLE(OpenOfficeConnection con, String sourceURL)
throws IOException, IllegalArgumentException, NoSuchElementException,
WrappedTargetException, UnknownPropertyException, NeedsRunningStateException, WrongStateException{
XComponent conponent=null;
PropertyValue[] loadProps = new PropertyValue[1];
loadProps[0] = new PropertyValue();
loadProps[0].Name = "Hidden";
loadProps[0].Value = new Boolean(true);
try{
conponent = con.getDesktop().loadComponentFromURL(sourceURL, "_Blank", 0, loadProps);
XTextDocument document = (XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, conponent);
XTextEmbeddedObjectsSupplier oTSSupp = (XTextEmbeddedObjectsSupplier)UnoRuntime.queryInterface( XTextEmbeddedObjectsSupplier.class, document );
XNameAccess access = oTSSupp.getEmbeddedObjects();
String[] names = access.getElementNames();
for(String name : names){
Object anyOb = access.getByName(name);
XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, anyOb);
Object o = xPropSet.getPropertyValue("CLSID");
//returns CLSID 00000000-0000-0000-0000-000000000000
System.out.println("CLSID " +o);

XEmbeddedObjectSupplier2 os = (XEmbeddedObjectSupplier2)AnyConverter.toObject(XEmbeddedObjectSupplier2.class, anyOb);
XEmbeddedObject eo = os.getExtendedControlOverEmbeddedObject();
if ( eo.getComponent() != null ){
System.out.println("got the component" ); // its null
}
int[] validStates = eo.getReachableStates();
for(int state : validStates){
System.out.println("Valid State " + state); // none
}
int nOldState = eo.getCurrentState();
System.out.println("state " + nOldState); // state =0
}
} finally {
if ( conponent != null ){
conponent.dispose();
}
}
}
</code>
Back to top
View user's profile Send private message
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Mon Apr 14, 2008 12:04 pm    Post subject: Reply with quote

Hi,

to the best of my knowledge getComponent only works for embedded OO Objects. For embedded non-OO objects, you may try two approaches:
(i) if the XEmbeddedObject supports XTransferable, you may ask for the data specifying a DataFlavor
(ii) if the XTextEmbeddedObject (Object anyOb in your code) has a ExtendedControlOverEmbeddedObject, and if this supports XEmbedPersist, you can store to a newly created storage, from which you later can read.

Browsing the unzipped odt is not a bad idea, either

Good luck,

ms777
Back to top
View user's profile Send private message
cactuscomputing
General User
General User


Joined: 14 Apr 2008
Posts: 7

PostPosted: Mon Apr 14, 2008 1:18 pm    Post subject: Reply with quote

Ah- #2 might work as querying for XEmbedPersist returns a service! As for #1 I thought I needed the XComponent for that? Anyway I'll get on with option #2.

Cheers
Sean
Back to top
View user's profile Send private message
cactuscomputing
General User
General User


Joined: 14 Apr 2008
Posts: 7

PostPosted: Tue Apr 15, 2008 8:42 am    Post subject: Problem solved Reply with quote

Hi,

Code works great, I've posted the solution as a code snippet.

R
Sean
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group