| View previous topic :: View next topic |
| Author |
Message |
cactuscomputing General User

Joined: 14 Apr 2008 Posts: 7
|
Posted: Mon Apr 14, 2008 7:23 am Post subject: Obtaining the bytes of an embedded OLE object |
|
|
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 |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Mon Apr 14, 2008 12:04 pm Post subject: |
|
|
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 |
|
 |
cactuscomputing General User

Joined: 14 Apr 2008 Posts: 7
|
Posted: Mon Apr 14, 2008 1:18 pm Post subject: |
|
|
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 |
|
 |
cactuscomputing General User

Joined: 14 Apr 2008 Posts: 7
|
Posted: Tue Apr 15, 2008 8:42 am Post subject: Problem solved |
|
|
Hi,
Code works great, I've posted the solution as a code snippet.
R
Sean |
|
| Back to top |
|
 |
|
|
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
|