/**
 *  wrongPowder is developed by wrong-entertainment & powder
 *
 *
 *  Copyright 2011 Paul Vollmer & Tim Pulver
 *  paulvollmer.net
 *  vollmerpaul@yahoo.de
 *  timpulver.de
 *  pulver.tim@googlemail.com
 * 
 *  This file is part of wrongPowder library.
 *
 *  wrongPowder is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU Lesser General Public License for more details.
 *  
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with wrongPowder. If not, see <http://www.gnu.org/licenses/>.
 * 
 *  @author		##author##
 *  @modified	##date##
 *  @version	##version##
 */

package wrongPowder.util.string;

import java.io.BufferedReader;
import java.io.InputStream;

import processing.core.PApplet;





/**
 * DudenAnalyse class will help
 * 
 * @example config_basic 
 */
public class DudenAnalyse {
	
	PApplet p5;
	
	public String[] sourcecode;
	
	public String wordtype;
	public String frequency;
	public String worttrennung;
	public String herkunft;
	
	
	
	
	
	/**
	 * A Constructor, usually called in the setup() method in your sketch to
	 * initialize and start the library.
	 * 
	 * @example config_basic
	 */
	public DudenAnalyse(PApplet p) {
		p5 = p;
	}
	
	
	
	
	
	/**
	 * Initailize a text array and save string to variable text.
	 *
	 * @param txt Filename
	 */
	public void search(String url) {
		System.out.println("Start searching duden.de");		  
	}
	
	
	public void checkWord(String word) {
		BufferedReader reader = p5.createReader("http://www.duden.de/rechtschreibung/"+word);
		
		try {
			String line;
			String sourcecode = "";
			// save each line to sourcecode variable
			while ((line = reader.readLine()) != null) {
			    sourcecode = sourcecode+line;
			    //System.out.println(line);
			}
			//System.out.println(sourcecode);
			wordtype = htmlParse(sourcecode, "wortart\">", 2, "<");
			frequency = htmlParse(sourcecode, "frequenzklasse_", 1, "\">");
			worttrennung = htmlParse(sourcecode, "Worttrennung:</dt><dd class=\"content\">", 1, "</dd>");
			herkunft = htmlParse(sourcecode, "Herkunft</a></h2><dl><dd class=\"content\">", 1, "</dd></dl></div>");
			
		}
		catch (Exception e) {
			//e.printStackTrace(); 
			//System.err.println(word+" No wordtype available ");
			//wordtype = "not available";
			//herkunft = "not available";
			
		}
	}




	/**
	 * 
	 * @param content The content to parse
	 * @param keyIn The String to begin parsing.
	 * @param a Set the array iterator of the parsed temp string.
	 * @param keyOut
	 * @return Parsed string content.
	 */
	public String htmlParse(String content, String keyIn, int a, String keyOut) {
		String finalParse = "Not available";
		
		String[] tempParse1 = p5.split(content, keyIn);
		/*System.out.println("\nKEYIN\n");
		for (int i = 0; i < tempParse1.length; i++) {
			System.out.println("["+i+"]\t"+tempParse1[i]);
		}*/
		
		String[] tempParse2 = p5.split(tempParse1[a], keyOut);
		/*System.out.println("\nKEYOUT\n");
		for (int i = 0; i < temp2.length; i++) {
			System.out.println("["+i+"]\t"+temp2[i]);
		}*/
		
		finalParse = tempParse2[0];
		return finalParse;
	}
	
	

}
@@ -870,16 +870,46 @@
 Applet;%0A
+import wrongPowder.io.Reader;%0A
 %0A%0A%0A%0A%0A/**
@@ -1018,16 +1018,32 @@
 let p5;%0A
+%09Reader reader;%0A
 %09%0A%09publi
@@ -1379,16 +1379,42 @@
 p5 = p;%0A
+%09%09reader = new Reader(p);%0A
 %09%7D%0A%09%0A%09%0A%09
@@ -1657,47 +1657,68 @@
 %7B%0A%09%09
-BufferedReader rea
+// Load the sourcecode%0A%09%09String tempSourceco
 de
-r
  = 
-p5.createReader
+reader.load
 (%22ht
@@ -1766,254 +1766,34 @@
 ;%0A%09%09
-%0A%09%09try %7B%0A%09%09%09String line;%0A%09%09%09String sourcecode = %22%22;%0A%09%09%09// save each line to sourcecode variable%0A%09%09%09while ((line = reader.readLine()) != null) %7B%0A%09%09%09    sourcecode = sourcecode+line;%0A%09%09%09    //System.out.println(line);%0A%09%09%09%7D%0A%09%09%09//System.out.println(s
+//System.out.println(tempS
 ourc
@@ -1798,24 +1798,26 @@
 rcecode);%0A%09%09
+%0A%09
 %09wordtype = 
@@ -1818,33 +1818,37 @@
 ype = htmlParse(
-s
+tempS
 ourcecode, %22wort
@@ -1865,17 +1865,16 @@
 , %22%3C%22);%0A
-%09
 %09%09freque
@@ -1881,33 +1881,37 @@
 ncy = htmlParse(
-s
+tempS
 ourcecode, %22freq
@@ -1937,17 +1937,16 @@
 %22%3E%22);%0A%09%09
-%09
 worttren
@@ -1954,33 +1954,37 @@
 ung = htmlParse(
-s
+tempS
 ourcecode, %22Wort
@@ -2037,17 +2037,16 @@
 d%3E%22);%0A%09%09
-%09
 herkunft
@@ -2058,17 +2058,21 @@
 mlParse(
-s
+tempS
 ourcecod
@@ -2149,198 +2149,8 @@
 %22);%0A
-%09%09%09%0A%09%09%7D%0A%09%09catch (Exception e) %7B%0A%09%09%09//e.printStackTrace(); %0A%09%09%09//System.err.println(word+%22 No wordtype available %22);%0A%09%09%09//wordtype = %22not available%22;%0A%09%09%09//herkunft = %22not available%22;%0A%09%09%09%0A%09%09%7D%0A
 %09%7D%0A%0A

Use Reader class to catch sourcecode