1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| package com.applet;
import java.applet.Applet;
import java.io.File;
import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;
public class EditingDocument extends Applet {
private static final long serialVersionUID = 1L;
public void init(String fileName, String mime, String mode) {
String [] filename = fileName.split(";");
if (mime.equals("application/vnd.ms-excel")) {
openDoc("excel.exe",filename[0], mode);
}else if (mime.equals("application/vnd.ms-powerpoint")) {
openDoc("powerpnt",filename[0], mode);
} else {
openDoc("winword",filename[0], mode);
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private void openDoc(final String appli, final String fileName, final String mode){
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
//Launcher l = new Launcher();
//l.createLauncher(fileName);
Runtime runtime = Runtime.getRuntime();
if (!mode.equals("write")) {
//File file = new File(l.getLocalFile());
//file.setWritable(false);
}
try
{
runtime.exec("cmd /c start " + appli + " " /*+ l.getLocalFile()*/);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
});
}
} |