Revision 666c8e11

b/AndroidManifest.xml
3 3
	android:versionCode="3" android:versionName="1.2" package="com.rackspace.cloud.android">
4 4
	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
5 5
	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
6
	<application android:name=".AndroidCloudApplication" android:icon="@drawable/rackspace60"
6
	<application android:name=".AndroidCloudApplication" android:icon="@drawable/pithos_icon"
7 7
		android:label="@string/app_name" android:debuggable="true">
8 8
		<activity android:name=".RackspaceCloudActivity"
9 9
			android:label="@string/app_name">
b/res/values/strings.xml
1 1
<?xml version="1.0" encoding="utf-8"?>
2 2
<resources>
3

  
3 4
    <string name="hello">Hello World, RackspaceCloudActivity!</string>
4 5
    <string name="app_name">Pithos+</string>
5
<string name="username">User Name:</string>
6
<string name="apikey">API Key:</string>
7
<string name="login">Login</string>
8
<string name="authenticating">Authenticating...</string>
9
<string name="fields_missing">Fields Missing</string>
10
<string name="username_and_apikey_required">User Name and API Key are required.</string>
11
<string name="ok">OK</string>
12
<string name="country">Country Datacenter</string>
13
<string-array name="country_entries">
14
     <item>US</item>
15
     <item>UK</item>
16
</string-array>
17
<string-array name="country_values">
18
     <item>0</item>
19
     <item>1</item>
20
</string-array>
21
<string name="country_default_value">0</string>
22
<string name="preference_name">Preferences</string>
23
<string name="weekly_backup_prompt">Select a weekly backup window</string>
24
<string-array name="weeklyBackupValues">
25
	<item> Disabled</item>
26
	<item> Sunday</item>
27
	<item> Monday</item>
28
	<item> Tuesday</item>
29
	<item> Wednesday</item>
30
	<item> Thursday</item>
31
	<item> Friday</item>
32
	<item> Saturday</item>
33
</string-array>
34
<string name="daily_backup_prompt">Select a daily backup window</string>
35
<string-array name="dailyBackupValues">
36
	<item> Disabled</item>
37
	<item> 0000-0200</item>
38
	<item> 0200-0400</item>
39
	<item> 0400-0600</item>
40
	<item> 0600-0800</item>
41
	<item> 0800-1000</item>
42
	<item> 1000-1200</item>
43
	<item> 1200-1400</item>
44
	<item> 1400-1600</item>
45
	<item> 1600-1800</item>
46
	<item> 1800-2000</item>
47
	<item> 2000-2200</item>
48
	<item> 2200-0000</item>
49
</string-array>
50
<string name="change_password_warning">The root password will be updated and the server will be restarted.  This process will only work
6
    <string name="username">User Name:</string>
7
    <string name="apikey">API Key:</string>
8
    <string name="login">Login</string>
9
    <string name="authenticating">Authenticating...</string>
10
    <string name="fields_missing">Fields Missing</string>
11
    <string name="username_and_apikey_required">User Name and API Key are required.</string>
12
    <string name="ok">OK</string>
13
    <string name="country">Country Datacenter</string>
14

  
15
    <string-array name="country_entries">
16
        <item>US</item>
17
        <item>UK</item>
18
    </string-array>
19
    <string-array name="country_values">
20
        <item>0</item>
21
        <item>1</item>
22
    </string-array>
23

  
24
    <string name="country_default_value">0</string>
25
    <string name="preference_name">Preferences</string>
26
    <string name="weekly_backup_prompt">Select a weekly backup window</string>
27

  
28
    <string-array name="weeklyBackupValues">
29
        <item> Disabled</item>
30
        <item> Sunday</item>
31
        <item> Monday</item>
32
        <item> Tuesday</item>
33
        <item> Wednesday</item>
34
        <item> Thursday</item>
35
        <item> Friday</item>
36
        <item> Saturday</item>
37
    </string-array>
38

  
39
    <string name="daily_backup_prompt">Select a daily backup window</string>
40

  
41
    <string-array name="dailyBackupValues">
42
        <item> Disabled</item>
43
        <item> 0000-0200</item>
44
        <item> 0200-0400</item>
45
        <item> 0400-0600</item>
46
        <item> 0600-0800</item>
47
        <item> 0800-1000</item>
48
        <item> 1000-1200</item>
49
        <item> 1200-1400</item>
50
        <item> 1400-1600</item>
51
        <item> 1600-1800</item>
52
        <item> 1800-2000</item>
53
        <item> 2000-2200</item>
54
        <item> 2200-0000</item>
55
    </string-array>
56

  
57
    <string name="change_password_warning">The root password will be updated and the server will be restarted.  This process will only work
51 58
	if you have a user line for \"root\" in your passwd or shadow file.</string>
52
<string name="contact_uk">0800-083-3012</string>
53
<string name="contact_us">877-934-0407</string>
54
<string name="confirm_resize">Confirming the resize will destroy the saved copy of your original server.</string>
55
<string name="virtual_ip_type">Virtual\nIp Type</string>
59
    <string name="contact_uk">0800-083-3012</string>
60
    <string name="contact_us">877-934-0407</string>
61
    <string name="confirm_resize">Confirming the resize will destroy the saved copy of your original server.</string>
62
    <string name="virtual_ip_type">Virtual\nIp Type</string>
56 63

  
57
</resources>
64
</resources>
b/src/com/rackspace/cloud/android/ContainerObjectDetails.java
149 149
		if (state != null && state.containsKey("container")) {
150 150
			objects = (ContainerObjects) state.getSerializable("container");
151 151
		}
152
		loadObjectData();
152
		if(containerNames.equals(Container.MYSHARED)||containerNames.equals(Container.OTHERS))
153
			loadObjectData();
154
		else
155
			new ContainerObjectRefreshTask().execute(null);
153 156

  
154 157
		if (cdnEnabled.equals("true")) {
155 158
			this.previewButton = (Button) findViewById(R.id.preview_button);
......
228 231

  
229 232
		// Content Type
230 233
		TextView cType = (TextView) findViewById(R.id.view_content_type);
231
		cType.setText(objects.getContentType().toString());
234
		if(objects.getContentType()!=null)
235
			cType.setText(objects.getContentType().toString());
236
		else
237
			cType.setText("");
232 238

  
233 239
		// Last Modification date
234 240
		String strDate = objects.getLastMod();
......
584 590

  
585 591
					@Override
586 592
					public void onClick(View v1) {
587

  
593
						if (storageIsReady()) {
594
							new ContainerObjectDownloadTask().execute(String.valueOf(perm.getVersion()));
595
						} else {
596
							showAlert("Error", "Storage not found.");
597
						}
588 598
						// getDownloadTask().execute(perm.getUri()+"?version="+perm.getVersion());
589 599
						// properties.removeView(v);
590 600

  
......
636 646
			showDialog(deleteObject);
637 647
			return true;
638 648
		case R.id.refresh:
639
			loadObjectData();
649
			if(containerNames.equals(Container.MYSHARED)||containerNames.equals(Container.OTHERS))
650
				loadObjectData();
651
			else
652
				new ContainerObjectRefreshTask().execute(null);
653

  
640 654
			return true;
641 655
		case R.id.save:
642 656
			new ContainerObjectUpdateTask().execute();
......
774 788
	}
775 789

  
776 790
	// Task's
791
	
792
	private class ContainerObjectRefreshTask extends
793
				AsyncTask<Void, Void, ContainerObjects> {
794
			
795
			private CloudServersException exception;
796
			
797
			protected void onPreExecute() {
798
				showDialog();
799
				app.setDeleteingObject(true);
800
				deleteObjTask = new DeleteObjectListenerTask();
801
				deleteObjTask.execute();
802
			}
803
			
804
			@Override
805
			protected ContainerObjects doInBackground(Void... arg0) {
806
				ContainerObjects bundle = null;
807
				try {
808
					bundle = (new ContainerObjectManager(getContext()))
809
							.executeHead(containerNames, objects.getCName());
810
				} catch (CloudServersException e) {
811
					exception = e;
812
				}
813
			
814
				return bundle;
815
			}
816
			
817
			@Override
818
			protected void onPostExecute(ContainerObjects bundle) {
819
				hideDialog();
820
				if (bundle != null) {
821
					objects=bundle;
822
					loadObjectData();
823
				} else if (exception != null) {
824
					showToast("There was a problem deleting your file: "
825
							+ exception.getMessage());
826
				}
827
			}
828
	}
777 829

  
778 830
	private class ContainerObjectDeleteTask extends
779 831
			AsyncTask<Void, Void, HttpBundle> {
......
827 879
	}
828 880

  
829 881
	private class ContainerObjectDownloadTask extends
830
			AsyncTask<Void, Void, HttpBundle> {
882
			AsyncTask<String, Void, HttpBundle> {
831 883

  
832 884
		private CloudServersException exception;
833 885

  
......
840 892
		}
841 893

  
842 894
		@Override
843
		protected HttpBundle doInBackground(Void... arg0) {
895
		protected HttpBundle doInBackground(String... arg0) {
844 896
			HttpBundle bundle = null;
845 897
			try {
846
				bundle = (new ContainerObjectManager(getContext())).getObject(
898
				if(arg0.length==1 && arg0[0]!=null)
899
					bundle = (new ContainerObjectManager(getContext())).getObject(
900
							containerNames, objects.getCName(),arg0[0]);
901
				else
902
					bundle = (new ContainerObjectManager(getContext())).getObject(
847 903
						containerNames, objects.getCName());
848 904
			} catch (CloudServersException e) {
849 905
				exception = e;
b/src/com/rackspace/cloud/files/api/client/ContainerObjectManager.java
17 17
import javax.xml.parsers.SAXParser;
18 18
import javax.xml.parsers.SAXParserFactory;
19 19

  
20
import org.apache.http.Header;
20 21
import org.apache.http.HttpResponse;
21 22
import org.apache.http.client.ClientProtocolException;
22 23
import org.apache.http.client.methods.HttpDelete;
23 24
import org.apache.http.client.methods.HttpGet;
25
import org.apache.http.client.methods.HttpHead;
24 26
import org.apache.http.client.methods.HttpPost;
25 27
import org.apache.http.client.methods.HttpPut;
26 28
import org.apache.http.client.methods.HttpRequestBase;
......
61 63
		this.context = context;
62 64
	}
63 65
	
66
	public ContainerObjects executeHead(String containerName, String cname) throws CloudServersException{
67
		CustomHttpClient httpclient = new CustomHttpClient(context);
68
		String url = Account.getAccount().getStorageUrl()+"/"+ containerName
69
				+ "/" + cname+"?format=xml";
70
		Log.i(LOG,url);
71
		HttpHead get = new HttpHead(url);
72
		get.addHeader("Content-Type", "application/xml");
73
		get.addHeader(CustomHttpClient.X_STORAGE_TOKEN, storageToken);
74

  
75
		try {
76
			HttpResponse resp = httpclient.execute(get);
77
			BasicResponseHandler responseHandler = new BasicResponseHandler();
78
			String body = responseHandler.handleResponse(resp);
79

  
80
			if (resp.getStatusLine().getStatusCode() == 200
81
					|| resp.getStatusLine().getStatusCode() == 203) {
82
				
83
				ContainerObjects objects = new ContainerObjects();
84
				for(Header h : resp.getAllHeaders()){
85
					if(h.getName().equals("Content-Type"))
86
						objects.setContentType(h.getValue());
87
					else if(h.getName().equals("X-Object-Public"))
88
						objects.setIsPublic(h.getValue());
89
					else if(h.getName().equals("Content-Length"))
90
						objects.setBytes(Integer.parseInt(h.getValue()));
91
					else if(h.getName().equals("X-Object-Public"))
92
						objects.setIsPublic(h.getValue());
93
					else if(h.getName().equals("X-Object-Modified-By"))
94
						objects.setModifiedBy(h.getValue());
95
					else if(h.getName().equals("X-Object-UUID"))
96
						objects.setObjectUUID(h.getValue());
97
					else if(h.getName().equals("X-Object-Hash"))
98
						objects.setObjectHash(h.getValue());
99
					else if(h.getName().equals("X-Object-Version"))
100
						objects.setVersion(h.getValue());
101
					else if(h.getName().equals("X-Object-Version-Timestamp"))
102
						objects.setVersionTimestamp(h.getValue());
103
					else if(h.getName().equals("X-Object-Sharing"))
104
						objects.setObjectSharing(h.getValue());
105
					else if(h.getName().equals("Last-Modified"))
106
						objects.setLastMod(h.getValue());
107
					else if(h.getName().startsWith("X-Object-Meta")){
108
						if(objects.getMetadata()==null)
109
							objects.setMetadata(new HashMap<String, String>());
110
						objects.getMetadata().put(h.getName().replaceAll("X-Object-Meta-", ""),h.getValue());
111
					}
112
						
113
				}
114
				objects.setContainerName(containerName);
115
				objects.setCName(cname);
116
				return objects;
117

  
118
			} else {
119
				CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
120
				SAXParser saxParser = SAXParserFactory.newInstance()
121
						.newSAXParser();
122
				XMLReader xmlReader = saxParser.getXMLReader();
123
				xmlReader.setContentHandler(parser);
124
				xmlReader.parse(new InputSource(new StringReader(body)));
125
				CloudServersException cse = parser.getException();
126
				throw cse;
127
			}
128
		} catch (ClientProtocolException e) {
129
			CloudServersException cse = new CloudServersException();
130
			cse.setMessage(e.getLocalizedMessage());
131
			throw cse;
132
		} catch (IOException e) {
133
			CloudServersException cse = new CloudServersException();
134
			cse.setMessage(e.getLocalizedMessage());
135
			throw cse;
136
		} catch (ParserConfigurationException e) {
137
			CloudServersException cse = new CloudServersException();
138
			cse.setMessage(e.getLocalizedMessage());
139
			throw cse;
140
		} catch (SAXException e) {
141
			CloudServersException cse = new CloudServersException();
142
			cse.setMessage(e.getLocalizedMessage());
143
			throw cse;
144
		} catch (FactoryConfigurationError e) {
145
			CloudServersException cse = new CloudServersException();
146
			cse.setMessage(e.getLocalizedMessage());
147
			throw cse;
148
		}
149
		
150
	}
64 151
	
65 152
	private List<ContainerObjects> executeGet(String containerName, String url) throws CloudServersException{
66 153
		CustomHttpClient httpclient = new CustomHttpClient(context);
......
344 431
	}
345 432
	
346 433
	
434
	public HttpBundle getObject(String Container, String Object, String version)
435
			throws CloudServersException {
436
		String url = getSafeURL(Account.getAccount().getStorageUrl(), Container
437
				+ "/" + Object+"?version="+version);
438
		return executeMethod(GET, url);
439
	}
440
	
441
	
347 442

  
348 443
	public HttpBundle addObject(String Container, String Path, String Object,
349 444
			String type) throws CloudServersException {

Also available in: Unified diff