--- android/Side9/src/dk/thoerup/side9/Side9Xml.java 2010/03/23 13:34:52 632 +++ android/Side9/src/dk/thoerup/side9/Side9Xml.java 2011/02/09 17:39:54 1224 @@ -11,32 +11,40 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; + import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; +import android.util.Log; + + public class Side9Xml { - static final int WIDTH = 100; + static final int WIDTH = 450; static final String BASEURL = "http://apps.todic.net/side9/"; - public static Document parseXML(String str) throws SAXException, IOException, ParserConfigurationException + public static Document parseXML(byte data[]) throws SAXException, IOException, ParserConfigurationException { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - return builder.parse( new ByteArrayInputStream(str.getBytes()) ); + + return builder.parse( new ByteArrayInputStream( data) ); } public static byte[] getContent(String uri) throws IOException { - byte buffer[] = new byte[256]; + byte buffer[] = new byte[4096]; + + ByteArrayOutputStream baos = new ByteArrayOutputStream(32768); //start buffer size - instead of default 32bytes URL url = new URL(uri); URLConnection connection = url.openConnection(); + connection.setConnectTimeout(2500); InputStream is = connection.getInputStream(); try { @@ -54,12 +62,13 @@ return baos.toByteArray(); } - public Side9Data loadXml() throws IOException, ParserConfigurationException, SAXException{ - String dataURL = BASEURL + "xml.php?width=" + WIDTH; + public static Side9Data loadXml(String androidID) throws IOException, ParserConfigurationException, SAXException{ + String dataURL = BASEURL + "xml.php?width=" + WIDTH + "&androidID=" + androidID; + Log.i("Side9Xml", "URL=" + dataURL); + - byte data[] = getContent( dataURL ); - String xmlData = new String(data, "UTF-8"); - Document doc = parseXML(xmlData); + byte data[] = getContent( dataURL ); + Document doc = parseXML( data ); Node rootNode = doc.getDocumentElement(); // stations NodeList nodes = rootNode.getChildNodes(); @@ -85,6 +94,11 @@ if (name.equals("caption")) side9Data.caption = content; } + + Log.i("Side9Xml", "url: " + side9Data.url); + Log.i("Side9Xml", "size: " + side9Data.width + "/" + side9Data.height); + Log.i("Side9Xml", "capt: " + side9Data.caption); +