root / src / com / rackspace / cloud / files / api / client / parsers / ContainerObjectXMLparser.java @ 240418be
History | View | Annotate | Download (2.6 kB)
1 |
package com.rackspace.cloud.files.api.client.parsers; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
|
5 |
import org.xml.sax.Attributes; |
6 |
import org.xml.sax.helpers.DefaultHandler; |
7 |
|
8 |
import android.util.Log; |
9 |
|
10 |
import com.rackspace.cloud.files.api.client.ContainerObjects; |
11 |
|
12 |
/**
|
13 |
*
|
14 |
* @author Phillip Toohill
|
15 |
*
|
16 |
*/
|
17 |
public class ContainerObjectXMLparser extends DefaultHandler { |
18 |
|
19 |
private ContainerObjects object;
|
20 |
private ArrayList<ContainerObjects> files; |
21 |
|
22 |
private StringBuffer currentData; |
23 |
public String LOG = "ViewFilesXMLparser"; |
24 |
|
25 |
public void startDocument() { |
26 |
Log.v(LOG, "startDocument");
|
27 |
} |
28 |
|
29 |
public void endDocument() { |
30 |
Log.v(LOG, "endDocument = true");
|
31 |
} |
32 |
|
33 |
public void startElement(String uri, String name, String qName, |
34 |
Attributes atts) {
|
35 |
|
36 |
currentData = new StringBuffer(); |
37 |
if ("container".equals(name)) { |
38 |
files = new ArrayList<ContainerObjects>(); |
39 |
} else if ("object".equals(name)) { |
40 |
object = new ContainerObjects();
|
41 |
} |
42 |
} |
43 |
|
44 |
public void endElement(String uri, String name, String qName) { |
45 |
|
46 |
String value = currentData.toString().trim();
|
47 |
|
48 |
if ("container".equals(name)) { |
49 |
|
50 |
} else if ("object".equals(name)) { |
51 |
if (files != null) { |
52 |
files.add(object); |
53 |
} |
54 |
} else if ("name".equals(name)) { |
55 |
object.setCName(value); |
56 |
} else if ("content_type".equals(name)) { |
57 |
object.setContentType(value); |
58 |
} else if ("hash".equals(name)) { |
59 |
object.setHash(value); |
60 |
} else if ("bytes".equals(name)) { |
61 |
object.setBytes(Integer.parseInt(value));
|
62 |
} else if ("last_modified".equals(name)) { |
63 |
object.setLastMod(value); |
64 |
|
65 |
} |
66 |
} |
67 |
|
68 |
public void characters(char ch[], int start, int length) { |
69 |
|
70 |
System.out.print("Characters: \""); |
71 |
|
72 |
for (int i = start; i < start + length; i++) { |
73 |
switch (ch[i]) {
|
74 |
case '\\': |
75 |
System.out.print("\\\\"); |
76 |
break;
|
77 |
case '"': |
78 |
System.out.print("\\\""); |
79 |
break;
|
80 |
case '\n': |
81 |
System.out.print("\\n"); |
82 |
break;
|
83 |
case '\r': |
84 |
System.out.print("\\r"); |
85 |
break;
|
86 |
case '\t': |
87 |
System.out.print("\\t"); |
88 |
break;
|
89 |
default:
|
90 |
System.out.print(ch[i]);
|
91 |
break;
|
92 |
} |
93 |
} |
94 |
System.out.print("\"\n"); |
95 |
// String strCharacters = new String(ch, start, length);
|
96 |
for (int i = start; i < (start + length); i++) { |
97 |
currentData.append(ch[i]); |
98 |
} |
99 |
} |
100 |
|
101 |
public ContainerObjects getObject() {
|
102 |
return object;
|
103 |
} |
104 |
|
105 |
public void setObject(ContainerObjects object) { |
106 |
this.object = object;
|
107 |
} |
108 |
|
109 |
/**
|
110 |
* @return the files
|
111 |
*/
|
112 |
public ArrayList<ContainerObjects> getViewFiles() { |
113 |
return files;
|
114 |
} |
115 |
|
116 |
/**
|
117 |
* @param files
|
118 |
* the servers to set
|
119 |
*/
|
120 |
public void setFiles(ArrayList<ContainerObjects> files) { |
121 |
this.files = files;
|
122 |
} |
123 |
|
124 |
} |