Statistics
| Branch: | Revision:

root / src / com / rackspace / cloud / files / api / client / parsers / ContainerObjectXMLparser.java @ 240418be

History | View | Annotate | Download (2.6 kB)

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