package com.dw.lib.test;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.*;
import org.jsoup.select.Elements;
public class jsoupTest {
	
	public static void printByClass(Document doc, String className) {
		Elements e = doc.getElementsByClass(className);
		String output = e.toString();
		if(output.equals("")) return;
		
		System.out.println(jtidyTest.html2text(output));
	}
	
	public static void printUsage() {
		System.out.println("jdict [word list]");
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			
			if(args.length <= 0) {
				printUsage();
			}
			
			//String word = args[0];
			
			String[] className = {
					"phonetic",
					"dict-basic-ul", 
					"layout detail", 
					"layout dual",
					"layout en", 
					"layout sort",
					"layout anno",
					"layout auth",
					"layout nfo",
					"layout nwd"
					};

			for (int i = 0; i < args.length; i++) {
				System.out.println(String.format("%s: ", args[i]));

				Document doc = Jsoup.connect(String.format("http://dict.cn/%s", args[i])).get();
				for (String s : className)
					printByClass(doc, s);
			}
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

@@ -276,16 +276,40 @@
 sName);%0A
+%09%09if(e == null) return;%0A
 %09%09String
@@ -332,16 +332,16 @@
 ring();%0A
-
 %09%09if(out
@@ -415,32 +415,321 @@
 (output));%0A%09%7D%0A%09%0A
+%09public static void printByTag(Document doc, String tagName) %7B%0A%09%09Elements e = doc.getElementsByTag(tagName);%0A%09%09if(e == null) return;%0A%09%09String output = e.toString();%0A%09%09if(output.equals(%22%22)) return;%0A%09%09%0A%09%09for(Element x: e) %7B%0A%09%09%09System.out.println(jtidyTest.html2text(x.toString()));%0A%09%09%7D%0A%09%7D%0A%09%0A
 %09public static v
@@ -790,16 +790,62 @@
 ist%5D%22);%0A
+%09%09System.out.println(%22jdict -e %5Bword list%5D%22);%0A
 %09%7D%0A%09%0A%09pu
@@ -985,16 +985,123 @@
 %09%09%7D%0A%09%09%09%0A
+%09%09%09boolean e2e = false;%0A%09%09%09int index = 0;%0A%09%09%09if(args%5B0%5D == %22-e%22) %7B%0A%09%09%09%09e2e = true;%0A%09%09%09%09index = 1;%0A%09%09%09%7D%0A%09%09%09%0A
 %09%09%09//Str
@@ -1358,16 +1358,20 @@
 %09%09%09%09%7D;%0A%0A
+%09%09%09%0A
 %09%09%09for (
@@ -1378,17 +1378,21 @@
 int i = 
-0
+index
 ; i %3C ar
@@ -1582,16 +1582,16 @@
 ssName)%0A
-
 %09%09%09%09%09pri
@@ -1609,16 +1609,198 @@
 oc, s);%0A
+%09%09%09%09if(e2e) %7B%0A%09%09%09%09%09Document docE2E = Jsoup.connect(String.format(%22http://www.dict.org/bin/Dict?Form=Dict2&Database=*&Query=%25s%22, args%5Bi%5D)).get();%0A%09%09%09%09%09printByTag(docE2E,%22pre%22);%0A%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%09

add dict.org into jdict command