mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 10:27:45 +00:00 
			
		
		
		
	Keep http phrase in RemoteOperationResult as last chance for a detailed user message
This commit is contained in:
		
							parent
							
								
									67665b8691
								
							
						
					
					
						commit
						14d646ea1d
					
				| @ -45,6 +45,7 @@ import com.owncloud.android.lib.common.utils.Log_OC; | ||||
| import org.apache.commons.httpclient.ConnectTimeoutException; | ||||
| import org.apache.commons.httpclient.Header; | ||||
| import org.apache.commons.httpclient.HttpException; | ||||
| import org.apache.commons.httpclient.HttpMethod; | ||||
| import org.apache.commons.httpclient.HttpStatus; | ||||
| import org.apache.jackrabbit.webdav.DavException; | ||||
| import org.json.JSONException; | ||||
| @ -63,9 +64,8 @@ import javax.net.ssl.SSLException; | ||||
| public class RemoteOperationResult implements Serializable { | ||||
| 
 | ||||
|     /** Generated - should be refreshed every time the class changes!! */ | ||||
|     ; | ||||
|     private static final long serialVersionUID = 4968939884332372230L; | ||||
| 
 | ||||
|     private static final long serialVersionUID = -1909603208238358633L; | ||||
|     private static final String TAG = RemoteOperationResult.class.getSimpleName(); | ||||
| 
 | ||||
|     public enum ResultCode { | ||||
| @ -120,6 +120,7 @@ public class RemoteOperationResult implements Serializable { | ||||
| 
 | ||||
|     private boolean mSuccess = false; | ||||
|     private int mHttpCode = -1; | ||||
|     private String mHttpPhrase = null; | ||||
|     private Exception mException = null; | ||||
|     private ResultCode mCode = ResultCode.UNKNOWN_ERROR; | ||||
|     private String mRedirectedLocation; | ||||
| @ -128,6 +129,13 @@ public class RemoteOperationResult implements Serializable { | ||||
| 
 | ||||
|     private ArrayList<Object> mData; | ||||
| 
 | ||||
|     /** | ||||
|      * Public constructor from result code. | ||||
|      * | ||||
|      * To be used when the caller takes the responsibility of interpreting the result of a {@link RemoteOperation} | ||||
|      * | ||||
|      * @param code      {@link ResultCode} decided by the caller. | ||||
|      */ | ||||
|     public RemoteOperationResult(ResultCode code) { | ||||
|         mCode = code; | ||||
|         mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL || | ||||
| @ -136,96 +144,15 @@ public class RemoteOperationResult implements Serializable { | ||||
|         mData = null; | ||||
|     } | ||||
| 
 | ||||
|     private RemoteOperationResult(boolean success, int httpCode) { | ||||
|         mSuccess = success; | ||||
|         mHttpCode = httpCode; | ||||
| 
 | ||||
|         if (success) { | ||||
|             mCode = ResultCode.OK; | ||||
| 
 | ||||
|         } else if (httpCode > 0) { | ||||
|             switch (httpCode) { | ||||
|                 case HttpStatus.SC_UNAUTHORIZED: | ||||
|                     mCode = ResultCode.UNAUTHORIZED; | ||||
|                     break; | ||||
|                 case HttpStatus.SC_NOT_FOUND: | ||||
|                     mCode = ResultCode.FILE_NOT_FOUND; | ||||
|                     break; | ||||
|                 case HttpStatus.SC_INTERNAL_SERVER_ERROR: | ||||
|                     mCode = ResultCode.INSTANCE_NOT_CONFIGURED; | ||||
|                     break; | ||||
|                 case HttpStatus.SC_CONFLICT: | ||||
|                     mCode = ResultCode.CONFLICT; | ||||
|                     break; | ||||
|                 case HttpStatus.SC_INSUFFICIENT_STORAGE: | ||||
|                     mCode = ResultCode.QUOTA_EXCEEDED; | ||||
|                     break; | ||||
|                 case HttpStatus.SC_FORBIDDEN: | ||||
|                     mCode = ResultCode.FORBIDDEN; | ||||
|                     break; | ||||
|                 case HttpStatus.SC_SERVICE_UNAVAILABLE: | ||||
|                     mCode = ResultCode.MAINTENANCE_MODE; | ||||
|                     break; | ||||
|                 default: | ||||
|                     mCode = ResultCode.UNHANDLED_HTTP_CODE; | ||||
|                     Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + | ||||
|                             httpCode); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public RemoteOperationResult(boolean success, int httpCode, Header[] headers) { | ||||
|         this(success, httpCode); | ||||
|         if (headers != null) { | ||||
|             Header current; | ||||
|             for (int i = 0; i < headers.length; i++) { | ||||
|                 current = headers[i]; | ||||
|                 if ("location".equals(current.getName().toLowerCase())) { | ||||
|                     mRedirectedLocation = current.getValue(); | ||||
|                     continue; | ||||
|                 } | ||||
|                 if ("www-authenticate".equals(current.getName().toLowerCase())) { | ||||
|                     mAuthenticate = current.getValue(); | ||||
|                     continue; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         if (isIdPRedirection()) { | ||||
|             mCode = ResultCode.UNAUTHORIZED;    // overrides default ResultCode.UNKNOWN | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public RemoteOperationResult(boolean success, String bodyResponse, int httpCode) { | ||||
|         mSuccess = success; | ||||
|         mHttpCode = httpCode; | ||||
| 
 | ||||
|         if (success) { | ||||
|             mCode = ResultCode.OK; | ||||
| 
 | ||||
|         } else if (httpCode > 0) { | ||||
|             switch (httpCode) { | ||||
|                 case HttpStatus.SC_BAD_REQUEST: | ||||
| 
 | ||||
|                     InputStream is = new ByteArrayInputStream(bodyResponse.getBytes()); | ||||
|                     InvalidCharacterExceptionParser xmlParser = new InvalidCharacterExceptionParser(); | ||||
|                     try { | ||||
|                         if (xmlParser.parseXMLResponse(is)) | ||||
|                             mCode = ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER; | ||||
| 
 | ||||
|                     } catch (Exception e) { | ||||
|                         mCode = ResultCode.UNHANDLED_HTTP_CODE; | ||||
|                         Log_OC.e(TAG, "Exception reading exception from server", e); | ||||
|                     } | ||||
|                     break; | ||||
|                 default: | ||||
|                     mCode = ResultCode.UNHANDLED_HTTP_CODE; | ||||
|                     Log_OC.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + | ||||
|                             httpCode); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Public constructor from exception. | ||||
|      * | ||||
|      * To be used when an exception prevented the end of the {@link RemoteOperation}. | ||||
|      * | ||||
|      * Determines a {@link ResultCode} depending on the type of the exception. | ||||
|      * | ||||
|      * @param e     Exception that interrupted the {@link RemoteOperation} | ||||
|      */ | ||||
|     public RemoteOperationResult(Exception e) { | ||||
|         mException = e; | ||||
| 
 | ||||
| @ -276,6 +203,133 @@ public class RemoteOperationResult implements Serializable { | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Public constructor from separate elements of an HTTP or DAV response. | ||||
|      * | ||||
|      * To be used when the result needs to be interpreted from the response of an HTTP/DAV method. | ||||
|      * | ||||
|      * Determines a {@link ResultCode} from the already executed method received as a parameter. Generally, | ||||
|      * will depend on the HTTP code and HTTP response headers received. In some cases will inspect also the | ||||
|      * response body. | ||||
|      * | ||||
|      * @param success       The operation was considered successful or not. | ||||
|      * @param httpMethod    HTTP/DAV method already executed which response will be examined to interpret the | ||||
|      *                      result. | ||||
|      */ | ||||
|     public RemoteOperationResult(boolean success, HttpMethod httpMethod) throws IOException { | ||||
|         this( | ||||
|             success, | ||||
|             httpMethod.getStatusCode(), | ||||
|             httpMethod.getStatusText(), | ||||
|             httpMethod.getResponseHeaders() | ||||
|         ); | ||||
| 
 | ||||
|         if (mHttpCode == HttpStatus.SC_BAD_REQUEST) {   // 400 | ||||
|             String bodyResponse = httpMethod.getResponseBodyAsString(); | ||||
|                 // do not get for other HTTP codes!; could not be available | ||||
| 
 | ||||
|             if (bodyResponse != null && bodyResponse.length() > 0) { | ||||
|                 InputStream is = new ByteArrayInputStream(bodyResponse.getBytes()); | ||||
|                 InvalidCharacterExceptionParser xmlParser = new InvalidCharacterExceptionParser(); | ||||
|                 try { | ||||
|                     if (xmlParser.parseXMLResponse(is)) { | ||||
|                         mCode = ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER; | ||||
|                     } | ||||
| 
 | ||||
|                 } catch (Exception e) { | ||||
|                     Log_OC.w(TAG, "Error reading exception from server: " + e.getMessage()); | ||||
|                     // mCode stays as set in this(success, httpCode, headers) | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Public constructor from separate elements of an HTTP or DAV response. | ||||
|      * | ||||
|      * To be used when the result needs to be interpreted from HTTP response elements that could come from | ||||
|      * different requests (WARNING: black magic, try to avoid). | ||||
|      * | ||||
|      * If all the fields come from the same HTTP/DAV response, {@link #RemoteOperationResult(boolean, HttpMethod)} | ||||
|      * should be used instead. | ||||
|      * | ||||
|      * Determines a {@link ResultCode} depending on the HTTP code and HTTP response headers received. | ||||
|      * | ||||
|      * @param success       The operation was considered successful or not. | ||||
|      * @param httpCode      HTTP status code returned by an HTTP/DAV method. | ||||
|      * @param httpPhrase    HTTP status line phrase returned by an HTTP/DAV method | ||||
|      * @param httpHeaders   HTTP response header returned by an HTTP/DAV method | ||||
|      */ | ||||
|     public RemoteOperationResult(boolean success, int httpCode, String httpPhrase, Header[] httpHeaders) { | ||||
|         this(success, httpCode, httpPhrase); | ||||
|         if (httpHeaders != null) { | ||||
|             Header current; | ||||
|             for (Header httpHeader : httpHeaders) { | ||||
|                 current = httpHeader; | ||||
|                 if ("location".equals(current.getName().toLowerCase())) { | ||||
|                     mRedirectedLocation = current.getValue(); | ||||
|                     continue; | ||||
|                 } | ||||
|                 if ("www-authenticate".equals(current.getName().toLowerCase())) { | ||||
|                     mAuthenticate = current.getValue(); | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         if (isIdPRedirection()) { | ||||
|             mCode = ResultCode.UNAUTHORIZED;    // overrides default ResultCode.UNKNOWN | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Private constructor for results built interpreting a HTTP or DAV response. | ||||
|      * | ||||
|      * Determines a {@link ResultCode} depending of the type of the exception. | ||||
|      * | ||||
|      * @param success       Operation was successful or not. | ||||
|      * @param httpCode      HTTP status code returned by the HTTP/DAV method. | ||||
|      * @param httpPhrase    HTTP status line phrase returned by the HTTP/DAV method | ||||
|      */ | ||||
|     private RemoteOperationResult(boolean success, int httpCode, String httpPhrase) { | ||||
|         mSuccess = success; | ||||
|         mHttpCode = httpCode; | ||||
|         mHttpPhrase = httpPhrase; | ||||
| 
 | ||||
|         if (success) { | ||||
|             mCode = ResultCode.OK; | ||||
| 
 | ||||
|         } else if (httpCode > 0) { | ||||
|             switch (httpCode) { | ||||
|                 case HttpStatus.SC_UNAUTHORIZED:                    // 401 | ||||
|                     mCode = ResultCode.UNAUTHORIZED; | ||||
|                     break; | ||||
|                 case HttpStatus.SC_FORBIDDEN:                       // 403 | ||||
|                     mCode = ResultCode.FORBIDDEN; | ||||
|                     break; | ||||
|                 case HttpStatus.SC_NOT_FOUND:                       // 404 | ||||
|                     mCode = ResultCode.FILE_NOT_FOUND; | ||||
|                     break; | ||||
|                 case HttpStatus.SC_CONFLICT:                        // 409 | ||||
|                     mCode = ResultCode.CONFLICT; | ||||
|                     break; | ||||
|                 case HttpStatus.SC_INTERNAL_SERVER_ERROR:           // 500 | ||||
|                     mCode = ResultCode.INSTANCE_NOT_CONFIGURED;     // assuming too much... | ||||
|                     break; | ||||
|                 case HttpStatus.SC_SERVICE_UNAVAILABLE:             // 503 | ||||
|                     mCode = ResultCode.MAINTENANCE_MODE; | ||||
|                     break; | ||||
|                 case HttpStatus.SC_INSUFFICIENT_STORAGE:            // 507 | ||||
|                     mCode = ResultCode.QUOTA_EXCEEDED;              // surprise! | ||||
|                     break; | ||||
|                 default: | ||||
|                     mCode = ResultCode.UNHANDLED_HTTP_CODE;         // UNKNOWN ERROR | ||||
|                     Log_OC.d(TAG, | ||||
|                         "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + | ||||
|                         mHttpCode + " " + mHttpPhrase | ||||
|                     ); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public void setData(ArrayList<Object> files) { | ||||
|         mData = files; | ||||
| @ -297,6 +351,10 @@ public class RemoteOperationResult implements Serializable { | ||||
|         return mHttpCode; | ||||
|     } | ||||
| 
 | ||||
|     public String getHttpPhrase() { | ||||
|         return mHttpPhrase; | ||||
|     } | ||||
| 
 | ||||
|     public ResultCode getCode() { | ||||
|         return mCode; | ||||
|     } | ||||
|  | ||||
| @ -39,6 +39,7 @@ import com.owncloud.android.lib.common.network.ChunkFromFileChannelRequestEntity | ||||
| import com.owncloud.android.lib.common.network.ProgressiveDataTransferer; | ||||
| import com.owncloud.android.lib.common.network.WebdavUtils; | ||||
| import com.owncloud.android.lib.common.operations.InvalidCharacterExceptionParser; | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult; | ||||
| import com.owncloud.android.lib.common.utils.Log_OC; | ||||
| 
 | ||||
| 
 | ||||
| @ -53,20 +54,21 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation | ||||
|     private static final String TAG = ChunkedUploadRemoteFileOperation.class.getSimpleName(); | ||||
| 
 | ||||
|     public ChunkedUploadRemoteFileOperation(String storagePath, String remotePath, String mimeType, | ||||
|                                             String fileLastModifTimestamp){ | ||||
|                                             String fileLastModifTimestamp) { | ||||
|         super(storagePath, remotePath, mimeType, fileLastModifTimestamp); | ||||
|     } | ||||
| 
 | ||||
|     public ChunkedUploadRemoteFileOperation( | ||||
|             String storagePath, String remotePath, String mimeType, String requiredEtag, | ||||
|             String fileLastModifTimestamp | ||||
|     ){ | ||||
| 		 super(storagePath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp); | ||||
| 	} | ||||
|         String storagePath, String remotePath, String mimeType, String requiredEtag, | ||||
|         String fileLastModifTimestamp | ||||
|     ) { | ||||
|         super(storagePath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected int uploadFile(OwnCloudClient client) throws IOException { | ||||
|     protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOException { | ||||
|         int status = -1; | ||||
|         RemoteOperationResult result = null; | ||||
| 
 | ||||
|         FileChannel channel = null; | ||||
|         RandomAccessFile raf = null; | ||||
| @ -76,24 +78,24 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation | ||||
|             channel = raf.getChannel(); | ||||
|             mEntity = new ChunkFromFileChannelRequestEntity(channel, mMimeType, CHUNK_SIZE, file); | ||||
|             synchronized (mDataTransferListeners) { | ||||
| 				((ProgressiveDataTransferer)mEntity) | ||||
|                         .addDatatransferProgressListeners(mDataTransferListeners); | ||||
| 			} | ||||
|                 ((ProgressiveDataTransferer) mEntity) | ||||
|                     .addDatatransferProgressListeners(mDataTransferListeners); | ||||
|             } | ||||
| 
 | ||||
|             long offset = 0; | ||||
|             String uriPrefix = client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath) + | ||||
|                     "-chunking-" + Math.abs((new Random()).nextInt(9000)+1000) + "-" ; | ||||
|                 "-chunking-" + Math.abs((new Random()).nextInt(9000) + 1000) + "-"; | ||||
|             long totalLength = file.length(); | ||||
|             long chunkCount = (long) Math.ceil((double)totalLength / CHUNK_SIZE); | ||||
|             long chunkCount = (long) Math.ceil((double) totalLength / CHUNK_SIZE); | ||||
|             String chunkSizeStr = String.valueOf(CHUNK_SIZE); | ||||
|             String totalLengthStr = String.valueOf(file.length()); | ||||
|             for (int chunkIndex = 0; chunkIndex < chunkCount ; chunkIndex++, offset += CHUNK_SIZE) { | ||||
|             for (int chunkIndex = 0; chunkIndex < chunkCount; chunkIndex++, offset += CHUNK_SIZE) { | ||||
|                 if (chunkIndex == chunkCount - 1) { | ||||
|                     chunkSizeStr = String.valueOf(CHUNK_SIZE * chunkCount - totalLength); | ||||
|                 } | ||||
|                 if (mPutMethod != null) { | ||||
|                     mPutMethod.releaseConnection();     // let the connection available | ||||
|                                                         // for other methods | ||||
|                     // for other methods | ||||
|                 } | ||||
|                 mPutMethod = new PutMethod(uriPrefix + chunkCount + "-" + chunkIndex); | ||||
|                 if (mRequiredEtag != null && mRequiredEtag.length() > 0) { | ||||
| @ -121,24 +123,15 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation | ||||
| 
 | ||||
|                 status = client.executeMethod(mPutMethod); | ||||
| 
 | ||||
|                 if (status == 400) { | ||||
|                     InvalidCharacterExceptionParser xmlParser = | ||||
|                             new InvalidCharacterExceptionParser(); | ||||
|                     InputStream is = new ByteArrayInputStream( | ||||
|                             mPutMethod.getResponseBodyAsString().getBytes()); | ||||
|                     try { | ||||
|                         mForbiddenCharsInServer = xmlParser.parseXMLResponse(is); | ||||
| 
 | ||||
|                     } catch (Exception e) { | ||||
|                         mForbiddenCharsInServer = false; | ||||
|                         Log_OC.e(TAG, "Exception reading exception from server", e); | ||||
|                     } | ||||
|                 } | ||||
|                 result = new RemoteOperationResult( | ||||
|                     isSuccess(status), | ||||
|                     mPutMethod | ||||
|                 ); | ||||
| 
 | ||||
|                 client.exhaustResponse(mPutMethod.getResponseBodyAsStream()); | ||||
|                 Log_OC.d(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + | ||||
|                         ", chunk index " + chunkIndex + ", count " + chunkCount + | ||||
|                         ", HTTP result status " + status); | ||||
|                     ", chunk index " + chunkIndex + ", count " + chunkCount + | ||||
|                     ", HTTP result status " + status); | ||||
| 
 | ||||
|                 if (!isSuccess(status)) | ||||
|                     break; | ||||
| @ -152,7 +145,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation | ||||
|             if (mPutMethod != null) | ||||
|                 mPutMethod.releaseConnection();    // let the connection available for other methods | ||||
|         } | ||||
|         return status; | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -129,15 +129,8 @@ public class CopyRemoteFileOperation extends RemoteOperation { | ||||
|                 /// for other errors that could be explicitly handled, check first: | ||||
|                 /// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 | ||||
| 
 | ||||
|             } else if (status == 400) { | ||||
|                 result = new RemoteOperationResult(copyMethod.succeeded(), | ||||
|                         copyMethod.getResponseBodyAsString(), status); | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult( | ||||
|                         isSuccess(status),    // copy.succeeded()? trustful? | ||||
|                         status, | ||||
|                         copyMethod.getResponseHeaders() | ||||
|                 ); | ||||
|                 result = new RemoteOperationResult(isSuccess(status), copyMethod); | ||||
|                 client.exhaustResponse(copyMethod.getResponseBodyAsStream()); | ||||
|             } | ||||
| 
 | ||||
| @ -196,11 +189,7 @@ public class CopyRemoteFileOperation extends RemoteOperation { | ||||
|         if (failFound) { | ||||
|             result = new RemoteOperationResult(ResultCode.PARTIAL_COPY_DONE); | ||||
|         } else { | ||||
|             result = new RemoteOperationResult( | ||||
|                     true, | ||||
|                     HttpStatus.SC_MULTI_STATUS, | ||||
|                     copyMethod.getResponseHeaders() | ||||
|             ); | ||||
|             result = new RemoteOperationResult(true, copyMethod); | ||||
|         } | ||||
| 
 | ||||
|         return result; | ||||
|  | ||||
| @ -40,7 +40,6 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion; | ||||
|  * | ||||
|  * @author David A. Velasco | ||||
|  * @author masensio | ||||
|  * | ||||
|  */ | ||||
| public class CreateRemoteFolderOperation extends RemoteOperation { | ||||
| 
 | ||||
| @ -56,9 +55,9 @@ public class CreateRemoteFolderOperation extends RemoteOperation { | ||||
|     /** | ||||
|      * Constructor | ||||
|      * | ||||
|      * @param remotePath            Full path to the new directory to create in the remote server. | ||||
|      * @param createFullPath        'True' means that all the ancestor folders should be created | ||||
|      *                              if don't exist yet. | ||||
|      * @param remotePath     Full path to the new directory to create in the remote server. | ||||
|      * @param createFullPath 'True' means that all the ancestor folders should be created | ||||
|      *                       if don't exist yet. | ||||
|      */ | ||||
|     public CreateRemoteFolderOperation(String remotePath, boolean createFullPath) { | ||||
|         mRemotePath = remotePath; | ||||
| @ -68,27 +67,27 @@ public class CreateRemoteFolderOperation extends RemoteOperation { | ||||
|     /** | ||||
|      * Performs the operation | ||||
|      * | ||||
|      * @param   client      Client object to communicate with the remote ownCloud server. | ||||
|      * @param client Client object to communicate with the remote ownCloud server. | ||||
|      */ | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result = null; | ||||
|         OwnCloudVersion version = client.getOwnCloudVersion(); | ||||
|         boolean versionWithForbiddenChars = | ||||
|                 (version != null && version.isVersionWithForbiddenCharacters()); | ||||
|             (version != null && version.isVersionWithForbiddenCharacters()); | ||||
|         boolean noInvalidChars = FileUtils.isValidPath(mRemotePath, versionWithForbiddenChars); | ||||
|         if (noInvalidChars) { | ||||
|         	result = createFolder(client); | ||||
|     		if (!result.isSuccess() && mCreateFullPath &&  | ||||
|     				RemoteOperationResult.ResultCode.CONFLICT == result.getCode()) { | ||||
|     			result = createParentFolder(FileUtils.getParentPath(mRemotePath), client); | ||||
|     			if (result.isSuccess()) { | ||||
| 	    			result = createFolder(client);	// second (and last) try | ||||
|     			} | ||||
|     		} | ||||
|             result = createFolder(client); | ||||
|             if (!result.isSuccess() && mCreateFullPath && | ||||
|                 RemoteOperationResult.ResultCode.CONFLICT == result.getCode()) { | ||||
|                 result = createParentFolder(FileUtils.getParentPath(mRemotePath), client); | ||||
|                 if (result.isSuccess()) { | ||||
|                     result = createFolder(client);    // second (and last) try | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|         } else { | ||||
|         	result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); | ||||
|             result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); | ||||
|         } | ||||
| 
 | ||||
|         return result; | ||||
| @ -98,38 +97,29 @@ public class CreateRemoteFolderOperation extends RemoteOperation { | ||||
|     private RemoteOperationResult createFolder(OwnCloudClient client) { | ||||
|         RemoteOperationResult result = null; | ||||
|         MkColMethod mkcol = null; | ||||
|     	try { | ||||
|     		mkcol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); | ||||
|     		int status =  client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT); | ||||
|             if ( status == 400 ) { | ||||
|                 result = new RemoteOperationResult(mkcol.succeeded(), | ||||
|                         mkcol.getResponseBodyAsString(), status); | ||||
|                 Log_OC.d(TAG, mkcol.getResponseBodyAsString()); | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(mkcol.succeeded(), status, | ||||
|                         mkcol.getResponseHeaders()); | ||||
|                 Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage()); | ||||
|             } | ||||
|         try { | ||||
|             mkcol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); | ||||
|             client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT); | ||||
|             result = new RemoteOperationResult(mkcol.succeeded(), mkcol); | ||||
|             Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage()); | ||||
|             client.exhaustResponse(mkcol.getResponseBodyAsStream()); | ||||
| 
 | ||||
|     	} catch (Exception e) { | ||||
|     		result = new RemoteOperationResult(e); | ||||
|     		Log_OC.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e); | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             Log_OC.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e); | ||||
| 
 | ||||
|     	} finally { | ||||
|     		if (mkcol != null) | ||||
|     			mkcol.releaseConnection(); | ||||
|     	} | ||||
|     	return result; | ||||
| 	} | ||||
|         } finally { | ||||
|             if (mkcol != null) | ||||
|                 mkcol.releaseConnection(); | ||||
|         } | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
| 	private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client) { | ||||
|     private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client) { | ||||
|         RemoteOperation operation = new CreateRemoteFolderOperation(parentPath, | ||||
|                                                                 mCreateFullPath); | ||||
|             mCreateFullPath); | ||||
|         return operation.execute(client); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -56,9 +56,9 @@ import com.owncloud.android.lib.common.utils.Log_OC; | ||||
| 
 | ||||
| public class DownloadRemoteFileOperation extends RemoteOperation { | ||||
| 
 | ||||
| 	private static final String TAG = DownloadRemoteFileOperation.class.getSimpleName(); | ||||
|     private static final String TAG = DownloadRemoteFileOperation.class.getSimpleName(); | ||||
| 
 | ||||
| 	private Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>(); | ||||
|     private Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>(); | ||||
|     private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false); | ||||
|     private long mModificationTimestamp = 0; | ||||
|     private String mEtag = ""; | ||||
| @ -67,39 +67,38 @@ public class DownloadRemoteFileOperation extends RemoteOperation { | ||||
|     private String mRemotePath; | ||||
|     private String mLocalFolderPath; | ||||
| 
 | ||||
| 	public DownloadRemoteFileOperation(String remotePath, String localFolderPath) { | ||||
| 		mRemotePath = remotePath; | ||||
| 		mLocalFolderPath = localFolderPath; | ||||
| 	} | ||||
|     public DownloadRemoteFileOperation(String remotePath, String localFolderPath) { | ||||
|         mRemotePath = remotePath; | ||||
|         mLocalFolderPath = localFolderPath; | ||||
|     } | ||||
| 
 | ||||
| 	@Override | ||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { | ||||
| 		RemoteOperationResult result = null; | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result = null; | ||||
| 
 | ||||
|         /// download will be performed to a temporal file, then moved to the final location | ||||
|         File tmpFile = new File(getTmpPath()); | ||||
| 
 | ||||
|         /// perform the download | ||||
|         try { | ||||
|         	tmpFile.getParentFile().mkdirs(); | ||||
|         	int status = downloadFile(client, tmpFile); | ||||
|         	result = new RemoteOperationResult(isSuccess(status), status, | ||||
|                     (mGet != null ? mGet.getResponseHeaders() : null)); | ||||
|         	Log_OC.i(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + | ||||
|                     result.getLogMessage()); | ||||
|             tmpFile.getParentFile().mkdirs(); | ||||
|             int status = downloadFile(client, tmpFile); | ||||
|             result = new RemoteOperationResult(isSuccess(status), mGet); | ||||
|             Log_OC.i(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + | ||||
|                 result.getLogMessage()); | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             Log_OC.e(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + | ||||
|                     result.getLogMessage(), e); | ||||
|                 result.getLogMessage(), e); | ||||
|         } | ||||
| 
 | ||||
|         return result; | ||||
| 	} | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     protected int downloadFile(OwnCloudClient client, File targetFile) throws HttpException, | ||||
|             IOException, OperationCancelledException { | ||||
|         IOException, OperationCancelledException { | ||||
|         int status = -1; | ||||
|         boolean savedFile = false; | ||||
|         mGet = new GetMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); | ||||
| @ -116,13 +115,13 @@ public class DownloadRemoteFileOperation extends RemoteOperation { | ||||
| 
 | ||||
|                 Header contentLength = mGet.getResponseHeader("Content-Length"); | ||||
|                 long totalToTransfer = (contentLength != null && | ||||
|                         contentLength.getValue().length() >0) ? | ||||
|                         Long.parseLong(contentLength.getValue()) : 0; | ||||
|                     contentLength.getValue().length() > 0) ? | ||||
|                     Long.parseLong(contentLength.getValue()) : 0; | ||||
| 
 | ||||
|                 byte[] bytes = new byte[4096]; | ||||
|                 int readResult = 0; | ||||
|                 while ((readResult = bis.read(bytes)) != -1) { | ||||
|                     synchronized(mCancellationRequested) { | ||||
|                     synchronized (mCancellationRequested) { | ||||
|                         if (mCancellationRequested.get()) { | ||||
|                             mGet.abort(); | ||||
|                             throw new OperationCancelledException(); | ||||
| @ -134,20 +133,20 @@ public class DownloadRemoteFileOperation extends RemoteOperation { | ||||
|                         it = mDataTransferListeners.iterator(); | ||||
|                         while (it.hasNext()) { | ||||
|                             it.next().onTransferProgress(readResult, transferred, totalToTransfer, | ||||
|                                     targetFile.getName()); | ||||
|                                 targetFile.getName()); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|                 if (transferred == totalToTransfer) {  // Check if the file is completed | ||||
|                 	savedFile = true; | ||||
|                 	Header modificationTime = mGet.getResponseHeader("Last-Modified"); | ||||
|                     savedFile = true; | ||||
|                     Header modificationTime = mGet.getResponseHeader("Last-Modified"); | ||||
|                     if (modificationTime == null) { | ||||
|                         modificationTime = mGet.getResponseHeader("last-modified"); | ||||
|                     } | ||||
|                 	if (modificationTime != null) { | ||||
|                 		Date d = WebdavUtils.parseResponseDate((String) modificationTime.getValue()); | ||||
|                 		mModificationTimestamp = (d != null) ? d.getTime() : 0; | ||||
|                 	} else { | ||||
|                     if (modificationTime != null) { | ||||
|                         Date d = WebdavUtils.parseResponseDate((String) modificationTime.getValue()); | ||||
|                         mModificationTimestamp = (d != null) ? d.getTime() : 0; | ||||
|                     } else { | ||||
|                         Log_OC.e(TAG, "Could not read modification time from response downloading " + mRemotePath); | ||||
|                     } | ||||
| 
 | ||||
| @ -157,7 +156,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation { | ||||
|                     } | ||||
| 
 | ||||
|                 } else { | ||||
|                 	client.exhaustResponse(mGet.getResponseBodyAsStream()); | ||||
|                     client.exhaustResponse(mGet.getResponseBodyAsStream()); | ||||
|                     // TODO some kind of error control! | ||||
|                 } | ||||
| 
 | ||||
| @ -183,7 +182,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation { | ||||
|         return mLocalFolderPath + mRemotePath; | ||||
|     } | ||||
| 
 | ||||
|     public void addDatatransferProgressListener (OnDatatransferProgressListener listener) { | ||||
|     public void addDatatransferProgressListener(OnDatatransferProgressListener listener) { | ||||
|         synchronized (mDataTransferListeners) { | ||||
|             mDataTransferListeners.add(listener); | ||||
|         } | ||||
| @ -199,9 +198,9 @@ public class DownloadRemoteFileOperation extends RemoteOperation { | ||||
|         mCancellationRequested.set(true);   // atomic set; there is no need of synchronizing it | ||||
|     } | ||||
| 
 | ||||
| 	public long getModificationTimestamp() { | ||||
| 		return mModificationTimestamp; | ||||
| 	} | ||||
|     public long getModificationTimestamp() { | ||||
|         return mModificationTimestamp; | ||||
|     } | ||||
| 
 | ||||
|     public String getEtag() { | ||||
|         return mEtag; | ||||
|  | ||||
| @ -96,7 +96,12 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation { | ||||
|             client.exhaustResponse(head.getResponseBodyAsStream()); | ||||
|             boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) || | ||||
|                     (status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent); | ||||
|             result = new RemoteOperationResult(success, status, head.getResponseHeaders()); | ||||
|             result = new RemoteOperationResult( | ||||
|                 success, | ||||
|                 status, | ||||
|                 head.getStatusText(), | ||||
|                 head.getResponseHeaders() | ||||
|             ); | ||||
|             Log_OC.d(TAG, "Existence check for " + client.getWebdavUri() + | ||||
|                     WebdavUtils.encodePath(mPath) + " targeting for " + | ||||
|                     (mSuccessIfAbsent ? " absence " : " existence ") + | ||||
|  | ||||
| @ -45,113 +45,105 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion; | ||||
| /** | ||||
|  * Remote operation moving a remote file or folder in the ownCloud server to a different folder | ||||
|  * in the same account. | ||||
|  *  | ||||
|  * <p> | ||||
|  * Allows renaming the moving file/folder at the same time. | ||||
|  * | ||||
|  * @author David A. Velasco | ||||
|  */ | ||||
| public class MoveRemoteFileOperation extends RemoteOperation { | ||||
| 
 | ||||
| 	private static final String TAG = MoveRemoteFileOperation.class.getSimpleName(); | ||||
|     private static final String TAG = MoveRemoteFileOperation.class.getSimpleName(); | ||||
| 
 | ||||
| 	private static final int MOVE_READ_TIMEOUT = 600000; | ||||
| 	private static final int MOVE_CONNECTION_TIMEOUT = 5000; | ||||
|     private static final int MOVE_READ_TIMEOUT = 600000; | ||||
|     private static final int MOVE_CONNECTION_TIMEOUT = 5000; | ||||
| 
 | ||||
|     private String mSrcRemotePath; | ||||
|     private String mTargetRemotePath; | ||||
| 
 | ||||
| 	private boolean mOverwrite; | ||||
|     private boolean mOverwrite; | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|      * Constructor. | ||||
|      *  | ||||
|      * <p> | ||||
|      * TODO Paths should finish in "/" in the case of folders. ? | ||||
|      * | ||||
|      * @param srcRemotePath		Remote path of the file/folder to move.   | ||||
|      * @param targetRemotePath	Remove path desired for the file/folder after moving it. | ||||
|      * @param srcRemotePath    Remote path of the file/folder to move. | ||||
|      * @param targetRemotePath Remove path desired for the file/folder after moving it. | ||||
|      */ | ||||
| 	public MoveRemoteFileOperation( | ||||
| 			String srcRemotePath, String targetRemotePath, boolean overwrite | ||||
| 			) { | ||||
|     public MoveRemoteFileOperation( | ||||
|         String srcRemotePath, String targetRemotePath, boolean overwrite | ||||
|     ) { | ||||
| 
 | ||||
| 		mSrcRemotePath = srcRemotePath; | ||||
| 		mTargetRemotePath = targetRemotePath; | ||||
| 		mOverwrite = overwrite; | ||||
| 	} | ||||
|         mSrcRemotePath = srcRemotePath; | ||||
|         mTargetRemotePath = targetRemotePath; | ||||
|         mOverwrite = overwrite; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 	 /** | ||||
|     /** | ||||
|      * Performs the rename operation. | ||||
|      * | ||||
|      * @param   client      Client object to communicate with the remote ownCloud server. | ||||
|      * @param client Client object to communicate with the remote ownCloud server. | ||||
|      */ | ||||
| 	@Override | ||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
| 
 | ||||
| 		OwnCloudVersion version = client.getOwnCloudVersion(); | ||||
| 		boolean versionWithForbiddenChars = | ||||
|                 (version != null && version.isVersionWithForbiddenCharacters()); | ||||
|         OwnCloudVersion version = client.getOwnCloudVersion(); | ||||
|         boolean versionWithForbiddenChars = | ||||
|             (version != null && version.isVersionWithForbiddenCharacters()); | ||||
| 
 | ||||
|     	/// check parameters | ||||
|         /// check parameters | ||||
|         if (!FileUtils.isValidPath(mTargetRemotePath, versionWithForbiddenChars)) { | ||||
|         	return new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); | ||||
|             return new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); | ||||
|         } | ||||
| 
 | ||||
|         if (mTargetRemotePath.equals(mSrcRemotePath)) { | ||||
|         	// nothing to do! | ||||
|             // nothing to do! | ||||
|             return new RemoteOperationResult(ResultCode.OK); | ||||
|         } | ||||
| 
 | ||||
|         if (mTargetRemotePath.startsWith(mSrcRemotePath)) { | ||||
|         	return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT); | ||||
|             return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT); | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         /// perform remote operation | ||||
| 		//LocalMoveMethod move = null; | ||||
| 		MoveMethod move = null; | ||||
| 		RemoteOperationResult result = null; | ||||
|         MoveMethod move = null; | ||||
|         RemoteOperationResult result = null; | ||||
|         try { | ||||
|             move = new MoveMethod( | ||||
|             		client.getWebdavUri() + WebdavUtils.encodePath(mSrcRemotePath), | ||||
|             		client.getWebdavUri() + WebdavUtils.encodePath(mTargetRemotePath), | ||||
|             		mOverwrite | ||||
|     		); | ||||
|                 client.getWebdavUri() + WebdavUtils.encodePath(mSrcRemotePath), | ||||
|                 client.getWebdavUri() + WebdavUtils.encodePath(mTargetRemotePath), | ||||
|                 mOverwrite | ||||
|             ); | ||||
|             int status = client.executeMethod(move, MOVE_READ_TIMEOUT, MOVE_CONNECTION_TIMEOUT); | ||||
| 
 | ||||
|             /// process response | ||||
|         	if (status == HttpStatus.SC_MULTI_STATUS) { | ||||
|         		result = processPartialError(move); | ||||
|             if (status == HttpStatus.SC_MULTI_STATUS) { | ||||
|                 result = processPartialError(move); | ||||
| 
 | ||||
|         	} else if (status == HttpStatus.SC_PRECONDITION_FAILED && !mOverwrite) { | ||||
|             } else if (status == HttpStatus.SC_PRECONDITION_FAILED && !mOverwrite) { | ||||
| 
 | ||||
|         		result = new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); | ||||
|         		client.exhaustResponse(move.getResponseBodyAsStream()); | ||||
|                 result = new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); | ||||
|                 client.exhaustResponse(move.getResponseBodyAsStream()); | ||||
| 
 | ||||
| 
 | ||||
|     		/// for other errors that could be explicitly handled, check first: | ||||
|     		/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 | ||||
|                 /// for other errors that could be explicitly handled, check first: | ||||
|                 /// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 | ||||
| 
 | ||||
|         	} else if (status == 400) { | ||||
| 				result = new RemoteOperationResult(move.succeeded(), | ||||
| 						move.getResponseBodyAsString(), status); | ||||
| 			} else { | ||||
| 					result = new RemoteOperationResult( | ||||
| 							isSuccess(status), 	// move.succeeded()? trustful? | ||||
| 							status, | ||||
| 							move.getResponseHeaders() | ||||
| 					); | ||||
| 					client.exhaustResponse(move.getResponseBodyAsStream()); | ||||
| 			} | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(isSuccess(status), move); | ||||
|                 client.exhaustResponse(move.getResponseBodyAsStream()); | ||||
|             } | ||||
| 
 | ||||
|             Log.i(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " + | ||||
|         		result.getLogMessage()); | ||||
|                 result.getLogMessage()); | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             Log.e(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " + | ||||
|         		result.getLogMessage(), e); | ||||
|                 result.getLogMessage(), e); | ||||
| 
 | ||||
|         } finally { | ||||
|             if (move != null) | ||||
| @ -159,61 +151,56 @@ public class MoveRemoteFileOperation extends RemoteOperation { | ||||
|         } | ||||
| 
 | ||||
|         return result; | ||||
| 	} | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 *  Analyzes a multistatus response from the OC server to generate an appropriate result. | ||||
| 	 *  | ||||
| 	 *  In WebDAV, a MOVE request on collections (folders) can be PARTIALLY successful: some | ||||
| 	 *  children are moved, some other aren't. | ||||
| 	 *   | ||||
| 	 *  According to the WebDAV specification, a multistatus response SHOULD NOT include partial   | ||||
| 	 *  successes (201, 204) nor for descendants of already failed children (424) in the response  | ||||
| 	 *  entity. But SHOULD NOT != MUST NOT, so take carefully.  | ||||
| 	 *  | ||||
| 	 *  @param 	move	Move operation just finished with a multistatus response | ||||
| 	 *  @return	A result for the {@link MoveRemoteFileOperation} caller | ||||
| 	 *   | ||||
| 	 *  @throws IOException 	If the response body could not be parsed | ||||
| 	 *  @throws DavException 	If the status code is other than MultiStatus or if obtaining | ||||
| 	 *  						the response XML document fails | ||||
| 	 */ | ||||
|     /** | ||||
|      * Analyzes a multistatus response from the OC server to generate an appropriate result. | ||||
|      * <p> | ||||
|      * In WebDAV, a MOVE request on collections (folders) can be PARTIALLY successful: some | ||||
|      * children are moved, some other aren't. | ||||
|      * <p> | ||||
|      * According to the WebDAV specification, a multistatus response SHOULD NOT include partial | ||||
|      * successes (201, 204) nor for descendants of already failed children (424) in the response | ||||
|      * entity. But SHOULD NOT != MUST NOT, so take carefully. | ||||
|      * | ||||
|      * @param move Move operation just finished with a multistatus response | ||||
|      * @throws IOException  If the response body could not be parsed | ||||
|      * @throws DavException If the status code is other than MultiStatus or if obtaining | ||||
|      *                      the response XML document fails | ||||
|      * @return A result for the {@link MoveRemoteFileOperation} caller | ||||
|      */ | ||||
|     private RemoteOperationResult processPartialError(MoveMethod move) | ||||
|     		throws IOException, DavException { | ||||
|     	// Adding a list of failed descendants to the result could be interesting; or maybe not. | ||||
|     	// For the moment, let's take the easy way. | ||||
|         throws IOException, DavException { | ||||
|         // Adding a list of failed descendants to the result could be interesting; or maybe not. | ||||
|         // For the moment, let's take the easy way. | ||||
| 
 | ||||
|     	/// check that some error really occurred   | ||||
|     	MultiStatusResponse[] responses = move.getResponseBodyAsMultiStatus().getResponses(); | ||||
|     	Status[] status = null; | ||||
|     	boolean failFound = false; | ||||
|     	for (int i = 0; i < responses.length && !failFound; i++ ) { | ||||
|     		status = responses[i].getStatus(); | ||||
|     		failFound = ( | ||||
|     				status != null &&  | ||||
|     				status.length > 0 &&  | ||||
|     				status[0].getStatusCode() > 299 | ||||
| 			); | ||||
|     	} | ||||
|         /// check that some error really occurred | ||||
|         MultiStatusResponse[] responses = move.getResponseBodyAsMultiStatus().getResponses(); | ||||
|         Status[] status = null; | ||||
|         boolean failFound = false; | ||||
|         for (int i = 0; i < responses.length && !failFound; i++) { | ||||
|             status = responses[i].getStatus(); | ||||
|             failFound = ( | ||||
|                 status != null && | ||||
|                     status.length > 0 && | ||||
|                     status[0].getStatusCode() > 299 | ||||
|             ); | ||||
|         } | ||||
| 
 | ||||
|     	RemoteOperationResult result; | ||||
|     	if (failFound) { | ||||
|     		result = new RemoteOperationResult(ResultCode.PARTIAL_MOVE_DONE); | ||||
|     	} else { | ||||
|     		result = new RemoteOperationResult( | ||||
|             		true, | ||||
|             		HttpStatus.SC_MULTI_STATUS,  | ||||
|             		move.getResponseHeaders() | ||||
|     		); | ||||
|     	} | ||||
|         RemoteOperationResult result; | ||||
|         if (failFound) { | ||||
|             result = new RemoteOperationResult(ResultCode.PARTIAL_MOVE_DONE); | ||||
|         } else { | ||||
|             result = new RemoteOperationResult(true, move); | ||||
|         } | ||||
| 
 | ||||
|     	return result;  | ||||
|         return result; | ||||
| 
 | ||||
| 	} | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 	protected boolean isSuccess(int status) { | ||||
|     protected boolean isSuccess(int status) { | ||||
|         return status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT; | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -57,63 +57,63 @@ public class ReadRemoteFileOperation extends RemoteOperation { | ||||
|     /** | ||||
|      * Constructor | ||||
|      * | ||||
|      * @param remotePath		Remote path of the file.  | ||||
|      * @param remotePath Remote path of the file. | ||||
|      */ | ||||
|     public ReadRemoteFileOperation(String remotePath) { | ||||
|     	mRemotePath = remotePath; | ||||
|         mRemotePath = remotePath; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Performs the read operation. | ||||
|      * | ||||
|      * @param client		Client object to communicate with the remote ownCloud server. | ||||
|      * @param client Client object to communicate with the remote ownCloud server. | ||||
|      */ | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|     	PropFindMethod propfind = null; | ||||
|     	RemoteOperationResult result = null; | ||||
|         PropFindMethod propfind = null; | ||||
|         RemoteOperationResult result = null; | ||||
| 
 | ||||
|     	/// take the duty of check the server for the current state of the file there | ||||
|     	try { | ||||
|         /// take the duty of check the server for the current state of the file there | ||||
|         try { | ||||
|             // remote request | ||||
|     		propfind = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath), | ||||
|     				WebdavUtils.getFilePropSet(),    // PropFind Properties | ||||
|     				DavConstants.DEPTH_0); | ||||
|     		int status; | ||||
|     		status = client.executeMethod(propfind, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); | ||||
|             propfind = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath), | ||||
|                 WebdavUtils.getFilePropSet(),    // PropFind Properties | ||||
|                 DavConstants.DEPTH_0); | ||||
|             int status; | ||||
|             status = client.executeMethod(propfind, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); | ||||
| 
 | ||||
|     		boolean isSuccess = ( | ||||
|     				status == HttpStatus.SC_MULTI_STATUS || | ||||
|     				status == HttpStatus.SC_OK | ||||
| 			); | ||||
|     		if (isSuccess) { | ||||
|     			// Parse response | ||||
|     			MultiStatus resp = propfind.getResponseBodyAsMultiStatus(); | ||||
| 				WebdavEntry we = new WebdavEntry(resp.getResponses()[0], | ||||
|                         client.getWebdavUri().getPath()); | ||||
| 				RemoteFile remoteFile = new RemoteFile(we); | ||||
| 				ArrayList<Object> files = new ArrayList<Object>(); | ||||
| 				files.add(remoteFile); | ||||
|             boolean isSuccess = ( | ||||
|                 status == HttpStatus.SC_MULTI_STATUS || | ||||
|                     status == HttpStatus.SC_OK | ||||
|             ); | ||||
|             if (isSuccess) { | ||||
|                 // Parse response | ||||
|                 MultiStatus resp = propfind.getResponseBodyAsMultiStatus(); | ||||
|                 WebdavEntry we = new WebdavEntry(resp.getResponses()[0], | ||||
|                     client.getWebdavUri().getPath()); | ||||
|                 RemoteFile remoteFile = new RemoteFile(we); | ||||
|                 ArrayList<Object> files = new ArrayList<Object>(); | ||||
|                 files.add(remoteFile); | ||||
| 
 | ||||
|     			// Result of the operation | ||||
|     			result = new RemoteOperationResult(true, status, propfind.getResponseHeaders()); | ||||
|     			result.setData(files); | ||||
|                 // Result of the operation | ||||
|                 result = new RemoteOperationResult(true, propfind); | ||||
|                 result.setData(files); | ||||
| 
 | ||||
|     		} else { | ||||
|     			client.exhaustResponse(propfind.getResponseBodyAsStream()); | ||||
|     			result = new RemoteOperationResult(false, status, propfind.getResponseHeaders()); | ||||
|     		} | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(false, propfind); | ||||
|                 client.exhaustResponse(propfind.getResponseBodyAsStream()); | ||||
|             } | ||||
| 
 | ||||
|     	} catch (Exception e) { | ||||
|     		result = new RemoteOperationResult(e); | ||||
|     		e.printStackTrace(); | ||||
|     		Log_OC.e(TAG, "Synchronizing  file " + mRemotePath + ": " + result.getLogMessage(), | ||||
|                     result.getException()); | ||||
|     	} finally { | ||||
|     		if (propfind != null) | ||||
|     			propfind.releaseConnection(); | ||||
|     	} | ||||
|     	return result; | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             e.printStackTrace(); | ||||
|             Log_OC.e(TAG, "Synchronizing  file " + mRemotePath + ": " + result.getLogMessage(), | ||||
|                 result.getException()); | ||||
|         } finally { | ||||
|             if (propfind != null) | ||||
|                 propfind.releaseConnection(); | ||||
|         } | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -47,57 +47,57 @@ import com.owncloud.android.lib.common.utils.Log_OC; | ||||
| 
 | ||||
| public class ReadRemoteFolderOperation extends RemoteOperation { | ||||
| 
 | ||||
| 	private static final String TAG = ReadRemoteFolderOperation.class.getSimpleName(); | ||||
|     private static final String TAG = ReadRemoteFolderOperation.class.getSimpleName(); | ||||
| 
 | ||||
| 	private String mRemotePath; | ||||
| 	private ArrayList<Object> mFolderAndFiles; | ||||
|     private String mRemotePath; | ||||
|     private ArrayList<Object> mFolderAndFiles; | ||||
| 
 | ||||
| 	/** | ||||
|     /** | ||||
|      * Constructor | ||||
|      * | ||||
|      * @param remotePath		Remote path of the file.  | ||||
|      * @param remotePath Remote path of the file. | ||||
|      */ | ||||
| 	public ReadRemoteFolderOperation(String remotePath) { | ||||
| 		mRemotePath = remotePath; | ||||
| 	} | ||||
|     public ReadRemoteFolderOperation(String remotePath) { | ||||
|         mRemotePath = remotePath; | ||||
|     } | ||||
| 
 | ||||
| 	/** | ||||
|     /** | ||||
|      * Performs the read operation. | ||||
|      * | ||||
|      * @param   client      Client object to communicate with the remote ownCloud server. | ||||
|      * @param client Client object to communicate with the remote ownCloud server. | ||||
|      */ | ||||
| 	@Override | ||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { | ||||
| 		RemoteOperationResult result = null; | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result = null; | ||||
|         PropFindMethod query = null; | ||||
| 
 | ||||
|         try { | ||||
|             // remote request | ||||
|             query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath), | ||||
|                     WebdavUtils.getAllPropSet(),    // PropFind Properties | ||||
|                     DavConstants.DEPTH_1); | ||||
|                 WebdavUtils.getAllPropSet(),    // PropFind Properties | ||||
|                 DavConstants.DEPTH_1); | ||||
|             int status = client.executeMethod(query); | ||||
| 
 | ||||
|             // check and process response | ||||
|             boolean isSuccess = ( | ||||
|                     status == HttpStatus.SC_MULTI_STATUS || | ||||
|                 status == HttpStatus.SC_MULTI_STATUS || | ||||
|                     status == HttpStatus.SC_OK | ||||
| 		            ); | ||||
|             ); | ||||
|             if (isSuccess) { | ||||
|             	// get data from remote folder  | ||||
|             	MultiStatus dataInServer = query.getResponseBodyAsMultiStatus(); | ||||
|             	readData(dataInServer, client); | ||||
|                 // get data from remote folder | ||||
|                 MultiStatus dataInServer = query.getResponseBodyAsMultiStatus(); | ||||
|                 readData(dataInServer, client); | ||||
| 
 | ||||
|             	// Result of the operation | ||||
|             	result = new RemoteOperationResult(true, status, query.getResponseHeaders()); | ||||
|             	// Add data to the result | ||||
|             	if (result.isSuccess()) { | ||||
|             		result.setData(mFolderAndFiles); | ||||
|             	} | ||||
|                 // Result of the operation | ||||
|                 result = new RemoteOperationResult(true, query); | ||||
|                 // Add data to the result | ||||
|                 if (result.isSuccess()) { | ||||
|                     result.setData(mFolderAndFiles); | ||||
|                 } | ||||
|             } else { | ||||
|                 // synchronization failed | ||||
|                 client.exhaustResponse(query.getResponseBodyAsStream()); | ||||
|                 result = new RemoteOperationResult(false, status, query.getResponseHeaders()); | ||||
|                 result = new RemoteOperationResult(false, query); | ||||
|             } | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
| @ -108,11 +108,11 @@ public class ReadRemoteFolderOperation extends RemoteOperation { | ||||
|             if (query != null) | ||||
|                 query.releaseConnection();  // let the connection available for other methods | ||||
|             if (result.isSuccess()) { | ||||
|                 Log_OC.i(TAG, "Synchronized "  + mRemotePath + ": " + result.getLogMessage()); | ||||
|                 Log_OC.i(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage()); | ||||
|             } else { | ||||
|                 if (result.isException()) { | ||||
|                     Log_OC.e(TAG, "Synchronized " + mRemotePath  + ": " + result.getLogMessage(), | ||||
|                             result.getException()); | ||||
|                     Log_OC.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage(), | ||||
|                         result.getException()); | ||||
|                 } else { | ||||
|                     Log_OC.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage()); | ||||
|                 } | ||||
| @ -120,28 +120,27 @@ public class ReadRemoteFolderOperation extends RemoteOperation { | ||||
| 
 | ||||
|         } | ||||
|         return result; | ||||
| 	} | ||||
|     } | ||||
| 
 | ||||
|     public boolean isMultiStatus(int status) { | ||||
|         return (status == HttpStatus.SC_MULTI_STATUS); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      *  Read the data retrieved from the server about the contents of the target folder  | ||||
|      * Read the data retrieved from the server about the contents of the target folder | ||||
|      * | ||||
|      *  | ||||
|      *  @param remoteData     	Full response got from the server with the data of the target  | ||||
|      *                          folder and its direct children. | ||||
|      *  @param client           Client instance to the remote server where the data were  | ||||
|      *                          retrieved.   | ||||
|      *  @return                 | ||||
|      * @param remoteData Full response got from the server with the data of the target | ||||
|      *                   folder and its direct children. | ||||
|      * @param client     Client instance to the remote server where the data were | ||||
|      *                   retrieved. | ||||
|      * @return | ||||
|      */ | ||||
|     private void readData(MultiStatus remoteData, OwnCloudClient client) { | ||||
|         mFolderAndFiles = new ArrayList<Object>(); | ||||
| 
 | ||||
|         // parse data from remote folder  | ||||
|         WebdavEntry we = new WebdavEntry(remoteData.getResponses()[0], | ||||
|                 client.getWebdavUri().getPath()); | ||||
|             client.getWebdavUri().getPath()); | ||||
|         mFolderAndFiles.add(fillOCFile(we)); | ||||
| 
 | ||||
|         // loop to update every child | ||||
| @ -158,8 +157,8 @@ public class ReadRemoteFolderOperation extends RemoteOperation { | ||||
|     /** | ||||
|      * Creates and populates a new {@link RemoteFile} object with the data read from the server. | ||||
|      * | ||||
|      * @param we        WebDAV entry read from the server for a WebDAV resource (remote file or folder). | ||||
|      * @return          New OCFile instance representing the remote resource described by we. | ||||
|      * @param we WebDAV entry read from the server for a WebDAV resource (remote file or folder). | ||||
|      * @return New OCFile instance representing the remote resource described by we. | ||||
|      */ | ||||
|     private RemoteFile fillOCFile(WebdavEntry we) { | ||||
|         RemoteFile file = new RemoteFile(we.decodedPath()); | ||||
|  | ||||
| @ -45,46 +45,48 @@ public class RemoveRemoteFileOperation extends RemoteOperation { | ||||
|     private static final int REMOVE_READ_TIMEOUT = 30000; | ||||
|     private static final int REMOVE_CONNECTION_TIMEOUT = 5000; | ||||
| 
 | ||||
| 	private String mRemotePath; | ||||
|     private String mRemotePath; | ||||
| 
 | ||||
|     /** | ||||
|      * Constructor | ||||
|      * | ||||
|      * @param remotePath	RemotePath of the remote file or folder to remove from the server | ||||
|      * @param remotePath RemotePath of the remote file or folder to remove from the server | ||||
|      */ | ||||
| 	public RemoveRemoteFileOperation(String remotePath) { | ||||
| 		mRemotePath = remotePath; | ||||
| 	} | ||||
|     public RemoveRemoteFileOperation(String remotePath) { | ||||
|         mRemotePath = remotePath; | ||||
|     } | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Performs the rename operation. | ||||
| 	 *  | ||||
| 	 * @param client	Client object to communicate with the remote ownCloud server. | ||||
| 	 */ | ||||
| 	@Override | ||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { | ||||
| 		RemoteOperationResult result = null; | ||||
|     /** | ||||
|      * Performs the rename operation. | ||||
|      * | ||||
|      * @param client Client object to communicate with the remote ownCloud server. | ||||
|      */ | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result = null; | ||||
|         DeleteMethod delete = null; | ||||
| 
 | ||||
|         try { | ||||
|         	delete = new DeleteMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); | ||||
|         	int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT); | ||||
|             delete = new DeleteMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); | ||||
|             int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT); | ||||
| 
 | ||||
|         	delete.getResponseBodyAsString();   // exhaust the response, although not interesting | ||||
|         	result = new RemoteOperationResult((delete.succeeded() || | ||||
|                     status == HttpStatus.SC_NOT_FOUND), status, delete.getResponseHeaders()); | ||||
|         	Log_OC.i(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage()); | ||||
|             delete.getResponseBodyAsString();   // exhaust the response, although not interesting | ||||
|             result = new RemoteOperationResult( | ||||
|                 (delete.succeeded() || status == HttpStatus.SC_NOT_FOUND), | ||||
|                 delete | ||||
|             ); | ||||
|             Log_OC.i(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage()); | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|         	result = new RemoteOperationResult(e); | ||||
|         	Log_OC.e(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage(), e); | ||||
|             result = new RemoteOperationResult(e); | ||||
|             Log_OC.e(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage(), e); | ||||
| 
 | ||||
|         } finally { | ||||
|         	if (delete != null) | ||||
|         		delete.releaseConnection(); | ||||
|             if (delete != null) | ||||
|                 delete.releaseConnection(); | ||||
|         } | ||||
| 
 | ||||
| 		return result; | ||||
| 	} | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -45,10 +45,10 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion; | ||||
|  */ | ||||
| public class RenameRemoteFileOperation extends RemoteOperation { | ||||
| 
 | ||||
| 	private static final String TAG = RenameRemoteFileOperation.class.getSimpleName(); | ||||
|     private static final String TAG = RenameRemoteFileOperation.class.getSimpleName(); | ||||
| 
 | ||||
| 	private static final int RENAME_READ_TIMEOUT = 600000; | ||||
| 	private static final int RENAME_CONNECTION_TIMEOUT = 5000; | ||||
|     private static final int RENAME_READ_TIMEOUT = 600000; | ||||
|     private static final int RENAME_CONNECTION_TIMEOUT = 5000; | ||||
| 
 | ||||
|     private String mOldName; | ||||
|     private String mOldRemotePath; | ||||
| @ -59,40 +59,40 @@ public class RenameRemoteFileOperation extends RemoteOperation { | ||||
|     /** | ||||
|      * Constructor | ||||
|      * | ||||
|      * @param oldName			Old name of the file. | ||||
|      * @param oldRemotePath		Old remote path of the file.  | ||||
|      * @param newName			New name to set as the name of file. | ||||
|      * @param isFolder			'true' for folder and 'false' for files | ||||
|      * @param oldName       Old name of the file. | ||||
|      * @param oldRemotePath Old remote path of the file. | ||||
|      * @param newName       New name to set as the name of file. | ||||
|      * @param isFolder      'true' for folder and 'false' for files | ||||
|      */ | ||||
| 	public RenameRemoteFileOperation(String oldName, String oldRemotePath, String newName, | ||||
|     public RenameRemoteFileOperation(String oldName, String oldRemotePath, String newName, | ||||
|                                      boolean isFolder) { | ||||
| 		mOldName = oldName; | ||||
| 		mOldRemotePath = oldRemotePath; | ||||
| 		mNewName = newName; | ||||
|         mOldName = oldName; | ||||
|         mOldRemotePath = oldRemotePath; | ||||
|         mNewName = newName; | ||||
| 
 | ||||
|         String parent = (new File(mOldRemotePath)).getParent(); | ||||
|         parent = (parent.endsWith(FileUtils.PATH_SEPARATOR)) ? parent : parent + | ||||
|                 FileUtils.PATH_SEPARATOR; | ||||
|         mNewRemotePath =  parent + mNewName; | ||||
|             FileUtils.PATH_SEPARATOR; | ||||
|         mNewRemotePath = parent + mNewName; | ||||
|         if (isFolder) { | ||||
|             mNewRemotePath += FileUtils.PATH_SEPARATOR; | ||||
|         } | ||||
| 	} | ||||
|     } | ||||
| 
 | ||||
| 	 /** | ||||
|     /** | ||||
|      * Performs the rename operation. | ||||
|      * | ||||
|      * @param   client      Client object to communicate with the remote ownCloud server. | ||||
|      * @param client Client object to communicate with the remote ownCloud server. | ||||
|      */ | ||||
| 	@Override | ||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { | ||||
| 		RemoteOperationResult result = null; | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result = null; | ||||
| 
 | ||||
| 		LocalMoveMethod move = null; | ||||
|         LocalMoveMethod move = null; | ||||
| 
 | ||||
|         OwnCloudVersion version = client.getOwnCloudVersion(); | ||||
|         boolean versionWithForbiddenChars = | ||||
|                 (version != null && version.isVersionWithForbiddenCharacters()); | ||||
|             (version != null && version.isVersionWithForbiddenCharacters()); | ||||
|         boolean noInvalidChars = FileUtils.isValidPath(mNewRemotePath, versionWithForbiddenChars); | ||||
| 
 | ||||
|         if (noInvalidChars) { | ||||
| @ -106,29 +106,21 @@ public class RenameRemoteFileOperation extends RemoteOperation { | ||||
|                     return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); | ||||
|                 } | ||||
| 
 | ||||
|                 move = new LocalMoveMethod( client.getWebdavUri() + | ||||
|                         WebdavUtils.encodePath(mOldRemotePath), | ||||
|                         client.getWebdavUri() + WebdavUtils.encodePath(mNewRemotePath)); | ||||
|                 int status = client.executeMethod(move, RENAME_READ_TIMEOUT, | ||||
|                         RENAME_CONNECTION_TIMEOUT); | ||||
|                 move = new LocalMoveMethod(client.getWebdavUri() + | ||||
|                     WebdavUtils.encodePath(mOldRemotePath), | ||||
|                     client.getWebdavUri() + WebdavUtils.encodePath(mNewRemotePath)); | ||||
|                 client.executeMethod(move, RENAME_READ_TIMEOUT, RENAME_CONNECTION_TIMEOUT); | ||||
|                 result = new RemoteOperationResult(move.succeeded(), move); | ||||
|                 Log_OC.i(TAG, "Rename " + mOldRemotePath + " to " + mNewRemotePath + ": " + | ||||
|                             result.getLogMessage() | ||||
|                 ); | ||||
|                 client.exhaustResponse(move.getResponseBodyAsStream()); | ||||
| 
 | ||||
|                 if (status == 400) { | ||||
|                     result = new RemoteOperationResult(move.succeeded(), | ||||
|                             move.getResponseBodyAsString(), status); | ||||
|                     Log_OC.d(TAG, move.getResponseBodyAsString()); | ||||
|                 } else { | ||||
|                     client.exhaustResponse(move.getResponseBodyAsStream());//exhaust response, | ||||
|                                                                          // although not interesting | ||||
|                     result = new RemoteOperationResult(move.succeeded(), status, | ||||
|                             move.getResponseHeaders()); | ||||
|                     Log_OC.i(TAG, "Rename " + mOldRemotePath + " to " + mNewRemotePath + ": " + | ||||
|                             result.getLogMessage()); | ||||
|                 } | ||||
|             } catch (Exception e) { | ||||
|                 result = new RemoteOperationResult(e); | ||||
|                 Log_OC.e(TAG, "Rename " + mOldRemotePath + " to " + | ||||
|                         ((mNewRemotePath==null) ? mNewName : mNewRemotePath) + ": " + | ||||
|                         result.getLogMessage(), e); | ||||
|                     ((mNewRemotePath == null) ? mNewName : mNewRemotePath) + ": " + | ||||
|                     result.getLogMessage(), e); | ||||
| 
 | ||||
|             } finally { | ||||
|                 if (move != null) | ||||
| @ -136,16 +128,15 @@ public class RenameRemoteFileOperation extends RemoteOperation { | ||||
|             } | ||||
| 
 | ||||
|         } else { | ||||
|         	result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); | ||||
|             result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); | ||||
|         } | ||||
| 
 | ||||
|         return result; | ||||
| 	} | ||||
|     } | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Move operation | ||||
| 	 *  | ||||
| 	 */ | ||||
|     /** | ||||
|      * Move operation | ||||
|      */ | ||||
|     private class LocalMoveMethod extends DavMethodBase { | ||||
| 
 | ||||
|         public LocalMoveMethod(String uri, String dest) { | ||||
|  | ||||
| @ -69,7 +69,6 @@ public class UploadRemoteFileOperation extends RemoteOperation { | ||||
|     protected String mMimeType; | ||||
|     protected String mFileLastModifTimestamp; | ||||
|     protected PutMethod mPutMethod = null; | ||||
|     protected boolean mForbiddenCharsInServer = false; | ||||
|     protected String mRequiredEtag = null; | ||||
| 
 | ||||
|     protected final AtomicBoolean mCancellationRequested = new AtomicBoolean(false); | ||||
| @ -112,14 +111,7 @@ public class UploadRemoteFileOperation extends RemoteOperation { | ||||
| 
 | ||||
|             } else { | ||||
|                 // perform the upload | ||||
|                 int status = uploadFile(client); | ||||
|                 if (mForbiddenCharsInServer){ | ||||
|                     result = new RemoteOperationResult( | ||||
|                             RemoteOperationResult.ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER); | ||||
|                 } else { | ||||
|                     result = new RemoteOperationResult(isSuccess(status), status, | ||||
|                             (mPutMethod != null ? mPutMethod.getResponseHeaders() : null)); | ||||
|                 } | ||||
|                 result = uploadFile(client); | ||||
|             } | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
| @ -144,8 +136,9 @@ public class UploadRemoteFileOperation extends RemoteOperation { | ||||
|                 status == HttpStatus.SC_NO_CONTENT)); | ||||
|     } | ||||
| 
 | ||||
|     protected int uploadFile(OwnCloudClient client) throws IOException { | ||||
|         int status = -1; | ||||
|     protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOException { | ||||
|         int status; | ||||
|         RemoteOperationResult result; | ||||
|         try { | ||||
|             File f = new File(mLocalPath); | ||||
|             mEntity  = new FileRequestEntity(f, mMimeType); | ||||
| @ -163,25 +156,16 @@ public class UploadRemoteFileOperation extends RemoteOperation { | ||||
|             mPutMethod.setRequestEntity(mEntity); | ||||
|             status = client.executeMethod(mPutMethod); | ||||
| 
 | ||||
|             if (status == 400) { | ||||
|                 InvalidCharacterExceptionParser xmlParser = new InvalidCharacterExceptionParser(); | ||||
|                 InputStream is = new ByteArrayInputStream( | ||||
|                         mPutMethod.getResponseBodyAsString().getBytes()); | ||||
|                 try { | ||||
|                     mForbiddenCharsInServer = xmlParser.parseXMLResponse(is); | ||||
| 
 | ||||
|                 } catch (Exception e) { | ||||
|                     mForbiddenCharsInServer = false; | ||||
|                     Log_OC.e(TAG, "Exception reading exception from server", e); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             result = new RemoteOperationResult( | ||||
|                 isSuccess(status), | ||||
|                 mPutMethod | ||||
|             ); | ||||
|             client.exhaustResponse(mPutMethod.getResponseBodyAsStream()); | ||||
| 
 | ||||
|         } finally { | ||||
|             mPutMethod.releaseConnection(); // let the connection available for other methods | ||||
|         } | ||||
|         return status; | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
|     public Set<OnDatatransferProgressListener> getDataTransferListeners() { | ||||
|  | ||||
| @ -39,137 +39,138 @@ import com.owncloud.android.lib.common.utils.Log_OC; | ||||
|  */ | ||||
| public class CreateRemoteShareOperation extends RemoteOperation { | ||||
| 
 | ||||
| 	private static final String TAG = CreateRemoteShareOperation.class.getSimpleName(); | ||||
|     private static final String TAG = CreateRemoteShareOperation.class.getSimpleName(); | ||||
| 
 | ||||
| 	private static final String PARAM_PATH = "path"; | ||||
| 	private static final String PARAM_SHARE_TYPE = "shareType"; | ||||
| 	private static final String PARAM_SHARE_WITH = "shareWith"; | ||||
| 	private static final String PARAM_PUBLIC_UPLOAD = "publicUpload"; | ||||
| 	private static final String PARAM_PASSWORD = "password"; | ||||
| 	private static final String PARAM_PERMISSIONS = "permissions"; | ||||
|     private static final String PARAM_PATH = "path"; | ||||
|     private static final String PARAM_SHARE_TYPE = "shareType"; | ||||
|     private static final String PARAM_SHARE_WITH = "shareWith"; | ||||
|     private static final String PARAM_PUBLIC_UPLOAD = "publicUpload"; | ||||
|     private static final String PARAM_PASSWORD = "password"; | ||||
|     private static final String PARAM_PERMISSIONS = "permissions"; | ||||
| 
 | ||||
| 	private String mRemoteFilePath; | ||||
| 	private ShareType mShareType; | ||||
| 	private String mShareWith; | ||||
| 	private boolean mPublicUpload; | ||||
| 	private String mPassword; | ||||
| 	private int mPermissions; | ||||
| 	private boolean mGetShareDetails; | ||||
|     private String mRemoteFilePath; | ||||
|     private ShareType mShareType; | ||||
|     private String mShareWith; | ||||
|     private boolean mPublicUpload; | ||||
|     private String mPassword; | ||||
|     private int mPermissions; | ||||
|     private boolean mGetShareDetails; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Constructor | ||||
| 	 * @param remoteFilePath	Full path of the file/folder being shared. Mandatory argument | ||||
| 	 * @param shareType			0 = user, 1 = group, 3 = Public link. Mandatory argument | ||||
| 	 * @param shareWith			User/group ID with who the file should be shared.  This is mandatory for shareType | ||||
| 	 *                          of 0 or 1 | ||||
| 	 * @param publicUpload		If false (default) public cannot upload to a public shared folder. | ||||
| 	 * 							If true public can upload to a shared folder. Only available for public link shares | ||||
| 	 * @param password			Password to protect a public link share. Only available for public link shares | ||||
| 	 * @param permissions		1 - Read only Default for public shares | ||||
| 	 * 							2 - Update | ||||
| 	 * 							4 - Create | ||||
| 	 * 							8 - Delete | ||||
| 	 * 							16- Re-share | ||||
| 	 * 							31- All above Default for private shares | ||||
| 	 * 							For user or group shares. | ||||
| 	 * 							To obtain combinations, add the desired values together.   | ||||
| 	 * 							For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27. | ||||
| 	 */ | ||||
| 	public CreateRemoteShareOperation( | ||||
| 			String remoteFilePath, | ||||
| 			ShareType shareType, | ||||
| 			String shareWith, | ||||
| 			boolean publicUpload, | ||||
| 			String password, | ||||
| 			int permissions | ||||
| 	) { | ||||
|     /** | ||||
|      * Constructor | ||||
|      * | ||||
|      * @param remoteFilePath Full path of the file/folder being shared. Mandatory argument | ||||
|      * @param shareType      0 = user, 1 = group, 3 = Public link. Mandatory argument | ||||
|      * @param shareWith      User/group ID with who the file should be shared.  This is mandatory for shareType | ||||
|      *                       of 0 or 1 | ||||
|      * @param publicUpload   If false (default) public cannot upload to a public shared folder. | ||||
|      *                       If true public can upload to a shared folder. Only available for public link shares | ||||
|      * @param password       Password to protect a public link share. Only available for public link shares | ||||
|      * @param permissions    1 - Read only Default for public shares | ||||
|      *                       2 - Update | ||||
|      *                       4 - Create | ||||
|      *                       8 - Delete | ||||
|      *                       16- Re-share | ||||
|      *                       31- All above Default for private shares | ||||
|      *                       For user or group shares. | ||||
|      *                       To obtain combinations, add the desired values together. | ||||
|      *                       For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27. | ||||
|      */ | ||||
|     public CreateRemoteShareOperation( | ||||
|         String remoteFilePath, | ||||
|         ShareType shareType, | ||||
|         String shareWith, | ||||
|         boolean publicUpload, | ||||
|         String password, | ||||
|         int permissions | ||||
|     ) { | ||||
| 
 | ||||
| 		mRemoteFilePath = remoteFilePath; | ||||
| 		mShareType = shareType; | ||||
| 		mShareWith = shareWith; | ||||
| 		mPublicUpload = publicUpload; | ||||
| 		mPassword = password; | ||||
| 		mPermissions = permissions; | ||||
| 		mGetShareDetails = false; 		// defaults to false for backwards compatibility | ||||
| 	} | ||||
|         mRemoteFilePath = remoteFilePath; | ||||
|         mShareType = shareType; | ||||
|         mShareWith = shareWith; | ||||
|         mPublicUpload = publicUpload; | ||||
|         mPassword = password; | ||||
|         mPermissions = permissions; | ||||
|         mGetShareDetails = false;        // defaults to false for backwards compatibility | ||||
|     } | ||||
| 
 | ||||
| 	public boolean isGettingShareDetails () { | ||||
| 		return mGetShareDetails; | ||||
| 	} | ||||
|     public boolean isGettingShareDetails() { | ||||
|         return mGetShareDetails; | ||||
|     } | ||||
| 
 | ||||
| 	public void setGetShareDetails(boolean set) { | ||||
| 		mGetShareDetails = set; | ||||
| 	} | ||||
|     public void setGetShareDetails(boolean set) { | ||||
|         mGetShareDetails = set; | ||||
|     } | ||||
| 
 | ||||
| 	@Override | ||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { | ||||
| 		RemoteOperationResult result = null; | ||||
| 		int status = -1; | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result = null; | ||||
|         int status = -1; | ||||
| 
 | ||||
| 		PostMethod post = null; | ||||
|         PostMethod post = null; | ||||
| 
 | ||||
| 		try { | ||||
| 			// Post Method | ||||
| 			post = new PostMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); | ||||
|         try { | ||||
|             // Post Method | ||||
|             post = new PostMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); | ||||
| 
 | ||||
| 			post.setRequestHeader( "Content-Type", | ||||
|                     "application/x-www-form-urlencoded; charset=utf-8"); // necessary for special characters | ||||
|             post.setRequestHeader("Content-Type", | ||||
|                 "application/x-www-form-urlencoded; charset=utf-8"); // necessary for special characters | ||||
| 
 | ||||
| 			post.addParameter(PARAM_PATH, mRemoteFilePath); | ||||
| 			post.addParameter(PARAM_SHARE_TYPE, Integer.toString(mShareType.getValue())); | ||||
| 			post.addParameter(PARAM_SHARE_WITH, mShareWith); | ||||
| 			if (mPublicUpload) { | ||||
| 				post.addParameter(PARAM_PUBLIC_UPLOAD, Boolean.toString(true)); | ||||
| 			} | ||||
| 			if (mPassword != null && mPassword.length() > 0) { | ||||
| 				post.addParameter(PARAM_PASSWORD, mPassword); | ||||
| 			} | ||||
| 			if (OCShare.DEFAULT_PERMISSION != mPermissions) { | ||||
| 				post.addParameter(PARAM_PERMISSIONS, Integer.toString(mPermissions)); | ||||
| 			} | ||||
|             post.addParameter(PARAM_PATH, mRemoteFilePath); | ||||
|             post.addParameter(PARAM_SHARE_TYPE, Integer.toString(mShareType.getValue())); | ||||
|             post.addParameter(PARAM_SHARE_WITH, mShareWith); | ||||
|             if (mPublicUpload) { | ||||
|                 post.addParameter(PARAM_PUBLIC_UPLOAD, Boolean.toString(true)); | ||||
|             } | ||||
|             if (mPassword != null && mPassword.length() > 0) { | ||||
|                 post.addParameter(PARAM_PASSWORD, mPassword); | ||||
|             } | ||||
|             if (OCShare.DEFAULT_PERMISSION != mPermissions) { | ||||
|                 post.addParameter(PARAM_PERMISSIONS, Integer.toString(mPermissions)); | ||||
|             } | ||||
| 
 | ||||
| 			post.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); | ||||
|             post.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); | ||||
| 
 | ||||
| 			status = client.executeMethod(post); | ||||
|             status = client.executeMethod(post); | ||||
| 
 | ||||
| 			if(isSuccess(status)) { | ||||
| 				String response = post.getResponseBodyAsString(); | ||||
|             if (isSuccess(status)) { | ||||
|                 String response = post.getResponseBodyAsString(); | ||||
| 
 | ||||
| 				ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( | ||||
| 						new ShareXMLParser() | ||||
| 				); | ||||
| 				parser.setOneOrMoreSharesRequired(true); | ||||
| 				parser.setOwnCloudVersion(client.getOwnCloudVersion()); | ||||
| 				parser.setServerBaseUri(client.getBaseUri()); | ||||
| 				result = parser.parse(response); | ||||
|                 ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( | ||||
|                     new ShareXMLParser() | ||||
|                 ); | ||||
|                 parser.setOneOrMoreSharesRequired(true); | ||||
|                 parser.setOwnCloudVersion(client.getOwnCloudVersion()); | ||||
|                 parser.setServerBaseUri(client.getBaseUri()); | ||||
|                 result = parser.parse(response); | ||||
| 
 | ||||
| 				if (result.isSuccess() && mGetShareDetails) { | ||||
| 					// retrieve more info - POST only returns the index of the new share | ||||
| 					OCShare emptyShare = (OCShare) result.getData().get(0); | ||||
| 					GetRemoteShareOperation getInfo = new GetRemoteShareOperation( | ||||
| 							emptyShare.getRemoteId() | ||||
| 					); | ||||
| 					result = getInfo.execute(client); | ||||
| 				} | ||||
|                 if (result.isSuccess() && mGetShareDetails) { | ||||
|                     // retrieve more info - POST only returns the index of the new share | ||||
|                     OCShare emptyShare = (OCShare) result.getData().get(0); | ||||
|                     GetRemoteShareOperation getInfo = new GetRemoteShareOperation( | ||||
|                         emptyShare.getRemoteId() | ||||
|                     ); | ||||
|                     result = getInfo.execute(client); | ||||
|                 } | ||||
| 
 | ||||
| 			} else { | ||||
| 				result = new RemoteOperationResult(false, status, post.getResponseHeaders()); | ||||
| 			} | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(false, post); | ||||
|             } | ||||
| 
 | ||||
| 		} catch (Exception e) { | ||||
| 			result = new RemoteOperationResult(e); | ||||
| 			Log_OC.e(TAG, "Exception while Creating New Share", e); | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             Log_OC.e(TAG, "Exception while Creating New Share", e); | ||||
| 
 | ||||
| 		} finally { | ||||
| 			if (post != null) { | ||||
| 				post.releaseConnection(); | ||||
| 			} | ||||
| 		} | ||||
| 		return result; | ||||
| 	} | ||||
|         } finally { | ||||
|             if (post != null) { | ||||
|                 post.releaseConnection(); | ||||
|             } | ||||
|         } | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
| 	private boolean isSuccess(int status) { | ||||
| 		return (status == HttpStatus.SC_OK); | ||||
| 	} | ||||
|     private boolean isSuccess(int status) { | ||||
|         return (status == HttpStatus.SC_OK); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -39,62 +39,62 @@ import org.apache.commons.httpclient.methods.GetMethod; | ||||
| 
 | ||||
| public class GetRemoteShareOperation extends RemoteOperation { | ||||
| 
 | ||||
| 	private static final String TAG = GetRemoteShareOperation.class.getSimpleName(); | ||||
|     private static final String TAG = GetRemoteShareOperation.class.getSimpleName(); | ||||
| 
 | ||||
| 	private long mRemoteId; | ||||
|     private long mRemoteId; | ||||
| 
 | ||||
| 
 | ||||
| 	public GetRemoteShareOperation(long remoteId) { | ||||
| 		mRemoteId = remoteId; | ||||
| 	} | ||||
|     public GetRemoteShareOperation(long remoteId) { | ||||
|         mRemoteId = remoteId; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 	@Override | ||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { | ||||
| 		RemoteOperationResult result = null; | ||||
| 		int status = -1; | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result = null; | ||||
|         int status = -1; | ||||
| 
 | ||||
| 		// Get Method         | ||||
| 		GetMethod get = null; | ||||
|         // Get Method | ||||
|         GetMethod get = null; | ||||
| 
 | ||||
| 		// Get the response | ||||
| 		try{ | ||||
| 			get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + "/" + Long.toString(mRemoteId)); | ||||
| 			get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); | ||||
|         // Get the response | ||||
|         try { | ||||
|             get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + "/" + Long.toString(mRemoteId)); | ||||
|             get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); | ||||
| 
 | ||||
| 			status = client.executeMethod(get); | ||||
|             status = client.executeMethod(get); | ||||
| 
 | ||||
| 			if(isSuccess(status)) { | ||||
| 				String response = get.getResponseBodyAsString(); | ||||
|             if (isSuccess(status)) { | ||||
|                 String response = get.getResponseBodyAsString(); | ||||
| 
 | ||||
| 				// Parse xml response and obtain the list of shares | ||||
| 				ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( | ||||
| 						new ShareXMLParser() | ||||
| 				); | ||||
| 				parser.setOneOrMoreSharesRequired(true); | ||||
| 				parser.setOwnCloudVersion(client.getOwnCloudVersion()); | ||||
| 				parser.setServerBaseUri(client.getBaseUri()); | ||||
| 				result = parser.parse(response); | ||||
|                 // Parse xml response and obtain the list of shares | ||||
|                 ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( | ||||
|                     new ShareXMLParser() | ||||
|                 ); | ||||
|                 parser.setOneOrMoreSharesRequired(true); | ||||
|                 parser.setOwnCloudVersion(client.getOwnCloudVersion()); | ||||
|                 parser.setServerBaseUri(client.getBaseUri()); | ||||
|                 result = parser.parse(response); | ||||
| 
 | ||||
| 			} else { | ||||
| 				result = new RemoteOperationResult(false, status, get.getResponseHeaders()); | ||||
| 			} | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(false, get); | ||||
|             } | ||||
| 
 | ||||
| 		} catch (Exception e) { | ||||
| 			result = new RemoteOperationResult(e); | ||||
| 			Log_OC.e(TAG, "Exception while getting remote shares ", e); | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             Log_OC.e(TAG, "Exception while getting remote shares ", e); | ||||
| 
 | ||||
| 		} finally { | ||||
| 			if (get != null) { | ||||
| 				get.releaseConnection(); | ||||
| 			} | ||||
| 		} | ||||
| 		return result; | ||||
| 	} | ||||
|         } finally { | ||||
|             if (get != null) { | ||||
|                 get.releaseConnection(); | ||||
|             } | ||||
|         } | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
| 	private boolean isSuccess(int status) { | ||||
| 		return (status == HttpStatus.SC_OK); | ||||
| 	} | ||||
|     private boolean isSuccess(int status) { | ||||
|         return (status == HttpStatus.SC_OK); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -166,13 +166,13 @@ public class GetRemoteShareesOperation extends RemoteOperation{ | ||||
|                 } | ||||
| 
 | ||||
|                 // Result | ||||
|                 result = new RemoteOperationResult(true, status, get.getResponseHeaders()); | ||||
|                 result = new RemoteOperationResult(true, get); | ||||
|                 result.setData(data); | ||||
| 
 | ||||
|                 Log_OC.d(TAG, "*** Get Users or groups completed " ); | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(false, status, get.getResponseHeaders()); | ||||
|                 result = new RemoteOperationResult(false, get); | ||||
|                 String response = get.getResponseBodyAsString(); | ||||
|                 Log_OC.e(TAG, "Failed response while getting users/groups from the server "); | ||||
|                 if (response != null) { | ||||
|  | ||||
| @ -42,88 +42,88 @@ import com.owncloud.android.lib.common.utils.Log_OC; | ||||
|  */ | ||||
| public class GetRemoteSharesForFileOperation extends RemoteOperation { | ||||
| 
 | ||||
| 	private static final String TAG = GetRemoteSharesForFileOperation.class.getSimpleName(); | ||||
|     private static final String TAG = GetRemoteSharesForFileOperation.class.getSimpleName(); | ||||
| 
 | ||||
| 	private static final String PARAM_PATH = "path"; | ||||
| 	private static final String PARAM_RESHARES = "reshares"; | ||||
| 	private static final String PARAM_SUBFILES = "subfiles"; | ||||
|     private static final String PARAM_PATH = "path"; | ||||
|     private static final String PARAM_RESHARES = "reshares"; | ||||
|     private static final String PARAM_SUBFILES = "subfiles"; | ||||
| 
 | ||||
| 	private String mRemoteFilePath; | ||||
| 	private boolean mReshares; | ||||
| 	private boolean mSubfiles; | ||||
|     private String mRemoteFilePath; | ||||
|     private boolean mReshares; | ||||
|     private boolean mSubfiles; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Constructor | ||||
| 	 *  | ||||
| 	 * @param remoteFilePath    Path to file or folder | ||||
| 	 * @param reshares          If set to false (default), only shares owned by the current user are | ||||
| 	 *                          returned. | ||||
| 	 *                          If set to true, shares owned by any user from the given file are returned. | ||||
| 	 * @param subfiles          If set to false (default), lists only the folder being shared | ||||
| 	 *                          If set to true, all shared files within the folder are returned. | ||||
| 	 */ | ||||
| 	public GetRemoteSharesForFileOperation(String remoteFilePath, boolean reshares, | ||||
| 										   boolean subfiles) { | ||||
| 		mRemoteFilePath = remoteFilePath; | ||||
| 		mReshares = reshares; | ||||
| 		mSubfiles = subfiles; | ||||
| 	} | ||||
|     /** | ||||
|      * Constructor | ||||
|      * | ||||
|      * @param remoteFilePath Path to file or folder | ||||
|      * @param reshares       If set to false (default), only shares owned by the current user are | ||||
|      *                       returned. | ||||
|      *                       If set to true, shares owned by any user from the given file are returned. | ||||
|      * @param subfiles       If set to false (default), lists only the folder being shared | ||||
|      *                       If set to true, all shared files within the folder are returned. | ||||
|      */ | ||||
|     public GetRemoteSharesForFileOperation(String remoteFilePath, boolean reshares, | ||||
|                                            boolean subfiles) { | ||||
|         mRemoteFilePath = remoteFilePath; | ||||
|         mReshares = reshares; | ||||
|         mSubfiles = subfiles; | ||||
|     } | ||||
| 
 | ||||
| 	@Override | ||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { | ||||
| 		RemoteOperationResult result = null; | ||||
| 		int status = -1; | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result = null; | ||||
|         int status = -1; | ||||
| 
 | ||||
| 		GetMethod get = null; | ||||
|         GetMethod get = null; | ||||
| 
 | ||||
| 		try { | ||||
| 			// Get Method | ||||
| 			get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); | ||||
|         try { | ||||
|             // Get Method | ||||
|             get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); | ||||
| 
 | ||||
| 			// Add Parameters to Get Method | ||||
| 			get.setQueryString(new NameValuePair[]{ | ||||
| 					new NameValuePair(PARAM_PATH, mRemoteFilePath), | ||||
| 					new NameValuePair(PARAM_RESHARES, String.valueOf(mReshares)), | ||||
| 					new NameValuePair(PARAM_SUBFILES, String.valueOf(mSubfiles)) | ||||
| 			}); | ||||
|             // Add Parameters to Get Method | ||||
|             get.setQueryString(new NameValuePair[]{ | ||||
|                 new NameValuePair(PARAM_PATH, mRemoteFilePath), | ||||
|                 new NameValuePair(PARAM_RESHARES, String.valueOf(mReshares)), | ||||
|                 new NameValuePair(PARAM_SUBFILES, String.valueOf(mSubfiles)) | ||||
|             }); | ||||
| 
 | ||||
| 			get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); | ||||
|             get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); | ||||
| 
 | ||||
| 			status = client.executeMethod(get); | ||||
|             status = client.executeMethod(get); | ||||
| 
 | ||||
| 			if(isSuccess(status)) { | ||||
| 				String response = get.getResponseBodyAsString(); | ||||
|             if (isSuccess(status)) { | ||||
|                 String response = get.getResponseBodyAsString(); | ||||
| 
 | ||||
| 				// Parse xml response and obtain the list of shares | ||||
| 				ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( | ||||
| 						new ShareXMLParser() | ||||
| 				); | ||||
| 				parser.setOwnCloudVersion(client.getOwnCloudVersion()); | ||||
| 				parser.setServerBaseUri(client.getBaseUri()); | ||||
| 				result = parser.parse(response); | ||||
|                 // Parse xml response and obtain the list of shares | ||||
|                 ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( | ||||
|                     new ShareXMLParser() | ||||
|                 ); | ||||
|                 parser.setOwnCloudVersion(client.getOwnCloudVersion()); | ||||
|                 parser.setServerBaseUri(client.getBaseUri()); | ||||
|                 result = parser.parse(response); | ||||
| 
 | ||||
| 				if (result.isSuccess()) { | ||||
| 					Log_OC.d(TAG, "Got " + result.getData().size() + " shares"); | ||||
| 				} | ||||
|                 if (result.isSuccess()) { | ||||
|                     Log_OC.d(TAG, "Got " + result.getData().size() + " shares"); | ||||
|                 } | ||||
| 
 | ||||
| 			} else { | ||||
| 				result = new RemoteOperationResult(false, status, get.getResponseHeaders()); | ||||
| 			} | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(false, get); | ||||
|             } | ||||
| 
 | ||||
| 		} catch (Exception e) { | ||||
| 			result = new RemoteOperationResult(e); | ||||
| 			Log_OC.e(TAG, "Exception while getting shares", e); | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             Log_OC.e(TAG, "Exception while getting shares", e); | ||||
| 
 | ||||
| 		} finally { | ||||
| 			if (get != null) { | ||||
| 				get.releaseConnection(); | ||||
| 			} | ||||
| 		} | ||||
| 		return result; | ||||
| 	} | ||||
|         } finally { | ||||
|             if (get != null) { | ||||
|                 get.releaseConnection(); | ||||
|             } | ||||
|         } | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
| 	private boolean isSuccess(int status) { | ||||
| 		return (status == HttpStatus.SC_OK); | ||||
| 	} | ||||
|     private boolean isSuccess(int status) { | ||||
|         return (status == HttpStatus.SC_OK); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -36,60 +36,59 @@ import com.owncloud.android.lib.common.utils.Log_OC; | ||||
| 
 | ||||
| /** | ||||
|  * Get the data from the server about ALL the known shares owned by the requester. | ||||
|  *  | ||||
|  */ | ||||
| 
 | ||||
| public class GetRemoteSharesOperation extends RemoteOperation { | ||||
| 
 | ||||
| 	private static final String TAG = GetRemoteSharesOperation.class.getSimpleName(); | ||||
|     private static final String TAG = GetRemoteSharesOperation.class.getSimpleName(); | ||||
| 
 | ||||
| 
 | ||||
| 	public GetRemoteSharesOperation() { | ||||
| 	} | ||||
|     public GetRemoteSharesOperation() { | ||||
|     } | ||||
| 
 | ||||
| 	@Override | ||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { | ||||
| 		RemoteOperationResult result = null; | ||||
| 		int status = -1; | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result = null; | ||||
|         int status = -1; | ||||
| 
 | ||||
| 		// Get Method         | ||||
| 		GetMethod get = null; | ||||
|         // Get Method | ||||
|         GetMethod get = null; | ||||
| 
 | ||||
| 		// Get the response | ||||
| 		try{ | ||||
| 			get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); | ||||
| 			get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); | ||||
| 			status = client.executeMethod(get); | ||||
|         // Get the response | ||||
|         try { | ||||
|             get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); | ||||
|             get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); | ||||
|             status = client.executeMethod(get); | ||||
| 
 | ||||
| 			if(isSuccess(status)) { | ||||
| 				String response = get.getResponseBodyAsString(); | ||||
|             if (isSuccess(status)) { | ||||
|                 String response = get.getResponseBodyAsString(); | ||||
| 
 | ||||
| 				// Parse xml response and obtain the list of shares | ||||
| 				ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( | ||||
| 						new ShareXMLParser() | ||||
| 				); | ||||
| 				parser.setOwnCloudVersion(client.getOwnCloudVersion()); | ||||
| 				parser.setServerBaseUri(client.getBaseUri()); | ||||
| 				result = parser.parse(response); | ||||
| 			} else { | ||||
| 				result = new RemoteOperationResult(false, status, get.getResponseHeaders()); | ||||
| 			} | ||||
|                 // Parse xml response and obtain the list of shares | ||||
|                 ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( | ||||
|                     new ShareXMLParser() | ||||
|                 ); | ||||
|                 parser.setOwnCloudVersion(client.getOwnCloudVersion()); | ||||
|                 parser.setServerBaseUri(client.getBaseUri()); | ||||
|                 result = parser.parse(response); | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(false, get); | ||||
|             } | ||||
| 
 | ||||
| 		} catch (Exception e) { | ||||
| 			result = new RemoteOperationResult(e); | ||||
| 			Log_OC.e(TAG, "Exception while getting remote shares ", e); | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             Log_OC.e(TAG, "Exception while getting remote shares ", e); | ||||
| 
 | ||||
| 		} finally { | ||||
| 			if (get != null) { | ||||
| 				get.releaseConnection(); | ||||
| 			} | ||||
| 		} | ||||
| 		return result; | ||||
| 	} | ||||
|         } finally { | ||||
|             if (get != null) { | ||||
|                 get.releaseConnection(); | ||||
|             } | ||||
|         } | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
| 	private boolean isSuccess(int status) { | ||||
| 		return (status == HttpStatus.SC_OK); | ||||
| 	} | ||||
|     private boolean isSuccess(int status) { | ||||
|         return (status == HttpStatus.SC_OK); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -40,63 +40,63 @@ import com.owncloud.android.lib.common.utils.Log_OC; | ||||
| 
 | ||||
| public class RemoveRemoteShareOperation extends RemoteOperation { | ||||
| 
 | ||||
| 	private static final String TAG = RemoveRemoteShareOperation.class.getSimpleName(); | ||||
|     private static final String TAG = RemoveRemoteShareOperation.class.getSimpleName(); | ||||
| 
 | ||||
| 	private int mRemoteShareId; | ||||
|     private int mRemoteShareId; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Constructor | ||||
| 	 *  | ||||
| 	 * @param remoteShareId		Share ID | ||||
| 	 */ | ||||
|     /** | ||||
|      * Constructor | ||||
|      * | ||||
|      * @param remoteShareId Share ID | ||||
|      */ | ||||
| 
 | ||||
| 	public RemoveRemoteShareOperation(int remoteShareId) { | ||||
| 		mRemoteShareId = remoteShareId; | ||||
|     public RemoveRemoteShareOperation(int remoteShareId) { | ||||
|         mRemoteShareId = remoteShareId; | ||||
| 
 | ||||
| 	} | ||||
|     } | ||||
| 
 | ||||
| 	@Override | ||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { | ||||
| 		RemoteOperationResult result = null; | ||||
| 		int status = -1; | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result = null; | ||||
|         int status = -1; | ||||
| 
 | ||||
| 		DeleteMethod delete = null; | ||||
|         DeleteMethod delete = null; | ||||
| 
 | ||||
| 		try { | ||||
| 			String id = "/" + String.valueOf(mRemoteShareId); | ||||
| 			delete = new DeleteMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + id); | ||||
|         try { | ||||
|             String id = "/" + String.valueOf(mRemoteShareId); | ||||
|             delete = new DeleteMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + id); | ||||
| 
 | ||||
| 			delete.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); | ||||
|             delete.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); | ||||
| 
 | ||||
| 			status = client.executeMethod(delete); | ||||
|             status = client.executeMethod(delete); | ||||
| 
 | ||||
| 			if(isSuccess(status)) { | ||||
| 				String response = delete.getResponseBodyAsString(); | ||||
|             if (isSuccess(status)) { | ||||
|                 String response = delete.getResponseBodyAsString(); | ||||
| 
 | ||||
| 				// Parse xml response and obtain the list of shares | ||||
| 				ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( | ||||
| 						new ShareXMLParser() | ||||
| 				); | ||||
| 				result = parser.parse(response); | ||||
|                 // Parse xml response and obtain the list of shares | ||||
|                 ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( | ||||
|                     new ShareXMLParser() | ||||
|                 ); | ||||
|                 result = parser.parse(response); | ||||
| 
 | ||||
| 				Log_OC.d(TAG, "Unshare " + id + ": " + result.getLogMessage()); | ||||
|                 Log_OC.d(TAG, "Unshare " + id + ": " + result.getLogMessage()); | ||||
| 
 | ||||
| 			} else { | ||||
| 				result = new RemoteOperationResult(false, status, delete.getResponseHeaders()); | ||||
| 			} | ||||
| 		} catch (Exception e) { | ||||
| 			result = new RemoteOperationResult(e); | ||||
| 			Log_OC.e(TAG, "Unshare Link Exception " + result.getLogMessage(), e); | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(false, delete); | ||||
|             } | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
|             Log_OC.e(TAG, "Unshare Link Exception " + result.getLogMessage(), e); | ||||
| 
 | ||||
| 		} finally { | ||||
| 			if (delete != null) | ||||
| 				delete.releaseConnection(); | ||||
| 		} | ||||
| 		return result; | ||||
| 	} | ||||
|         } finally { | ||||
|             if (delete != null) | ||||
|                 delete.releaseConnection(); | ||||
|         } | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 	private boolean isSuccess(int status) { | ||||
| 		return (status == HttpStatus.SC_OK); | ||||
| 	} | ||||
|     private boolean isSuccess(int status) { | ||||
|         return (status == HttpStatus.SC_OK); | ||||
|     } | ||||
| } | ||||
| @ -216,7 +216,7 @@ public class UpdateRemoteShareOperation extends RemoteOperation { | ||||
|                     result = parser.parse(response); | ||||
| 
 | ||||
|                 } else { | ||||
|                     result = new RemoteOperationResult(false, status, put.getResponseHeaders()); | ||||
|                     result = new RemoteOperationResult(false, put); | ||||
|                 } | ||||
|                 if (!result.isSuccess()) { | ||||
|                     break; | ||||
|  | ||||
| @ -242,18 +242,18 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation { | ||||
|                     } | ||||
|                     // Result | ||||
|                     data.add(capability); | ||||
|                     result = new RemoteOperationResult(true, status, get.getResponseHeaders()); | ||||
|                     result = new RemoteOperationResult(true, get); | ||||
|                     result.setData(data); | ||||
| 
 | ||||
|                     Log_OC.d(TAG, "*** Get Capabilities completed "); | ||||
|                 } else { | ||||
|                     result = new RemoteOperationResult(statusProp, statuscode, null); | ||||
|                     result = new RemoteOperationResult(statusProp, statuscode, null, null); | ||||
|                     Log_OC.e(TAG, "Failed response while getting capabilities from the server "); | ||||
|                     Log_OC.e(TAG, "*** status: " + statusProp + "; message: " + message); | ||||
|                 } | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(false, status, get.getResponseHeaders()); | ||||
|                 result = new RemoteOperationResult(false, get); | ||||
|                 String response = get.getResponseBodyAsString(); | ||||
|                 Log_OC.e(TAG, "Failed response while getting capabilities from the server "); | ||||
|                 if (response != null) { | ||||
|  | ||||
| @ -49,7 +49,6 @@ import com.owncloud.android.lib.common.utils.Log_OC; | ||||
|  * | ||||
|  * @author David A. Velasco | ||||
|  * @author masensio | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| public class GetRemoteStatusOperation extends RemoteOperation { | ||||
| @ -81,79 +80,74 @@ public class GetRemoteStatusOperation extends RemoteOperation { | ||||
| 
 | ||||
|             HttpParams params = get.getParams().getDefaultParams(); | ||||
|             params.setParameter(HttpMethodParams.USER_AGENT, | ||||
|                     OwnCloudClientManagerFactory.getUserAgent()); | ||||
|                 OwnCloudClientManagerFactory.getUserAgent()); | ||||
|             get.getParams().setDefaults(params); | ||||
| 
 | ||||
|             client.setFollowRedirects(false); | ||||
|             boolean isRedirectToNonSecureConnection = false; | ||||
|             int status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT); | ||||
|             mLatestResult = new RemoteOperationResult( | ||||
|             		(status == HttpStatus.SC_OK), | ||||
|             		status, | ||||
|             		get.getResponseHeaders() | ||||
|     		); | ||||
|             mLatestResult = new RemoteOperationResult((status == HttpStatus.SC_OK), get); | ||||
| 
 | ||||
|         	String redirectedLocation = mLatestResult.getRedirectedLocation(); | ||||
|         	while (redirectedLocation != null && redirectedLocation.length() > 0 | ||||
| 							&& !mLatestResult.isSuccess()) { | ||||
|             String redirectedLocation = mLatestResult.getRedirectedLocation(); | ||||
|             while (redirectedLocation != null && redirectedLocation.length() > 0 | ||||
|                 && !mLatestResult.isSuccess()) { | ||||
| 
 | ||||
|         		isRedirectToNonSecureConnection |= ( | ||||
|         				baseUrlSt.startsWith("https://") &&  | ||||
|         				redirectedLocation.startsWith("http://") | ||||
| 				); | ||||
|         		get.releaseConnection(); | ||||
|         		get = new GetMethod(redirectedLocation); | ||||
|         		status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT); | ||||
|         		mLatestResult = new RemoteOperationResult( | ||||
|         				(status == HttpStatus.SC_OK),  | ||||
|         				status,  | ||||
|         				get.getResponseHeaders() | ||||
| 				);  | ||||
|         		redirectedLocation = mLatestResult.getRedirectedLocation(); | ||||
|         	} | ||||
|                 isRedirectToNonSecureConnection |= ( | ||||
|                     baseUrlSt.startsWith("https://") && | ||||
|                         redirectedLocation.startsWith("http://") | ||||
|                 ); | ||||
|                 get.releaseConnection(); | ||||
|                 get = new GetMethod(redirectedLocation); | ||||
|                 status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT); | ||||
|                 mLatestResult = new RemoteOperationResult( | ||||
|                     (status == HttpStatus.SC_OK), | ||||
|                     get | ||||
|                 ); | ||||
|                 redirectedLocation = mLatestResult.getRedirectedLocation(); | ||||
|             } | ||||
| 
 | ||||
|             String response = get.getResponseBodyAsString(); | ||||
|             if (status == HttpStatus.SC_OK) { | ||||
|                 JSONObject json = new JSONObject(response); | ||||
|                 if (!json.getBoolean(NODE_INSTALLED)) { | ||||
|                     mLatestResult = new RemoteOperationResult( | ||||
|                     		RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); | ||||
|                         RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); | ||||
|                 } else { | ||||
|                     String version = json.getString(NODE_VERSION); | ||||
| 					OwnCloudVersion ocVersion = new OwnCloudVersion(version); | ||||
|                     OwnCloudVersion ocVersion = new OwnCloudVersion(version); | ||||
|                     if (!ocVersion.isVersionValid()) { | ||||
|                         mLatestResult = new RemoteOperationResult( | ||||
|                         		RemoteOperationResult.ResultCode.BAD_OC_VERSION); | ||||
|                             RemoteOperationResult.ResultCode.BAD_OC_VERSION); | ||||
| 
 | ||||
|                     } else { | ||||
|                     	// success | ||||
|                     	if (isRedirectToNonSecureConnection) { | ||||
|                     		mLatestResult = new RemoteOperationResult( | ||||
|                     				RemoteOperationResult.ResultCode. | ||||
|                     					OK_REDIRECT_TO_NON_SECURE_CONNECTION | ||||
|         					); | ||||
|                     	} else { | ||||
|                     		mLatestResult = new RemoteOperationResult( | ||||
|                     				baseUrlSt.startsWith("https://") ? | ||||
|                     						RemoteOperationResult.ResultCode.OK_SSL : | ||||
|                 							RemoteOperationResult.ResultCode.OK_NO_SSL | ||||
| 							); | ||||
|                 		} | ||||
|                         // success | ||||
|                         if (isRedirectToNonSecureConnection) { | ||||
|                             mLatestResult = new RemoteOperationResult( | ||||
|                                 RemoteOperationResult.ResultCode. | ||||
|                                     OK_REDIRECT_TO_NON_SECURE_CONNECTION | ||||
|                             ); | ||||
|                         } else { | ||||
|                             mLatestResult = new RemoteOperationResult( | ||||
|                                 baseUrlSt.startsWith("https://") ? | ||||
|                                     RemoteOperationResult.ResultCode.OK_SSL : | ||||
|                                     RemoteOperationResult.ResultCode.OK_NO_SSL | ||||
|                             ); | ||||
|                         } | ||||
| 
 | ||||
| 						ArrayList<Object> data = new ArrayList<Object>(); | ||||
| 						data.add(ocVersion); | ||||
| 						mLatestResult.setData(data); | ||||
| 						retval = true; | ||||
|                         ArrayList<Object> data = new ArrayList<Object>(); | ||||
|                         data.add(ocVersion); | ||||
|                         mLatestResult.setData(data); | ||||
|                         retval = true; | ||||
|                     } | ||||
|                 } | ||||
| 
 | ||||
|             } else { | ||||
|                 mLatestResult = new RemoteOperationResult(false, status, get.getResponseHeaders()); | ||||
|                 mLatestResult = new RemoteOperationResult(false, get); | ||||
|             } | ||||
| 
 | ||||
|         } catch (JSONException e) { | ||||
|             mLatestResult = new RemoteOperationResult( | ||||
|             		RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); | ||||
|                 RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             mLatestResult = new RemoteOperationResult(e); | ||||
| @ -168,7 +162,7 @@ public class GetRemoteStatusOperation extends RemoteOperation { | ||||
| 
 | ||||
|         } else if (mLatestResult.getException() != null) { | ||||
|             Log_OC.e(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage(), | ||||
|             		mLatestResult.getException()); | ||||
|                 mLatestResult.getException()); | ||||
| 
 | ||||
|         } else { | ||||
|             Log_OC.e(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage()); | ||||
| @ -179,15 +173,15 @@ public class GetRemoteStatusOperation extends RemoteOperation { | ||||
| 
 | ||||
|     private boolean isOnline() { | ||||
|         ConnectivityManager cm = (ConnectivityManager) mContext | ||||
|                 .getSystemService(Context.CONNECTIVITY_SERVICE); | ||||
|             .getSystemService(Context.CONNECTIVITY_SERVICE); | ||||
|         return cm != null && cm.getActiveNetworkInfo() != null | ||||
|                 && cm.getActiveNetworkInfo().isConnectedOrConnecting(); | ||||
|             && cm.getActiveNetworkInfo().isConnectedOrConnecting(); | ||||
|     } | ||||
| 
 | ||||
| 	@Override | ||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         if (!isOnline()) { | ||||
|         	return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION); | ||||
|             return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION); | ||||
|         } | ||||
|         String baseUriStr = client.getBaseUri().toString(); | ||||
|         if (baseUriStr.startsWith("http://") || baseUriStr.startsWith("https://")) { | ||||
| @ -196,13 +190,13 @@ public class GetRemoteStatusOperation extends RemoteOperation { | ||||
|         } else { | ||||
|             client.setBaseUri(Uri.parse("https://" + baseUriStr)); | ||||
|             boolean httpsSuccess = tryConnection(client); | ||||
| 			if (!httpsSuccess && !mLatestResult.isSslRecoverableException()) { | ||||
|             if (!httpsSuccess && !mLatestResult.isSslRecoverableException()) { | ||||
|                 Log_OC.d(TAG, "establishing secure connection failed, trying non secure connection"); | ||||
|                 client.setBaseUri(Uri.parse("http://" + baseUriStr)); | ||||
|                 tryConnection(client); | ||||
|             } | ||||
|         } | ||||
|         return mLatestResult; | ||||
| 	} | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -143,15 +143,15 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation { | ||||
|                 } | ||||
| 
 | ||||
|                 // Result | ||||
|                 result = new RemoteOperationResult(true, status, get.getResponseHeaders()); | ||||
|                 result = new RemoteOperationResult(true, get); | ||||
|                 ResultData resultData = new ResultData(bos.toByteArray(), mimeType, etag); | ||||
|                 ArrayList<Object> data = new ArrayList<Object>(); | ||||
|                 data.add(resultData); | ||||
|                 result.setData(data); | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(false, get); | ||||
|                 client.exhaustResponse(get.getResponseBodyAsStream()); | ||||
|                 result = new RemoteOperationResult(false, status, get.getResponseHeaders()); | ||||
|             } | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|  | ||||
| @ -86,14 +86,14 @@ public class GetRemoteUserInfoOperation extends RemoteOperation { | ||||
|                 userInfo.mEmail = respData.getString(NODE_EMAIL); | ||||
| 
 | ||||
|                 // Result | ||||
|                 result = new RemoteOperationResult(true, status, get.getResponseHeaders()); | ||||
|                 result = new RemoteOperationResult(true, get); | ||||
|                 // Username in result.data | ||||
|                 ArrayList<Object> data = new ArrayList<Object>(); | ||||
|                 data.add(userInfo); | ||||
|                 result.setData(data); | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(false, status, get.getResponseHeaders()); | ||||
|                 result = new RemoteOperationResult(false, get); | ||||
|                 String response = get.getResponseBodyAsString(); | ||||
|                 Log_OC.e(TAG, "Failed response while getting user information "); | ||||
|                 if (response != null) { | ||||
|  | ||||
| @ -107,14 +107,14 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation { | ||||
| 
 | ||||
| 
 | ||||
|                 // Result | ||||
|                 result = new RemoteOperationResult(true, status, get.getResponseHeaders()); | ||||
|                 result = new RemoteOperationResult(true, get); | ||||
|                 //Quota data in data collection | ||||
|                 ArrayList<Object> data = new ArrayList<Object>(); | ||||
|                 data.add(new Quota(quotaFree, quotaUsed, quotaTotal, quotaRelative)); | ||||
|                 result.setData(data); | ||||
| 
 | ||||
|             } else { | ||||
|                 result = new RemoteOperationResult(false, status, get.getResponseHeaders()); | ||||
|                 result = new RemoteOperationResult(false, get); | ||||
|                 String response = get.getResponseBodyAsString(); | ||||
|                 Log_OC.e(TAG, "Failed response while getting user quota information "); | ||||
|                 if (response != null) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user