/[projects]/android/Side9/src/dk/thoerup/side9/Side9Xml.java
ViewVC logotype

Diff of /android/Side9/src/dk/thoerup/side9/Side9Xml.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 634 by torben, Wed Mar 24 07:27:34 2010 UTC revision 854 by torben, Wed Jun 16 07:40:59 2010 UTC
# Line 11  import javax.xml.parsers.DocumentBuilder Line 11  import javax.xml.parsers.DocumentBuilder
11  import javax.xml.parsers.DocumentBuilderFactory;  import javax.xml.parsers.DocumentBuilderFactory;
12  import javax.xml.parsers.ParserConfigurationException;  import javax.xml.parsers.ParserConfigurationException;
13    
14    import org.apache.http.HttpResponse;
15    import org.apache.http.client.HttpClient;
16    import org.apache.http.client.methods.HttpGet;
17    import org.apache.http.impl.client.DefaultHttpClient;
18  import org.w3c.dom.Document;  import org.w3c.dom.Document;
19  import org.w3c.dom.Node;  import org.w3c.dom.Node;
20  import org.w3c.dom.NodeList;  import org.w3c.dom.NodeList;
# Line 22  import android.util.Log; Line 26  import android.util.Log;
26    
27  public class Side9Xml {  public class Side9Xml {
28                    
29          static final int WIDTH = 300;          static final int WIDTH = 450;
30          static final String BASEURL = "http://apps.todic.net/side9/";          static final String BASEURL = "http://apps.todic.net/side9/";
31    
32          public static Document parseXML(String str) throws SAXException, IOException, ParserConfigurationException          public static Document parseXML(String str) throws SAXException, IOException, ParserConfigurationException
33          {          {
34                  DocumentBuilder builder =  DocumentBuilderFactory.newInstance().newDocumentBuilder();                  DocumentBuilder builder =  DocumentBuilderFactory.newInstance().newDocumentBuilder();
35                    
36                  return  builder.parse( new ByteArrayInputStream(str.getBytes()) );                                return  builder.parse( new ByteArrayInputStream(str.getBytes()) );              
37          }          }
38                    
# Line 35  public class Side9Xml { Line 40  public class Side9Xml {
40          public static byte[] getContent(String uri) throws IOException {          public static byte[] getContent(String uri) throws IOException {
41                  byte buffer[] = new byte[256];                  byte buffer[] = new byte[256];
42                                    
43    
44                    
45                  ByteArrayOutputStream baos = new ByteArrayOutputStream(32768); //start buffer size - instead of default 32bytes                  ByteArrayOutputStream baos = new ByteArrayOutputStream(32768); //start buffer size - instead of default 32bytes
46                                    
47                  URL url = new URL(uri);                  URL url = new URL(uri);
48                  URLConnection connection = url.openConnection();                  URLConnection connection = url.openConnection();
49                    connection.setConnectTimeout(2500);
50                  InputStream is = connection.getInputStream();                  InputStream is = connection.getInputStream();
51                                    
52                  try {                  try {
# Line 60  public class Side9Xml { Line 68  public class Side9Xml {
68                  String dataURL = BASEURL + "xml.php?width=" + WIDTH;                  String dataURL = BASEURL + "xml.php?width=" + WIDTH;
69                                    
70                  byte data[] = getContent( dataURL );                  byte data[] = getContent( dataURL );
71                  String xmlData = new String(data, "UTF-8");                  String xmlData = new String(data, "ISO-8859-1");
72                    xmlData = xmlData.replace("encoding=\"ISO-8859-1\"", "");
73                    
74                  Document doc = parseXML(xmlData);                                Document doc = parseXML(xmlData);              
75                                    
76                  Node rootNode = doc.getDocumentElement(); // stations                  Node rootNode = doc.getDocumentElement(); // stations

Legend:
Removed from v.634  
changed lines
  Added in v.854

  ViewVC Help
Powered by ViewVC 1.1.20