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

XML Import via UNO and Java

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


Joined: 10 Apr 2004
Posts: 3

PostPosted: Sat Apr 10, 2004 9:05 am    Post subject: XML Import via UNO and Java Reply with quote

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
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Sat Apr 10, 2004 9:18 am    Post subject: Reply with quote

Are you specifying which import filter to use?

What type of XML document? DocBook? Or what?
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Guest






PostPosted: Sat Apr 10, 2004 10:09 am    Post subject: Reply with quote

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
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Sat Apr 10, 2004 11:00 am    Post subject: Reply with quote

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
View user's profile Send private message
dk2678
Newbie
Newbie


Joined: 10 Apr 2004
Posts: 3

PostPosted: Sun Apr 11, 2004 12:54 am    Post subject: Reply with quote

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
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Sun Apr 11, 2004 6:58 am    Post subject: Reply with quote

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
View user's profile Send private message
dk2678
Newbie
Newbie


Joined: 10 Apr 2004
Posts: 3

PostPosted: Sun Apr 11, 2004 7:49 am    Post subject: Reply with quote

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
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Sun Apr 11, 2004 8:28 pm    Post subject: Reply with quote

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
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