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

using input streams: how to detect the type

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


Joined: 26 Feb 2004
Posts: 68

PostPosted: Mon Jun 06, 2005 5:14 am    Post subject: using input streams: how to detect the type Reply with quote

I load OO file from a stream: how can I detect the file type?

I need the file type to validate possible convertion filters.

So, how can I detect the "file" type, if I use a stream instead of an url ?

thx.
Back to top
View user's profile Send private message
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Mon Jun 06, 2005 10:48 am    Post subject: Reply with quote

this is the basics in BASIC ... see the TypeDetection Doc for all the details ...
Code:
Sub Main
 
sUrl = ConvertToUrl("C:\Windows\Desktop\test2.txt")

oSFA       = createUNOService ("com.sun.star.ucb.SimpleFileAccess")
oInpStream = oSFA.openFileRead(sUrl)

Dim aProps(1) as new  com.sun.star.beans.PropertyValue
aProps(0).Name = "InputStream"
aProps(0).Value = oInpStream

'To give the URL is not necessary.
'If no URL is given, bDeepDetection must be true, of course
aProps(1).Name = "URL"
aProps(1).Value = sUrl

oTD = createUnoService("com.sun.star.document.TypeDetection")

sType = oTD.queryTypeByDescriptor(aProps(), false)

oInpStream.closeInput()

msgbox sType

end sub
Back to top
View user's profile Send private message
dcrintea
Power User
Power User


Joined: 26 Feb 2004
Posts: 68

PostPosted: Tue Jun 07, 2005 4:20 am    Post subject: thx Reply with quote

Thank you,

but what do you use to call createUnoService method ?
where can I find this API?
Back to top
View user's profile Send private message
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Tue Jun 07, 2005 4:38 am    Post subject: Reply with quote

createUnoService is a BASIC construct. The equivalent of createUnoService in other languages depends of the language. Which are you using ?

createUnoService
http://www.oooforum.org/forum/viewtopic.phtml?p=13027#13027

calling OO API from other languages
http://www.oooforum.org/forum/viewtopic.phtml?t=9815
Back to top
View user's profile Send private message
dcrintea
Power User
Power User


Joined: 26 Feb 2004
Posts: 68

PostPosted: Tue Jun 07, 2005 5:13 am    Post subject: hello Reply with quote

I use Java.

I tried:

Code:

            PropertyValue testProperties[] = new PropertyValue[ 1 ];
            testProperties[ 0 ] = new PropertyValue();
            testProperties[ 0 ].Name = "InputStream";
            testProperties[ 0 ].Value = is;           
           

            XTypeDetection td = xRemoteServiceManager.createInstance("com.sun.star.document.TypeDetection");

           
            System.out.println(td.queryTypeByDescriptor(testProperties, true));   


but no success
Back to top
View user's profile Send private message
dcrintea
Power User
Power User


Joined: 26 Feb 2004
Posts: 68

PostPosted: Tue Jun 07, 2005 5:25 am    Post subject: Reply with quote

I do:

Code:

            PropertyValue testProperties[] = new PropertyValue[ 1 ];
            testProperties[ 0 ] = new PropertyValue();
            testProperties[ 0 ].Name = "InputStream";
            testProperties[ 0 ].Value = is;           
           

            XTypeDetection td = ( XTypeDetection ) UnoRuntime.queryInterface( XTypeDetection.class, xo );

           
            System.out.println(td.queryTypeByDescriptor(testProperties, true));


when I compile it says:

queryTypeByDescriptor(com.sun.star.beans.PropertyValue[][], boolean)

in com.sun.star.document.XTypeDetection cannot be applied to

(com.sun.star.beans.PropertyValue[], boolean)

What's wrong with the properties?
Back to top
View user's profile Send private message
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Tue Jun 07, 2005 5:26 am    Post subject: Reply with quote

sorry - cant help you with Java

I would recommend to try first with td.queryTypeByUrl and a local file to see if the object instantiation works
Back to top
View user's profile Send private message
dcrintea
Power User
Power User


Joined: 26 Feb 2004
Posts: 68

PostPosted: Tue Jun 07, 2005 5:49 am    Post subject: ... Reply with quote

I've changed the properties to:

Code:

      PropertyValue testProperties[][] = new PropertyValue[ 1 ][ 1 ];
            testProperties[ 0 ][ 0 ] = new PropertyValue();
            testProperties[ 0 ][ 0 ].Name = "InputStream";
            testProperties[ 0 ][ 0 ].Value = is;


BUT

XTypeDetection td = ( XTypeDetection ) UnoRuntime.queryInterface( XTypeDetection.class, xo);

create a null XTypeDetection.

Any idea?
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


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

PostPosted: Tue Jun 07, 2005 6:16 am    Post subject: Reply with quote

In this thread, but also a direct question over here
http://www.oooforum.org/forum/viewtopic.phtml?t=20890
there was a question about createUnoService() in Java. The other thread linked has some additional information.


Short simple answer to question about createUnoService.

Basic provides createUnoService() as a global convenience function. It is exactly equivalent to calling createInstance() on the global ServiceManager. (i.e. NOT on the service manager of some particular object, such as a document, but on the ServiceManager that you first obtain from your initial connection to OOo.)



Other Basic translation notes...

Basic also provides createUnoStruct(). This is easily done in Java by instantiating the specific struct (as a java class). e.g. a Basic call to createUnoStruct("com.sun.star.beans.PropertyValue") in Java would simply be to declare a variable and create a new instance....
PropertyValue xyz = new PropertyValue();

Basic provides a global variable StarDesktop. This is simply the singleton instance of the Desktop object that you get by calling createInstance( "com.sun.star.frame.Desktop" ) on the global service manager.

Basic provides HasUnoInterfaces() function which is simply a way to do introspection to see if a service supports particular interfaces. I have posted examples (search OOoForum for HasUnoInterfaces) of how to implement this function in other languages.
_________________
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