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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
public class TestInitMoz {
private static String pathXUL = "xulrunner-1.8.1.3/";
public static void main(String[] args) {
System.out.println("Debut");
System.setProperty("org.eclipse.swt.browser.XULRunnerPath", pathXUL);
Mozilla mozilla = Mozilla.getInstance();
GREVersionRange[] range = new GREVersionRange[1];
range[0] = new GREVersionRange("1.8.0.*", false, "1.8.1.*", true);
try {
File grePath = new File (pathXUL);
LocationProvider locProvider = new LocationProvider(grePath,createTempProfileDir());
mozilla.initialize(grePath);
mozilla.initEmbedding(grePath, grePath, locProvider);
mozilla.notifyProfile();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (XPCOMException e) {
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
Display display = new Display();
Shell shell = new Shell (display);
shell.setText("Mozilla");
shell.setSize(800,600);
shell.setLayout(new FillLayout());
Browser browser = new Browser(shell,SWT.MOZILLA);
if (browser == null){
System.out.println("Browser marche pas");
}
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
mozilla.termEmbedding();
System.out.println("Fini");
}
private static File createTempProfileDir() throws IOException {
// Get name of temporary profile directory
File profile = File.createTempFile("mozilla-test-", null);
profile.delete();
// On some operating systems (particularly Windows), the previous
// temporary profile may not have been deleted. Delete them now.
File[] files = profile.getParentFile()
.listFiles(new FileFilter() {
public boolean accept(File file) {
if (file.getName().startsWith("mozilla-test-")) {
return true;
}
return false;
}
});
for (int i = 0; i < files.length; i++) {
deleteDir(files[i]);
}
// Create temporary profile directory
profile.mkdir();
return profile;
}
private static void deleteDir(File dir) {
File[] files = dir.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory()) {
deleteDir(files[i]);
}
files[i].delete();
}
dir.delete();
}
} |
Partager