root / src / com / rackspace / cloud / loadbalancer / api / parsers / CloudLoadBalancersFaultXMLParser.java @ 23bc5e75
History | View | Annotate | Download (1.9 kB)
1 |
/**
|
---|---|
2 |
*
|
3 |
*/
|
4 |
package com.rackspace.cloud.loadbalancer.api.parsers; |
5 |
|
6 |
import org.xml.sax.Attributes; |
7 |
import org.xml.sax.helpers.DefaultHandler; |
8 |
|
9 |
import com.rackspace.cloud.loadbalancers.api.client.http.LoadBalancersException; |
10 |
|
11 |
import android.util.Log; |
12 |
|
13 |
public class CloudLoadBalancersFaultXMLParser extends DefaultHandler { |
14 |
|
15 |
private LoadBalancersException exception;
|
16 |
private StringBuffer currentData; |
17 |
|
18 |
public void startDocument() { |
19 |
exception = new LoadBalancersException();
|
20 |
} |
21 |
|
22 |
public void endDocument() { |
23 |
} |
24 |
|
25 |
public void startElement(String uri, String name, String qName, Attributes atts) { |
26 |
|
27 |
currentData = new StringBuffer(); |
28 |
if ("cloudServersFault".equals(name)) { |
29 |
exception.setCode(Integer.parseInt(atts.getValue("code"))); |
30 |
} |
31 |
} |
32 |
|
33 |
public void endElement(String uri, String name, String qName) { |
34 |
if ("message".equals(name)) { |
35 |
exception.setMessage(currentData.toString()); |
36 |
} else if ("details".equals(name)) { |
37 |
exception.setDetails(currentData.toString()); |
38 |
} |
39 |
} |
40 |
|
41 |
public void characters(char ch[], int start, int length) { |
42 |
Log.d("Rackspace-Cloud", "Characters: \""); |
43 |
for (int i = start; i < start + length; i++) { |
44 |
switch (ch[i]) {
|
45 |
case '\\': |
46 |
Log.d("Rackspace-Cloud", "\\\\"); |
47 |
break;
|
48 |
case '"': |
49 |
Log.d("Rackspace-Cloud", "\\\""); |
50 |
break;
|
51 |
case '\n': |
52 |
Log.d("Rackspace-Cloud", "\\n"); |
53 |
break;
|
54 |
case '\r': |
55 |
Log.d("Rackspace-Cloud", "\\r"); |
56 |
break;
|
57 |
case '\t': |
58 |
Log.d("Rackspace-Cloud", "\\t"); |
59 |
break;
|
60 |
default:
|
61 |
Log.d("Rackspace-Cloud", String.valueOf(ch[i])); |
62 |
break;
|
63 |
} |
64 |
} |
65 |
Log.d("Rackspace-Cloud", "\"\n"); |
66 |
|
67 |
|
68 |
for (int i = start; i < (start + length); i++) { |
69 |
currentData.append(ch[i]); |
70 |
} |
71 |
} |
72 |
|
73 |
/**
|
74 |
* @return the exception
|
75 |
*/
|
76 |
public LoadBalancersException getException() {
|
77 |
return exception;
|
78 |
} |
79 |
|
80 |
/**
|
81 |
* @param exception the exception to set
|
82 |
*/
|
83 |
public void setException(LoadBalancersException exception) { |
84 |
this.exception = exception;
|
85 |
} |
86 |
|
87 |
|
88 |
} |