KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > extensions > pdfbox > OooProcess


1 package org.lucane.extensions.pdfbox;
2
3 import java.io.IOException JavaDoc;
4
5 import org.lucane.common.Logging;
6
7 public class OooProcess implements Runnable JavaDoc
8 {
9     private String JavaDoc command;
10     private boolean shutdowned;
11     private Process JavaDoc process;
12     
13     public OooProcess(String JavaDoc command)
14     {
15         this.command = command;
16         this.shutdowned = false;
17     }
18     
19     public void run()
20     {
21         String JavaDoc[] params = {
22                 command,
23                 "-accept=socket,host=localhost,port=2002;urp;",
24                 "-headless",
25                 "-invisible"};
26         
27         try {
28             while(!shutdowned)
29             {
30                 if(process == null)
31                 {
32                     Logging.getLogger().info("Starting OpenOffice.org");
33                     process = Runtime.getRuntime().exec(params);
34                 }
35                 
36                 try {
37                     int returnCode = process.waitFor();
38                     process = null;
39                     Logging.getLogger().warning("OpenOffice.org exited with status : " + returnCode);
40
41                     if(returnCode == 0)
42                         throw new RuntimeException JavaDoc("Unable to start openoffice, is it already running ?");
43                 } catch (InterruptedException JavaDoc e) {
44                     System.err.println("OooProcess interrupted : ");
45                     e.printStackTrace();
46                 }
47             }
48         } catch(IOException JavaDoc ioe) {
49             throw new RuntimeException JavaDoc("Unable to start openoffice", ioe);
50         }
51     }
52     
53     public void shutdown()
54     {
55         this.shutdowned = true;
56                 if(this.process != null)
57                     this.process.destroy();
58     }
59 }
Popular Tags