Revision 038ac9a4

b/src/com/rackspace/cloud/files/api/client/Container.java
22 22
	private int Ttl;
23 23
	public String cdnUrl;
24 24
	public boolean logRetention;
25
	
26
	private Map<String,String> xContainerPolicy;
27
	
25

  
26
	private Map<String, String> xContainerPolicy;
27

  
28 28
	public String toXML() {
29 29
		String xml = "";
30 30
		xml = "<container xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" name=\""
......
136 136
	public void setLogRetention(boolean logRetention) {
137 137
		this.logRetention = logRetention;
138 138
	}
139
	
139

  
140 140
	public Map<String, String> getxContainerPolicy() {
141 141
		return xContainerPolicy;
142 142
	}
143
	
143

  
144 144
	public void setxContainerPolicy(Map<String, String> xContainerPolicy) {
145 145
		this.xContainerPolicy = xContainerPolicy;
146 146
	}
......
158 158
				+ ", getObjectSharing()=" + getObjectSharing()
159 159
				+ ", getMetadata()=" + getMetadata() + "]";
160 160
	}
161
	
162
	
161

  
163 162
}
b/src/com/rackspace/cloud/files/api/client/ContainerManager.java
132 132
				cse.setMessage(e.getLocalizedMessage());
133 133
				throw cse;
134 134
			}
135
		}
136
		else{
135
		} else {
137 136
			Container c = new Container();
138 137
			c.setCdnEnabled(true);
139 138
			c.setCdnUrl(Account.getAccount().getStorageUrl());
......
254 253
		HttpGet get = new HttpGet(Account.getAccount().getStorageUrl()
255 254
				+ "?format=xml");
256 255
		ArrayList<Container> containers = new ArrayList<Container>();
257
		get.addHeader(CustomHttpClient.X_STORAGE_TOKEN, Account.getAccount().getStorageToken());
256
		get.addHeader(CustomHttpClient.X_STORAGE_TOKEN, Account.getAccount()
257
				.getStorageToken());
258 258
		get.addHeader("Content-Type", "application/xml");
259 259

  
260 260
		try {
b/src/com/rackspace/cloud/files/api/client/ContainerObjectManager.java
35 35
import com.rackspace.cloud.servers.api.client.http.HttpBundle;
36 36
import com.rackspace.cloud.servers.api.client.parsers.CloudServersFaultXMLParser;
37 37

  
38
/** 
38
/**
39 39
 * 
40 40
 * @author Phillip Toohill
41
 *
41
 * 
42 42
 */
43 43
public class ContainerObjectManager extends EntityManager {
44 44

  
45 45
	public String LOG = "ContainerObjectManager";
46 46
	private Context context;
47
	public static final String storageToken = Account.getAccount().getStorageToken();
48
	
47
	public static final String storageToken = Account.getAccount()
48
			.getStorageToken();
49

  
49 50
	public ContainerObjectManager(Context context) {
50 51
		this.context = context;
51 52
	}
52 53

  
53
	public ArrayList<ContainerObjects> createList(boolean detail, String passName) throws CloudServersException {
54
		
54
	public ArrayList<ContainerObjects> createList(boolean detail,
55
			String passName) throws CloudServersException {
56

  
55 57
		CustomHttpClient httpclient = new CustomHttpClient(context);
56
		String url = getSafeURL(Account.getAccount().getStorageUrl(), passName) + "?format=xml";
58
		String url = getSafeURL(Account.getAccount().getStorageUrl(), passName)
59
				+ "?format=xml";
57 60
		HttpGet get = new HttpGet(url);
58 61
		ArrayList<ContainerObjects> files = new ArrayList<ContainerObjects>();
59
		
60
		
62

  
61 63
		get.addHeader("Content-Type", "application/xml");
62 64
		get.addHeader(CustomHttpClient.X_STORAGE_TOKEN, storageToken);
63
		
64
		
65
				
66
		try {			
67
			HttpResponse resp = httpclient.execute(get);		    
68
		    BasicResponseHandler responseHandler = new BasicResponseHandler();
69
		    String body = responseHandler.handleResponse(resp);
70
		    
71
		    if (resp.getStatusLine().getStatusCode() == 200 || resp.getStatusLine().getStatusCode() == 203) {		    	
72
		    	ContainerObjectXMLparser filesXMLParser = new ContainerObjectXMLparser();
73
		    	SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
74
		    	XMLReader xmlReader = saxParser.getXMLReader();
75
		    	xmlReader.setContentHandler(filesXMLParser);
76
	            
77
		    	xmlReader.parse(new InputSource(new StringReader(body)));
78
		    	files = filesXMLParser.getViewFiles();
79
		    	
80
		    } else {
81
		    	CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
82
		    	SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
83
		    	XMLReader xmlReader = saxParser.getXMLReader();
84
		    	xmlReader.setContentHandler(parser);
85
		    	xmlReader.parse(new InputSource(new StringReader(body)));		    	
86
		    	CloudServersException cse = parser.getException();		    	
87
		    	throw cse;
88
		    }
65

  
66
		try {
67
			HttpResponse resp = httpclient.execute(get);
68
			BasicResponseHandler responseHandler = new BasicResponseHandler();
69
			String body = responseHandler.handleResponse(resp);
70

  
71
			if (resp.getStatusLine().getStatusCode() == 200
72
					|| resp.getStatusLine().getStatusCode() == 203) {
73
				ContainerObjectXMLparser filesXMLParser = new ContainerObjectXMLparser();
74
				SAXParser saxParser = SAXParserFactory.newInstance()
75
						.newSAXParser();
76
				XMLReader xmlReader = saxParser.getXMLReader();
77
				xmlReader.setContentHandler(filesXMLParser);
78

  
79
				xmlReader.parse(new InputSource(new StringReader(body)));
80
				files = filesXMLParser.getViewFiles();
81

  
82
			} else {
83
				CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
84
				SAXParser saxParser = SAXParserFactory.newInstance()
85
						.newSAXParser();
86
				XMLReader xmlReader = saxParser.getXMLReader();
87
				xmlReader.setContentHandler(parser);
88
				xmlReader.parse(new InputSource(new StringReader(body)));
89
				CloudServersException cse = parser.getException();
90
				throw cse;
91
			}
89 92
		} catch (ClientProtocolException e) {
90 93
			CloudServersException cse = new CloudServersException();
91 94
			cse.setMessage(e.getLocalizedMessage());
......
108 111
			throw cse;
109 112
		}
110 113
		return files;
111
		
114

  
112 115
	}
113 116

  
114
	public HttpBundle deleteObject(String Container, String Object) throws CloudServersException {
117
	public HttpBundle deleteObject(String Container, String Object)
118
			throws CloudServersException {
115 119
		HttpResponse resp = null;
116 120
		CustomHttpClient httpclient = new CustomHttpClient(context);
117
		String url = getSafeURL(Account.getAccount().getStorageUrl(), Container + "/" + Object);
121
		String url = getSafeURL(Account.getAccount().getStorageUrl(), Container
122
				+ "/" + Object);
118 123
		HttpDelete deleteObject = new HttpDelete(url);
119
				
120
		deleteObject.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
124

  
125
		deleteObject.addHeader("X-Auth-Token", Account.getAccount()
126
				.getAuthToken());
121 127
		httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class);
122 128

  
123 129
		HttpBundle bundle = new HttpBundle();
124 130
		bundle.setCurlRequest(deleteObject);
125
		
126
		try {			
131

  
132
		try {
127 133
			resp = httpclient.execute(deleteObject);
128 134
			bundle.setHttpResponse(resp);
129 135
		} catch (ClientProtocolException e) {
......
138 144
			CloudServersException cse = new CloudServersException();
139 145
			cse.setMessage(e.getLocalizedMessage());
140 146
			throw cse;
141
		}	
147
		}
142 148
		return bundle;
143 149
	}
144
	
145
	public HttpBundle getObject(String Container, String Object) throws CloudServersException {
150

  
151
	public HttpBundle getObject(String Container, String Object)
152
			throws CloudServersException {
146 153
		HttpResponse resp = null;
147 154
		CustomHttpClient httpclient = new CustomHttpClient(context);
148
		String url = getSafeURL(Account.getAccount().getStorageUrl(), Container + "/" + Object);
155
		String url = getSafeURL(Account.getAccount().getStorageUrl(), Container
156
				+ "/" + Object);
149 157
		HttpGet getObject = new HttpGet(url);
150
		getObject.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
158
		getObject
159
				.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
151 160
		httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class);
152 161

  
153 162
		HttpBundle bundle = new HttpBundle();
154 163
		bundle.setCurlRequest(getObject);
155
		
156
		try {			
164

  
165
		try {
157 166
			resp = httpclient.execute(getObject);
158 167
			bundle.setHttpResponse(resp);
159 168
		} catch (ClientProtocolException e) {
......
168 177
			CloudServersException cse = new CloudServersException();
169 178
			cse.setMessage(e.getLocalizedMessage());
170 179
			throw cse;
171
		}	
180
		}
172 181
		return bundle;
173 182
	}
174
	
175
	public HttpBundle addObject(String Container, String Path, String Object, String type) throws CloudServersException {
183

  
184
	public HttpBundle addObject(String Container, String Path, String Object,
185
			String type) throws CloudServersException {
176 186
		HttpResponse resp = null;
177 187
		CustomHttpClient httpclient = new CustomHttpClient(context);
178
		String url = getSafeURL(Account.getAccount().getStorageUrl(), Container + "/" + Path + Object);
188
		String url = getSafeURL(Account.getAccount().getStorageUrl(), Container
189
				+ "/" + Path + Object);
179 190
		HttpPut addObject = new HttpPut(url);
180
		
181
		addObject.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
191

  
192
		addObject
193
				.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
182 194
		addObject.addHeader("Content-Type", type);
183 195
		httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class);
184
		
196

  
185 197
		HttpBundle bundle = new HttpBundle();
186 198
		bundle.setCurlRequest(addObject);
187 199

  
188
		try {			
200
		try {
189 201
			resp = httpclient.execute(addObject);
190 202
			bundle.setHttpResponse(resp);
191 203
		} catch (ClientProtocolException e) {
......
200 212
			CloudServersException cse = new CloudServersException();
201 213
			cse.setMessage(e.getLocalizedMessage());
202 214
			throw cse;
203
		}	
215
		}
204 216
		return bundle;
205 217
	}
206
	
218

  
207 219
	/*
208
	 * used for adding text files, requires an extra parameter to 
209
	 * store the data for the file
220
	 * used for adding text files, requires an extra parameter to store the data
221
	 * for the file
210 222
	 */
211
	public HttpBundle addObject(String Container, String Path, String Object, String type, String data) throws CloudServersException {
223
	public HttpBundle addObject(String Container, String Path, String Object,
224
			String type, String data) throws CloudServersException {
212 225
		HttpResponse resp = null;
213 226
		CustomHttpClient httpclient = new CustomHttpClient(context);
214
		String url = getSafeURL(Account.getAccount().getStorageUrl(), Container + "/" + Path + Object);
227
		String url = getSafeURL(Account.getAccount().getStorageUrl(), Container
228
				+ "/" + Path + Object);
215 229
		HttpPut addObject = new HttpPut(url);
216
				
217
		addObject.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
230

  
231
		addObject
232
				.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
218 233
		addObject.addHeader("Content-Type", type);
219 234
		httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class);
220 235

  
......
227 242
			throw cse;
228 243
		}
229 244
		addObject.setEntity(tmp);
230
		
245

  
231 246
		HttpBundle bundle = new HttpBundle();
232 247
		bundle.setCurlRequest(addObject);
233
		
234
		try {			
248

  
249
		try {
235 250
			resp = httpclient.execute(addObject);
236 251
			bundle.setHttpResponse(resp);
237 252
		} catch (ClientProtocolException e) {
......
246 261
			CloudServersException cse = new CloudServersException();
247 262
			cse.setMessage(e.getLocalizedMessage());
248 263
			throw cse;
249
		}	
264
		}
250 265
		return bundle;
251 266
	}
252
	
253
	private String getSafeURL(String badURL, String name){
267

  
268
	private String getSafeURL(String badURL, String name) {
254 269
		URI uri = null;
255 270
		try {
256 271
			uri = new URI("https", badURL.substring(8), "/" + name + "/", "");
......
265 280
			// TODO Auto-generated catch block
266 281
			e1.printStackTrace();
267 282
		}
268
		return url.substring(0, url.length()-2);
283
		return url.substring(0, url.length() - 2);
269 284
	}
270 285

  
271 286
}
b/src/com/rackspace/cloud/files/api/client/ContainerObjects.java
6 6

  
7 7
/**
8 8
 * @author Phillip Toohill dead2hill@gmail.com
9
 *
9
 * 
10 10
 */
11 11
public class ContainerObjects extends Entity {
12 12

  
......
17 17
	private int bytes;
18 18
	private String cname;
19 19
	private String contentType;
20
	
21
	private boolean isFolder(){
20

  
21
	private boolean isFolder() {
22 22
		return contentType.startsWith("application/folder;");
23 23
	}
24
	
25
	
24

  
26 25
	/**
27 26
	 * 
28 27
	 * @return the object
......
30 29
	public String getObject() {
31 30
		return object;
32 31
	}
32

  
33 33
	/**
34 34
	 * 
35
	 * @param object from container
35
	 * @param object
36
	 *            from container
36 37
	 */
37
	public void setObject(String object)	{
38
	public void setObject(String object) {
38 39
		this.object = object;
39 40
	}
41

  
40 42
	/**
41 43
	 * @return the hash
42 44
	 */
43 45
	public String getHash() {
44 46
		return hash;
45 47
	}
48

  
46 49
	/**
47
	 * @param hash hash of object
50
	 * @param hash
51
	 *            hash of object
48 52
	 */
49 53
	public void setHash(String hash) {
50 54
		this.hash = hash;
51 55
	}
56

  
52 57
	/**
53 58
	 * 
54 59
	 * @return the LastMod ification of file
......
56 61
	public String getLastMod() {
57 62
		return lastMod;
58 63
	}
59
	
64

  
60 65
	/**
61 66
	 * 
62
	 * @param lastMod that LastMod is set to
67
	 * @param lastMod
68
	 *            that LastMod is set to
63 69
	 */
64 70
	public void setLastMod(String lastMod) {
65 71
		this.lastMod = lastMod;
66 72
	}
73

  
67 74
	/**
68 75
	 * 
69 76
	 * @return the object's name
70
	*/
77
	 */
71 78
	public String getCName() {
72 79
		return cname;
73 80
	}
81

  
74 82
	/**
75 83
	 * 
76
	 * @param name the object is set to
84
	 * @param name
85
	 *            the object is set to
77 86
	 */
78 87
	public void setCName(String cname) {
79 88
		this.cname = cname;
80 89
	}
90

  
81 91
	/**
82 92
	 * 
83 93
	 * @return the objects size
......
85 95
	public int getBytes() {
86 96
		return bytes;
87 97
	}
98

  
88 99
	/**
89 100
	 * 
90
	 * @param the bytes the object is set to
101
	 * @param the
102
	 *            bytes the object is set to
91 103
	 */
92 104
	public void setBytes(int bytes) {
93 105
		this.bytes = bytes;
94 106
	}
107

  
95 108
	/**
96 109
	 * 
97
	 * @param contentType the object is set to
110
	 * @param contentType
111
	 *            the object is set to
98 112
	 */
99 113
	public void setContentType(String contentType) {
100 114
		this.contentType = contentType;
101
		
115

  
102 116
	}
117

  
103 118
	/**
104 119
	 * 
105 120
	 * @return the objects content type
106 121
	 */
107
	public String getContentType(){
122
	public String getContentType() {
108 123
		return contentType;
109 124
	}
125

  
110 126
	@Override
111 127
	public String toString() {
112
		return "ContainerObjects [" + "getCName()="
113
				+ getCName() + " object=" + object + ", hash=" + hash
114
				+ ", lastMod=" + lastMod + ", bytes=" + bytes + ", cname="
115
				+ cname + ", contentType=" + contentType + ", getId()="
116
				+ getId() + ", getName()=" + getName() + ", getModifiedBy()="
117
				+ getModifiedBy() + ", getVersion()=" + getVersion()
118
				+ ", getVersionTimestamp()=" + getVersionTimestamp()
119
				+ ", getObjectUUID()=" + getObjectUUID() + ", getObjectHash()="
120
				+ getObjectHash() + ", getObjectSharing()="
121
				+ getObjectSharing() + ", getMetadata()=" + getMetadata() + "]";
128
		return "ContainerObjects [" + "getCName()=" + getCName() + " object="
129
				+ object + ", hash=" + hash + ", lastMod=" + lastMod
130
				+ ", bytes=" + bytes + ", cname=" + cname + ", contentType="
131
				+ contentType + ", getId()=" + getId() + ", getName()="
132
				+ getName() + ", getModifiedBy()=" + getModifiedBy()
133
				+ ", getVersion()=" + getVersion() + ", getVersionTimestamp()="
134
				+ getVersionTimestamp() + ", getObjectUUID()="
135
				+ getObjectUUID() + ", getObjectHash()=" + getObjectHash()
136
				+ ", getObjectSharing()=" + getObjectSharing()
137
				+ ", getMetadata()=" + getMetadata() + "]";
122 138
	}
123
	
124
	
125
	
126
}   
127 139

  
140
}
b/src/com/rackspace/cloud/files/api/client/CustomHttpClient.java
34 34
 *         other version than 2.3.1.
35 35
 */
36 36
public class CustomHttpClient extends DefaultHttpClient {
37
	public static final String X_AUTH_TOKEN="X-Auth-Token";
38
	public static final String X_STORAGE_TOKEN="X-Auth-Token";
37
	public static final String X_AUTH_TOKEN = "X-Auth-Token";
38
	public static final String X_STORAGE_TOKEN = "X-Auth-Token";
39 39
	private static KeyStore trusted;
40 40
	final Context context;
41 41

  
b/src/com/rackspace/cloud/files/api/client/parsers/ContainerObjectXMLparser.java
20 20

  
21 21
	private ContainerObjects object;
22 22
	private ArrayList<ContainerObjects> files;
23
	private Map<String,String> metadata;
23
	private Map<String, String> metadata;
24 24
	private String key;
25
	
26 25

  
27 26
	private StringBuffer currentData;
28 27
	public String LOG = "ViewFilesXMLparser";
......
59 58
				Log.d(LOG, object.toString());
60 59
				files.add(object);
61 60
			}
62
		}else if ("x_object_meta".equals(name)) {
63
			if(object!=null){
61
		} else if ("x_object_meta".equals(name)) {
62
			if (object != null) {
64 63
				object.setMetadata(metadata);
65 64
				metadata = null;
66 65
			}
67 66

  
68
		}
69
		else if ("key".equals(name)&&metadata!=null) {
67
		} else if ("key".equals(name) && metadata != null) {
70 68
			key = value;
71
		}
72
		else if ("value".equals(name)&&metadata!=null) {
73
			if(key!=null)
74
				metadata.put(key,value);
75
		}
76
		else if ("name".equals(name)) {
69
		} else if ("value".equals(name) && metadata != null) {
70
			if (key != null)
71
				metadata.put(key, value);
72
		} else if ("name".equals(name)) {
77 73
			object.setCName(value);
78 74
		} else if ("content_type".equals(name)) {
79 75
			object.setContentType(value);
......
85 81
			object.setLastMod(value);
86 82

  
87 83
		}
88
		//x_object_modified_by
89
		//x_object_version
90
		//x_object_hash
91
		//x_object_uuid
92
		//x_object_version_timestamp
93
		//x_object_sharing
84
		// x_object_modified_by
85
		// x_object_version
86
		// x_object_hash
87
		// x_object_uuid
88
		// x_object_version_timestamp
89
		// x_object_sharing
94 90
		else if ("x_object_modified_by".equals(name)) {
95 91
			object.setModifiedBy(value);
96 92

  
97
		}
98
		else if ("x_object_version".equals(name)) {
93
		} else if ("x_object_version".equals(name)) {
99 94
			object.setVersion(value);
100 95

  
101
		}
102
		else if ("x_object_hash".equals(name)) {
96
		} else if ("x_object_hash".equals(name)) {
103 97
			object.setObjectHash(value);
104 98

  
105
		}
106
		else if ("x_object_uuid".equals(name)) {
99
		} else if ("x_object_uuid".equals(name)) {
107 100
			object.setObjectUUID(value);
108 101

  
109
		}
110
		else if ("x_object_public".equals(name)) {
102
		} else if ("x_object_public".equals(name)) {
111 103
			object.setIsPublic(value);
112
		}
113
		else if ("x_object_version_timestamp".equals(name)) {
104
		} else if ("x_object_version_timestamp".equals(name)) {
114 105
			object.setVersionTimestamp(value);
115 106

  
116
		}
117
		else if ("x_object_sharing".equals(name)) {
107
		} else if ("x_object_sharing".equals(name)) {
118 108
			object.setObjectSharing(value);
119 109

  
120 110
		}
......
122 112

  
123 113
	public void characters(char ch[], int start, int length) {
124 114

  
125
		//Log.d("Rackspace-Cloud", "Characters:    \"");
115
		// Log.d("Rackspace-Cloud", "Characters:    \"");
126 116

  
127 117
		for (int i = start; i < start + length; i++) {
128 118
			switch (ch[i]) {
129 119
			case '\\':
130
				//Log.d("Rackspace-Cloud", "\\\\");
120
				// Log.d("Rackspace-Cloud", "\\\\");
131 121
				break;
132 122
			case '"':
133
				//Log.d("Rackspace-Cloud", "\\\"");
123
				// Log.d("Rackspace-Cloud", "\\\"");
134 124
				break;
135 125
			case '\n':
136
				//Log.d("Rackspace-Cloud", "\\n");
126
				// Log.d("Rackspace-Cloud", "\\n");
137 127
				break;
138 128
			case '\r':
139
				//Log.d("Rackspace-Cloud", "\\r");
129
				// Log.d("Rackspace-Cloud", "\\r");
140 130
				break;
141 131
			case '\t':
142
				//Log.d("Rackspace-Cloud", "\\t");
132
				// Log.d("Rackspace-Cloud", "\\t");
143 133
				break;
144 134
			default:
145
				//Log.d("Rackspace-Cloud", String.valueOf(ch[i]));
135
				// Log.d("Rackspace-Cloud", String.valueOf(ch[i]));
146 136
				break;
147 137
			}
148 138
		}
149
		//Log.d("Rackspace-Cloud", "\"\n");
139
		// Log.d("Rackspace-Cloud", "\"\n");
150 140
		// String strCharacters = new String(ch, start, length);
151 141
		for (int i = start; i < (start + length); i++) {
152 142
			currentData.append(ch[i]);
b/src/com/rackspace/cloud/files/api/client/parsers/ContainerXMLParser.java
19 19
public class ContainerXMLParser extends DefaultHandler {
20 20

  
21 21
	private Container container;
22
	private Map<String,String> xContainerPolicy;
23
	private Map<String,String> metadata;
22
	private Map<String, String> xContainerPolicy;
23
	private Map<String, String> metadata;
24 24
	private ArrayList<Container> containers;
25 25
	private String key;
26
	
26

  
27 27
	private StringBuffer currentData;
28 28

  
29 29
	public void startElement(String uri, String name, String qName,
......
36 36
			container = new Container();
37 37
		} else if ("x_container_policy".equals(name)) {
38 38
			xContainerPolicy = new HashMap<String, String>();
39
		}  else if ("x_object_meta".equals(name)) {
39
		} else if ("x_object_meta".equals(name)) {
40 40
			metadata = new HashMap<String, String>();
41 41
		}
42 42
	}
......
55 55
			Log.d("ViewContainersXMLparser", container.toString());
56 56
			containers.add(container);
57 57

  
58
		}else if ("x_container_policy".equals(name)) {
59
			if(container!=null){
58
		} else if ("x_container_policy".equals(name)) {
59
			if (container != null) {
60 60
				container.setxContainerPolicy(xContainerPolicy);
61 61
				xContainerPolicy = null;
62 62
			}
63 63

  
64
		}
65
		else if ("key".equals(name)&&xContainerPolicy!=null) {
64
		} else if ("key".equals(name) && xContainerPolicy != null) {
66 65
			key = value;
67
		}
68
		else if ("value".equals(name)&&xContainerPolicy!=null) {
69
			if(key!=null)
70
				xContainerPolicy.put(key,value);
71
		}
72
		else if ("x_object_meta".equals(name)) {
73
			if(container!=null){
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) {
74 71
				container.setMetadata(metadata);
75 72
				metadata = null;
76 73
			}
77 74

  
78
		}
79
		else if ("key".equals(name)&&metadata!=null) {
75
		} else if ("key".equals(name) && metadata != null) {
80 76
			key = value;
81
		}
82
		else if ("value".equals(name)&&metadata!=null) {
83
			if(key!=null)
84
				metadata.put(key,value);
85
		}
86
		else if ("name".equals(name)) {
77
		} else if ("value".equals(name) && metadata != null) {
78
			if (key != null)
79
				metadata.put(key, value);
80
		} else if ("name".equals(name)) {
87 81
			container.setName(value);
88 82
		} else if ("count".equals(name)) {
89 83
			container.setCount(Integer.parseInt(value));
......
97 91
			container.setCdnUrl(value);
98 92
		} else if ("log_retention".equals(name)) {
99 93
			container.setLogRetention("True".equals(value));
100
		}
101
		 else if ("x_object_public".equals(name)) {
102
				container.setIsPublic(value);
103
			}
104
		else if ("x_object_modified_by".equals(name)) {
94
		} else if ("x_object_public".equals(name)) {
95
			container.setIsPublic(value);
96
		} else if ("x_object_modified_by".equals(name)) {
105 97
			container.setModifiedBy(value);
106 98

  
107
		}
108
		else if ("x_object_version".equals(name)) {
99
		} else if ("x_object_version".equals(name)) {
109 100
			container.setVersion(value);
110 101

  
111
		}
112
		else if ("x_object_hash".equals(name)) {
102
		} else if ("x_object_hash".equals(name)) {
113 103
			container.setObjectHash(value);
114 104

  
115
		}
116
		else if ("x_object_uuid".equals(name)) {
105
		} else if ("x_object_uuid".equals(name)) {
117 106
			container.setObjectUUID(value);
118 107

  
119
		}
120
		else if ("x_object_version_timestamp".equals(name)) {
108
		} else if ("x_object_version_timestamp".equals(name)) {
121 109
			container.setVersionTimestamp(value);
122 110

  
123
		}
124
		else if ("x_object_sharing".equals(name)) {
111
		} else if ("x_object_sharing".equals(name)) {
125 112
			container.setObjectSharing(value);
126 113

  
127 114
		}
......
130 117

  
131 118
	public void characters(char ch[], int start, int length) {
132 119

  
133
		//Log.d("Rackspace-Cloud", "Characters:    \"");
120
		// Log.d("Rackspace-Cloud", "Characters:    \"");
134 121

  
135 122
		for (int i = start; i < start + length; i++) {
136 123
			switch (ch[i]) {
137 124
			case '\\':
138
			//	Log.d("Rackspace-Cloud", "\\\\");
125
				// Log.d("Rackspace-Cloud", "\\\\");
139 126
				break;
140 127
			case '"':
141
			//	Log.d("Rackspace-Cloud", "\\\"");
128
				// Log.d("Rackspace-Cloud", "\\\"");
142 129
				break;
143 130
			case '\n':
144
			//	Log.d("Rackspace-Cloud", "\\n");
131
				// Log.d("Rackspace-Cloud", "\\n");
145 132
				break;
146 133
			case '\r':
147
			//	Log.d("Rackspace-Cloud", "\\r");
134
				// Log.d("Rackspace-Cloud", "\\r");
148 135
				break;
149 136
			case '\t':
150
			//	Log.d("Rackspace-Cloud", "\\t");
137
				// Log.d("Rackspace-Cloud", "\\t");
151 138
				break;
152 139
			default:
153
			//	Log.d("Rackspace-Cloud", String.valueOf(ch[i]));
140
				// Log.d("Rackspace-Cloud", String.valueOf(ch[i]));
154 141
				break;
155 142
			}
156 143
		}
157
		//Log.d("Rackspace-Cloud", "\"\n");
144
		// Log.d("Rackspace-Cloud", "\"\n");
158 145

  
159 146
		for (int i = start; i < (start + length); i++) {
160 147
			currentData.append(ch[i]);
b/src/com/rackspace/cloud/servers/api/client/Account.java
3 3
 */
4 4
package com.rackspace.cloud.servers.api.client;
5 5

  
6

  
7

  
8 6
/**
9 7
 * @author Mike Mayo - mike.mayo@rackspace.com - twitter.com/greenisus
10
 *
8
 * 
11 9
 */
12
public class Account implements java.io.Serializable{
13
	
10
public class Account implements java.io.Serializable {
11

  
14 12
	/**
15 13
	 * 
16 14
	 */
......
24 22
	private transient String storageToken;
25 23
	private transient String cdnManagementUrl;
26 24
	private transient static Account currentAccount;
27
	
28
	
29
	public static Account getAccount(){
25

  
26
	public static Account getAccount() {
30 27
		return currentAccount;
31 28
	}
32
	
33
	public static void setAccount(Account account){
29

  
30
	public static void setAccount(Account account) {
34 31
		Account.currentAccount = account;
35 32
	}
36
	
33

  
37 34
	/**
38 35
	 * @return the serverUrl
39 36
	 */
......
42 39
	}
43 40

  
44 41
	/**
45
	 * @param serverUrl the serverUrl to set
42
	 * @param serverUrl
43
	 *            the serverUrl to set
46 44
	 */
47 45
	public void setServerUrl(String serverUrl) {
48 46
		this.serverUrl = serverUrl;
......
54 52
	public String getStorageUrl() {
55 53
		return storageUrl;
56 54
	}
55

  
57 56
	/**
58 57
	 * @return the storageToken
59 58
	 */
60 59
	public String getStorageToken() {
61 60
		return storageToken;
62 61
	}
62

  
63 63
	/**
64
	 * @param storageUrl the storageUrl to set
64
	 * @param storageUrl
65
	 *            the storageUrl to set
65 66
	 */
66 67
	public void setStorageUrl(String storageUrl) {
67 68
		this.storageUrl = storageUrl;
......
75 76
	}
76 77

  
77 78
	/**
78
	 * @param cdnManagementUrl the cdnManagementUrl to set
79
	 * @param cdnManagementUrl
80
	 *            the cdnManagementUrl to set
79 81
	 */
80 82
	public void setCdnManagementUrl(String cdnManagementUrl) {
81 83
		this.cdnManagementUrl = cdnManagementUrl;
......
89 91
	}
90 92

  
91 93
	/**
92
	 * @param authToken the authToken to set
94
	 * @param authToken
95
	 *            the authToken to set
93 96
	 */
94 97
	public void setAuthToken(String authToken) {
95 98
		this.authToken = authToken;
......
103 106
	}
104 107

  
105 108
	/**
106
	 * @param authToken the authToken to set
109
	 * @param authToken
110
	 *            the authToken to set
107 111
	 */
108 112
	public void setAuthServer(String authServer) {
109 113
		this.authServer = authServer;
110 114
	}
111 115

  
112
	
113 116
	/**
114 117
	 * @return the username
115 118
	 */
116 119
	public String getUsername() {
117 120
		return username;
118 121
	}
119
	
122

  
120 123
	/**
121
	 * @param username the username to set
124
	 * @param username
125
	 *            the username to set
122 126
	 */
123 127
	public void setUsername(String username) {
124 128
		this.username = username;
125 129
	}
126
	
130

  
127 131
	/**
128 132
	 * @return the apiKey
129 133
	 */
130 134
	public String getApiKey() {
131 135
		return apiKey;
132 136
	}
133
	
137

  
134 138
	/**
135
	 * @param apiKey the apiKey to set
139
	 * @param apiKey
140
	 *            the apiKey to set
136 141
	 */
137 142
	public void setApiKey(String apiKey) {
138 143
		this.apiKey = apiKey;
139 144
	}
140
   /**
145

  
146
	/**
141 147
    */
142 148
	public void setStorageToken(String storageToken) {
143 149
		this.storageToken = storageToken;
144
		
150

  
145 151
	}
146
	
147
}
148 152

  
153
}
b/src/com/rackspace/cloud/servers/api/client/Backup.java
1 1
package com.rackspace.cloud.servers.api.client;
2 2

  
3 3
public class Backup {
4
	
5
	private static final String[] weeklyBackupValues = {"DISABLED", "SUNDAY", "MONDAY", 
6
			"TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"};
7
	
8
	private static final String[] dailyBackupValues = {"DISABLED", "H_0000_0200", "H_0200_0400", "H_0400_0600", "H_0600_0800",
9
					"H_0800_1000", "H_1000_1200", "H_1200_1400", "H_1400_1600", "H_1600_1800", "H_1800_2000",
10
					"H_2000_2200", "H_2200_0000"};
11
	
12
	public static String getWeeklyValue(int i){
4

  
5
	private static final String[] weeklyBackupValues = { "DISABLED", "SUNDAY",
6
			"MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY" };
7

  
8
	private static final String[] dailyBackupValues = { "DISABLED",
9
			"H_0000_0200", "H_0200_0400", "H_0400_0600", "H_0600_0800",
10
			"H_0800_1000", "H_1000_1200", "H_1200_1400", "H_1400_1600",
11
			"H_1600_1800", "H_1800_2000", "H_2000_2200", "H_2200_0000" };
12

  
13
	public static String getWeeklyValue(int i) {
13 14
		return weeklyBackupValues[i];
14 15
	}
15
	
16
	public static String getDailyValue(int i){
16

  
17
	public static String getDailyValue(int i) {
17 18
		return dailyBackupValues[i];
18 19
	}
19 20

  
b/src/com/rackspace/cloud/servers/api/client/CloudServersException.java
5 5

  
6 6
/**
7 7
 * @author Mike Mayo - mike.mayo@rackspace.com - twitter.com/greenisus
8
 *
8
 * 
9 9
 */
10 10
public class CloudServersException extends Exception {
11 11

  
......
13 13
	private int code;
14 14
	private String message;
15 15
	private String details;
16
	
16

  
17 17
	/**
18 18
	 * @return the code
19 19
	 */
20 20
	public int getCode() {
21 21
		return code;
22 22
	}
23

  
23 24
	/**
24
	 * @param code the code to set
25
	 * @param code
26
	 *            the code to set
25 27
	 */
26 28
	public void setCode(int code) {
27 29
		this.code = code;
28 30
	}
31

  
29 32
	/**
30 33
	 * @return the message
31 34
	 */
32 35
	public String getMessage() {
33 36
		return message;
34 37
	}
38

  
35 39
	/**
36
	 * @param message the message to set
40
	 * @param message
41
	 *            the message to set
37 42
	 */
38 43
	public void setMessage(String message) {
39 44
		this.message = message;
40 45
	}
46

  
41 47
	/**
42 48
	 * @return the details
43 49
	 */
44 50
	public String getDetails() {
45 51
		return details;
46 52
	}
53

  
47 54
	/**
48
	 * @param details the details to set
55
	 * @param details
56
	 *            the details to set
49 57
	 */
50 58
	public void setDetails(String details) {
51 59
		this.details = details;
52 60
	}
53
	
54
	
61

  
55 62
}
b/src/com/rackspace/cloud/servers/api/client/Entity.java
8 8

  
9 9
/**
10 10
 * @author Mike Mayo - mike.mayo@rackspace.com - twitter.com/greenisus
11
 *
11
 * 
12 12
 */
13 13
public class Entity implements Serializable {
14
	
14

  
15 15
	private static final long serialVersionUID = 6865922063268248789L;
16 16
	private String id;
17 17
	private String name;
18
	
19
	//new attributes
18

  
19
	// new attributes
20 20
	private String modifiedBy;
21 21
	private String version;
22 22
	private String versionTimestamp;
23 23
	private String objectUUID;
24 24
	private String objectHash;
25 25
	private String objectSharing;
26
	private Map<String,String> metadata;
26
	private Map<String, String> metadata;
27 27
	private String isPublic;
28

  
28 29
	/**
29 30
	 * @return the id
30 31
	 */
......
33 34
	}
34 35

  
35 36
	/**
36
	 * @param id the id to set
37
	 * @param id
38
	 *            the id to set
37 39
	 */
38 40
	public void setId(String id) {
39 41
		this.id = id;
......
47 49
	}
48 50

  
49 51
	/**
50
	 * @param name the name to set
52
	 * @param name
53
	 *            the name to set
51 54
	 */
52 55
	public void setName(String name) {
53 56
		this.name = name;
......
108 111
	public void setMetadata(Map<String, String> metadata) {
109 112
		this.metadata = metadata;
110 113
	}
111
	
114

  
112 115
	public String getIsPublic() {
113 116
		return isPublic;
114 117
	}
115
	
118

  
116 119
	public void setIsPublic(String isPublic) {
117 120
		this.isPublic = isPublic;
118 121
	}
b/src/com/rackspace/cloud/servers/api/client/EntityManager.java
7 7

  
8 8
/**
9 9
 * @author Mike Mayo - mike.mayo@rackspace.com - twitter.com/greenisus
10
 *
10
 * 
11 11
 */
12 12
public class EntityManager {
13
	
13

  
14 14
	protected String cacheBuster() {
15 15
		Calendar calendar = Calendar.getInstance();
16 16
		java.util.Date now = calendar.getTime();
17
		java.sql.Timestamp currentTimestamp = new java.sql.Timestamp(now.getTime());		
17
		java.sql.Timestamp currentTimestamp = new java.sql.Timestamp(
18
				now.getTime());
18 19
		return "?now=" + currentTimestamp.getTime();
19 20
	}
20
		
21

  
21 22
	//
22 23
	// CRUD Operations
23 24
	//
24
	
25
	public void create(Entity entity) throws CloudServersException {		
25

  
26
	public void create(Entity entity) throws CloudServersException {
26 27
	}
27
	
28

  
28 29
	public void remove(Entity e) {
29
		
30

  
30 31
	}
31
	
32

  
32 33
	public void update(Entity e) {
33
		
34

  
34 35
	}
35
	
36

  
36 37
	public void refresh(Entity e) {
37
		
38

  
38 39
	}
39
	
40

  
40 41
	public Entity find(long id) throws CloudServersException {
41 42
		return null;
42 43
	}
43
	
44

  
44 45
	//
45 46
	// Polling Operations
46 47
	//
47 48
	public void wait(Entity e) {
48
		
49

  
49 50
	}
50
	
51

  
51 52
	public void wait(Entity e, long timeout) {
52
	
53

  
53 54
	}
54 55
	/*
55
	public void notify(Entity e, ChangeListener ch) {
56
		
57
	}
58
	
59
	public void stopNotify(Entity e, ChangeListener ch) {
60
		
61
	}
62
	*/
63
	
56
	 * public void notify(Entity e, ChangeListener ch) {
57
	 * 
58
	 * }
59
	 * 
60
	 * public void stopNotify(Entity e, ChangeListener ch) {
61
	 * 
62
	 * }
63
	 */
64

  
64 65
	//
65 66
	// Lists
66 67
	//
67 68
	/*
68
	public ArrayList createList(boolean detail) throws CloudServersException {
69
		return null;
70
	}
71
	public EntityList createDeltaList(boolean detail, long changesSince) {
72
		return null;
73
	}	
74
	public EntityList createList(boolean detail, long offset, long limit) {
75
		return null;
76
	}
77
	public EntityList createDeltaList(boolean detail, long changesSince, long offset, long limit) {
78
		return null;
79
	}
80
	*/
69
	 * public ArrayList createList(boolean detail) throws CloudServersException
70
	 * { return null; } public EntityList createDeltaList(boolean detail, long
71
	 * changesSince) { return null; } public EntityList createList(boolean
72
	 * detail, long offset, long limit) { return null; } public EntityList
73
	 * createDeltaList(boolean detail, long changesSince, long offset, long
74
	 * limit) { return null; }
75
	 */
81 76
}
b/src/com/rackspace/cloud/servers/api/client/Flavor.java
7 7

  
8 8
/**
9 9
 * @author Mike Mayo - mike.mayo@rackspace.com - twitter.com/greenisus
10
 *
10
 * 
11 11
 */
12 12
public class Flavor extends Entity {
13 13

  
......
15 15
	private static TreeMap<String, Flavor> flavors;
16 16
	private String disk;
17 17
	private String ram;
18
	
18

  
19 19
	/**
20 20
	 * @return the disk
21 21
	 */
22 22
	public String getDisk() {
23 23
		return disk;
24 24
	}
25

  
25 26
	/**
26
	 * @param disk the disk to set
27
	 * @param disk
28
	 *            the disk to set
27 29
	 */
28 30
	public void setDisk(String disk) {
29 31
		this.disk = disk;
30 32
	}
33

  
31 34
	/**
32 35
	 * @return the ram
33 36
	 */
34 37
	public String getRam() {
35 38
		return ram;
36 39
	}
40

  
37 41
	/**
38
	 * @param ram the ram to set
42
	 * @param ram
43
	 *            the ram to set
39 44
	 */
40 45
	public void setRam(String ram) {
41 46
		this.ram = ram;
42 47
	}
48

  
43 49
	/**
44 50
	 * @return the flavors
45 51
	 */
46 52
	public static TreeMap<String, Flavor> getFlavors() {
47 53
		return flavors;
48 54
	}
55

  
49 56
	/**
50
	 * @param flavors the flavors to set
57
	 * @param flavors
58
	 *            the flavors to set
51 59
	 */
52 60
	public static void setFlavors(TreeMap<String, Flavor> flavors) {
53 61
		Flavor.flavors = flavors;
54 62
	}
55
	
56
	
63

  
57 64
}
b/src/com/rackspace/cloud/servers/api/client/FlavorManager.java
27 27

  
28 28
/**
29 29
 * @author Mike Mayo - mike.mayo@rackspace.com - twitter.com/greenisus
30
 *
30
 * 
31 31
 */
32 32
public class FlavorManager extends EntityManager {
33 33

  
34 34
	public ArrayList<Flavor> createList(boolean detail, Context context) {
35
		
35

  
36 36
		ArrayList<Flavor> flavors = new ArrayList<Flavor>();
37
		if(Account.getAccount().getServerUrl()!=null){
37
		if (Account.getAccount().getServerUrl() != null) {
38 38
			CustomHttpClient httpclient = new CustomHttpClient(context);
39
			HttpGet get = new HttpGet(Account.getAccount().getServerUrl() + "/flavors/detail.xml?now=cache_time2");
39
			HttpGet get = new HttpGet(Account.getAccount().getServerUrl()
40
					+ "/flavors/detail.xml?now=cache_time2");
40 41
			get.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
41
			try {			
42
			try {
42 43
				HttpResponse resp = httpclient.execute(get);
43
			    BasicResponseHandler responseHandler = new BasicResponseHandler();
44
			    String body = responseHandler.handleResponse(resp);
45
			    
46
			    if (resp.getStatusLine().getStatusCode() == 200 || resp.getStatusLine().getStatusCode() == 203) {		    	
47
			    	FlavorsXMLParser flavorsXMLParser = new FlavorsXMLParser();
48
			    	SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
49
			    	XMLReader xmlReader = saxParser.getXMLReader();
50
			    	xmlReader.setContentHandler(flavorsXMLParser);
51
			    	xmlReader.parse(new InputSource(new StringReader(body)));	
52
			    	flavors = flavorsXMLParser.getFlavors();	
53
			    }
44
				BasicResponseHandler responseHandler = new BasicResponseHandler();
45
				String body = responseHandler.handleResponse(resp);
46

  
47
				if (resp.getStatusLine().getStatusCode() == 200
48
						|| resp.getStatusLine().getStatusCode() == 203) {
49
					FlavorsXMLParser flavorsXMLParser = new FlavorsXMLParser();
50
					SAXParser saxParser = SAXParserFactory.newInstance()
51
							.newSAXParser();
52
					XMLReader xmlReader = saxParser.getXMLReader();
53
					xmlReader.setContentHandler(flavorsXMLParser);
54
					xmlReader.parse(new InputSource(new StringReader(body)));
55
					flavors = flavorsXMLParser.getFlavors();
56
				}
54 57
			} catch (ClientProtocolException cpe) {
55 58
				// we'll end up with an empty list; that's good enough
56 59
			} catch (IOException e) {
b/src/com/rackspace/cloud/servers/api/client/Image.java
9 9

  
10 10
/**
11 11
 * @author Mike Mayo - mike.mayo@rackspace.com - twitter.com/greenisus
12
 *
12
 * 
13 13
 */
14
public class Image extends Entity implements Comparable<Image>{
14
public class Image extends Entity implements Comparable<Image> {
15 15

  
16 16
	private static final long serialVersionUID = -9020224299062520935L;
17 17
	private static TreeMap<String, Image> images;
18 18
	private String status;
19 19
	private String updated;
20
	
20

  
21 21
	public int iconResourceId() {
22 22
		int iconResourceId = R.drawable.cloudservers_icon; // default if unknown
23
		
23

  
24 24
		if ("2".equals(getId())) {
25 25
			iconResourceId = R.drawable.centos_icon;
26 26
		} else if ("3".equals(getId())) {
......
88 88
		}
89 89
		return iconResourceId;
90 90
	}
91
	
91

  
92 92
	public int logoResourceId() {
93
		int logoResourceId = R.drawable.cloudservers_large; // default if unknown
94
		
93
		int logoResourceId = R.drawable.cloudservers_large; // default if
94
															// unknown
95

  
95 96
		if ("2".equals(getId())) {
96 97
			logoResourceId = R.drawable.centos_large;
97 98
		} else if ("3".equals(getId())) {
......
157 158
		} else if ("71".equals(getId())) {
158 159
			logoResourceId = R.drawable.fedora_large;
159 160
		}
160
		
161

  
161 162
		return logoResourceId;
162 163
	}
163
	
164

  
164 165
	/**
165 166
	 * @return the status
166 167
	 */
167 168
	public String getStatus() {
168 169
		return status;
169 170
	}
171

  
170 172
	/**
171
	 * @param status the status to set
173
	 * @param status
174
	 *            the status to set
172 175
	 */
173 176
	public void setStatus(String status) {
174 177
		this.status = status;
175 178
	}
179

  
176 180
	/**
177 181
	 * @return the updated
178 182
	 */
179 183
	public String getUpdated() {
180 184
		return updated;
181 185
	}
186

  
182 187
	/**
183
	 * @param updated the updated to set
188
	 * @param updated
189
	 *            the updated to set
184 190
	 */
185 191
	public void setUpdated(String updated) {
186 192
		this.updated = updated;
......
194 200
	}
195 201

  
196 202
	/**
197
	 * @param images the images to set
203
	 * @param images
204
	 *            the images to set
198 205
	 */
199 206
	public static void setImages(TreeMap<String, Image> images) {
200 207
		Image.images = images;
......
204 211
	public int compareTo(Image b) {
205 212
		return this.getName().compareTo(b.getName());
206 213
	}
207
	
208
	
214

  
209 215
}
b/src/com/rackspace/cloud/servers/api/client/ImageManager.java
27 27

  
28 28
/**
29 29
 * @author Mike Mayo - mike.mayo@rackspace.com - twitter.com/greenisus
30
 *
30
 * 
31 31
 */
32 32
public class ImageManager extends EntityManager {
33 33

  
34 34
	public ArrayList<Image> createList(boolean detail, Context context) {
35
		
35

  
36 36
		ArrayList<Image> images = new ArrayList<Image>();
37
		if(Account.getAccount().getServerUrl()!=null){
37
		if (Account.getAccount().getServerUrl() != null) {
38 38
			CustomHttpClient httpclient = new CustomHttpClient(context);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff