| View previous topic :: View next topic |
| Author |
Message |
dk2678 Newbie

Joined: 10 Apr 2004 Posts: 3
|
Posted: Sat Apr 10, 2004 9:05 am Post subject: XML Import via UNO and Java |
|
|
Hi,
I have a problem importing XML document via UNO with the java method loadComponentFromUrl().
The returned component is always null. If I try to import other document types it runs fine.
If I try importing the XML-Document manually it works fine also.
Does somebody has an idea.
thanks alot
Dirk |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
Guest
|
Posted: Sat Apr 10, 2004 10:09 am Post subject: |
|
|
The XML-File is a generated file by Cocoon which has OOo conform tags.
The Import Filter is a self created xslt-File which copies the whole content of the file.
With that xslt-file I created my own ImportFilter in OOo. |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Sat Apr 10, 2004 11:00 am Post subject: |
|
|
When you import the file manually, you are probably manually specifying which import filter to use.
You need to also specify the import filter when importing via. the API.
For most of the built in import filters, the Type Detection mechanism looks at the incomming file and can automatically determine which filter to use. Therefore, in many of the gazillion code examples in this forum where, for instance, an Excel file is imported, or a Word file is imported, no import filter is specified, because Type Detection figures out which import filter to use when one was not specified.
You probably need to pass an array of a single com.sun.star.beans.PropertyValue, containing a "Name" of "FilterName", and a "Value" of "xxxxx" where "xxxxx" is the name of your filter. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
dk2678 Newbie

Joined: 10 Apr 2004 Posts: 3
|
Posted: Sun Apr 11, 2004 12:54 am Post subject: |
|
|
Hi
here is the code which loads the document.
| Code: | // set properties for the input filter
PropertyValue[] loadPropos = new PropertyValue[1];
loadPropos[0] = new PropertyValue();
loadPropos[0].Name = "FilterName";
loadPropos[0].Value = DocumentConverter.loadConvertType;
Object objectDocumentToStore =
DocumentConverter.xcomponentloader.loadComponentFromURL(stringUrl, "_blank", 0, loadPropos ); |
What happens is OOo comes up and stays with a grey background. With other input documents than xml it works fine. |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Sun Apr 11, 2004 6:58 am Post subject: |
|
|
I suppose the real question is what filter name to use.
Run this Basic program in the Basic IDE. It produces a Writer document of the filters you have installed and available.
| Code: | Sub Main
oFF = createUnoService( "com.sun.star.document.FilterFactory" )
oFilterNames = oFF.getElementNames()
' Create a Writer doc and save the filter names to it.
oDoc = StarDesktop.loadComponentFromURL( "private:factory/swriter", "_blank", 0, Array() )
oText = oDoc.getText()
oCursor = oText.createTextCursor()
oCursor.gotoEnd( False )
' Print the filter names into a Writer document.
For i = LBound( oFilterNames ) To UBound( oFilterNames )
oText.insertString( oCursor, oFilterNames(i), False )
oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
Next
End Sub |
Then look for a suitable filter name. Try hardcoding the filter name string as an experiment.
Is the loadConvertType a suitable and valid filter name?
You should be able to write a short Basic program that opens your document with a suitable filter string. This is probably the fastest way to identify what filter name to use and prove that it works. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
dk2678 Newbie

Joined: 10 Apr 2004 Posts: 3
|
Posted: Sun Apr 11, 2004 7:49 am Post subject: |
|
|
if try opening the document in OOo and use the same Filter that the code is using it works fine. So I don't think that the Filter is the problem. And its also possible to open html through the api with the same filter.
Are there any known problems importing xml throught he api? |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Sun Apr 11, 2004 8:28 pm Post subject: |
|
|
If you're opening the document manually, then can you be sure that your code is specifying the same filter?
If it is the html filter we're talking about, I don't know why it would have any problems with html that also happens to be proper xml. Especially, if you can open it manually.
One thing about opening html. If you let Type Detection pick the filter, it will pick the filter that opens Html into the Web module. You may instead want to open Html into the Writer module -- in which case you must specify the proper filter. (This has been discussed in the past.)
I'm thinking that a trivial Basic program that just opens the document, specifying a filter, would prove that you have discovered the right filter name to use, and it should work in your Java code. Also I'm thinking that a trivial Basic program would be the fastest way keep trying different filter names. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
|