Statistics
| Branch: | Revision:

root / src / com / rackspace / cloud / loadbalancer / api / parsers / AlgorithmsXMLParser.java @ 6ecf99bb

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.Algorithm;
14

    
15
public class AlgorithmsXMLParser extends DefaultHandler {
16
        private Algorithm algorithm;
17
        private ArrayList<Algorithm> algorithms;
18
        private StringBuffer currentData;
19

    
20
        public void startDocument() {
21
        }
22

    
23
        public void endDocument() {
24
        }
25

    
26
        public void startElement(String uri, String name, String qName, Attributes atts) {
27

    
28
                currentData = new StringBuffer();
29
                if ("algorithms".equals(name)) {
30
                        algorithms = new ArrayList<Algorithm>();
31
                } else if ("algorithm".equals(name)) {
32
                        algorithm = new Algorithm();
33
                        algorithm.setName(atts.getValue("name"));
34
                }
35
        }
36

    
37
        public void endElement(String uri, String name, String qName) {
38
                if ("algorithm".equals(name)) {
39
                        if (algorithms != null) {
40
                                algorithms.add(algorithm);
41
                        }
42
                }                
43
        }
44

    
45
        public void characters(char ch[], int start, int length) {
46
                Log.d("Rackspace-Cloud", "Characters:    \"");
47
                for (int i = start; i < start + length; i++) {
48
                        switch (ch[i]) {
49
                        case '\\':
50
                                Log.d("Rackspace-Cloud", "\\\\");
51
                                break;
52
                        case '"':
53
                                Log.d("Rackspace-Cloud", "\\\"");
54
                                break;
55
                        case '\n':
56
                                Log.d("Rackspace-Cloud", "\\n");
57
                                break;
58
                        case '\r':
59
                                Log.d("Rackspace-Cloud", "\\r");
60
                                break;
61
                        case '\t':
62
                                Log.d("Rackspace-Cloud", "\\t");
63
                                break;
64
                        default:
65
                                Log.d("Rackspace-Cloud", String.valueOf(ch[i]));
66
                                break;
67
                        }
68
                }
69
                Log.d("Rackspace-Cloud", "\"\n");
70

    
71

    
72
                for (int i = start; i < (start + length); i++) {
73
                        currentData.append(ch[i]);
74
                }
75
        }
76

    
77
        /**
78
         * @return the algorithm
79
         */
80
        public Algorithm getAlgorithm() {
81
                return algorithm;
82
        }
83

    
84
        /**
85
         * @param algorithm the algorithm to set
86
         */
87
        public void setAlgorithm(Algorithm algorithm) {
88
                this.algorithm = algorithm;
89
        }
90

    
91
        /**
92
         * @return the algorithms
93
         */
94
        public ArrayList<Algorithm> getAlgorithms() {
95
                return algorithms;
96
        }
97

    
98
        /**
99
         * @param algorithms the algorithms to set
100
         */
101
        public void setAlgorithms(ArrayList<Algorithm> algorithms) {
102
                this.algorithms = algorithms;
103
        }
104

    
105
}