Advertisement
Advertisement
| 05.21.2008 at 07:56PM PDT, ID: 23423155 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: |
public void fetch_device_data(String device_name){
String s = null;
String data = null;
try {
Process p = Runtime.getRuntime().exec("wget -O - http://user:pass@61.10.0.168/cgi-bin/chkdocoper_chid.cgi?"+device_name);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
while ((s = stdInput.readLine()) != null) {
data += s;
}
}
catch (IOException e) {
write_log("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}
if(data != null){
int first_pos = data.indexOf("<table");
int last_pos = data.lastIndexOf("</table>");
if(first_pos != -1 && last_pos != -1){
data = data.substring(first_pos, last_pos + 8);
data = data.replaceAll("<[/]{0,1}table[^>]*>", ""); //Remove all table tags
data = data.replaceAll("<(tr|td)[^>]*>", "<$1>"); //Remove all the attributes in tr and td tags
data = data.replaceAll("<([/]{0,1}[a-z]*)>[ ]*", "<$1>").trim();
data = data.replaceAll("</(td|tr)>", ""); //Remove all ending tr and td tags
data = data.replaceFirst("<tr>", ""); //Remove the first tr tag, which is not required, during split
String temp[] = data.split("<tr>");
result = new String[temp.length][];
for(int i=0; i<temp.length; i++){
temp[i] = temp[i].replaceFirst("<td>", "");
result[i] = temp[i].split("<td>");
}
}
}
}
|