rendered paste bodypackage ootrigger;
import java.applet.*;
import java.awt.*;
import java.lang.ProcessBuilder;
import java.lang.System;
import ootrigger.RegReader;
public class OOtrigger extends Applet {
private Process m_ooproc; // current openoffice process
private ProcessBuilder m_ooffice;
@Override
public void init(){
m_ooproc = null;
m_ooffice = null;
}
@Override
public void start() {
// detecting OS
if(System.getProperty("os.name").equals("Linux")) {
// linux, eaasssy job
printMessage("Found "+ System.getProperty("os.name") +"..", true);
printMessage("Starting OpenOffice..", false);
m_ooffice = new ProcessBuilder("oowriter2");
printMessage("ok", true);
}
else if (System.getProperty("os.name").equals("Windows XP") ) {
// god bless us, its windows, lets read the reg to find
// the openoffice installtion
printMessage("Found "+ System.getProperty("os.name") +"..", true);
printMessage("Getting OpenOffice installtion path..", false);
String ooPath = getOOInstallPath();
if(ooPath != null){
printMessage("ok", true);
printMessage("Starting OpenOffice..", false);
m_ooffice = new ProcessBuilder(ooPath+"\\swriter.exe");
}
else
printError("Could not find OpenOffice installation! Aborting..", true);
}
else {
printError("OS" + System.getProperty("os.name") + " not supported!", true);
printWarning("shutting down..", true);
destroy();
}
try{
m_ooproc = m_ooffice.start();
}
catch(Exception e)
{
printError("Can`t start OpenOffice!" , true);
}
}
public void paint(){
}
@Override
public void update(Graphics g)
{
paint (g);
}
@Override
public void destroy(){
// closing openoffcie
if(m_ooproc != null)
m_ooproc.destroy();
}
private String getOOInstallPath() {
RegReader regAccess = new RegReader();
return regAccess.getOOInstallPath();
}
private void printError (String text, boolean cr){
if(cr)
System.err.println(text);
else
System.err.print(text);
}
private void printMessage (String text, boolean cr){
if(cr)
System.out.println(text);
else
System.out.print(text);
}
private void printWarning (String text, boolean cr){
if(cr)
System.out.println(text);
else
System.out.print(text);
}
}