mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-28 00:48:50 +00:00 
			
		
		
		
	Merge pull request #34 from owncloud/update_error_messages_for_non_permitted_actions
Added error codes and controls for non permitted actions
This commit is contained in:
		
						commit
						6b155fb802
					
				| @ -33,3 +33,4 @@ | ||||
|         android:targetSdkVersion="19" /> | ||||
| 
 | ||||
| </manifest> | ||||
| 
 | ||||
|  | ||||
| @ -43,14 +43,13 @@ import org.apache.commons.httpclient.params.HttpMethodParams; | ||||
| import org.apache.http.HttpStatus; | ||||
| import org.apache.http.params.CoreProtocolPNames; | ||||
| 
 | ||||
| import android.net.Uri; | ||||
| import android.util.Log; | ||||
| 
 | ||||
| import com.owncloud.android.lib.common.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials; | ||||
| import com.owncloud.android.lib.common.accounts.AccountUtils; | ||||
| import com.owncloud.android.lib.common.network.WebdavUtils; | ||||
| 
 | ||||
| 
 | ||||
| import android.net.Uri; | ||||
| import android.util.Log; | ||||
| 
 | ||||
| public class OwnCloudClient extends HttpClient { | ||||
| 	 | ||||
|     private static final String TAG = OwnCloudClient.class.getSimpleName(); | ||||
| @ -88,7 +87,7 @@ public class OwnCloudClient extends HttpClient { | ||||
|         		HttpVersion.HTTP_1_1); | ||||
|          | ||||
|         getParams().setCookiePolicy( | ||||
|         		CookiePolicy.BROWSER_COMPATIBILITY);	// to keep sessions | ||||
|         		CookiePolicy.IGNORE_COOKIES); | ||||
|         getParams().setParameter( | ||||
|         		PARAM_SINGLE_COOKIE_HEADER, 			// to avoid problems with some web servers | ||||
|         		PARAM_SINGLE_COOKIE_HEADER_VALUE); | ||||
| @ -189,8 +188,8 @@ public class OwnCloudClient extends HttpClient { | ||||
| 	        Log.d(TAG + " #" + mInstanceNumber, "REQUEST " +  | ||||
| 	        		method.getName() + " " + method.getPath()); | ||||
|          | ||||
| 	        logCookiesAtRequest(method.getRequestHeaders(), "before"); | ||||
| 	        logCookiesAtState("before"); | ||||
| //	        logCookiesAtRequest(method.getRequestHeaders(), "before"); | ||||
| //	        logCookiesAtState("before"); | ||||
| 	         | ||||
| 	        int status = super.executeMethod(method); | ||||
|          | ||||
| @ -198,9 +197,9 @@ public class OwnCloudClient extends HttpClient { | ||||
| 	        	status = patchRedirection(status, method); | ||||
| 	        } | ||||
| 
 | ||||
| 	        logCookiesAtRequest(method.getRequestHeaders(), "after"); | ||||
| 	        logCookiesAtState("after"); | ||||
| 	        logSetCookiesAtResponse(method.getResponseHeaders()); | ||||
| //	        logCookiesAtRequest(method.getRequestHeaders(), "after"); | ||||
| //	        logCookiesAtState("after"); | ||||
| //	        logSetCookiesAtResponse(method.getResponseHeaders()); | ||||
| 	         | ||||
| 	        return status; | ||||
| 	         | ||||
| @ -348,17 +347,17 @@ public class OwnCloudClient extends HttpClient { | ||||
|          | ||||
| 	} | ||||
| 	 | ||||
| 	public String getCookiesString(){ | ||||
| 		Cookie[] cookies = getState().getCookies();  | ||||
| 		String cookiesString =""; | ||||
| 		for (Cookie cookie: cookies) { | ||||
| 	public String getCookiesString() { | ||||
| 		Cookie[] cookies = getState().getCookies(); | ||||
| 		String cookiesString = ""; | ||||
| 		for (Cookie cookie : cookies) { | ||||
| 			cookiesString = cookiesString + cookie.toString() + ";"; | ||||
| 			 | ||||
| 			logCookie(cookie); | ||||
| 
 | ||||
| 			// logCookie(cookie); | ||||
| 		} | ||||
| 		 | ||||
| 
 | ||||
| 		return cookiesString; | ||||
| 		 | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	public int getConnectionTimeout() { | ||||
|  | ||||
| @ -29,6 +29,8 @@ import java.util.HashMap; | ||||
| import java.util.Iterator; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| import org.apache.commons.httpclient.cookie.CookiePolicy; | ||||
| 
 | ||||
| import android.accounts.Account; | ||||
| import android.accounts.AuthenticatorException; | ||||
| import android.accounts.OperationCanceledException; | ||||
| @ -102,6 +104,9 @@ public class SingleSessionManager implements OwnCloudClientManager { | ||||
|     				account.getBaseUri(),  | ||||
|     				context.getApplicationContext(),  | ||||
|     				true);	// TODO remove dependency on OwnCloudClientFactory | ||||
|             client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); | ||||
|             	// enable cookie tracking | ||||
|              | ||||
|     		 | ||||
|     		// Restore Cookies ?? | ||||
|     		AccountUtils.restoreCookies(accountName, client, context);		 | ||||
|  | ||||
| @ -29,11 +29,6 @@ import java.io.IOException; | ||||
| 
 | ||||
| import org.apache.commons.httpclient.Cookie; | ||||
| 
 | ||||
| import com.owncloud.android.lib.common.OwnCloudClient; | ||||
| import com.owncloud.android.lib.common.OwnCloudCredentials; | ||||
| import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; | ||||
| import com.owncloud.android.lib.resources.status.OwnCloudVersion; | ||||
| 
 | ||||
| import android.accounts.Account; | ||||
| import android.accounts.AccountManager; | ||||
| import android.accounts.AccountsException; | ||||
| @ -43,6 +38,11 @@ import android.content.Context; | ||||
| import android.net.Uri; | ||||
| import android.util.Log; | ||||
| 
 | ||||
| import com.owncloud.android.lib.common.OwnCloudClient; | ||||
| import com.owncloud.android.lib.common.OwnCloudCredentials; | ||||
| import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; | ||||
| import com.owncloud.android.lib.resources.status.OwnCloudVersion; | ||||
| 
 | ||||
| public class AccountUtils { | ||||
| 	 | ||||
| 	private static final String TAG = AccountUtils.class.getSimpleName(); | ||||
| @ -220,7 +220,7 @@ public class AccountUtils { | ||||
| 			String cookiesString = client.getCookiesString(); | ||||
| 			if (cookiesString != "") { | ||||
| 				ac.setUserData(savedAccount, Constants.KEY_COOKIES, cookiesString);  | ||||
| 				Log.d(TAG, "Saving Cookies: "+ cookiesString ); | ||||
| 				// Log.d(TAG, "Saving Cookies: "+ cookiesString ); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
|  | ||||
| @ -35,32 +35,30 @@ import android.net.Uri; | ||||
| public class WebdavUtils { | ||||
|     public static final SimpleDateFormat DISPLAY_DATE_FORMAT = new SimpleDateFormat( | ||||
|             "dd.MM.yyyy hh:mm"); | ||||
|     private static final String DATETIME_FORMATS[] = { | ||||
|             "yyyy-MM-dd'T'HH:mm:ss'Z'", | ||||
|             "EEE, dd MMM yyyy HH:mm:ss zzz", | ||||
|             "yyyy-MM-dd'T'HH:mm:ss.sss'Z'", | ||||
|             "yyyy-MM-dd'T'HH:mm:ssZ", | ||||
|             "EEE MMM dd HH:mm:ss zzz yyyy", | ||||
|             "EEEEEE, dd-MMM-yy HH:mm:ss zzz", | ||||
|             "EEE MMMM d HH:mm:ss yyyy", | ||||
|             "yyyy-MM-dd hh:mm:ss" }; | ||||
| 
 | ||||
|     public static String prepareXmlForPropFind() { | ||||
|         String ret = "<?xml version=\"1.0\" ?><D:propfind xmlns:D=\"DAV:\"><D:allprop/></D:propfind>"; | ||||
|         return ret; | ||||
|     } | ||||
| 
 | ||||
|     public static String prepareXmlForPatch() { | ||||
|         return "<?xml version=\"1.0\" ?><D:propertyupdate xmlns:D=\"DAV:\"></D:propertyupdate>"; | ||||
|     } | ||||
|      | ||||
|     private static final SimpleDateFormat DATETIME_FORMATS[] = { | ||||
|     	new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US), | ||||
|     	new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),	 | ||||
| 		new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sss'Z'", Locale.US), | ||||
| 		new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US), | ||||
| 		new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US), | ||||
| 		new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US), | ||||
| 		new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US), | ||||
| 		new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.US) | ||||
| 	}; | ||||
| 
 | ||||
|     public static Date parseResponseDate(String date) { | ||||
|         Date returnDate = null; | ||||
|         SimpleDateFormat format = null; | ||||
|         for (int i = 0; i < DATETIME_FORMATS.length; ++i) { | ||||
|             try { | ||||
|                 returnDate = new SimpleDateFormat (DATETIME_FORMATS[i], Locale.US).parse(date); | ||||
|             	format = DATETIME_FORMATS[i]; | ||||
|             	synchronized(format) { | ||||
|             		returnDate = format.parse(date); | ||||
|             	} | ||||
|                 return returnDate; | ||||
|             } catch (ParseException e) { | ||||
|             	// this is not the format | ||||
|             } | ||||
|         } | ||||
|         return null; | ||||
|  | ||||
| @ -41,13 +41,13 @@ import org.apache.commons.httpclient.HttpStatus; | ||||
| import org.apache.jackrabbit.webdav.DavException; | ||||
| import org.json.JSONException; | ||||
| 
 | ||||
| import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; | ||||
| import com.owncloud.android.lib.common.network.CertificateCombinedException; | ||||
| 
 | ||||
| import android.accounts.Account; | ||||
| import android.accounts.AccountsException; | ||||
| import android.util.Log; | ||||
| 
 | ||||
| import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; | ||||
| import com.owncloud.android.lib.common.network.CertificateCombinedException; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * The result of a remote operation required to an ownCloud server. | ||||
| @ -98,7 +98,9 @@ public class RemoteOperationResult implements Serializable { | ||||
|         ACCOUNT_NOT_THE_SAME, | ||||
|         INVALID_CHARACTER_IN_NAME, | ||||
|         SHARE_NOT_FOUND, | ||||
|         LOCAL_STORAGE_NOT_REMOVED | ||||
| 		LOCAL_STORAGE_NOT_REMOVED, | ||||
| 		FORBIDDEN, | ||||
| 		SHARE_FORBIDDEN | ||||
|     } | ||||
| 
 | ||||
|     private boolean mSuccess = false; | ||||
| @ -140,6 +142,9 @@ public class RemoteOperationResult implements Serializable { | ||||
|             case HttpStatus.SC_INSUFFICIENT_STORAGE: | ||||
|                 mCode = ResultCode.QUOTA_EXCEEDED; | ||||
|                 break; | ||||
| 			case HttpStatus.SC_FORBIDDEN: | ||||
| 				mCode = ResultCode.FORBIDDEN; | ||||
| 				break; | ||||
|             default: | ||||
|                 mCode = ResultCode.UNHANDLED_HTTP_CODE; | ||||
|                 Log.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + httpCode); | ||||
|  | ||||
| @ -142,6 +142,9 @@ public class CreateRemoteShareOperation extends RemoteOperation { | ||||
| 				} else if (xmlParser.isFileNotFound()){ | ||||
| 					result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND); | ||||
| 					 | ||||
| 				} else if (xmlParser.isFailure()) { | ||||
| 					result = new RemoteOperationResult(ResultCode.SHARE_FORBIDDEN); | ||||
| 
 | ||||
| 				} else { | ||||
| 					result = new RemoteOperationResult(false, status, post.getResponseHeaders());	 | ||||
| 				} | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user