/[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 854 by torben, Wed Jun 16 07:40:59 2010 UTC revision 1224 by torben, Wed Feb 9 17:39:54 2011 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;  
 import org.apache.http.client.HttpClient;  
 import org.apache.http.client.methods.HttpGet;  
 import org.apache.http.impl.client.DefaultHttpClient;  
15  import org.w3c.dom.Document;  import org.w3c.dom.Document;
16  import org.w3c.dom.Node;  import org.w3c.dom.Node;
17  import org.w3c.dom.NodeList;  import org.w3c.dom.NodeList;
18  import org.xml.sax.SAXException;  import org.xml.sax.SAXException;
19    
20    
21  import android.util.Log;  import android.util.Log;
22    
23    
# Line 29  public class Side9Xml { Line 27  public class Side9Xml {
27          static final int WIDTH = 450;          static final int WIDTH = 450;
28          static final String BASEURL = "http://apps.todic.net/side9/";          static final String BASEURL = "http://apps.todic.net/side9/";
29    
30          public static Document parseXML(String str) throws SAXException, IOException, ParserConfigurationException          public static Document parseXML(byte data[]) throws SAXException, IOException, ParserConfigurationException
31          {          {
32                  DocumentBuilder builder =  DocumentBuilderFactory.newInstance().newDocumentBuilder();                  DocumentBuilder builder =  DocumentBuilderFactory.newInstance().newDocumentBuilder();
33                                    
34                  return  builder.parse( new ByteArrayInputStream(str.getBytes()) );                                return  builder.parse( new ByteArrayInputStream( data)  );              
35          }          }
36                    
37                    
38          public static byte[] getContent(String uri) throws IOException {          public static byte[] getContent(String uri) throws IOException {
39                  byte buffer[] = new byte[256];                  byte buffer[] = new byte[4096];
40                                    
41    
42                                    
# Line 64  public class Side9Xml { Line 62  public class Side9Xml {
62                  return baos.toByteArray();                  return baos.toByteArray();
63          }          }
64                    
65          public static Side9Data loadXml() throws IOException, ParserConfigurationException, SAXException{          public static Side9Data loadXml(String androidID) throws IOException, ParserConfigurationException, SAXException{
66                  String dataURL = BASEURL + "xml.php?width=" + WIDTH;                  String dataURL = BASEURL + "xml.php?width=" + WIDTH + "&androidID=" + androidID;
67                                    Log.i("Side9Xml", "URL=" + dataURL);
68                  byte data[] = getContent( dataURL );                          
                 String xmlData = new String(data, "ISO-8859-1");  
                 xmlData = xmlData.replace("encoding=\"ISO-8859-1\"", "");  
69                                    
70                  Document doc = parseXML(xmlData);                                byte data[] = getContent( dataURL );            
71                    Document doc = parseXML( data );                
72                                    
73                  Node rootNode = doc.getDocumentElement(); // stations                  Node rootNode = doc.getDocumentElement(); // stations
74                  NodeList nodes = rootNode.getChildNodes();                  NodeList nodes = rootNode.getChildNodes();

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

  ViewVC Help
Powered by ViewVC 1.1.20