1 4 package com.dappit.Dapper.parser.example; 5 6 import java.io.File ; 7 8 import org.dom4j.DocumentException; 9 import org.w3c.dom.Document ; 10 11 import com.dappit.Dapper.parser.EnviromentController; 12 import com.dappit.Dapper.parser.MozillaParser; 13 import com.dappit.Dapper.parser.ParserInitializationException; 14 15 19 public class ParserExample { 20 21 public static void main(String [] args) throws Exception 22 { 23 25 File parserLibraryFile = new File ("native/bin/MozillaParser" + EnviromentController.getSharedLibraryExtension()); 26 String parserLibrary = parserLibraryFile.getAbsolutePath(); 27 System.out.println("Loading Parser Library :" + parserLibrary); 28 final File mozillaDistBinDirectory = new File ("mozilla.dist.bin."+EnviromentController.getOperatingSystemName()); 30 31 32 MozillaParser.init(parserLibrary,mozillaDistBinDirectory.getAbsolutePath()); 33 34 Thread thread1 = new Thread () 35 { 36 37 public void run(){ 38 try 39 { 40 41 MozillaParser parser = new MozillaParser(); 42 43 String html = "<html><body>"; 44 for (int i=0; i<100; i++) 45 html += "<li><table><tr><td>1111111111111111</table>\n"; 46 html += "</body></html>"; 47 Document document = parser.parse(html); 48 System.out.println("Generated document :" + ((org.dom4j.Document)document).asXML()); 49 } 50 catch (ParserInitializationException e) 51 { 52 e.printStackTrace(); 53 } catch (DocumentException e) { 54 e.printStackTrace(); 56 } 57 System.out.println("done..."); 58 } 59 }; 60 61 Thread thread2 = new Thread (){ 62 63 public void run(){ 64 try 65 { 66 MozillaParser parser = new MozillaParser(); 68 System.out.println("parsing..."); 69 70 String html = "<html><body>"; 71 for (int i=0; i<100; i++) 72 html += "<li><table><tr><td>222222222222222</table>\n"; 73 html += "</body></html>"; 74 Document document = parser.parse(html); 75 System.out.println("Generated document :" + ((org.dom4j.Document)document).asXML()); 76 } 77 catch (Exception e) 78 { 79 e.printStackTrace(); 80 } 81 System.out.println("done..."); 82 } 83 }; 84 85 thread1.start(); 86 thread2.start(); 87 thread1.join(); 88 thread2.join(); 89 90 } 99 100 } 101 | Popular Tags |