package de.superx.bin; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import org.apache.commons.io.FileUtils; import org.xml.sax.SAXException; import com.meterware.httpunit.GetMethodWebRequest; import com.meterware.httpunit.WebConversation; import com.meterware.httpunit.WebRequest; import com.meterware.httpunit.WebResponse; import com.meterware.httpunit.WebTable; import de.memtext.util.StringUtils; public class SxTestXmlCreator { public static void main(String args[]) { if (args.length != 1) { System.out.println("usage SxTestXmlCreator filename (which contains url or sql)"); System.exit(-1); } try { File f = new File(args[0]); createTestXml(f); } catch (Exception e) { System.out.println(e); } } private static void createTestXml(File f) throws MalformedURLException, IOException, SAXException { String input = StringUtils.readFile(f); //if (input.startsWith("http")) String url = input; WebConversation wc = new WebConversation(); WebRequest req = new GetMethodWebRequest(url); WebResponse resp = wc.getResponse(req); if (resp.getTables().length == 0) { System.out.println("Keine Tabelle geliefert\n" + resp.getText()); System.exit(1); } WebTable table = resp.getTables()[1]; String params = url.substring(url.indexOf("?") + 1); params = params.trim(); if (params.charAt(params.length() - 1) == '\n') params = params.substring(0, params.length() - 2); StringBuffer erg = new StringBuffer("\n \n"); for (int col = 0; col < table.getColumnCount(); col++) { for (int row = 0; row < table.getRowCount(); row++) { String val = table.getTableCell(row, col).getText(); //wenn \n vorkommt test auskommentieren if (val.indexOf("\n") > -1) erg.append(""); } } erg.append("\n"); FileUtils.writeStringToFile(new File("temp.xml"), erg.toString()); System.out.println("XML ist in temp.xml"); } } //Created on 27.04.2006 at 14:47:18