> how i will open (from Java Application) the MS word format /html
> documentsin repective Applications in Linux OS?
> (e.g. *.doc with Microsoft Word and html in IExplorer)
I asked for some info in these groups a long while back to help me do
exactly that. Unfortunately, I didn't learn nearly as much as I would
have liked. But I learned enough to get the basics figured out.
The specific method depends on the presence of a "file manager" type
application for the user which has been used to designate appropriate
applications for selected file extensions.
What I did in the Linux version of our product was require an external
properties file. I required the presence of two properties, which I
named "file.view" and "url.view", so that I could handle either a file
or a user-provided URL, respectively. The value of each property must
contain the command line to which I will append a URI. If a file is to
be opened, I use the File object's toURI method. If a user-provided URL
is to be opened, I create a URI object around it and use that.
In a CDE setting (popular on Solaris but sometimes used in Linux), the
"file.view" property contains "dtaction Open". I constructed a string
array by separating the CDE command line at the spaces, and the file URI
goes into the third spot. Then I just use a Runtime.exec call to launch
it.
In CDE, the command "dtaction WebBrowser" is used with HTTP URLs, and
the same thing is done.
I commonly use KDE on our Linux box. There, I've found that the command
"kfmclient exec" works for both of the above properties.
And in a Gnome environment, if the "nautilus" program is used for file
management, the command line for both of those properties only needs
"nautilus" and then the URI.
In some respects, this puts the burden on Linux users of determining
what the proper command is for their environment. But with the variety
of desktops and file managers, I think it's hard to do much else.
I don't use an external properties file for Windows or Mac OS X since
both of those have predetermined mechanisms for handing off URIs to
specified applications. For Windows, I kept it very simple and built a
string array around "cmd /c start URI". Our app isn't available on any
Windows earlier than 2000, so that command is great; on Win98 it won't
work. Our app isn't yet supported on Mac OS X, but I'm planning ahead.
For that platform, the command line is "open URI", which hands off the
URI to either a local application (for a file) or to the user's
designated web browser, FTP app, etc.
HTH.
= Steve =

Signature
Steve W. Jackson
Montgomery, Alabama
Ayodhya - 13 Jul 2006 05:28 GMT
Thanx Steve for the nice explanation.i'll use this concept in my
application.But i could nt understand where the "file manager" type
application is used.i am attaching the code snippet for windows..
void openDocument(String filename)
{
String path = (String) documentInfo_.get(filename);//u get the URL
from here
String os = System.getProperty("os.name");
String command="";
if(os.startsWith("Windows"))
command = "rundll32 SHELL32.DLL,ShellExec_RunDLL";
else if(os.startsWith("LInux"))
;//TODO
try
{
//path is kept within double quotes.
command += " \"" + path + "\"";
Process process = Runtime.getRuntime().exec(command);
}
catch (Exception e)
{
e.printStackTrace();
}
}
Thank you
Ayodhya
> > how i will open (from Java Application) the MS word format /html
> > documentsin repective Applications in Linux OS?
[quoted text clipped - 49 lines]
>
> = Steve =
Steve W. Jackson - 13 Jul 2006 16:01 GMT
> Thanx Steve for the nice explanation.i'll use this concept in my
> application.But i could nt understand where the "file manager" type
[quoted text clipped - 26 lines]
> Thank you
> Ayodhya
I don't use the rundll32 part for Windows. Unless you need to support
Windows versions earlier than Windows 2000, I find the use of "cmd /c
start filename" to be much simpler. And if the file's extension isn't
something the current system has a designated application for, Windows
itself automatically prompts for instructions -- although that may be
true with the rundll32 approach.
I would also advise you to make a point of using a string array for the
command line you construct. If you pass a string to the version of
exec() that takes one, it's parsed for you. With some commands, that
leads to grief. With the above rundll32 command, you would want two
separate array entries there and a third for the quoted file name with
path.
The "file manager" application I referred to only pertains to Linux.
Windows and Mac OS X have built-in features for handling a file
according to its type (extension only in Windows, handled by Windows
Explorer, and possible combinations of things for Mac OS X, handled by
its Finder). But Linux, at its heart, is a pure *nix system, where the
graphical environment of a user's choice is simply "pasted" on top, so
to speak. Whatever environment you use will have some means of
responding to double-clicks of files.
= Steve =

Signature
Steve W. Jackson
Montgomery, Alabama
Ayodhya - 13 Jul 2006 09:29 GMT
HI Steve,
I ahve implementaed the command u suggested but the linux os could not
recognise the "dtaction" command.
Yeah i have used the "kfmclient exec" which opens the word/html
document in KDE.but i need the documents should open in respective
applications(e.g .doc file should open in Openoffice, which comes by
default in linux").
Please suggest wht to do.
Thanks for ur suggestion.
Ayodhya
> > how i will open (from Java Application) the MS word format /html
> > documentsin repective Applications in Linux OS?
[quoted text clipped - 49 lines]
>
> = Steve =
Steve W. Jackson - 13 Jul 2006 16:08 GMT
> HI Steve,
>
[quoted text clipped - 10 lines]
> Thanks for ur suggestion.
> Ayodhya
The "dtaction" commands only apply if you're using CDE, the Common
Desktop Environment. It's most widely used, to the best of my
knowledge, on Solaris systems and not so much on Linux.
If you're using KDE and followed my earlier advice, then you took a file
referred to by a java.io.File object and created a URI from it using the
toURI() method. Construct a string array with three parts. In the
first part (index 0), put "kfmclient", the second (index 1) is "exec",
and the third (index 2) is the URI's value obtained by using the URI's
toString() method. Then call Runtime.getRuntime().exec(stringArray) to
launch it.
If you haven't instructed your KDE system to handle ".doc" files with
OpenOffice, it's not going to happen. It's been a while since I did
this with my Linux box, but I seem to recall being prompted...maybe not.
= Steve =

Signature
Steve W. Jackson
Montgomery, Alabama