commit 006434d860ae703d4ae05b5e6323bc8d16b81f5f
Author: Adam Menz <adam.menz@rackspace.com>
Date:   Wed Jun 29 08:48:03 2011 -0500

    fixed issue #1 on github, also added some support for file names with
    non url safe characters (still in progress)

diff --git a/src/com/rackspace/cloud/files/api/client/ContainerManager.java b/src/com/rackspace/cloud/files/api/client/ContainerManager.java
index 1895cf6..53caa4e 100644
--- a/src/com/rackspace/cloud/files/api/client/ContainerManager.java
+++ b/src/com/rackspace/cloud/files/api/client/ContainerManager.java
@@ -2,6 +2,9 @@ package com.rackspace.cloud.files.api.client;
 
 import java.io.IOException;
 import java.io.StringReader;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 
 import javax.xml.parsers.FactoryConfigurationError;
@@ -46,8 +49,11 @@ public class ContainerManager extends EntityManager {
 	public HttpBundle create(Editable editable) throws CloudServersException {
 		HttpResponse resp = null;
 		CustomHttpClient httpclient = new CustomHttpClient(context);
-		HttpPut put = new HttpPut(Account.getAccount().getStorageUrl() + "/" + editable);
-
+		
+		String url = getSafeURL(Account.getAccount().getStorageUrl(), editable.toString());
+		HttpPut put = new HttpPut(url);
+		Log.d("info", "captin the url create " + url);
+		
 		put.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
 		httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class);
 
@@ -134,8 +140,9 @@ public class ContainerManager extends EntityManager {
 			throws CloudServersException {
 		HttpResponse resp = null;
 		CustomHttpClient httpclient = new CustomHttpClient(context);
-		HttpPut put = new HttpPut(Account.getAccount().getCdnManagementUrl() + "/"
-				+ container);
+		String url = getSafeURL(Account.getAccount().getCdnManagementUrl(), container);
+		HttpPut put = new HttpPut(url);
+		Log.d("info", "captin the url enable " + url);
 
 		put.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
 		put.addHeader("X-TTL", ttl);
@@ -168,9 +175,10 @@ public class ContainerManager extends EntityManager {
 	throws CloudServersException {
        HttpResponse resp = null;
  	    CustomHttpClient httpclient = new CustomHttpClient(context);
-       	HttpPost post = new HttpPost(Account.getAccount().getCdnManagementUrl() + "/"
-		+ container);
-
+ 	   String url = getSafeURL(Account.getAccount().getCdnManagementUrl(), container);
+       	HttpPost post = new HttpPost(url);
+       	Log.d("info", "captin the url disable " + url);
+       	
        	post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
        		post.addHeader("X-TTL", ttl);
        		post.addHeader("X-Log-Retention", logRet);
@@ -202,8 +210,10 @@ public class ContainerManager extends EntityManager {
 	public HttpBundle delete(String string) throws CloudServersException {
 		HttpResponse resp = null;
 		CustomHttpClient httpclient = new CustomHttpClient(context);
-		HttpDelete put = new HttpDelete(Account.getAccount().getStorageUrl() + "/" + string);
-
+		String url = getSafeURL(Account.getAccount().getStorageUrl(), string);
+		HttpDelete put = new HttpDelete(url);
+		Log.d("info", "captin the url delete " + url);
+		
 		put.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
 		httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class);
 
@@ -288,5 +298,23 @@ public class ContainerManager extends EntityManager {
 
 		return containers;
 	}
+	
+	private String getSafeURL(String badURL, String name){
+		URI uri = null;
+		try {
+			uri = new URI("https", badURL.substring(8), "/" + name.toString()+"/", "");
+		} catch (URISyntaxException e1) {
+			// TODO Auto-generated catch block
+			e1.printStackTrace();
+		}
+		String url = null;
+		try {
+			url = uri.toURL().toString();
+		} catch (MalformedURLException e1) {
+			// TODO Auto-generated catch block
+			e1.printStackTrace();
+		}
+		return url.substring(0, url.length()-1);
+	}
 
 }
\ No newline at end of file
diff --git a/src/com/rackspace/cloud/files/api/client/ContainerObjectManager.java b/src/com/rackspace/cloud/files/api/client/ContainerObjectManager.java
index 1450726..5c66e6d 100644
--- a/src/com/rackspace/cloud/files/api/client/ContainerObjectManager.java
+++ b/src/com/rackspace/cloud/files/api/client/ContainerObjectManager.java
@@ -2,6 +2,10 @@ package com.rackspace.cloud.files.api.client;
 
 import java.io.IOException;
 import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 
 import javax.xml.parsers.FactoryConfigurationError;
@@ -14,6 +18,7 @@ import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.methods.HttpDelete;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.BasicResponseHandler;
 import org.apache.http.protocol.RequestExpectContinue;
 import org.xml.sax.InputSource;
@@ -21,6 +26,7 @@ import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
 
 import android.content.Context;
+import android.util.Log;
 
 import com.rackspace.cloud.files.api.client.parsers.ContainerObjectXMLparser;
 import com.rackspace.cloud.servers.api.client.Account;
@@ -47,7 +53,9 @@ public class ContainerObjectManager extends EntityManager {
 	public ArrayList<ContainerObjects> createList(boolean detail, String passName) throws CloudServersException {
 		
 		CustomHttpClient httpclient = new CustomHttpClient(context);
-		HttpGet get = new HttpGet(Account.getAccount().getStorageUrl()+"/"+passName + "?format=xml");
+		String url = getSafeURL(Account.getAccount().getStorageUrl(), passName) + "?format=xml";
+		Log.d("info", "captin the url creatlist: " + url);
+		HttpGet get = new HttpGet(url);
 		ArrayList<ContainerObjects> files = new ArrayList<ContainerObjects>();
 		
 		
@@ -107,7 +115,9 @@ public class ContainerObjectManager extends EntityManager {
 	public HttpBundle deleteObject(String Container, String Object) throws CloudServersException {
 		HttpResponse resp = null;
 		CustomHttpClient httpclient = new CustomHttpClient(context);
-		HttpDelete deleteObject = new HttpDelete(Account.getAccount().getStorageUrl() + "/" + Container + "/" + Object);
+		String url = getSafeURL(Account.getAccount().getStorageUrl(), Container + "/" + Object);
+		HttpDelete deleteObject = new HttpDelete(url);
+		Log.d("info", "captin the url deleteobject: " + url);
 				
 		deleteObject.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
 		httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class);
@@ -137,8 +147,9 @@ public class ContainerObjectManager extends EntityManager {
 	public HttpBundle getObject(String Container, String Object) throws CloudServersException {
 		HttpResponse resp = null;
 		CustomHttpClient httpclient = new CustomHttpClient(context);
-		HttpGet getObject = new HttpGet(Account.getAccount().getStorageUrl() + "/" + Container + "/" + Object);
-				
+		String url = getSafeURL(Account.getAccount().getStorageUrl(), Container + "/" + Object);
+		HttpGet getObject = new HttpGet(url);
+		Log.d("info", "captin the url getobject: " + url);		
 		getObject.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
 		httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class);
 
@@ -167,8 +178,10 @@ public class ContainerObjectManager extends EntityManager {
 	public HttpBundle addObject(String Container, String Path, String Object, String type) throws CloudServersException {
 		HttpResponse resp = null;
 		CustomHttpClient httpclient = new CustomHttpClient(context);
-		HttpPut addObject = new HttpPut(Account.getAccount().getStorageUrl() + "/" + Container + "/" + Path + Object);
-				
+		String url = getSafeURL(Account.getAccount().getStorageUrl(), Container + "/" + Path + Object);
+		HttpPut addObject = new HttpPut(url);
+		Log.d("info", "captin the url addobject: " + url);
+		
 		addObject.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
 		addObject.addHeader("Content-Type", type);
 		httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class);
@@ -202,12 +215,24 @@ public class ContainerObjectManager extends EntityManager {
 	public HttpBundle addObject(String Container, String Path, String Object, String type, String data) throws CloudServersException {
 		HttpResponse resp = null;
 		CustomHttpClient httpclient = new CustomHttpClient(context);
-		HttpPut addObject = new HttpPut(Account.getAccount().getStorageUrl() + "/" + Container + "/" + Path + Object);
+		String url = getSafeURL(Account.getAccount().getStorageUrl(), Container + "/" + Path + Object);
+		HttpPut addObject = new HttpPut(url);
+		Log.d("info", "captin the url addobject2: " + url);
 				
 		addObject.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
 		addObject.addHeader("Content-Type", type);
 		httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class);
 
+		StringEntity tmp = null;
+		try {
+			tmp = new StringEntity(data);
+		} catch (UnsupportedEncodingException e) {
+			CloudServersException cse = new CloudServersException();
+			cse.setMessage(e.getLocalizedMessage());
+			throw cse;
+		}
+		addObject.setEntity(tmp);
+		
 		HttpBundle bundle = new HttpBundle();
 		bundle.setCurlRequest(addObject);
 		
@@ -229,5 +254,23 @@ public class ContainerObjectManager extends EntityManager {
 		}	
 		return bundle;
 	}
+	
+	private String getSafeURL(String badURL, String name){
+		URI uri = null;
+		try {
+			uri = new URI("https", badURL.substring(8), "/" + name + "/", "");
+		} catch (URISyntaxException e1) {
+			// TODO Auto-generated catch block
+			e1.printStackTrace();
+		}
+		String url = null;
+		try {
+			url = uri.toURL().toString();
+		} catch (MalformedURLException e1) {
+			// TODO Auto-generated catch block
+			e1.printStackTrace();
+		}
+		return url.substring(0, url.length()-2);
+	}
 
 }
\ No newline at end of file
diff --git a/src/com/rackspace/cloud/servers/api/client/ServerManager.java b/src/com/rackspace/cloud/servers/api/client/ServerManager.java
index 4fb802d..2255530 100644
--- a/src/com/rackspace/cloud/servers/api/client/ServerManager.java
+++ b/src/com/rackspace/cloud/servers/api/client/ServerManager.java
@@ -27,6 +27,7 @@ import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
 
 import android.content.Context;
+import android.util.Log;
 
 import com.rackspace.cloud.files.api.client.CustomHttpClient;
 import com.rackspace.cloud.servers.api.client.http.HttpBundle;
@@ -264,6 +265,7 @@ public class ServerManager extends EntityManager {
 
 		StringEntity tmp = null;
 		try {
+			Log.d("info", "captin the flavor id is " + flavorId);
 			tmp = new StringEntity("<resize xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" flavorId=\"" + flavorId + "\"/>");
 		} catch (UnsupportedEncodingException e) {
 			CloudServersException cse = new CloudServersException();
diff --git a/src/com/rackspacecloud/android/AddFileActivity.java b/src/com/rackspacecloud/android/AddFileActivity.java
index b8b50e8..27cea0e 100644
--- a/src/com/rackspacecloud/android/AddFileActivity.java
+++ b/src/com/rackspacecloud/android/AddFileActivity.java
@@ -145,13 +145,13 @@ public class AddFileActivity extends Activity implements OnClickListener{
 				} else {
 					CloudServersException cse = parseCloudServersException(response);
 					if ("".equals(cse.getMessage())) {
-						startFileError("There was a problem creating your container.", bundle);
+						startFileError("There was a problem creating your file.", bundle);
 					} else {
-						startFileError("There was a problem creating your container: " + cse.getMessage() + " Check container name and try again", bundle);
+						startFileError("There was a problem creating your file: " + cse.getMessage() + " Check file name and try again", bundle);
 					}
 				}
 			} else if (exception != null) {
-				startFileError("There was a problem creating your container: " + exception.getMessage()+" Check container name and try again", bundle);				
+				startFileError("There was a problem creating your file: " + exception.getMessage()+" Check file name and try again", bundle);				
 			}			
 		}
     }
diff --git a/src/com/rackspacecloud/android/ContainerObjectDetails.java b/src/com/rackspacecloud/android/ContainerObjectDetails.java
index c088a3a..c1e3362 100644
--- a/src/com/rackspacecloud/android/ContainerObjectDetails.java
+++ b/src/com/rackspacecloud/android/ContainerObjectDetails.java
@@ -35,6 +35,7 @@ import android.net.Uri;
 import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.Environment;
+import android.util.Log;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
@@ -311,6 +312,8 @@ public class ContainerObjectDetails extends Activity {
 	    File file = new File(object.getAbsolutePath()); 
 	    String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString());
 	    String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
+	    Log.d("info", "captin the file name is " + object.getName());
+	    Log.d("info", "captin the uri is " + Uri.fromFile(object).toString());
 	    myIntent.setDataAndType(Uri.fromFile(file),mimetype);
 	    startActivity(myIntent);
 	}
diff --git a/src/com/rackspacecloud/android/ContainerObjectsActivity.java b/src/com/rackspacecloud/android/ContainerObjectsActivity.java
index 87d7a81..abe0954 100644
--- a/src/com/rackspacecloud/android/ContainerObjectsActivity.java
+++ b/src/com/rackspacecloud/android/ContainerObjectsActivity.java
@@ -235,7 +235,7 @@ public class ContainerObjectsActivity extends ListActivity {
 				fileNames[i] = file.getName();
 			}
 		}
-		
+				
 		displayCurrentFiles();
 	}
 	
@@ -612,6 +612,7 @@ public class ContainerObjectsActivity extends ListActivity {
 			if (exception != null) {
 				showAlert("Error", exception.getMessage());
 			}
+			Log.d("info", "captin the length of the fiels is " + result.size());
 			setFileList(result);
 			loadingFiles = false;
 		}
diff --git a/src/com/rackspacecloud/android/ListAccountsActivity.java b/src/com/rackspacecloud/android/ListAccountsActivity.java
index 48309c7..1770d5a 100644
--- a/src/com/rackspacecloud/android/ListAccountsActivity.java
+++ b/src/com/rackspacecloud/android/ListAccountsActivity.java
@@ -46,13 +46,17 @@ import android.widget.Toast;
 
 public class ListAccountsActivity extends ListActivity{
 
-	private ArrayList<Account> accounts;
+	private final int PASSWORD_PROMPT = 123;
 	private final String FILENAME = "accounts.data";
-	private Intent tabViewIntent;
+	
 	private boolean authenticating;
+	private ArrayList<Account> accounts;
+	private Intent tabViewIntent;
 	private ProgressDialog dialog;
 	private Context context;
-	private final int PASSWORD_PROMPT = 123;
+	
+	//need to store if the user has successfully logged in
+	private boolean loggedIn;
 
 
 	public void onCreate(Bundle savedInstanceState) {
@@ -69,6 +73,7 @@ public class ListAccountsActivity extends ListActivity{
 	protected void onSaveInstanceState(Bundle outState) {
 		super.onSaveInstanceState(outState);
 		outState.putBoolean("authenticating", authenticating);
+		outState.putBoolean("loggedIn", loggedIn);
 		//need to set authenticating back to true because it is set to false
 		//in hideDialog()
 		if(authenticating){
@@ -80,6 +85,12 @@ public class ListAccountsActivity extends ListActivity{
 	
 	@Override
 	protected void onRestoreInstanceState(Bundle state) {
+		if (state != null && state.containsKey("loggedIn")){
+			loggedIn = state.getBoolean("loggedIn");
+		}
+		else{
+			loggedIn = false;
+		}
 		if (state != null && state.containsKey("authenticating") && state.getBoolean("authenticating")) {
     		showDialog();
     	} else {
@@ -123,7 +134,7 @@ public class ListAccountsActivity extends ListActivity{
 	private void verifyPassword(){
 		PasswordManager pwManager = new PasswordManager(getSharedPreferences(
 				Preferences.SHARED_PREFERENCES_NAME, MODE_PRIVATE));
-		if(pwManager.hasPassword()){
+		if(pwManager.hasPassword() && !loggedIn){
 			createCustomDialog(PASSWORD_PROMPT);
 		}
 	}
@@ -153,9 +164,11 @@ public class ListAccountsActivity extends ListActivity{
 					if(!rightPassword(passwordText.getText().toString())){
 						passwordText.setText("");
 						showToast("Password was incorrect.");
+						loggedIn = false;
 					}
 					else{
 						dialog.dismiss();
+						loggedIn = true;
 					}
 				}
 				
diff --git a/src/com/rackspacecloud/android/ViewServerActivity.java b/src/com/rackspacecloud/android/ViewServerActivity.java
index 345ee6d..c8c5d0a 100644
--- a/src/com/rackspacecloud/android/ViewServerActivity.java
+++ b/src/com/rackspacecloud/android/ViewServerActivity.java
@@ -29,6 +29,7 @@ import android.content.Intent;
 import android.graphics.Color;
 import android.os.AsyncTask;
 import android.os.Bundle;
+import android.util.Log;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.Button;
@@ -338,6 +339,14 @@ public class ViewServerActivity extends Activity {
 		viewIntent.putExtra("request", bundle.getCurlRequest());
 		startActivity(viewIntent);
 	}
+	
+	private String prints(Object[] arr){
+		String result = "";
+		for(int i = 0; i < arr.length; i++){
+			result += arr[i] + " ";
+		}
+		return result;
+	}
 
 	@Override
 	protected Dialog onCreateDialog(int id) {
@@ -390,6 +399,7 @@ public class ViewServerActivity extends Activity {
 				})
 				.create();
 			case R.id.view_server_resize_button:
+				Log.d("info", "the flavor names are " + prints(flavorNames));
 				return new AlertDialog.Builder(ViewServerActivity.this)
 				.setItems(flavorNames, new ResizeClickListener())
 				.setIcon(R.drawable.alert_dialog_icon)
@@ -466,7 +476,8 @@ public class ViewServerActivity extends Activity {
 	private class ResizeClickListener implements android.content.DialogInterface.OnClickListener {
 
 		public void onClick(DialogInterface dialog, int which) {
-			selectedFlavorId = which + "";
+			//need to add one because server flavors state at index 1
+			selectedFlavorId = which + 1 + "";
 			new ResizeServerTask().execute((Void[]) null);
 		}
 
