root / src / com / rackspace / cloud / files / api / client / parsers / ContainerObjectXMLparser.java @ 3d6041e8
History | View | Annotate | Download (3.5 kB)
1 |
package com.rackspace.cloud.files.api.client.parsers; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.List; |
5 |
|
6 |
import com.rackspace.cloud.files.api.client.ContainerObjects; |
7 |
|
8 |
import org.xml.sax.Attributes; |
9 |
import org.xml.sax.helpers.DefaultHandler; |
10 |
|
11 |
import android.util.Log; |
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 |
private boolean find_Title = false; |
24 |
private boolean find_Hash = false; |
25 |
private boolean find_Bytes = false; |
26 |
private boolean find_lastMod = false; |
27 |
public String LOG = "ViewFilesXMLparser"; |
28 |
private boolean find_contentType = false; |
29 |
|
30 |
public void startDocument() { |
31 |
Log.v(LOG, "startDocument");
|
32 |
} |
33 |
|
34 |
public void endDocument() { |
35 |
Log.v(LOG, "endDocument = true");
|
36 |
} |
37 |
|
38 |
public void startElement(String uri, String name, String qName, Attributes atts) { |
39 |
|
40 |
currentData = new StringBuffer(); |
41 |
if ("container".equals(name)) { |
42 |
files = new ArrayList<ContainerObjects>(); |
43 |
|
44 |
|
45 |
} else if ("object".equals(name)) { |
46 |
object = new ContainerObjects();
|
47 |
}else if ("name".equals(name)){ |
48 |
this.find_Title = true; |
49 |
}else if ("content_type".equals(name)){ |
50 |
this.find_contentType = true; |
51 |
}else if ("hash".equals(name)){ |
52 |
this.find_Hash = true; |
53 |
}else if ("bytes".equals(name)){ |
54 |
this.find_Bytes = true; |
55 |
}else if ("last_modified".equals(name)) { |
56 |
this.find_lastMod=true; |
57 |
|
58 |
} |
59 |
|
60 |
} |
61 |
|
62 |
public void endElement(String uri, String name, String qName) { |
63 |
if ("container".equals(name)) { |
64 |
|
65 |
} else if ("object".equals(name)) { |
66 |
if (files != null) { |
67 |
files.add(object); |
68 |
} |
69 |
}else if ("name".equals(name)){ |
70 |
this.find_Title = false; |
71 |
}else if ("content_type".equals(name)){ |
72 |
this.find_contentType = false; |
73 |
}else if ("hash".equals(name)){ |
74 |
this.find_Hash = false; |
75 |
}else if ("bytes".equals(name)){ |
76 |
this.find_Bytes = false; |
77 |
}else if ("last_modified".equals(name)){ |
78 |
this.find_lastMod = false; |
79 |
|
80 |
|
81 |
} |
82 |
} |
83 |
|
84 |
public void characters(char ch[], int start, int length) { |
85 |
|
86 |
if(this.find_Title){ |
87 |
object.setCName(new String(ch, start, length)); |
88 |
} else if (this.find_contentType){ |
89 |
object.setContentType(new String(ch, start, length)); |
90 |
} else if (this.find_Hash) { |
91 |
object.setHash(new String(ch, start, length)); |
92 |
} else if (this.find_Bytes) { |
93 |
object.setBytes(new String(ch, start, length)); |
94 |
} else if (this.find_lastMod){ |
95 |
object.setLastMod(new String(ch, start, length)); |
96 |
} |
97 |
System.out.print("Characters: \""); |
98 |
|
99 |
for (int i = start; i < start + length; i++) { |
100 |
switch (ch[i]) {
|
101 |
case '\\': |
102 |
System.out.print("\\\\"); |
103 |
break;
|
104 |
case '"': |
105 |
System.out.print("\\\""); |
106 |
break;
|
107 |
case '\n': |
108 |
System.out.print("\\n"); |
109 |
break;
|
110 |
case '\r': |
111 |
System.out.print("\\r"); |
112 |
break;
|
113 |
case '\t': |
114 |
System.out.print("\\t"); |
115 |
break;
|
116 |
default:
|
117 |
System.out.print(ch[i]);
|
118 |
break;
|
119 |
} |
120 |
} |
121 |
System.out.print("\"\n"); |
122 |
//String strCharacters = new String(ch, start, length);
|
123 |
for (int i = start; i < (start + length); i++) { |
124 |
currentData.append(ch[i]); |
125 |
} |
126 |
} |
127 |
|
128 |
public ContainerObjects getObject() {
|
129 |
return object;
|
130 |
} |
131 |
|
132 |
public void setObject(ContainerObjects object) { |
133 |
this.object = object;
|
134 |
} |
135 |
|
136 |
/**
|
137 |
* @return the files
|
138 |
*/
|
139 |
public ArrayList<ContainerObjects> getViewFiles() { |
140 |
return files;
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* @param files the servers to set
|
145 |
*/
|
146 |
public void setFiles(ArrayList<ContainerObjects> files) { |
147 |
this.files = files;
|
148 |
} |
149 |
|
150 |
|
151 |
} |