root / src / com / rackspace / cloud / loadbalancer / api / parsers / ProtocolsXMLParser.java @ 4f9d1a69
History | View | Annotate | Download (2.1 kB)
1 |
/**
|
---|---|
2 |
*
|
3 |
*/
|
4 |
package com.rackspace.cloud.loadbalancer.api.parsers; |
5 |
|
6 |
import java.util.ArrayList; |
7 |
|
8 |
import org.xml.sax.Attributes; |
9 |
import org.xml.sax.helpers.DefaultHandler; |
10 |
|
11 |
import android.util.Log; |
12 |
|
13 |
import com.rackspace.cloud.loadbalancer.api.client.Protocol; |
14 |
|
15 |
|
16 |
public class ProtocolsXMLParser extends DefaultHandler { |
17 |
private Protocol protocol;
|
18 |
private ArrayList<Protocol> protocols; |
19 |
private StringBuffer currentData; |
20 |
|
21 |
public void startDocument() { |
22 |
} |
23 |
|
24 |
public void endDocument() { |
25 |
} |
26 |
|
27 |
public void startElement(String uri, String name, String qName, Attributes atts) { |
28 |
|
29 |
currentData = new StringBuffer(); |
30 |
if ("protocols".equals(name)) { |
31 |
protocols = new ArrayList<Protocol>(); |
32 |
} else if ("protocol".equals(name)) { |
33 |
protocol = new Protocol();
|
34 |
protocol.setName(atts.getValue("name"));
|
35 |
protocol.setDefaultPort(atts.getValue("port"));
|
36 |
} |
37 |
} |
38 |
|
39 |
public void endElement(String uri, String name, String qName) { |
40 |
if ("protocol".equals(name)) { |
41 |
if (protocols != null) { |
42 |
protocols.add(protocol); |
43 |
} |
44 |
} |
45 |
} |
46 |
|
47 |
public void characters(char ch[], int start, int length) { |
48 |
Log.d("Rackspace-Cloud", "Characters: \""); |
49 |
for (int i = start; i < start + length; i++) { |
50 |
switch (ch[i]) {
|
51 |
case '\\': |
52 |
Log.d("Rackspace-Cloud", "\\\\"); |
53 |
break;
|
54 |
case '"': |
55 |
Log.d("Rackspace-Cloud", "\\\""); |
56 |
break;
|
57 |
case '\n': |
58 |
Log.d("Rackspace-Cloud", "\\n"); |
59 |
break;
|
60 |
case '\r': |
61 |
Log.d("Rackspace-Cloud", "\\r"); |
62 |
break;
|
63 |
case '\t': |
64 |
Log.d("Rackspace-Cloud", "\\t"); |
65 |
break;
|
66 |
default:
|
67 |
Log.d("Rackspace-Cloud", String.valueOf(ch[i])); |
68 |
break;
|
69 |
} |
70 |
} |
71 |
Log.d("Rackspace-Cloud", "\"\n"); |
72 |
|
73 |
|
74 |
for (int i = start; i < (start + length); i++) { |
75 |
currentData.append(ch[i]); |
76 |
} |
77 |
} |
78 |
|
79 |
/**
|
80 |
* @return the protocol
|
81 |
*/
|
82 |
public Protocol getProtocol() {
|
83 |
return protocol;
|
84 |
} |
85 |
|
86 |
/**
|
87 |
* @param protocol the protocol to set
|
88 |
*/
|
89 |
public void setProtocol(Protocol protocol) { |
90 |
this.protocol = protocol;
|
91 |
} |
92 |
|
93 |
/**
|
94 |
* @return the protocols
|
95 |
*/
|
96 |
public ArrayList<Protocol> getProtocols() { |
97 |
return protocols;
|
98 |
} |
99 |
|
100 |
/**
|
101 |
* @param protocols the protocols to set
|
102 |
*/
|
103 |
public void setProtocols(ArrayList<Protocol> protocols) { |
104 |
this.protocols = protocols;
|
105 |
} |
106 |
|
107 |
} |