01: /**
02: *
03: */package com.dappit.Dapper.parser.example;
04:
05: import java.io.File;
06:
07: import org.dom4j.DocumentException;
08: import org.w3c.dom.Document;
09:
10: import com.dappit.Dapper.parser.EnviromentController;
11: import com.dappit.Dapper.parser.MozillaParser;
12: import com.dappit.Dapper.parser.ParserInitializationException;
13:
14: /**
15: * @author Ohad Serfaty
16: *
17: */
18: public class ParserExample {
19:
20: public static void main(String[] args) throws Exception {
21: // parser library :
22:
23: File parserLibraryFile = new File("./native/bin/MozillaParser"
24: + EnviromentController.getSharedLibraryExtension());
25: String parserLibrary = parserLibraryFile.getAbsolutePath();
26: System.out.println("Loading Parser Library :" + parserLibrary);
27: // mozilla.dist.bin directory :
28: final File mozillaDistBinDirectory = new File(
29: "mozilla.dist.bin."
30: + EnviromentController.getOperatingSystemName());
31:
32: MozillaParser.init(parserLibrary, mozillaDistBinDirectory
33: .getAbsolutePath());
34:
35: Thread thread1 = new Thread() {
36:
37: public void run() {
38: try {
39:
40: MozillaParser parser = new MozillaParser();
41:
42: String html = "<html><body>";
43: for (int i = 0; i < 100; i++)
44: html += "<li><table><tr><td>1111111111111111</table>\n";
45: html += "</body></html>";
46: Document document = parser.parse(html);
47: System.out.println("Generated document :"
48: + ((org.dom4j.Document) document).asXML());
49: } catch (DocumentException e) {
50: // TODO Auto-generated catch block
51: e.printStackTrace();
52: }
53: System.out.println("done...");
54: }
55: };
56:
57: Thread thread2 = new Thread() {
58:
59: public void run() {
60: try {
61: //MozillaParser.initXPCOM(mozillaDistBinDirectory.getAbsolutePath());
62: MozillaParser parser = new MozillaParser();
63: System.out.println("parsing...");
64:
65: String html = "<html><body>";
66: for (int i = 0; i < 100; i++)
67: html += "<li><table><tr><td>222222222222222</table>\n";
68: html += "</body></html>";
69: Document document = parser.parse(html);
70: System.out.println("Generated document :"
71: + ((org.dom4j.Document) document).asXML());
72: } catch (Exception e) {
73: e.printStackTrace();
74: }
75: System.out.println("done...");
76: }
77: };
78:
79: thread1.start();
80: thread2.start();
81: thread1.join();
82: thread2.join();
83:
84: // // start the mozilla parser with the right library/components directory :
85: // MozillaParser.init(parseLibrary, mozillaDistBinDirectory.getAbsolutePath());
86: //
87: // // parse the document :
88: // Document domDocument = MozillaParser.getInstance().parse("<html>Hello world!<html>");
89: //
90: // // stop the parser ( essential for a clean exit ).
91: // MozillaParser.getInstance().stopRunning();
92: }
93:
94: }
|