root / src / com / rackspace / cloud / files / api / client / parsers / ContainerXMLParser.java @ fc8b1f79
History | View | Annotate | Download (4.3 kB)
1 |
package com.rackspace.cloud.files.api.client.parsers; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.HashMap; |
5 |
import java.util.Map; |
6 |
|
7 |
import org.xml.sax.Attributes; |
8 |
import org.xml.sax.helpers.DefaultHandler; |
9 |
|
10 |
import android.util.Log; |
11 |
|
12 |
import com.rackspace.cloud.files.api.client.Container; |
13 |
|
14 |
/**
|
15 |
*
|
16 |
* @author Phillip Toohill
|
17 |
*
|
18 |
*/
|
19 |
public class ContainerXMLParser extends DefaultHandler { |
20 |
|
21 |
private Container container; |
22 |
private Map<String, String> xContainerPolicy; |
23 |
private Map<String, String> metadata; |
24 |
private ArrayList<Container> containers; |
25 |
private String key; |
26 |
|
27 |
private StringBuffer currentData; |
28 |
|
29 |
public void startElement(String uri, String name, String qName, |
30 |
Attributes atts) {
|
31 |
|
32 |
currentData = new StringBuffer(); |
33 |
if ("account".equals(name)) { |
34 |
containers = new ArrayList<Container>(); |
35 |
} else if ("container".equals(name)) { |
36 |
container = new Container(); |
37 |
} else if ("x_container_policy".equals(name)) { |
38 |
xContainerPolicy = new HashMap<String, String>(); |
39 |
} else if ("x_object_meta".equals(name)) { |
40 |
metadata = new HashMap<String, String>(); |
41 |
} |
42 |
} |
43 |
|
44 |
public void endElement(String uri, String name, String qName) { |
45 |
|
46 |
String value = currentData.toString().trim();
|
47 |
|
48 |
if ("account".equals(name)) { |
49 |
|
50 |
} else if ("container".equals(name)) { |
51 |
|
52 |
if (containers == null) { |
53 |
containers = new ArrayList<Container>(); |
54 |
} |
55 |
Log.d("ViewContainersXMLparser", container.toString());
|
56 |
containers.add(container); |
57 |
|
58 |
} else if ("x_container_policy".equals(name)) { |
59 |
if (container != null) { |
60 |
container.setxContainerPolicy(xContainerPolicy); |
61 |
xContainerPolicy = null;
|
62 |
} |
63 |
|
64 |
} else if ("key".equals(name) && xContainerPolicy != null) { |
65 |
key = value; |
66 |
} else if ("value".equals(name) && xContainerPolicy != null) { |
67 |
if (key != null) |
68 |
xContainerPolicy.put(key, value); |
69 |
} else if ("x_object_meta".equals(name)) { |
70 |
if (container != null) { |
71 |
container.setMetadata(metadata); |
72 |
metadata = null;
|
73 |
} |
74 |
|
75 |
} else if ("key".equals(name) && metadata != null) { |
76 |
key = value; |
77 |
} else if ("value".equals(name) && metadata != null) { |
78 |
if (key != null) |
79 |
metadata.put(key, value); |
80 |
} else if ("name".equals(name)) { |
81 |
container.setName(value); |
82 |
} else if ("count".equals(name)) { |
83 |
container.setCount(Integer.parseInt(value));
|
84 |
} else if ("bytes".equals(name)) { |
85 |
container.setBytes(Long.parseLong(value));
|
86 |
} else if ("cdn_enabled".equals(name)) { |
87 |
container.setCdnEnabled("True".equals(value));
|
88 |
} else if ("ttl".equals(name)) { |
89 |
container.setTtl(Integer.parseInt(value));
|
90 |
} else if ("cdn_url".equals(name)) { |
91 |
container.setCdnUrl(value); |
92 |
} else if ("log_retention".equals(name)) { |
93 |
container.setLogRetention("True".equals(value));
|
94 |
} else if ("x_object_public".equals(name)) { |
95 |
container.setIsPublic(value); |
96 |
} else if ("x_object_modified_by".equals(name)) { |
97 |
container.setModifiedBy(value); |
98 |
|
99 |
} else if ("x_object_version".equals(name)) { |
100 |
container.setVersion(value); |
101 |
|
102 |
} else if ("x_object_hash".equals(name)) { |
103 |
container.setObjectHash(value); |
104 |
|
105 |
} else if ("x_object_uuid".equals(name)) { |
106 |
container.setObjectUUID(value); |
107 |
|
108 |
} else if ("x_object_version_timestamp".equals(name)) { |
109 |
container.setVersionTimestamp(value); |
110 |
|
111 |
} else if ("x_object_sharing".equals(name)) { |
112 |
container.setObjectSharing(value); |
113 |
|
114 |
} |
115 |
|
116 |
} |
117 |
|
118 |
public void characters(char ch[], int start, int length) { |
119 |
|
120 |
// Log.d("Rackspace-Cloud", "Characters: \"");
|
121 |
|
122 |
for (int i = start; i < start + length; i++) { |
123 |
switch (ch[i]) {
|
124 |
case '\\': |
125 |
// Log.d("Rackspace-Cloud", "\\\\");
|
126 |
break;
|
127 |
case '"': |
128 |
// Log.d("Rackspace-Cloud", "\\\"");
|
129 |
break;
|
130 |
case '\n': |
131 |
// Log.d("Rackspace-Cloud", "\\n");
|
132 |
break;
|
133 |
case '\r': |
134 |
// Log.d("Rackspace-Cloud", "\\r");
|
135 |
break;
|
136 |
case '\t': |
137 |
// Log.d("Rackspace-Cloud", "\\t");
|
138 |
break;
|
139 |
default:
|
140 |
// Log.d("Rackspace-Cloud", String.valueOf(ch[i]));
|
141 |
break;
|
142 |
} |
143 |
} |
144 |
// Log.d("Rackspace-Cloud", "\"\n");
|
145 |
|
146 |
for (int i = start; i < (start + length); i++) { |
147 |
currentData.append(ch[i]); |
148 |
} |
149 |
} |
150 |
|
151 |
public Container getContainer() { |
152 |
return container;
|
153 |
} |
154 |
|
155 |
public void setContainer(Container container) { |
156 |
this.container = container;
|
157 |
} |
158 |
|
159 |
/**
|
160 |
* @return the files
|
161 |
*/
|
162 |
public ArrayList<Container> getContainers() { |
163 |
return containers;
|
164 |
} |
165 |
|
166 |
/**
|
167 |
* @param containers
|
168 |
* the servers to set
|
169 |
*/
|
170 |
public void setContainers(ArrayList<Container> containers) { |
171 |
this.containers = containers;
|
172 |
} |
173 |
|
174 |
} |