| View previous topic :: View next topic |
| Author |
Message |
dcrintea Power User

Joined: 26 Feb 2004 Posts: 68
|
Posted: Mon Jun 06, 2005 5:14 am Post subject: using input streams: how to detect the type |
|
|
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 |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Mon Jun 06, 2005 10:48 am Post subject: |
|
|
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 |
|
 |
dcrintea Power User

Joined: 26 Feb 2004 Posts: 68
|
Posted: Tue Jun 07, 2005 4:20 am Post subject: thx |
|
|
Thank you,
but what do you use to call createUnoService method ?
where can I find this API? |
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
|
| Back to top |
|
 |
dcrintea Power User

Joined: 26 Feb 2004 Posts: 68
|
Posted: Tue Jun 07, 2005 5:13 am Post subject: hello |
|
|
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 |
|
 |
dcrintea Power User

Joined: 26 Feb 2004 Posts: 68
|
Posted: Tue Jun 07, 2005 5:25 am Post subject: |
|
|
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 |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Tue Jun 07, 2005 5:26 am Post subject: |
|
|
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 |
|
 |
dcrintea Power User

Joined: 26 Feb 2004 Posts: 68
|
Posted: Tue Jun 07, 2005 5:49 am Post subject: ... |
|
|
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 |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Tue Jun 07, 2005 6:16 am Post subject: |
|
|
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 |
|
 |
|