Tobias Krais wrote:
Hi Andreas,
You shouldnt post "a complete application" as code snippet.
It's better to show some parts of you approach only.
yes and no. For one part I agree. If you are an expert, it is useful for
you to see only the relevant part of an application.
But I disagree because I am a newbie. And I waste 90% of my time with
finding out the conditions for code snippets and how to get them to
work. And you can imagine, this work is really discouraging.
I suggest a solution: I post the relevant part of the code as a snippet
and add a link to my homepage where you can find a sample application
for the snippet. Is this useful?
Do it as you like ...
At least my comment on this was not a "must" - it was a hint only.
But I know from my own experience: if an example shows more then two
facts at the same time, the "newbie" does not see the important things.
Trying all possible PDF export filters and catching occuring exceptions
isnt realy "good style" .-)
The better approach:
com.sun.star.frame.XModuleManager xMM =
(com.sun.star.frame.XModuleManager)UnoRuntime.queryInterface(
com.sun.star.frame.XModuleManager.class,
xSMGR.createInstance("com.sun.star.frame.ModuleManager"));
Here I have my first problems. Please give me a hint: what is the type
of xSMGR? How can I creat xSMGR? (I'm sure it is a very simple answer,
but I already searched about 4 hours for the solution...).
It's the remote service manager of the office cou can use to create
needed UNO services. In your example you used the following code to
create the Desktop service:
XMultiComponentFactory xRemoteServiceManager
= xRemoteContext.getServiceManager();
Object desktop = null;
try
{
desktop = xRemoteServiceManager.createInstanceWithContext(
"com.sun.star.frame.Desktop", xRemoteContext);
}
...
So my example must be rewritten as:
XModuleManager xMM = (XModuleManager)UnoRuntime.queryInterface(
XModuleManager.class,
xRemoteServiceManager.createInstanceWithContext(
"com.sun.star.frame.ModuleManager",
xRemoteContext));
String sOOoApp = null;
try{
sOOoApp = xMM.identify(openDocument);
}catch(com.sun.star.frame.UnknownModuleException)
{
...
}
// Now you know the application name of this document
// e.g. "com.sun.star.text.TextDocument" for writer
// And you can select the right filter:
String sPDFExportFilter = null;
if (sOOoApp.equals("com.sun.star.text.TextDocument"))
sPDFExportFilter = "writer_pdf_Export";
else
...
This is very good! Thank you, I will do it this way as soon as I find
the xSMGR.
see before .-)
<snip>
b)
Construction of URL's isnt realy platform independend here. You should
the JAVA classes File/URL/URI to create real URL's.
But be aware of a bug inside these JAVA classes. They construct file
URL's like "file:/test/file.txt", which does not represent valid file
URLs. You have to establish a workaround for that and convert "file:/"
hardly to "file:///".
On the other side I currently dont know, if OOo accepts such "wrong
formated" URL's too and convert it internaly .-)
Well its working -> I think OO will accept it. But I will use following
code for the snippet:
-----%<-----
public String createUNOFileURL(String filelocation)
{
String myUNOFileURL = null;
java.io.File newfile = new java.io.File(filelocation);
try {
myUNOFileURL
= newfile.toURL().toString().replace("file:/", "file:///");
}
catch (MalformedURLException e) {
System.out.println(e.getLocalizedMessage());
}
return myUNOFileURL;
}
Better use the helper service ... as Stephan Bergmann mentioned !
-----%<-----
}
catch(Exception e)
{
System.out.println("OpenOffice runs, but error opening
document:");
System.out.println(e.getLocalizedMessage());
}
if (openedDocument == null) {
System.err.println("I found the document but cannot open
it...");
System.exit(-4);
System.exit() isnt realy an option, if you work remote with OOo using
UNO. Your JAVA process will be killed hardly - fine . But the OOo
instance will stay alive inside memory ... Furhtermore it might contain
dead UNO objects (forgotten JAVA listener etcpp). And if you use this
office instance from it's normal UI it can happen that it crashes by
using these dead objects.
Solution:
Terminate the office from JAVA before you call exit()
If I understand right, this will exit all my offices or just this
instance. I even have no xDesktop -> I think I cannot add a
terminateListener. Am I right?
You used the desktop service already. It's the component you called
"loadComponentFromURL()" on it. And this object can do some more usefull
stuff for you. If you ask for the interface css.frame.XDesktop you will
be able to be notified in case somewhere try to terminate the office ...
or you can terminate the office by yourself.
By the way: Without doing special things it's not possible to start more
then one office at the same machine. At least there is only one active
office process in memory. And every JAVA Client will connect to the same
process.
... or
make sure that all your registered listener was deregistered before.
For I did not register any listeners, I think there is no need to
deregister them. Am I right?
No registered listener - no deregistration is needed - of course.
But if you change that ... .-)
Thank you for your help.
Greetings, Tobias
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Regards
Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]