mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Merge pull request #146 from owncloud/improve_error_feedback
Keep HTTP phrase in RemoteOperationResult as fallback user message
This commit is contained in:
		
						commit
						bdcab895a5
					
				| @ -45,6 +45,7 @@ import com.owncloud.android.lib.common.utils.Log_OC; | |||||||
| import org.apache.commons.httpclient.ConnectTimeoutException; | import org.apache.commons.httpclient.ConnectTimeoutException; | ||||||
| import org.apache.commons.httpclient.Header; | import org.apache.commons.httpclient.Header; | ||||||
| import org.apache.commons.httpclient.HttpException; | import org.apache.commons.httpclient.HttpException; | ||||||
|  | import org.apache.commons.httpclient.HttpMethod; | ||||||
| import org.apache.commons.httpclient.HttpStatus; | import org.apache.commons.httpclient.HttpStatus; | ||||||
| import org.apache.jackrabbit.webdav.DavException; | import org.apache.jackrabbit.webdav.DavException; | ||||||
| import org.json.JSONException; | import org.json.JSONException; | ||||||
| @ -63,9 +64,8 @@ import javax.net.ssl.SSLException; | |||||||
| public class RemoteOperationResult implements Serializable { | public class RemoteOperationResult implements Serializable { | ||||||
| 
 | 
 | ||||||
|     /** Generated - should be refreshed every time the class changes!! */ |     /** 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(); |     private static final String TAG = RemoteOperationResult.class.getSimpleName(); | ||||||
| 
 | 
 | ||||||
|     public enum ResultCode { |     public enum ResultCode { | ||||||
| @ -120,6 +120,7 @@ public class RemoteOperationResult implements Serializable { | |||||||
| 
 | 
 | ||||||
|     private boolean mSuccess = false; |     private boolean mSuccess = false; | ||||||
|     private int mHttpCode = -1; |     private int mHttpCode = -1; | ||||||
|  |     private String mHttpPhrase = null; | ||||||
|     private Exception mException = null; |     private Exception mException = null; | ||||||
|     private ResultCode mCode = ResultCode.UNKNOWN_ERROR; |     private ResultCode mCode = ResultCode.UNKNOWN_ERROR; | ||||||
|     private String mRedirectedLocation; |     private String mRedirectedLocation; | ||||||
| @ -128,6 +129,13 @@ public class RemoteOperationResult implements Serializable { | |||||||
| 
 | 
 | ||||||
|     private ArrayList<Object> mData; |     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) { |     public RemoteOperationResult(ResultCode code) { | ||||||
|         mCode = code; |         mCode = code; | ||||||
|         mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL || |         mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL || | ||||||
| @ -136,96 +144,15 @@ public class RemoteOperationResult implements Serializable { | |||||||
|         mData = null; |         mData = null; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private RemoteOperationResult(boolean success, int httpCode) { |     /** | ||||||
|         mSuccess = success; |      * Public constructor from exception. | ||||||
|         mHttpCode = httpCode; |      * | ||||||
| 
 |      * To be used when an exception prevented the end of the {@link RemoteOperation}. | ||||||
|         if (success) { |      * | ||||||
|             mCode = ResultCode.OK; |      * Determines a {@link ResultCode} depending on the type of the exception. | ||||||
| 
 |      * | ||||||
|         } else if (httpCode > 0) { |      * @param e     Exception that interrupted the {@link RemoteOperation} | ||||||
|             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 RemoteOperationResult(Exception e) { |     public RemoteOperationResult(Exception e) { | ||||||
|         mException = 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) { |     public void setData(ArrayList<Object> files) { | ||||||
|         mData = files; |         mData = files; | ||||||
| @ -297,6 +351,10 @@ public class RemoteOperationResult implements Serializable { | |||||||
|         return mHttpCode; |         return mHttpCode; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public String getHttpPhrase() { | ||||||
|  |         return mHttpPhrase; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public ResultCode getCode() { |     public ResultCode getCode() { | ||||||
|         return mCode; |         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.ProgressiveDataTransferer; | ||||||
| import com.owncloud.android.lib.common.network.WebdavUtils; | import com.owncloud.android.lib.common.network.WebdavUtils; | ||||||
| import com.owncloud.android.lib.common.operations.InvalidCharacterExceptionParser; | 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; | 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(); |     private static final String TAG = ChunkedUploadRemoteFileOperation.class.getSimpleName(); | ||||||
| 
 | 
 | ||||||
|     public ChunkedUploadRemoteFileOperation(String storagePath, String remotePath, String mimeType, |     public ChunkedUploadRemoteFileOperation(String storagePath, String remotePath, String mimeType, | ||||||
|                                             String fileLastModifTimestamp){ |                                             String fileLastModifTimestamp) { | ||||||
|         super(storagePath, remotePath, mimeType, fileLastModifTimestamp); |         super(storagePath, remotePath, mimeType, fileLastModifTimestamp); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public ChunkedUploadRemoteFileOperation( |     public ChunkedUploadRemoteFileOperation( | ||||||
|             String storagePath, String remotePath, String mimeType, String requiredEtag, |         String storagePath, String remotePath, String mimeType, String requiredEtag, | ||||||
|             String fileLastModifTimestamp |         String fileLastModifTimestamp | ||||||
|     ){ |     ) { | ||||||
| 		 super(storagePath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp); |         super(storagePath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp); | ||||||
| 	} |     } | ||||||
|      | 
 | ||||||
|     @Override |     @Override | ||||||
|     protected int uploadFile(OwnCloudClient client) throws IOException { |     protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOException { | ||||||
|         int status = -1; |         int status = -1; | ||||||
|  |         RemoteOperationResult result = null; | ||||||
| 
 | 
 | ||||||
|         FileChannel channel = null; |         FileChannel channel = null; | ||||||
|         RandomAccessFile raf = null; |         RandomAccessFile raf = null; | ||||||
| @ -76,24 +78,24 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation | |||||||
|             channel = raf.getChannel(); |             channel = raf.getChannel(); | ||||||
|             mEntity = new ChunkFromFileChannelRequestEntity(channel, mMimeType, CHUNK_SIZE, file); |             mEntity = new ChunkFromFileChannelRequestEntity(channel, mMimeType, CHUNK_SIZE, file); | ||||||
|             synchronized (mDataTransferListeners) { |             synchronized (mDataTransferListeners) { | ||||||
| 				((ProgressiveDataTransferer)mEntity) |                 ((ProgressiveDataTransferer) mEntity) | ||||||
|                         .addDatatransferProgressListeners(mDataTransferListeners); |                     .addDatatransferProgressListeners(mDataTransferListeners); | ||||||
| 			} |             } | ||||||
|              | 
 | ||||||
|             long offset = 0; |             long offset = 0; | ||||||
|             String uriPrefix = client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath) + |             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 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 chunkSizeStr = String.valueOf(CHUNK_SIZE); | ||||||
|             String totalLengthStr = String.valueOf(file.length()); |             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) { |                 if (chunkIndex == chunkCount - 1) { | ||||||
|                     chunkSizeStr = String.valueOf(CHUNK_SIZE * chunkCount - totalLength); |                     chunkSizeStr = String.valueOf(CHUNK_SIZE * chunkCount - totalLength); | ||||||
|                 } |                 } | ||||||
|                 if (mPutMethod != null) { |                 if (mPutMethod != null) { | ||||||
|                     mPutMethod.releaseConnection();     // let the connection available |                     mPutMethod.releaseConnection();     // let the connection available | ||||||
|                                                         // for other methods |                     // for other methods | ||||||
|                 } |                 } | ||||||
|                 mPutMethod = new PutMethod(uriPrefix + chunkCount + "-" + chunkIndex); |                 mPutMethod = new PutMethod(uriPrefix + chunkCount + "-" + chunkIndex); | ||||||
|                 if (mRequiredEtag != null && mRequiredEtag.length() > 0) { |                 if (mRequiredEtag != null && mRequiredEtag.length() > 0) { | ||||||
| @ -121,29 +123,20 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation | |||||||
| 
 | 
 | ||||||
|                 status = client.executeMethod(mPutMethod); |                 status = client.executeMethod(mPutMethod); | ||||||
| 
 | 
 | ||||||
|                 if (status == 400) { |                 result = new RemoteOperationResult( | ||||||
|                     InvalidCharacterExceptionParser xmlParser = |                     isSuccess(status), | ||||||
|                             new InvalidCharacterExceptionParser(); |                     mPutMethod | ||||||
|                     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); |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
| 
 | 
 | ||||||
|                 client.exhaustResponse(mPutMethod.getResponseBodyAsStream()); |                 client.exhaustResponse(mPutMethod.getResponseBodyAsStream()); | ||||||
|                 Log_OC.d(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + |                 Log_OC.d(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + | ||||||
|                         ", chunk index " + chunkIndex + ", count " + chunkCount + |                     ", chunk index " + chunkIndex + ", count " + chunkCount + | ||||||
|                         ", HTTP result status " + status); |                     ", HTTP result status " + status); | ||||||
| 
 | 
 | ||||||
|                 if (!isSuccess(status)) |                 if (!isSuccess(status)) | ||||||
|                     break; |                     break; | ||||||
|             } |             } | ||||||
|              | 
 | ||||||
|         } finally { |         } finally { | ||||||
|             if (channel != null) |             if (channel != null) | ||||||
|                 channel.close(); |                 channel.close(); | ||||||
| @ -152,7 +145,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation | |||||||
|             if (mPutMethod != null) |             if (mPutMethod != null) | ||||||
|                 mPutMethod.releaseConnection();    // let the connection available for other methods |                 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: |                 /// for other errors that could be explicitly handled, check first: | ||||||
|                 /// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 |                 /// 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 { |             } else { | ||||||
|                 result = new RemoteOperationResult( |                 result = new RemoteOperationResult(isSuccess(status), copyMethod); | ||||||
|                         isSuccess(status),    // copy.succeeded()? trustful? |  | ||||||
|                         status, |  | ||||||
|                         copyMethod.getResponseHeaders() |  | ||||||
|                 ); |  | ||||||
|                 client.exhaustResponse(copyMethod.getResponseBodyAsStream()); |                 client.exhaustResponse(copyMethod.getResponseBodyAsStream()); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
| @ -196,11 +189,7 @@ public class CopyRemoteFileOperation extends RemoteOperation { | |||||||
|         if (failFound) { |         if (failFound) { | ||||||
|             result = new RemoteOperationResult(ResultCode.PARTIAL_COPY_DONE); |             result = new RemoteOperationResult(ResultCode.PARTIAL_COPY_DONE); | ||||||
|         } else { |         } else { | ||||||
|             result = new RemoteOperationResult( |             result = new RemoteOperationResult(true, copyMethod); | ||||||
|                     true, |  | ||||||
|                     HttpStatus.SC_MULTI_STATUS, |  | ||||||
|                     copyMethod.getResponseHeaders() |  | ||||||
|             ); |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return result; |         return result; | ||||||
|  | |||||||
| @ -37,28 +37,27 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion; | |||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Remote operation performing the creation of a new folder in the ownCloud server. |  * Remote operation performing the creation of a new folder in the ownCloud server. | ||||||
|  *  |  | ||||||
|  * @author David A. Velasco  |  | ||||||
|  * @author masensio |  | ||||||
|  * |  * | ||||||
|  |  * @author David A. Velasco | ||||||
|  |  * @author masensio | ||||||
|  */ |  */ | ||||||
| public class CreateRemoteFolderOperation extends RemoteOperation { | public class CreateRemoteFolderOperation extends RemoteOperation { | ||||||
|      | 
 | ||||||
|     private static final String TAG = CreateRemoteFolderOperation.class.getSimpleName(); |     private static final String TAG = CreateRemoteFolderOperation.class.getSimpleName(); | ||||||
| 
 | 
 | ||||||
|     private static final int READ_TIMEOUT = 30000; |     private static final int READ_TIMEOUT = 30000; | ||||||
|     private static final int CONNECTION_TIMEOUT = 5000; |     private static final int CONNECTION_TIMEOUT = 5000; | ||||||
|      | 
 | ||||||
| 
 | 
 | ||||||
|     protected String mRemotePath; |     protected String mRemotePath; | ||||||
|     protected boolean mCreateFullPath; |     protected boolean mCreateFullPath; | ||||||
|      | 
 | ||||||
|     /** |     /** | ||||||
|      * Constructor |      * Constructor | ||||||
|      *  |      * | ||||||
|      * @param remotePath            Full path to the new directory to create in the remote server. |      * @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 |      * @param createFullPath 'True' means that all the ancestor folders should be created | ||||||
|      *                              if don't exist yet. |      *                       if don't exist yet. | ||||||
|      */ |      */ | ||||||
|     public CreateRemoteFolderOperation(String remotePath, boolean createFullPath) { |     public CreateRemoteFolderOperation(String remotePath, boolean createFullPath) { | ||||||
|         mRemotePath = remotePath; |         mRemotePath = remotePath; | ||||||
| @ -67,69 +66,60 @@ public class CreateRemoteFolderOperation extends RemoteOperation { | |||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Performs the operation |      * 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 |     @Override | ||||||
|     protected RemoteOperationResult run(OwnCloudClient client) { |     protected RemoteOperationResult run(OwnCloudClient client) { | ||||||
|         RemoteOperationResult result = null; |         RemoteOperationResult result = null; | ||||||
|         OwnCloudVersion version = client.getOwnCloudVersion(); |         OwnCloudVersion version = client.getOwnCloudVersion(); | ||||||
|         boolean versionWithForbiddenChars = |         boolean versionWithForbiddenChars = | ||||||
|                 (version != null && version.isVersionWithForbiddenCharacters()); |             (version != null && version.isVersionWithForbiddenCharacters()); | ||||||
|         boolean noInvalidChars = FileUtils.isValidPath(mRemotePath, versionWithForbiddenChars); |         boolean noInvalidChars = FileUtils.isValidPath(mRemotePath, versionWithForbiddenChars); | ||||||
|         if (noInvalidChars) { |         if (noInvalidChars) { | ||||||
|         	result = createFolder(client); |             result = createFolder(client); | ||||||
|     		if (!result.isSuccess() && mCreateFullPath &&  |             if (!result.isSuccess() && mCreateFullPath && | ||||||
|     				RemoteOperationResult.ResultCode.CONFLICT == result.getCode()) { |                 RemoteOperationResult.ResultCode.CONFLICT == result.getCode()) { | ||||||
|     			result = createParentFolder(FileUtils.getParentPath(mRemotePath), client); |                 result = createParentFolder(FileUtils.getParentPath(mRemotePath), client); | ||||||
|     			if (result.isSuccess()) { |                 if (result.isSuccess()) { | ||||||
| 	    			result = createFolder(client);	// second (and last) try |                     result = createFolder(client);    // second (and last) try | ||||||
|     			} |                 } | ||||||
|     		} |             } | ||||||
|         	 | 
 | ||||||
|         } else { |         } else { | ||||||
|         	result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); |             result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); | ||||||
|         } |         } | ||||||
|          | 
 | ||||||
|         return result; |         return result; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|      | 
 | ||||||
|     private RemoteOperationResult createFolder(OwnCloudClient client) { |     private RemoteOperationResult createFolder(OwnCloudClient client) { | ||||||
|         RemoteOperationResult result = null; |         RemoteOperationResult result = null; | ||||||
|         MkColMethod mkcol = null; |         MkColMethod mkcol = null; | ||||||
|     	try { |         try { | ||||||
|     		mkcol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); |             mkcol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); | ||||||
|     		int status =  client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT); |             client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT); | ||||||
|             if ( status == 400 ) { |             result = new RemoteOperationResult(mkcol.succeeded(), mkcol); | ||||||
|                 result = new RemoteOperationResult(mkcol.succeeded(), |             Log_OC.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage()); | ||||||
|                         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()); |  | ||||||
|             } |  | ||||||
|             client.exhaustResponse(mkcol.getResponseBodyAsStream()); |             client.exhaustResponse(mkcol.getResponseBodyAsStream()); | ||||||
| 
 | 
 | ||||||
|     	} catch (Exception e) { |         } catch (Exception e) { | ||||||
|     		result = new RemoteOperationResult(e); |             result = new RemoteOperationResult(e); | ||||||
|     		Log_OC.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e); |             Log_OC.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e); | ||||||
| 
 | 
 | ||||||
|     	} finally { |         } finally { | ||||||
|     		if (mkcol != null) |             if (mkcol != null) | ||||||
|     			mkcol.releaseConnection(); |                 mkcol.releaseConnection(); | ||||||
|     	} |         } | ||||||
|     	return result; |         return result; | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client) { |     private RemoteOperationResult createParentFolder(String parentPath, OwnCloudClient client) { | ||||||
|         RemoteOperation operation = new CreateRemoteFolderOperation(parentPath, |         RemoteOperation operation = new CreateRemoteFolderOperation(parentPath, | ||||||
|                                                                 mCreateFullPath); |             mCreateFullPath); | ||||||
|         return operation.execute(client); |         return operation.execute(client); | ||||||
|     } |     } | ||||||
|      | 
 | ||||||
|     |  | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -49,62 +49,61 @@ import com.owncloud.android.lib.common.utils.Log_OC; | |||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Remote operation performing the download of a remote file in the ownCloud server. |  * Remote operation performing the download of a remote file in the ownCloud server. | ||||||
|  *  |  * | ||||||
|  * @author David A. Velasco |  * @author David A. Velasco | ||||||
|  * @author masensio |  * @author masensio | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| public class DownloadRemoteFileOperation extends RemoteOperation { | 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 final AtomicBoolean mCancellationRequested = new AtomicBoolean(false); | ||||||
|     private long mModificationTimestamp = 0; |     private long mModificationTimestamp = 0; | ||||||
|     private String mEtag = ""; |     private String mEtag = ""; | ||||||
|     private GetMethod mGet; |     private GetMethod mGet; | ||||||
|      | 
 | ||||||
|     private String mRemotePath; |     private String mRemotePath; | ||||||
|     private String mLocalFolderPath; |     private String mLocalFolderPath; | ||||||
| 	 |  | ||||||
| 	public DownloadRemoteFileOperation(String remotePath, String localFolderPath) { |  | ||||||
| 		mRemotePath = remotePath; |  | ||||||
| 		mLocalFolderPath = localFolderPath; |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	@Override |     public DownloadRemoteFileOperation(String remotePath, String localFolderPath) { | ||||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { |         mRemotePath = remotePath; | ||||||
| 		RemoteOperationResult result = null; |         mLocalFolderPath = localFolderPath; | ||||||
|          |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     protected RemoteOperationResult run(OwnCloudClient client) { | ||||||
|  |         RemoteOperationResult result = null; | ||||||
|  | 
 | ||||||
|         /// download will be performed to a temporal file, then moved to the final location |         /// download will be performed to a temporal file, then moved to the final location | ||||||
|         File tmpFile = new File(getTmpPath()); |         File tmpFile = new File(getTmpPath()); | ||||||
|          | 
 | ||||||
|         /// perform the download |         /// perform the download | ||||||
|         try { |         try { | ||||||
|         	tmpFile.getParentFile().mkdirs(); |             tmpFile.getParentFile().mkdirs(); | ||||||
|         	int status = downloadFile(client, tmpFile); |             int status = downloadFile(client, tmpFile); | ||||||
|         	result = new RemoteOperationResult(isSuccess(status), status, |             result = new RemoteOperationResult(isSuccess(status), mGet); | ||||||
|                     (mGet != null ? mGet.getResponseHeaders() : null)); |             Log_OC.i(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + | ||||||
|         	Log_OC.i(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + |                 result.getLogMessage()); | ||||||
|                     result.getLogMessage()); |  | ||||||
| 
 | 
 | ||||||
|         } catch (Exception e) { |         } catch (Exception e) { | ||||||
|             result = new RemoteOperationResult(e); |             result = new RemoteOperationResult(e); | ||||||
|             Log_OC.e(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + |             Log_OC.e(TAG, "Download of " + mRemotePath + " to " + getTmpPath() + ": " + | ||||||
|                     result.getLogMessage(), e); |                 result.getLogMessage(), e); | ||||||
|         } |         } | ||||||
|          |  | ||||||
|         return result; |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	 |         return result; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|     protected int downloadFile(OwnCloudClient client, File targetFile) throws HttpException, |     protected int downloadFile(OwnCloudClient client, File targetFile) throws HttpException, | ||||||
|             IOException, OperationCancelledException { |         IOException, OperationCancelledException { | ||||||
|         int status = -1; |         int status = -1; | ||||||
|         boolean savedFile = false; |         boolean savedFile = false; | ||||||
|         mGet = new GetMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); |         mGet = new GetMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); | ||||||
|         Iterator<OnDatatransferProgressListener> it = null; |         Iterator<OnDatatransferProgressListener> it = null; | ||||||
|          | 
 | ||||||
|         FileOutputStream fos = null; |         FileOutputStream fos = null; | ||||||
|         try { |         try { | ||||||
|             status = client.executeMethod(mGet); |             status = client.executeMethod(mGet); | ||||||
| @ -113,16 +112,16 @@ public class DownloadRemoteFileOperation extends RemoteOperation { | |||||||
|                 BufferedInputStream bis = new BufferedInputStream(mGet.getResponseBodyAsStream()); |                 BufferedInputStream bis = new BufferedInputStream(mGet.getResponseBodyAsStream()); | ||||||
|                 fos = new FileOutputStream(targetFile); |                 fos = new FileOutputStream(targetFile); | ||||||
|                 long transferred = 0; |                 long transferred = 0; | ||||||
|                  | 
 | ||||||
|                 Header contentLength = mGet.getResponseHeader("Content-Length"); |                 Header contentLength = mGet.getResponseHeader("Content-Length"); | ||||||
|                 long totalToTransfer = (contentLength != null && |                 long totalToTransfer = (contentLength != null && | ||||||
|                         contentLength.getValue().length() >0) ? |                     contentLength.getValue().length() > 0) ? | ||||||
|                         Long.parseLong(contentLength.getValue()) : 0; |                     Long.parseLong(contentLength.getValue()) : 0; | ||||||
| 
 | 
 | ||||||
|                 byte[] bytes = new byte[4096]; |                 byte[] bytes = new byte[4096]; | ||||||
|                 int readResult = 0; |                 int readResult = 0; | ||||||
|                 while ((readResult = bis.read(bytes)) != -1) { |                 while ((readResult = bis.read(bytes)) != -1) { | ||||||
|                     synchronized(mCancellationRequested) { |                     synchronized (mCancellationRequested) { | ||||||
|                         if (mCancellationRequested.get()) { |                         if (mCancellationRequested.get()) { | ||||||
|                             mGet.abort(); |                             mGet.abort(); | ||||||
|                             throw new OperationCancelledException(); |                             throw new OperationCancelledException(); | ||||||
| @ -134,20 +133,20 @@ public class DownloadRemoteFileOperation extends RemoteOperation { | |||||||
|                         it = mDataTransferListeners.iterator(); |                         it = mDataTransferListeners.iterator(); | ||||||
|                         while (it.hasNext()) { |                         while (it.hasNext()) { | ||||||
|                             it.next().onTransferProgress(readResult, transferred, totalToTransfer, |                             it.next().onTransferProgress(readResult, transferred, totalToTransfer, | ||||||
|                                     targetFile.getName()); |                                 targetFile.getName()); | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 if (transferred == totalToTransfer) {  // Check if the file is completed |                 if (transferred == totalToTransfer) {  // Check if the file is completed | ||||||
|                 	savedFile = true; |                     savedFile = true; | ||||||
|                 	Header modificationTime = mGet.getResponseHeader("Last-Modified"); |                     Header modificationTime = mGet.getResponseHeader("Last-Modified"); | ||||||
|                     if (modificationTime == null) { |                     if (modificationTime == null) { | ||||||
|                         modificationTime = mGet.getResponseHeader("last-modified"); |                         modificationTime = mGet.getResponseHeader("last-modified"); | ||||||
|                     } |                     } | ||||||
|                 	if (modificationTime != null) { |                     if (modificationTime != null) { | ||||||
|                 		Date d = WebdavUtils.parseResponseDate((String) modificationTime.getValue()); |                         Date d = WebdavUtils.parseResponseDate((String) modificationTime.getValue()); | ||||||
|                 		mModificationTimestamp = (d != null) ? d.getTime() : 0; |                         mModificationTimestamp = (d != null) ? d.getTime() : 0; | ||||||
|                 	} else { |                     } else { | ||||||
|                         Log_OC.e(TAG, "Could not read modification time from response downloading " + mRemotePath); |                         Log_OC.e(TAG, "Could not read modification time from response downloading " + mRemotePath); | ||||||
|                     } |                     } | ||||||
| 
 | 
 | ||||||
| @ -157,14 +156,14 @@ public class DownloadRemoteFileOperation extends RemoteOperation { | |||||||
|                     } |                     } | ||||||
| 
 | 
 | ||||||
|                 } else { |                 } else { | ||||||
|                 	client.exhaustResponse(mGet.getResponseBodyAsStream()); |                     client.exhaustResponse(mGet.getResponseBodyAsStream()); | ||||||
|                     // TODO some kind of error control! |                     // TODO some kind of error control! | ||||||
|                 } |                 } | ||||||
|                  | 
 | ||||||
|             } else { |             } else { | ||||||
|                 client.exhaustResponse(mGet.getResponseBodyAsStream()); |                 client.exhaustResponse(mGet.getResponseBodyAsStream()); | ||||||
|             } |             } | ||||||
|                  | 
 | ||||||
|         } finally { |         } finally { | ||||||
|             if (fos != null) fos.close(); |             if (fos != null) fos.close(); | ||||||
|             if (!savedFile && targetFile.exists()) { |             if (!savedFile && targetFile.exists()) { | ||||||
| @ -174,34 +173,34 @@ public class DownloadRemoteFileOperation extends RemoteOperation { | |||||||
|         } |         } | ||||||
|         return status; |         return status; | ||||||
|     } |     } | ||||||
|      | 
 | ||||||
|     private boolean isSuccess(int status) { |     private boolean isSuccess(int status) { | ||||||
|         return (status == HttpStatus.SC_OK); |         return (status == HttpStatus.SC_OK); | ||||||
|     } |     } | ||||||
|      | 
 | ||||||
|     private String getTmpPath() { |     private String getTmpPath() { | ||||||
|         return mLocalFolderPath + mRemotePath; |         return mLocalFolderPath + mRemotePath; | ||||||
|     } |     } | ||||||
|      | 
 | ||||||
|     public void addDatatransferProgressListener (OnDatatransferProgressListener listener) { |     public void addDatatransferProgressListener(OnDatatransferProgressListener listener) { | ||||||
|         synchronized (mDataTransferListeners) { |         synchronized (mDataTransferListeners) { | ||||||
|             mDataTransferListeners.add(listener); |             mDataTransferListeners.add(listener); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|      | 
 | ||||||
|     public void removeDatatransferProgressListener(OnDatatransferProgressListener listener) { |     public void removeDatatransferProgressListener(OnDatatransferProgressListener listener) { | ||||||
|         synchronized (mDataTransferListeners) { |         synchronized (mDataTransferListeners) { | ||||||
|             mDataTransferListeners.remove(listener); |             mDataTransferListeners.remove(listener); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|      | 
 | ||||||
|     public void cancel() { |     public void cancel() { | ||||||
|         mCancellationRequested.set(true);   // atomic set; there is no need of synchronizing it |         mCancellationRequested.set(true);   // atomic set; there is no need of synchronizing it | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 	public long getModificationTimestamp() { |     public long getModificationTimestamp() { | ||||||
| 		return mModificationTimestamp; |         return mModificationTimestamp; | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
|     public String getEtag() { |     public String getEtag() { | ||||||
|         return mEtag; |         return mEtag; | ||||||
|  | |||||||
| @ -96,7 +96,12 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation { | |||||||
|             client.exhaustResponse(head.getResponseBodyAsStream()); |             client.exhaustResponse(head.getResponseBodyAsStream()); | ||||||
|             boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) || |             boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) || | ||||||
|                     (status == HttpStatus.SC_NOT_FOUND && 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() + |             Log_OC.d(TAG, "Existence check for " + client.getWebdavUri() + | ||||||
|                     WebdavUtils.encodePath(mPath) + " targeting for " + |                     WebdavUtils.encodePath(mPath) + " targeting for " + | ||||||
|                     (mSuccessIfAbsent ? " absence " : " existence ") + |                     (mSuccessIfAbsent ? " absence " : " existence ") + | ||||||
|  | |||||||
| @ -45,176 +45,163 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion; | |||||||
| /** | /** | ||||||
|  * Remote operation moving a remote file or folder in the ownCloud server to a different folder |  * Remote operation moving a remote file or folder in the ownCloud server to a different folder | ||||||
|  * in the same account. |  * in the same account. | ||||||
|  *  |  * <p> | ||||||
|  * Allows renaming the moving file/folder at the same time. |  * Allows renaming the moving file/folder at the same time. | ||||||
|  *  |  * | ||||||
|  * @author David A. Velasco |  * @author David A. Velasco | ||||||
|  */ |  */ | ||||||
| public class MoveRemoteFileOperation extends RemoteOperation { | 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_READ_TIMEOUT = 600000; | ||||||
| 	private static final int MOVE_CONNECTION_TIMEOUT = 5000; |     private static final int MOVE_CONNECTION_TIMEOUT = 5000; | ||||||
| 
 | 
 | ||||||
|     private String mSrcRemotePath; |     private String mSrcRemotePath; | ||||||
|     private String mTargetRemotePath; |     private String mTargetRemotePath; | ||||||
| 
 | 
 | ||||||
| 	private boolean mOverwrite; |     private boolean mOverwrite; | ||||||
|      | 
 | ||||||
|      | 
 | ||||||
|     /** |     /** | ||||||
|      * Constructor. |      * Constructor. | ||||||
|      *  |      * <p> | ||||||
|      * TODO Paths should finish in "/" in the case of folders. ? |      * TODO Paths should finish in "/" in the case of folders. ? | ||||||
|      *  |      * | ||||||
|      * @param srcRemotePath		Remote path of the file/folder to move.   |      * @param srcRemotePath    Remote path of the file/folder to move. | ||||||
|      * @param targetRemotePath	Remove path desired for the file/folder after moving it. |      * @param targetRemotePath Remove path desired for the file/folder after moving it. | ||||||
|      */ |      */ | ||||||
| 	public MoveRemoteFileOperation( |     public MoveRemoteFileOperation( | ||||||
| 			String srcRemotePath, String targetRemotePath, boolean overwrite |         String srcRemotePath, String targetRemotePath, boolean overwrite | ||||||
| 			) { |     ) { | ||||||
| 		 |  | ||||||
| 		mSrcRemotePath = srcRemotePath; |  | ||||||
| 		mTargetRemotePath = targetRemotePath; |  | ||||||
| 		mOverwrite = overwrite; |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	 |         mSrcRemotePath = srcRemotePath; | ||||||
| 	 /** |         mTargetRemotePath = targetRemotePath; | ||||||
|  |         mOverwrite = overwrite; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|      * Performs the rename operation. |      * 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 |     @Override | ||||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { |     protected RemoteOperationResult run(OwnCloudClient client) { | ||||||
| 
 | 
 | ||||||
| 		OwnCloudVersion version = client.getOwnCloudVersion(); |         OwnCloudVersion version = client.getOwnCloudVersion(); | ||||||
| 		boolean versionWithForbiddenChars = |         boolean versionWithForbiddenChars = | ||||||
|                 (version != null && version.isVersionWithForbiddenCharacters()); |             (version != null && version.isVersionWithForbiddenCharacters()); | ||||||
| 
 | 
 | ||||||
|     	/// check parameters |         /// check parameters | ||||||
|         if (!FileUtils.isValidPath(mTargetRemotePath, versionWithForbiddenChars)) { |         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)) { |         if (mTargetRemotePath.equals(mSrcRemotePath)) { | ||||||
|         	// nothing to do! |             // nothing to do! | ||||||
|             return new RemoteOperationResult(ResultCode.OK); |             return new RemoteOperationResult(ResultCode.OK); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (mTargetRemotePath.startsWith(mSrcRemotePath)) { |         if (mTargetRemotePath.startsWith(mSrcRemotePath)) { | ||||||
|         	return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT); |             return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT); | ||||||
|         } |         } | ||||||
|          | 
 | ||||||
| 
 | 
 | ||||||
|         /// perform remote operation |         /// perform remote operation | ||||||
| 		//LocalMoveMethod move = null; |         MoveMethod move = null; | ||||||
| 		MoveMethod move = null; |         RemoteOperationResult result = null; | ||||||
| 		RemoteOperationResult result = null; |  | ||||||
|         try { |         try { | ||||||
|             move = new MoveMethod( |             move = new MoveMethod( | ||||||
|             		client.getWebdavUri() + WebdavUtils.encodePath(mSrcRemotePath), |                 client.getWebdavUri() + WebdavUtils.encodePath(mSrcRemotePath), | ||||||
|             		client.getWebdavUri() + WebdavUtils.encodePath(mTargetRemotePath), |                 client.getWebdavUri() + WebdavUtils.encodePath(mTargetRemotePath), | ||||||
|             		mOverwrite |                 mOverwrite | ||||||
|     		); |             ); | ||||||
|             int status = client.executeMethod(move, MOVE_READ_TIMEOUT, MOVE_CONNECTION_TIMEOUT); |             int status = client.executeMethod(move, MOVE_READ_TIMEOUT, MOVE_CONNECTION_TIMEOUT); | ||||||
|              |  | ||||||
|             /// process response |  | ||||||
|         	if (status == HttpStatus.SC_MULTI_STATUS) { |  | ||||||
|         		result = processPartialError(move); |  | ||||||
|         		 |  | ||||||
|         	} else if (status == HttpStatus.SC_PRECONDITION_FAILED && !mOverwrite) { |  | ||||||
|         		 |  | ||||||
|         		result = new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); |  | ||||||
|         		client.exhaustResponse(move.getResponseBodyAsStream()); |  | ||||||
| 
 | 
 | ||||||
|         		 |             /// process response | ||||||
|     		/// for other errors that could be explicitly handled, check first: |             if (status == HttpStatus.SC_MULTI_STATUS) { | ||||||
|     		/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 |                 result = processPartialError(move); | ||||||
|         		 | 
 | ||||||
|         	} else if (status == 400) { |             } else if (status == HttpStatus.SC_PRECONDITION_FAILED && !mOverwrite) { | ||||||
| 				result = new RemoteOperationResult(move.succeeded(), | 
 | ||||||
| 						move.getResponseBodyAsString(), status); |                 result = new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); | ||||||
| 			} else { |                 client.exhaustResponse(move.getResponseBodyAsStream()); | ||||||
| 					result = new RemoteOperationResult( | 
 | ||||||
| 							isSuccess(status), 	// move.succeeded()? trustful? | 
 | ||||||
| 							status, |                 /// for other errors that could be explicitly handled, check first: | ||||||
| 							move.getResponseHeaders() |                 /// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 | ||||||
| 					); | 
 | ||||||
| 					client.exhaustResponse(move.getResponseBodyAsStream()); |             } else { | ||||||
| 			} |                 result = new RemoteOperationResult(isSuccess(status), move); | ||||||
|              |                 client.exhaustResponse(move.getResponseBodyAsStream()); | ||||||
|             Log.i(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " +  |             } | ||||||
|         		result.getLogMessage()); | 
 | ||||||
|              |             Log.i(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " + | ||||||
|  |                 result.getLogMessage()); | ||||||
|  | 
 | ||||||
|         } catch (Exception e) { |         } catch (Exception e) { | ||||||
|             result = new RemoteOperationResult(e); |             result = new RemoteOperationResult(e); | ||||||
|             Log.e(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " +  |             Log.e(TAG, "Move " + mSrcRemotePath + " to " + mTargetRemotePath + ": " + | ||||||
|         		result.getLogMessage(), e); |                 result.getLogMessage(), e); | ||||||
|              | 
 | ||||||
|         } finally { |         } finally { | ||||||
|             if (move != null) |             if (move != null) | ||||||
|                 move.releaseConnection(); |                 move.releaseConnection(); | ||||||
|         } |         } | ||||||
|         	 | 
 | ||||||
|         return result; |         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 |  | ||||||
| 	 */ |  | ||||||
|     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. |  | ||||||
|     	 |  | ||||||
|     	/// 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() |  | ||||||
|     		); |  | ||||||
|     	} |  | ||||||
| 		 |  | ||||||
|     	return result;  |  | ||||||
|     			 |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	protected boolean isSuccess(int status) { |     /** | ||||||
|  |      * 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. | ||||||
|  | 
 | ||||||
|  |         /// 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, move); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return result; | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     protected boolean isSuccess(int status) { | ||||||
|         return status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT; |         return status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT; | ||||||
|     } |     } | ||||||
|          | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -40,7 +40,7 @@ import com.owncloud.android.lib.common.utils.Log_OC; | |||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Remote operation performing the read a file from the ownCloud server. |  * Remote operation performing the read a file from the ownCloud server. | ||||||
|  *  |  * | ||||||
|  * @author David A. Velasco |  * @author David A. Velasco | ||||||
|  * @author masensio |  * @author masensio | ||||||
|  */ |  */ | ||||||
| @ -50,70 +50,70 @@ public class ReadRemoteFileOperation extends RemoteOperation { | |||||||
|     private static final String TAG = ReadRemoteFileOperation.class.getSimpleName(); |     private static final String TAG = ReadRemoteFileOperation.class.getSimpleName(); | ||||||
|     private static final int SYNC_READ_TIMEOUT = 40000; |     private static final int SYNC_READ_TIMEOUT = 40000; | ||||||
|     private static final int SYNC_CONNECTION_TIMEOUT = 5000; |     private static final int SYNC_CONNECTION_TIMEOUT = 5000; | ||||||
|      | 
 | ||||||
|     private String mRemotePath; |     private String mRemotePath; | ||||||
|      | 
 | ||||||
| 	 | 
 | ||||||
|     /** |     /** | ||||||
|      * Constructor |      * Constructor | ||||||
|      *  |      * | ||||||
|      * @param remotePath		Remote path of the file.  |      * @param remotePath Remote path of the file. | ||||||
|      */ |      */ | ||||||
|     public ReadRemoteFileOperation(String remotePath) { |     public ReadRemoteFileOperation(String remotePath) { | ||||||
|     	mRemotePath = remotePath; |         mRemotePath = remotePath; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Performs the read operation. |      * 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 |     @Override | ||||||
|     protected RemoteOperationResult run(OwnCloudClient client) { |     protected RemoteOperationResult run(OwnCloudClient client) { | ||||||
|     	PropFindMethod propfind = null; |         PropFindMethod propfind = null; | ||||||
|     	RemoteOperationResult result = null; |         RemoteOperationResult result = null; | ||||||
| 
 | 
 | ||||||
|     	/// take the duty of check the server for the current state of the file there |         /// take the duty of check the server for the current state of the file there | ||||||
|     	try { |         try { | ||||||
|             // remote request |             // remote request | ||||||
|     		propfind = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath), |             propfind = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath), | ||||||
|     				WebdavUtils.getFilePropSet(),    // PropFind Properties |                 WebdavUtils.getFilePropSet(),    // PropFind Properties | ||||||
|     				DavConstants.DEPTH_0); |                 DavConstants.DEPTH_0); | ||||||
|     		int status; |             int status; | ||||||
|     		status = client.executeMethod(propfind, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); |             status = client.executeMethod(propfind, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT); | ||||||
| 
 | 
 | ||||||
|     		boolean isSuccess = ( |             boolean isSuccess = ( | ||||||
|     				status == HttpStatus.SC_MULTI_STATUS || |                 status == HttpStatus.SC_MULTI_STATUS || | ||||||
|     				status == HttpStatus.SC_OK |                     status == HttpStatus.SC_OK | ||||||
| 			); |             ); | ||||||
|     		if (isSuccess) { |             if (isSuccess) { | ||||||
|     			// Parse response |                 // Parse response | ||||||
|     			MultiStatus resp = propfind.getResponseBodyAsMultiStatus(); |                 MultiStatus resp = propfind.getResponseBodyAsMultiStatus(); | ||||||
| 				WebdavEntry we = new WebdavEntry(resp.getResponses()[0], |                 WebdavEntry we = new WebdavEntry(resp.getResponses()[0], | ||||||
|                         client.getWebdavUri().getPath()); |                     client.getWebdavUri().getPath()); | ||||||
| 				RemoteFile remoteFile = new RemoteFile(we); |                 RemoteFile remoteFile = new RemoteFile(we); | ||||||
| 				ArrayList<Object> files = new ArrayList<Object>(); |                 ArrayList<Object> files = new ArrayList<Object>(); | ||||||
| 				files.add(remoteFile); |                 files.add(remoteFile); | ||||||
| 
 | 
 | ||||||
|     			// Result of the operation |                 // Result of the operation | ||||||
|     			result = new RemoteOperationResult(true, status, propfind.getResponseHeaders()); |                 result = new RemoteOperationResult(true, propfind); | ||||||
|     			result.setData(files); |                 result.setData(files); | ||||||
|     			 |  | ||||||
|     		} else { |  | ||||||
|     			client.exhaustResponse(propfind.getResponseBodyAsStream()); |  | ||||||
|     			result = new RemoteOperationResult(false, status, propfind.getResponseHeaders()); |  | ||||||
|     		} |  | ||||||
| 
 | 
 | ||||||
|     	} catch (Exception e) { |             } else { | ||||||
|     		result = new RemoteOperationResult(e); |                 result = new RemoteOperationResult(false, propfind); | ||||||
|     		e.printStackTrace(); |                 client.exhaustResponse(propfind.getResponseBodyAsStream()); | ||||||
|     		Log_OC.e(TAG, "Synchronizing  file " + mRemotePath + ": " + result.getLogMessage(), |             } | ||||||
|                     result.getException()); | 
 | ||||||
|     	} finally { |         } catch (Exception e) { | ||||||
|     		if (propfind != null) |             result = new RemoteOperationResult(e); | ||||||
|     			propfind.releaseConnection(); |             e.printStackTrace(); | ||||||
|     	} |             Log_OC.e(TAG, "Synchronizing  file " + mRemotePath + ": " + result.getLogMessage(), | ||||||
|     	return result; |                 result.getException()); | ||||||
|  |         } finally { | ||||||
|  |             if (propfind != null) | ||||||
|  |                 propfind.releaseConnection(); | ||||||
|  |         } | ||||||
|  |         return result; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -40,126 +40,125 @@ import com.owncloud.android.lib.common.utils.Log_OC; | |||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Remote operation performing the read of remote file or folder in the ownCloud server. |  * Remote operation performing the read of remote file or folder in the ownCloud server. | ||||||
|  *  |  * | ||||||
|  * @author David A. Velasco |  * @author David A. Velasco | ||||||
|  * @author masensio |  * @author masensio | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| public class ReadRemoteFolderOperation extends RemoteOperation { | 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 String mRemotePath; | ||||||
| 	private ArrayList<Object> mFolderAndFiles; |     private ArrayList<Object> mFolderAndFiles; | ||||||
| 	 | 
 | ||||||
| 	/** |     /** | ||||||
|      * Constructor |      * Constructor | ||||||
|      *  |      * | ||||||
|      * @param remotePath		Remote path of the file.  |      * @param remotePath Remote path of the file. | ||||||
|      */ |      */ | ||||||
| 	public ReadRemoteFolderOperation(String remotePath) { |     public ReadRemoteFolderOperation(String remotePath) { | ||||||
| 		mRemotePath = remotePath; |         mRemotePath = remotePath; | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	/** |     /** | ||||||
|      * Performs the read operation. |      * 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 |     @Override | ||||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { |     protected RemoteOperationResult run(OwnCloudClient client) { | ||||||
| 		RemoteOperationResult result = null; |         RemoteOperationResult result = null; | ||||||
|         PropFindMethod query = null; |         PropFindMethod query = null; | ||||||
|          | 
 | ||||||
|         try { |         try { | ||||||
|             // remote request |             // remote request | ||||||
|             query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath), |             query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath), | ||||||
|                     WebdavUtils.getAllPropSet(),    // PropFind Properties |                 WebdavUtils.getAllPropSet(),    // PropFind Properties | ||||||
|                     DavConstants.DEPTH_1); |                 DavConstants.DEPTH_1); | ||||||
|             int status = client.executeMethod(query); |             int status = client.executeMethod(query); | ||||||
| 
 | 
 | ||||||
|             // check and process response |             // check and process response | ||||||
|             boolean isSuccess = ( |             boolean isSuccess = ( | ||||||
|                     status == HttpStatus.SC_MULTI_STATUS || |                 status == HttpStatus.SC_MULTI_STATUS || | ||||||
|                     status == HttpStatus.SC_OK |                     status == HttpStatus.SC_OK | ||||||
| 		            ); |             ); | ||||||
|             if (isSuccess) { |             if (isSuccess) { | ||||||
|             	// get data from remote folder  |                 // get data from remote folder | ||||||
|             	MultiStatus dataInServer = query.getResponseBodyAsMultiStatus(); |                 MultiStatus dataInServer = query.getResponseBodyAsMultiStatus(); | ||||||
|             	readData(dataInServer, client); |                 readData(dataInServer, client); | ||||||
|             	 | 
 | ||||||
|             	// Result of the operation |                 // Result of the operation | ||||||
|             	result = new RemoteOperationResult(true, status, query.getResponseHeaders()); |                 result = new RemoteOperationResult(true, query); | ||||||
|             	// Add data to the result |                 // Add data to the result | ||||||
|             	if (result.isSuccess()) { |                 if (result.isSuccess()) { | ||||||
|             		result.setData(mFolderAndFiles); |                     result.setData(mFolderAndFiles); | ||||||
|             	} |                 } | ||||||
|             } else { |             } else { | ||||||
|                 // synchronization failed |                 // synchronization failed | ||||||
|                 client.exhaustResponse(query.getResponseBodyAsStream()); |                 client.exhaustResponse(query.getResponseBodyAsStream()); | ||||||
|                 result = new RemoteOperationResult(false, status, query.getResponseHeaders()); |                 result = new RemoteOperationResult(false, query); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|         } catch (Exception e) { |         } catch (Exception e) { | ||||||
|             result = new RemoteOperationResult(e); |             result = new RemoteOperationResult(e); | ||||||
|              | 
 | ||||||
| 
 | 
 | ||||||
|         } finally { |         } finally { | ||||||
|             if (query != null) |             if (query != null) | ||||||
|                 query.releaseConnection();  // let the connection available for other methods |                 query.releaseConnection();  // let the connection available for other methods | ||||||
|             if (result.isSuccess()) { |             if (result.isSuccess()) { | ||||||
|                 Log_OC.i(TAG, "Synchronized "  + mRemotePath + ": " + result.getLogMessage()); |                 Log_OC.i(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage()); | ||||||
|             } else { |             } else { | ||||||
|                 if (result.isException()) { |                 if (result.isException()) { | ||||||
|                     Log_OC.e(TAG, "Synchronized " + mRemotePath  + ": " + result.getLogMessage(), |                     Log_OC.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage(), | ||||||
|                             result.getException()); |                         result.getException()); | ||||||
|                 } else { |                 } else { | ||||||
|                     Log_OC.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage()); |                     Log_OC.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage()); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|              | 
 | ||||||
|         } |         } | ||||||
|         return result; |         return result; | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
|     public boolean isMultiStatus(int status) { |     public boolean isMultiStatus(int status) { | ||||||
|         return (status == HttpStatus.SC_MULTI_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 | ||||||
|      *  @param remoteData     	Full response got from the server with the data of the target  |      *                   folder and its direct children. | ||||||
|      *                          folder and its direct children. |      * @param client     Client instance to the remote server where the data were | ||||||
|      *  @param client           Client instance to the remote server where the data were  |      *                   retrieved. | ||||||
|      *                          retrieved.   |      * @return | ||||||
|      *  @return                 |  | ||||||
|      */ |      */ | ||||||
|     private void readData(MultiStatus remoteData, OwnCloudClient client) {   	 |     private void readData(MultiStatus remoteData, OwnCloudClient client) { | ||||||
|         mFolderAndFiles = new ArrayList<Object>(); |         mFolderAndFiles = new ArrayList<Object>(); | ||||||
|          | 
 | ||||||
|         // parse data from remote folder  |         // parse data from remote folder  | ||||||
|         WebdavEntry we = new WebdavEntry(remoteData.getResponses()[0], |         WebdavEntry we = new WebdavEntry(remoteData.getResponses()[0], | ||||||
|                 client.getWebdavUri().getPath()); |             client.getWebdavUri().getPath()); | ||||||
|         mFolderAndFiles.add(fillOCFile(we)); |         mFolderAndFiles.add(fillOCFile(we)); | ||||||
|          | 
 | ||||||
|         // loop to update every child |         // loop to update every child | ||||||
|         RemoteFile remoteFile = null; |         RemoteFile remoteFile = null; | ||||||
|         for (int i = 1; i < remoteData.getResponses().length; ++i) { |         for (int i = 1; i < remoteData.getResponses().length; ++i) { | ||||||
|             /// new OCFile instance with the data from the server |             /// new OCFile instance with the data from the server | ||||||
|             we = new WebdavEntry(remoteData.getResponses()[i], client.getWebdavUri().getPath());                         |             we = new WebdavEntry(remoteData.getResponses()[i], client.getWebdavUri().getPath()); | ||||||
|             remoteFile = fillOCFile(we); |             remoteFile = fillOCFile(we); | ||||||
|             mFolderAndFiles.add(remoteFile); |             mFolderAndFiles.add(remoteFile); | ||||||
|         } |         } | ||||||
|          | 
 | ||||||
|     } |     } | ||||||
|      | 
 | ||||||
|     /** |     /** | ||||||
|      * Creates and populates a new {@link RemoteFile} object with the data read from the server. |      * 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). |      * @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. |      * @return New OCFile instance representing the remote resource described by we. | ||||||
|      */ |      */ | ||||||
|     private RemoteFile fillOCFile(WebdavEntry we) { |     private RemoteFile fillOCFile(WebdavEntry we) { | ||||||
|         RemoteFile file = new RemoteFile(we.decodedPath()); |         RemoteFile file = new RemoteFile(we.decodedPath()); | ||||||
|  | |||||||
| @ -35,7 +35,7 @@ import com.owncloud.android.lib.common.utils.Log_OC; | |||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Remote operation performing the removal of a remote file or folder in the ownCloud server. |  * Remote operation performing the removal of a remote file or folder in the ownCloud server. | ||||||
|  *  |  * | ||||||
|  * @author David A. Velasco |  * @author David A. Velasco | ||||||
|  * @author masensio |  * @author masensio | ||||||
|  */ |  */ | ||||||
| @ -45,46 +45,48 @@ public class RemoveRemoteFileOperation extends RemoteOperation { | |||||||
|     private static final int REMOVE_READ_TIMEOUT = 30000; |     private static final int REMOVE_READ_TIMEOUT = 30000; | ||||||
|     private static final int REMOVE_CONNECTION_TIMEOUT = 5000; |     private static final int REMOVE_CONNECTION_TIMEOUT = 5000; | ||||||
| 
 | 
 | ||||||
| 	private String mRemotePath; |     private String mRemotePath; | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Constructor |      * 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) { |     public RemoveRemoteFileOperation(String remotePath) { | ||||||
| 		mRemotePath = remotePath; |         mRemotePath = remotePath; | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	/** |     /** | ||||||
| 	 * Performs the rename operation. |      * 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 |     @Override | ||||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { |     protected RemoteOperationResult run(OwnCloudClient client) { | ||||||
| 		RemoteOperationResult result = null; |         RemoteOperationResult result = null; | ||||||
|         DeleteMethod delete = null; |         DeleteMethod delete = null; | ||||||
|          | 
 | ||||||
|         try { |         try { | ||||||
|         	delete = new DeleteMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); |             delete = new DeleteMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); | ||||||
|         	int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT); |             int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT); | ||||||
|         	 | 
 | ||||||
|         	delete.getResponseBodyAsString();   // exhaust the response, although not interesting |             delete.getResponseBodyAsString();   // exhaust the response, although not interesting | ||||||
|         	result = new RemoteOperationResult((delete.succeeded() || |             result = new RemoteOperationResult( | ||||||
|                     status == HttpStatus.SC_NOT_FOUND), status, delete.getResponseHeaders()); |                 (delete.succeeded() || status == HttpStatus.SC_NOT_FOUND), | ||||||
|         	Log_OC.i(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage()); |                 delete | ||||||
|  |             ); | ||||||
|  |             Log_OC.i(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage()); | ||||||
| 
 | 
 | ||||||
|         } catch (Exception e) { |         } catch (Exception e) { | ||||||
|         	result = new RemoteOperationResult(e); |             result = new RemoteOperationResult(e); | ||||||
|         	Log_OC.e(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage(), e); |             Log_OC.e(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage(), e); | ||||||
| 
 | 
 | ||||||
|         } finally { |         } finally { | ||||||
|         	if (delete != null) |             if (delete != null) | ||||||
|         		delete.releaseConnection(); |                 delete.releaseConnection(); | ||||||
|         } |         } | ||||||
|          | 
 | ||||||
| 		return result; |         return result; | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -39,62 +39,62 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion; | |||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Remote operation performing the rename of a remote file or folder in the ownCloud server. |  * Remote operation performing the rename of a remote file or folder in the ownCloud server. | ||||||
|  *  |  * | ||||||
|  * @author David A. Velasco |  * @author David A. Velasco | ||||||
|  * @author masensio |  * @author masensio | ||||||
|  */ |  */ | ||||||
| public class RenameRemoteFileOperation extends RemoteOperation { | 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_READ_TIMEOUT = 600000; | ||||||
| 	private static final int RENAME_CONNECTION_TIMEOUT = 5000; |     private static final int RENAME_CONNECTION_TIMEOUT = 5000; | ||||||
| 
 | 
 | ||||||
|     private String mOldName; |     private String mOldName; | ||||||
|     private String mOldRemotePath; |     private String mOldRemotePath; | ||||||
|     private String mNewName; |     private String mNewName; | ||||||
|     private String mNewRemotePath; |     private String mNewRemotePath; | ||||||
|      | 
 | ||||||
|      | 
 | ||||||
|     /** |     /** | ||||||
|      * Constructor |      * Constructor | ||||||
|      *  |      * | ||||||
|      * @param oldName			Old name of the file. |      * @param oldName       Old name of the file. | ||||||
|      * @param oldRemotePath		Old remote path of the file.  |      * @param oldRemotePath Old remote path of the file. | ||||||
|      * @param newName			New name to set as the name of file. |      * @param newName       New name to set as the name of file. | ||||||
|      * @param isFolder			'true' for folder and 'false' for files |      * @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) { |                                      boolean isFolder) { | ||||||
| 		mOldName = oldName; |         mOldName = oldName; | ||||||
| 		mOldRemotePath = oldRemotePath; |         mOldRemotePath = oldRemotePath; | ||||||
| 		mNewName = newName; |         mNewName = newName; | ||||||
| 		 | 
 | ||||||
|         String parent = (new File(mOldRemotePath)).getParent(); |         String parent = (new File(mOldRemotePath)).getParent(); | ||||||
|         parent = (parent.endsWith(FileUtils.PATH_SEPARATOR)) ? parent : parent + |         parent = (parent.endsWith(FileUtils.PATH_SEPARATOR)) ? parent : parent + | ||||||
|                 FileUtils.PATH_SEPARATOR; |             FileUtils.PATH_SEPARATOR; | ||||||
|         mNewRemotePath =  parent + mNewName; |         mNewRemotePath = parent + mNewName; | ||||||
|         if (isFolder) { |         if (isFolder) { | ||||||
|             mNewRemotePath += FileUtils.PATH_SEPARATOR; |             mNewRemotePath += FileUtils.PATH_SEPARATOR; | ||||||
|         } |         } | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	 /** |     /** | ||||||
|      * Performs the rename operation. |      * 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 |     @Override | ||||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { |     protected RemoteOperationResult run(OwnCloudClient client) { | ||||||
| 		RemoteOperationResult result = null; |         RemoteOperationResult result = null; | ||||||
| 		 | 
 | ||||||
| 		LocalMoveMethod move = null; |         LocalMoveMethod move = null; | ||||||
| 
 | 
 | ||||||
|         OwnCloudVersion version = client.getOwnCloudVersion(); |         OwnCloudVersion version = client.getOwnCloudVersion(); | ||||||
|         boolean versionWithForbiddenChars = |         boolean versionWithForbiddenChars = | ||||||
|                 (version != null && version.isVersionWithForbiddenCharacters()); |             (version != null && version.isVersionWithForbiddenCharacters()); | ||||||
|         boolean noInvalidChars = FileUtils.isValidPath(mNewRemotePath, versionWithForbiddenChars); |         boolean noInvalidChars = FileUtils.isValidPath(mNewRemotePath, versionWithForbiddenChars); | ||||||
|          | 
 | ||||||
|         if (noInvalidChars) { |         if (noInvalidChars) { | ||||||
|             try { |             try { | ||||||
|                 if (mNewName.equals(mOldName)) { |                 if (mNewName.equals(mOldName)) { | ||||||
| @ -106,29 +106,21 @@ public class RenameRemoteFileOperation extends RemoteOperation { | |||||||
|                     return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); |                     return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 move = new LocalMoveMethod( client.getWebdavUri() + |                 move = new LocalMoveMethod(client.getWebdavUri() + | ||||||
|                         WebdavUtils.encodePath(mOldRemotePath), |                     WebdavUtils.encodePath(mOldRemotePath), | ||||||
|                         client.getWebdavUri() + WebdavUtils.encodePath(mNewRemotePath)); |                     client.getWebdavUri() + WebdavUtils.encodePath(mNewRemotePath)); | ||||||
|                 int status = client.executeMethod(move, RENAME_READ_TIMEOUT, |                 client.executeMethod(move, RENAME_READ_TIMEOUT, RENAME_CONNECTION_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) { |             } catch (Exception e) { | ||||||
|                 result = new RemoteOperationResult(e); |                 result = new RemoteOperationResult(e); | ||||||
|                 Log_OC.e(TAG, "Rename " + mOldRemotePath + " to " + |                 Log_OC.e(TAG, "Rename " + mOldRemotePath + " to " + | ||||||
|                         ((mNewRemotePath==null) ? mNewName : mNewRemotePath) + ": " + |                     ((mNewRemotePath == null) ? mNewName : mNewRemotePath) + ": " + | ||||||
|                         result.getLogMessage(), e); |                     result.getLogMessage(), e); | ||||||
| 
 | 
 | ||||||
|             } finally { |             } finally { | ||||||
|                 if (move != null) |                 if (move != null) | ||||||
| @ -136,16 +128,15 @@ public class RenameRemoteFileOperation extends RemoteOperation { | |||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|         } else { |         } else { | ||||||
|         	result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); |             result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); | ||||||
|         } |         } | ||||||
|         	 | 
 | ||||||
|         return result; |         return result; | ||||||
| 	} |     } | ||||||
| 	 | 
 | ||||||
| 	/** |     /** | ||||||
| 	 * Move operation |      * Move operation | ||||||
| 	 *  |      */ | ||||||
| 	 */ |  | ||||||
|     private class LocalMoveMethod extends DavMethodBase { |     private class LocalMoveMethod extends DavMethodBase { | ||||||
| 
 | 
 | ||||||
|         public LocalMoveMethod(String uri, String dest) { |         public LocalMoveMethod(String uri, String dest) { | ||||||
| @ -162,7 +153,7 @@ public class RenameRemoteFileOperation extends RemoteOperation { | |||||||
|         protected boolean isSuccess(int status) { |         protected boolean isSuccess(int status) { | ||||||
|             return status == 201 || status == 204; |             return status == 201 || status == 204; | ||||||
|         } |         } | ||||||
|              | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -69,7 +69,6 @@ public class UploadRemoteFileOperation extends RemoteOperation { | |||||||
|     protected String mMimeType; |     protected String mMimeType; | ||||||
|     protected String mFileLastModifTimestamp; |     protected String mFileLastModifTimestamp; | ||||||
|     protected PutMethod mPutMethod = null; |     protected PutMethod mPutMethod = null; | ||||||
|     protected boolean mForbiddenCharsInServer = false; |  | ||||||
|     protected String mRequiredEtag = null; |     protected String mRequiredEtag = null; | ||||||
| 
 | 
 | ||||||
|     protected final AtomicBoolean mCancellationRequested = new AtomicBoolean(false); |     protected final AtomicBoolean mCancellationRequested = new AtomicBoolean(false); | ||||||
| @ -112,14 +111,7 @@ public class UploadRemoteFileOperation extends RemoteOperation { | |||||||
| 
 | 
 | ||||||
|             } else { |             } else { | ||||||
|                 // perform the upload |                 // perform the upload | ||||||
|                 int status = uploadFile(client); |                 result = 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)); |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|         } catch (Exception e) { |         } catch (Exception e) { | ||||||
| @ -144,8 +136,9 @@ public class UploadRemoteFileOperation extends RemoteOperation { | |||||||
|                 status == HttpStatus.SC_NO_CONTENT)); |                 status == HttpStatus.SC_NO_CONTENT)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     protected int uploadFile(OwnCloudClient client) throws IOException { |     protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOException { | ||||||
|         int status = -1; |         int status; | ||||||
|  |         RemoteOperationResult result; | ||||||
|         try { |         try { | ||||||
|             File f = new File(mLocalPath); |             File f = new File(mLocalPath); | ||||||
|             mEntity  = new FileRequestEntity(f, mMimeType); |             mEntity  = new FileRequestEntity(f, mMimeType); | ||||||
| @ -163,25 +156,16 @@ public class UploadRemoteFileOperation extends RemoteOperation { | |||||||
|             mPutMethod.setRequestEntity(mEntity); |             mPutMethod.setRequestEntity(mEntity); | ||||||
|             status = client.executeMethod(mPutMethod); |             status = client.executeMethod(mPutMethod); | ||||||
| 
 | 
 | ||||||
|             if (status == 400) { |             result = new RemoteOperationResult( | ||||||
|                 InvalidCharacterExceptionParser xmlParser = new InvalidCharacterExceptionParser(); |                 isSuccess(status), | ||||||
|                 InputStream is = new ByteArrayInputStream( |                 mPutMethod | ||||||
|                         mPutMethod.getResponseBodyAsString().getBytes()); |             ); | ||||||
|                 try { |  | ||||||
|                     mForbiddenCharsInServer = xmlParser.parseXMLResponse(is); |  | ||||||
| 
 |  | ||||||
|                 } catch (Exception e) { |  | ||||||
|                     mForbiddenCharsInServer = false; |  | ||||||
|                     Log_OC.e(TAG, "Exception reading exception from server", e); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             client.exhaustResponse(mPutMethod.getResponseBodyAsStream()); |             client.exhaustResponse(mPutMethod.getResponseBodyAsStream()); | ||||||
| 
 | 
 | ||||||
|         } finally { |         } finally { | ||||||
|             mPutMethod.releaseConnection(); // let the connection available for other methods |             mPutMethod.releaseConnection(); // let the connection available for other methods | ||||||
|         } |         } | ||||||
|         return status; |         return result; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Set<OnDatatransferProgressListener> getDataTransferListeners() { |     public Set<OnDatatransferProgressListener> getDataTransferListeners() { | ||||||
|  | |||||||
| @ -39,137 +39,138 @@ import com.owncloud.android.lib.common.utils.Log_OC; | |||||||
|  */ |  */ | ||||||
| public class CreateRemoteShareOperation extends RemoteOperation { | 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_PATH = "path"; | ||||||
| 	private static final String PARAM_SHARE_TYPE = "shareType"; |     private static final String PARAM_SHARE_TYPE = "shareType"; | ||||||
| 	private static final String PARAM_SHARE_WITH = "shareWith"; |     private static final String PARAM_SHARE_WITH = "shareWith"; | ||||||
| 	private static final String PARAM_PUBLIC_UPLOAD = "publicUpload"; |     private static final String PARAM_PUBLIC_UPLOAD = "publicUpload"; | ||||||
| 	private static final String PARAM_PASSWORD = "password"; |     private static final String PARAM_PASSWORD = "password"; | ||||||
| 	private static final String PARAM_PERMISSIONS = "permissions"; |     private static final String PARAM_PERMISSIONS = "permissions"; | ||||||
| 
 | 
 | ||||||
| 	private String mRemoteFilePath; |     private String mRemoteFilePath; | ||||||
| 	private ShareType mShareType; |     private ShareType mShareType; | ||||||
| 	private String mShareWith; |     private String mShareWith; | ||||||
| 	private boolean mPublicUpload; |     private boolean mPublicUpload; | ||||||
| 	private String mPassword; |     private String mPassword; | ||||||
| 	private int mPermissions; |     private int mPermissions; | ||||||
| 	private boolean mGetShareDetails; |     private boolean mGetShareDetails; | ||||||
| 
 | 
 | ||||||
| 	/** |     /** | ||||||
| 	 * Constructor |      * 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 remoteFilePath Full path of the file/folder being shared. Mandatory argument | ||||||
| 	 * @param shareWith			User/group ID with who the file should be shared.  This is mandatory for shareType |      * @param shareType      0 = user, 1 = group, 3 = Public link. Mandatory argument | ||||||
| 	 *                          of 0 or 1 |      * @param shareWith      User/group ID with who the file should be shared.  This is mandatory for shareType | ||||||
| 	 * @param publicUpload		If false (default) public cannot upload to a public shared folder. |      *                       of 0 or 1 | ||||||
| 	 * 							If true public can upload to a shared folder. Only available for public link shares |      * @param publicUpload   If false (default) public cannot upload to a public shared folder. | ||||||
| 	 * @param password			Password to protect a public link share. Only available for public link shares |      *                       If true public can upload to a shared folder. Only available for public link shares | ||||||
| 	 * @param permissions		1 - Read only Default for public shares |      * @param password       Password to protect a public link share. Only available for public link shares | ||||||
| 	 * 							2 - Update |      * @param permissions    1 - Read only Default for public shares | ||||||
| 	 * 							4 - Create |      *                       2 - Update | ||||||
| 	 * 							8 - Delete |      *                       4 - Create | ||||||
| 	 * 							16- Re-share |      *                       8 - Delete | ||||||
| 	 * 							31- All above Default for private shares |      *                       16- Re-share | ||||||
| 	 * 							For user or group shares. |      *                       31- All above Default for private shares | ||||||
| 	 * 							To obtain combinations, add the desired values together.   |      *                       For user or group shares. | ||||||
| 	 * 							For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27. |      *                       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, |     public CreateRemoteShareOperation( | ||||||
| 			ShareType shareType, |         String remoteFilePath, | ||||||
| 			String shareWith, |         ShareType shareType, | ||||||
| 			boolean publicUpload, |         String shareWith, | ||||||
| 			String password, |         boolean publicUpload, | ||||||
| 			int permissions |         String password, | ||||||
| 	) { |         int permissions | ||||||
|  |     ) { | ||||||
| 
 | 
 | ||||||
| 		mRemoteFilePath = remoteFilePath; |         mRemoteFilePath = remoteFilePath; | ||||||
| 		mShareType = shareType; |         mShareType = shareType; | ||||||
| 		mShareWith = shareWith; |         mShareWith = shareWith; | ||||||
| 		mPublicUpload = publicUpload; |         mPublicUpload = publicUpload; | ||||||
| 		mPassword = password; |         mPassword = password; | ||||||
| 		mPermissions = permissions; |         mPermissions = permissions; | ||||||
| 		mGetShareDetails = false; 		// defaults to false for backwards compatibility |         mGetShareDetails = false;        // defaults to false for backwards compatibility | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	public boolean isGettingShareDetails () { |     public boolean isGettingShareDetails() { | ||||||
| 		return mGetShareDetails; |         return mGetShareDetails; | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	public void setGetShareDetails(boolean set) { |     public void setGetShareDetails(boolean set) { | ||||||
| 		mGetShareDetails = set; |         mGetShareDetails = set; | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	@Override |     @Override | ||||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { |     protected RemoteOperationResult run(OwnCloudClient client) { | ||||||
| 		RemoteOperationResult result = null; |         RemoteOperationResult result = null; | ||||||
| 		int status = -1; |         int status = -1; | ||||||
| 
 | 
 | ||||||
| 		PostMethod post = null; |         PostMethod post = null; | ||||||
| 
 | 
 | ||||||
| 		try { |         try { | ||||||
| 			// Post Method |             // Post Method | ||||||
| 			post = new PostMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); |             post = new PostMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); | ||||||
| 
 | 
 | ||||||
| 			post.setRequestHeader( "Content-Type", |             post.setRequestHeader("Content-Type", | ||||||
|                     "application/x-www-form-urlencoded; charset=utf-8"); // necessary for special characters |                 "application/x-www-form-urlencoded; charset=utf-8"); // necessary for special characters | ||||||
| 
 | 
 | ||||||
| 			post.addParameter(PARAM_PATH, mRemoteFilePath); |             post.addParameter(PARAM_PATH, mRemoteFilePath); | ||||||
| 			post.addParameter(PARAM_SHARE_TYPE, Integer.toString(mShareType.getValue())); |             post.addParameter(PARAM_SHARE_TYPE, Integer.toString(mShareType.getValue())); | ||||||
| 			post.addParameter(PARAM_SHARE_WITH, mShareWith); |             post.addParameter(PARAM_SHARE_WITH, mShareWith); | ||||||
| 			if (mPublicUpload) { |             if (mPublicUpload) { | ||||||
| 				post.addParameter(PARAM_PUBLIC_UPLOAD, Boolean.toString(true)); |                 post.addParameter(PARAM_PUBLIC_UPLOAD, Boolean.toString(true)); | ||||||
| 			} |             } | ||||||
| 			if (mPassword != null && mPassword.length() > 0) { |             if (mPassword != null && mPassword.length() > 0) { | ||||||
| 				post.addParameter(PARAM_PASSWORD, mPassword); |                 post.addParameter(PARAM_PASSWORD, mPassword); | ||||||
| 			} |             } | ||||||
| 			if (OCShare.DEFAULT_PERMISSION != mPermissions) { |             if (OCShare.DEFAULT_PERMISSION != mPermissions) { | ||||||
| 				post.addParameter(PARAM_PERMISSIONS, Integer.toString(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); |  | ||||||
| 
 | 
 | ||||||
| 			if(isSuccess(status)) { |             status = client.executeMethod(post); | ||||||
| 				String response = post.getResponseBodyAsString(); |  | ||||||
| 
 | 
 | ||||||
| 				ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( |             if (isSuccess(status)) { | ||||||
| 						new ShareXMLParser() |                 String response = post.getResponseBodyAsString(); | ||||||
| 				); |  | ||||||
| 				parser.setOneOrMoreSharesRequired(true); |  | ||||||
| 				parser.setOwnCloudVersion(client.getOwnCloudVersion()); |  | ||||||
| 				parser.setServerBaseUri(client.getBaseUri()); |  | ||||||
| 				result = parser.parse(response); |  | ||||||
| 
 | 
 | ||||||
| 				if (result.isSuccess() && mGetShareDetails) { |                 ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( | ||||||
| 					// retrieve more info - POST only returns the index of the new share |                     new ShareXMLParser() | ||||||
| 					OCShare emptyShare = (OCShare) result.getData().get(0); |                 ); | ||||||
| 					GetRemoteShareOperation getInfo = new GetRemoteShareOperation( |                 parser.setOneOrMoreSharesRequired(true); | ||||||
| 							emptyShare.getRemoteId() |                 parser.setOwnCloudVersion(client.getOwnCloudVersion()); | ||||||
| 					); |                 parser.setServerBaseUri(client.getBaseUri()); | ||||||
| 					result = getInfo.execute(client); |                 result = parser.parse(response); | ||||||
| 				} |  | ||||||
| 
 | 
 | ||||||
| 			} else { |                 if (result.isSuccess() && mGetShareDetails) { | ||||||
| 				result = new RemoteOperationResult(false, status, post.getResponseHeaders()); |                     // retrieve more info - POST only returns the index of the new share | ||||||
| 			} |                     OCShare emptyShare = (OCShare) result.getData().get(0); | ||||||
| 			 |                     GetRemoteShareOperation getInfo = new GetRemoteShareOperation( | ||||||
| 		} catch (Exception e) { |                         emptyShare.getRemoteId() | ||||||
| 			result = new RemoteOperationResult(e); |                     ); | ||||||
| 			Log_OC.e(TAG, "Exception while Creating New Share", e); |                     result = getInfo.execute(client); | ||||||
| 			 |                 } | ||||||
| 		} finally { |  | ||||||
| 			if (post != null) { |  | ||||||
| 				post.releaseConnection(); |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 		return result; |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	private boolean isSuccess(int status) { |             } else { | ||||||
| 		return (status == HttpStatus.SC_OK); |                 result = new RemoteOperationResult(false, post); | ||||||
| 	} |             } | ||||||
|  | 
 | ||||||
|  |         } 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; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private boolean isSuccess(int status) { | ||||||
|  |         return (status == HttpStatus.SC_OK); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -33,68 +33,68 @@ import com.owncloud.android.lib.common.utils.Log_OC; | |||||||
| import org.apache.commons.httpclient.HttpStatus; | import org.apache.commons.httpclient.HttpStatus; | ||||||
| import org.apache.commons.httpclient.methods.GetMethod; | import org.apache.commons.httpclient.methods.GetMethod; | ||||||
| 
 | 
 | ||||||
| /**  | /** | ||||||
|  * Get the data about a Share resource, known its remote ID. |  * Get the data about a Share resource, known its remote ID. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| public class GetRemoteShareOperation extends RemoteOperation { | 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) { |     public GetRemoteShareOperation(long remoteId) { | ||||||
| 		mRemoteId = remoteId; |         mRemoteId = remoteId; | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	@Override |     @Override | ||||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { |     protected RemoteOperationResult run(OwnCloudClient client) { | ||||||
| 		RemoteOperationResult result = null; |         RemoteOperationResult result = null; | ||||||
| 		int status = -1; |         int status = -1; | ||||||
| 
 | 
 | ||||||
| 		// Get Method         |         // Get Method | ||||||
| 		GetMethod get = null; |         GetMethod get = null; | ||||||
| 
 | 
 | ||||||
| 		// Get the response |         // Get the response | ||||||
| 		try{ |         try { | ||||||
| 			get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + "/" + Long.toString(mRemoteId)); |             get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + "/" + Long.toString(mRemoteId)); | ||||||
| 			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)) { |             if (isSuccess(status)) { | ||||||
| 				String response = get.getResponseBodyAsString(); |                 String response = get.getResponseBodyAsString(); | ||||||
| 
 | 
 | ||||||
| 				// Parse xml response and obtain the list of shares |                 // Parse xml response and obtain the list of shares | ||||||
| 				ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( |                 ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( | ||||||
| 						new ShareXMLParser() |                     new ShareXMLParser() | ||||||
| 				); |                 ); | ||||||
| 				parser.setOneOrMoreSharesRequired(true); |                 parser.setOneOrMoreSharesRequired(true); | ||||||
| 				parser.setOwnCloudVersion(client.getOwnCloudVersion()); |                 parser.setOwnCloudVersion(client.getOwnCloudVersion()); | ||||||
| 				parser.setServerBaseUri(client.getBaseUri()); |                 parser.setServerBaseUri(client.getBaseUri()); | ||||||
| 				result = parser.parse(response); |                 result = parser.parse(response); | ||||||
| 
 | 
 | ||||||
| 			} else { |             } else { | ||||||
| 				result = new RemoteOperationResult(false, status, get.getResponseHeaders()); |                 result = new RemoteOperationResult(false, get); | ||||||
| 			} |             } | ||||||
| 			 |  | ||||||
| 		} 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; |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	private boolean isSuccess(int status) { |         } catch (Exception e) { | ||||||
| 		return (status == HttpStatus.SC_OK); |             result = new RemoteOperationResult(e); | ||||||
| 	} |             Log_OC.e(TAG, "Exception while getting remote shares ", e); | ||||||
|  | 
 | ||||||
|  |         } finally { | ||||||
|  |             if (get != null) { | ||||||
|  |                 get.releaseConnection(); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         return result; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private boolean isSuccess(int status) { | ||||||
|  |         return (status == HttpStatus.SC_OK); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -166,13 +166,13 @@ public class GetRemoteShareesOperation extends RemoteOperation{ | |||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 // Result |                 // Result | ||||||
|                 result = new RemoteOperationResult(true, status, get.getResponseHeaders()); |                 result = new RemoteOperationResult(true, get); | ||||||
|                 result.setData(data); |                 result.setData(data); | ||||||
| 
 | 
 | ||||||
|                 Log_OC.d(TAG, "*** Get Users or groups completed " ); |                 Log_OC.d(TAG, "*** Get Users or groups completed " ); | ||||||
| 
 | 
 | ||||||
|             } else { |             } else { | ||||||
|                 result = new RemoteOperationResult(false, status, get.getResponseHeaders()); |                 result = new RemoteOperationResult(false, get); | ||||||
|                 String response = get.getResponseBodyAsString(); |                 String response = get.getResponseBodyAsString(); | ||||||
|                 Log_OC.e(TAG, "Failed response while getting users/groups from the server "); |                 Log_OC.e(TAG, "Failed response while getting users/groups from the server "); | ||||||
|                 if (response != null) { |                 if (response != null) { | ||||||
|  | |||||||
| @ -36,94 +36,94 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult; | |||||||
| import com.owncloud.android.lib.common.utils.Log_OC; | import com.owncloud.android.lib.common.utils.Log_OC; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Provide a list shares for a specific file.   |  * Provide a list shares for a specific file. | ||||||
|  * The input is the full path of the desired file.   |  * The input is the full path of the desired file. | ||||||
|  * The output is a list of everyone who has the file shared with them. |  * The output is a list of everyone who has the file shared with them. | ||||||
|  */ |  */ | ||||||
| public class GetRemoteSharesForFileOperation extends RemoteOperation { | 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 String mRemoteFilePath; |     private static final String PARAM_PATH = "path"; | ||||||
| 	private boolean mReshares; |     private static final String PARAM_RESHARES = "reshares"; | ||||||
| 	private boolean mSubfiles; |     private static final String PARAM_SUBFILES = "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 |     private String mRemoteFilePath; | ||||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { |     private boolean mReshares; | ||||||
| 		RemoteOperationResult result = null; |     private boolean mSubfiles; | ||||||
| 		int status = -1; |  | ||||||
| 
 | 
 | ||||||
| 		GetMethod get = null; |     /** | ||||||
|  |      * 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; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
| 		try { |     @Override | ||||||
| 			// Get Method |     protected RemoteOperationResult run(OwnCloudClient client) { | ||||||
| 			get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); |         RemoteOperationResult result = null; | ||||||
|  |         int status = -1; | ||||||
| 
 | 
 | ||||||
| 			// Add Parameters to Get Method |         GetMethod get = null; | ||||||
| 			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); |         try { | ||||||
|              |             // Get Method | ||||||
| 			status = client.executeMethod(get); |             get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); | ||||||
| 
 | 
 | ||||||
| 			if(isSuccess(status)) { |             // Add Parameters to Get Method | ||||||
| 				String response = get.getResponseBodyAsString(); |             get.setQueryString(new NameValuePair[]{ | ||||||
|  |                 new NameValuePair(PARAM_PATH, mRemoteFilePath), | ||||||
|  |                 new NameValuePair(PARAM_RESHARES, String.valueOf(mReshares)), | ||||||
|  |                 new NameValuePair(PARAM_SUBFILES, String.valueOf(mSubfiles)) | ||||||
|  |             }); | ||||||
| 
 | 
 | ||||||
| 				// Parse xml response and obtain the list of shares |             get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); | ||||||
| 				ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( |  | ||||||
| 						new ShareXMLParser() |  | ||||||
| 				); |  | ||||||
| 				parser.setOwnCloudVersion(client.getOwnCloudVersion()); |  | ||||||
| 				parser.setServerBaseUri(client.getBaseUri()); |  | ||||||
| 				result = parser.parse(response); |  | ||||||
| 
 | 
 | ||||||
| 				if (result.isSuccess()) { |             status = client.executeMethod(get); | ||||||
| 					Log_OC.d(TAG, "Got " + result.getData().size() + " shares"); |  | ||||||
| 				} |  | ||||||
| 
 | 
 | ||||||
| 			} else { |             if (isSuccess(status)) { | ||||||
| 				result = new RemoteOperationResult(false, status, get.getResponseHeaders()); |                 String response = get.getResponseBodyAsString(); | ||||||
| 			} |  | ||||||
| 			 |  | ||||||
| 		} catch (Exception e) { |  | ||||||
| 			result = new RemoteOperationResult(e); |  | ||||||
| 			Log_OC.e(TAG, "Exception while getting shares", e); |  | ||||||
| 			 |  | ||||||
| 		} finally { |  | ||||||
| 			if (get != null) { |  | ||||||
| 				get.releaseConnection(); |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 		return result; |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	private boolean isSuccess(int status) { |                 // Parse xml response and obtain the list of shares | ||||||
| 		return (status == HttpStatus.SC_OK); |                 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"); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |             } else { | ||||||
|  |                 result = new RemoteOperationResult(false, get); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             result = new RemoteOperationResult(e); | ||||||
|  |             Log_OC.e(TAG, "Exception while getting shares", e); | ||||||
|  | 
 | ||||||
|  |         } finally { | ||||||
|  |             if (get != null) { | ||||||
|  |                 get.releaseConnection(); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         return result; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private boolean isSuccess(int status) { | ||||||
|  |         return (status == HttpStatus.SC_OK); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -34,62 +34,61 @@ import com.owncloud.android.lib.common.operations.RemoteOperation; | |||||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult; | import com.owncloud.android.lib.common.operations.RemoteOperationResult; | ||||||
| import com.owncloud.android.lib.common.utils.Log_OC; | import com.owncloud.android.lib.common.utils.Log_OC; | ||||||
| 
 | 
 | ||||||
| /**  | /** | ||||||
|  * Get the data from the server about ALL the known shares owned by the requester. |  * Get the data from the server about ALL the known shares owned by the requester. | ||||||
|  *  |  | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| public class GetRemoteSharesOperation extends RemoteOperation { | 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 |     @Override | ||||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { |     protected RemoteOperationResult run(OwnCloudClient client) { | ||||||
| 		RemoteOperationResult result = null; |         RemoteOperationResult result = null; | ||||||
| 		int status = -1; |         int status = -1; | ||||||
| 
 | 
 | ||||||
| 		// Get Method         |         // Get Method | ||||||
| 		GetMethod get = null; |         GetMethod get = null; | ||||||
| 
 | 
 | ||||||
| 		// Get the response |         // Get the response | ||||||
| 		try{ |         try { | ||||||
| 			get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); |             get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); | ||||||
| 			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)) { |             if (isSuccess(status)) { | ||||||
| 				String response = get.getResponseBodyAsString(); |                 String response = get.getResponseBodyAsString(); | ||||||
| 
 | 
 | ||||||
| 				// Parse xml response and obtain the list of shares |                 // Parse xml response and obtain the list of shares | ||||||
| 				ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( |                 ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( | ||||||
| 						new ShareXMLParser() |                     new ShareXMLParser() | ||||||
| 				); |                 ); | ||||||
| 				parser.setOwnCloudVersion(client.getOwnCloudVersion()); |                 parser.setOwnCloudVersion(client.getOwnCloudVersion()); | ||||||
| 				parser.setServerBaseUri(client.getBaseUri()); |                 parser.setServerBaseUri(client.getBaseUri()); | ||||||
| 				result = parser.parse(response); |                 result = parser.parse(response); | ||||||
| 			} else { |             } else { | ||||||
| 				result = new RemoteOperationResult(false, status, get.getResponseHeaders()); |                 result = new RemoteOperationResult(false, get); | ||||||
| 			} |             } | ||||||
| 			 |  | ||||||
| 		} 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; |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	private boolean isSuccess(int status) { |         } catch (Exception e) { | ||||||
| 		return (status == HttpStatus.SC_OK); |             result = new RemoteOperationResult(e); | ||||||
| 	} |             Log_OC.e(TAG, "Exception while getting remote shares ", e); | ||||||
|  | 
 | ||||||
|  |         } finally { | ||||||
|  |             if (get != null) { | ||||||
|  |                 get.releaseConnection(); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         return result; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     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 { | public class RemoveRemoteShareOperation extends RemoteOperation { | ||||||
| 
 | 
 | ||||||
| 	private static final String TAG = RemoveRemoteShareOperation.class.getSimpleName(); |     private static final String TAG = RemoveRemoteShareOperation.class.getSimpleName(); | ||||||
| 	 |  | ||||||
| 	private int mRemoteShareId; |  | ||||||
| 	 |  | ||||||
| 	/** |  | ||||||
| 	 * Constructor |  | ||||||
| 	 *  |  | ||||||
| 	 * @param remoteShareId		Share ID |  | ||||||
| 	 */ |  | ||||||
| 	 |  | ||||||
| 	public RemoveRemoteShareOperation(int remoteShareId) { |  | ||||||
| 		mRemoteShareId = remoteShareId; |  | ||||||
| 		 |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	@Override |     private int mRemoteShareId; | ||||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { |  | ||||||
| 		RemoteOperationResult result = null; |  | ||||||
| 		int status = -1; |  | ||||||
| 
 | 
 | ||||||
| 		DeleteMethod delete = null; |     /** | ||||||
|  |      * Constructor | ||||||
|  |      * | ||||||
|  |      * @param remoteShareId Share ID | ||||||
|  |      */ | ||||||
| 
 | 
 | ||||||
| 		try { |     public RemoveRemoteShareOperation(int remoteShareId) { | ||||||
| 			String id = "/" + String.valueOf(mRemoteShareId); |         mRemoteShareId = remoteShareId; | ||||||
| 			delete = new DeleteMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + id); |  | ||||||
| 
 | 
 | ||||||
| 			delete.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); |     } | ||||||
| 
 | 
 | ||||||
| 			status = client.executeMethod(delete); |     @Override | ||||||
|  |     protected RemoteOperationResult run(OwnCloudClient client) { | ||||||
|  |         RemoteOperationResult result = null; | ||||||
|  |         int status = -1; | ||||||
| 
 | 
 | ||||||
| 			if(isSuccess(status)) { |         DeleteMethod delete = null; | ||||||
| 				String response = delete.getResponseBodyAsString(); |  | ||||||
| 
 | 
 | ||||||
| 				// Parse xml response and obtain the list of shares |         try { | ||||||
| 				ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( |             String id = "/" + String.valueOf(mRemoteShareId); | ||||||
| 						new ShareXMLParser() |             delete = new DeleteMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + id); | ||||||
| 				); |  | ||||||
| 				result = parser.parse(response); |  | ||||||
| 
 | 
 | ||||||
| 				Log_OC.d(TAG, "Unshare " + id + ": " + result.getLogMessage()); |             delete.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); | ||||||
| 
 | 
 | ||||||
| 			} else { |             status = client.executeMethod(delete); | ||||||
| 				result = new RemoteOperationResult(false, status, delete.getResponseHeaders()); |  | ||||||
| 			} |  | ||||||
| 		} catch (Exception e) { |  | ||||||
| 			result = new RemoteOperationResult(e); |  | ||||||
| 			Log_OC.e(TAG, "Unshare Link Exception " + result.getLogMessage(), e); |  | ||||||
| 
 | 
 | ||||||
| 		} finally { |             if (isSuccess(status)) { | ||||||
| 			if (delete != null) |                 String response = delete.getResponseBodyAsString(); | ||||||
| 				delete.releaseConnection(); | 
 | ||||||
| 		} |                 // Parse xml response and obtain the list of shares | ||||||
| 		return result; |                 ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( | ||||||
| 	} |                     new ShareXMLParser() | ||||||
|  |                 ); | ||||||
|  |                 result = parser.parse(response); | ||||||
|  | 
 | ||||||
|  |                 Log_OC.d(TAG, "Unshare " + id + ": " + result.getLogMessage()); | ||||||
|  | 
 | ||||||
|  |             } 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; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 	private boolean isSuccess(int status) { |     private boolean isSuccess(int status) { | ||||||
| 		return (status == HttpStatus.SC_OK); |         return (status == HttpStatus.SC_OK); | ||||||
| 	} |     } | ||||||
| } | } | ||||||
| @ -216,7 +216,7 @@ public class UpdateRemoteShareOperation extends RemoteOperation { | |||||||
|                     result = parser.parse(response); |                     result = parser.parse(response); | ||||||
| 
 | 
 | ||||||
|                 } else { |                 } else { | ||||||
|                     result = new RemoteOperationResult(false, status, put.getResponseHeaders()); |                     result = new RemoteOperationResult(false, put); | ||||||
|                 } |                 } | ||||||
|                 if (!result.isSuccess()) { |                 if (!result.isSuccess()) { | ||||||
|                     break; |                     break; | ||||||
|  | |||||||
| @ -242,18 +242,18 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation { | |||||||
|                     } |                     } | ||||||
|                     // Result |                     // Result | ||||||
|                     data.add(capability); |                     data.add(capability); | ||||||
|                     result = new RemoteOperationResult(true, status, get.getResponseHeaders()); |                     result = new RemoteOperationResult(true, get); | ||||||
|                     result.setData(data); |                     result.setData(data); | ||||||
| 
 | 
 | ||||||
|                     Log_OC.d(TAG, "*** Get Capabilities completed "); |                     Log_OC.d(TAG, "*** Get Capabilities completed "); | ||||||
|                 } else { |                 } 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, "Failed response while getting capabilities from the server "); | ||||||
|                     Log_OC.e(TAG, "*** status: " + statusProp + "; message: " + message); |                     Log_OC.e(TAG, "*** status: " + statusProp + "; message: " + message); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|             } else { |             } else { | ||||||
|                 result = new RemoteOperationResult(false, status, get.getResponseHeaders()); |                 result = new RemoteOperationResult(false, get); | ||||||
|                 String response = get.getResponseBodyAsString(); |                 String response = get.getResponseBodyAsString(); | ||||||
|                 Log_OC.e(TAG, "Failed response while getting capabilities from the server "); |                 Log_OC.e(TAG, "Failed response while getting capabilities from the server "); | ||||||
|                 if (response != null) { |                 if (response != null) { | ||||||
|  | |||||||
| @ -46,32 +46,31 @@ import com.owncloud.android.lib.common.utils.Log_OC; | |||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Checks if the server is valid and if the server supports the Share API |  * Checks if the server is valid and if the server supports the Share API | ||||||
|  *  |  * | ||||||
|  * @author David A. Velasco |  * @author David A. Velasco | ||||||
|  * @author masensio |  * @author masensio | ||||||
|  * |  | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| public class GetRemoteStatusOperation extends RemoteOperation { | public class GetRemoteStatusOperation extends RemoteOperation { | ||||||
|      | 
 | ||||||
|     /**  |     /** | ||||||
|      * Maximum time to wait for a response from the server when the connection is being tested,  |      * Maximum time to wait for a response from the server when the connection is being tested, | ||||||
|      * in MILLISECONDs. |      * in MILLISECONDs. | ||||||
|      */ |      */ | ||||||
|     public static final int TRY_CONNECTION_TIMEOUT = 5000; |     public static final int TRY_CONNECTION_TIMEOUT = 5000; | ||||||
|      | 
 | ||||||
|     private static final String TAG = GetRemoteStatusOperation.class.getSimpleName(); |     private static final String TAG = GetRemoteStatusOperation.class.getSimpleName(); | ||||||
|      | 
 | ||||||
|     private static final String NODE_INSTALLED = "installed"; |     private static final String NODE_INSTALLED = "installed"; | ||||||
|     private static final String NODE_VERSION = "version"; |     private static final String NODE_VERSION = "version"; | ||||||
|      | 
 | ||||||
|     private RemoteOperationResult mLatestResult; |     private RemoteOperationResult mLatestResult; | ||||||
|     private Context mContext; |     private Context mContext; | ||||||
| 
 | 
 | ||||||
|     public GetRemoteStatusOperation(Context context) { |     public GetRemoteStatusOperation(Context context) { | ||||||
|         mContext = context; |         mContext = context; | ||||||
|     } |     } | ||||||
|      | 
 | ||||||
|     private boolean tryConnection(OwnCloudClient client) { |     private boolean tryConnection(OwnCloudClient client) { | ||||||
|         boolean retval = false; |         boolean retval = false; | ||||||
|         GetMethod get = null; |         GetMethod get = null; | ||||||
| @ -81,95 +80,90 @@ public class GetRemoteStatusOperation extends RemoteOperation { | |||||||
| 
 | 
 | ||||||
|             HttpParams params = get.getParams().getDefaultParams(); |             HttpParams params = get.getParams().getDefaultParams(); | ||||||
|             params.setParameter(HttpMethodParams.USER_AGENT, |             params.setParameter(HttpMethodParams.USER_AGENT, | ||||||
|                     OwnCloudClientManagerFactory.getUserAgent()); |                 OwnCloudClientManagerFactory.getUserAgent()); | ||||||
|             get.getParams().setDefaults(params); |             get.getParams().setDefaults(params); | ||||||
| 
 | 
 | ||||||
|             client.setFollowRedirects(false); |             client.setFollowRedirects(false); | ||||||
|             boolean isRedirectToNonSecureConnection = false; |             boolean isRedirectToNonSecureConnection = false; | ||||||
|             int status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT); |             int status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT); | ||||||
|             mLatestResult = new RemoteOperationResult( |             mLatestResult = new RemoteOperationResult((status == HttpStatus.SC_OK), get); | ||||||
|             		(status == HttpStatus.SC_OK), |  | ||||||
|             		status, |  | ||||||
|             		get.getResponseHeaders() |  | ||||||
|     		); |  | ||||||
| 
 | 
 | ||||||
|         	String redirectedLocation = mLatestResult.getRedirectedLocation(); |             String redirectedLocation = mLatestResult.getRedirectedLocation(); | ||||||
|         	while (redirectedLocation != null && redirectedLocation.length() > 0 |             while (redirectedLocation != null && redirectedLocation.length() > 0 | ||||||
| 							&& !mLatestResult.isSuccess()) { |                 && !mLatestResult.isSuccess()) { | ||||||
|         		 | 
 | ||||||
|         		isRedirectToNonSecureConnection |= ( |                 isRedirectToNonSecureConnection |= ( | ||||||
|         				baseUrlSt.startsWith("https://") &&  |                     baseUrlSt.startsWith("https://") && | ||||||
|         				redirectedLocation.startsWith("http://") |                         redirectedLocation.startsWith("http://") | ||||||
| 				); |                 ); | ||||||
|         		get.releaseConnection(); |                 get.releaseConnection(); | ||||||
|         		get = new GetMethod(redirectedLocation); |                 get = new GetMethod(redirectedLocation); | ||||||
|         		status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT); |                 status = client.executeMethod(get, TRY_CONNECTION_TIMEOUT, TRY_CONNECTION_TIMEOUT); | ||||||
|         		mLatestResult = new RemoteOperationResult( |                 mLatestResult = new RemoteOperationResult( | ||||||
|         				(status == HttpStatus.SC_OK),  |                     (status == HttpStatus.SC_OK), | ||||||
|         				status,  |                     get | ||||||
|         				get.getResponseHeaders() |                 ); | ||||||
| 				);  |                 redirectedLocation = mLatestResult.getRedirectedLocation(); | ||||||
|         		redirectedLocation = mLatestResult.getRedirectedLocation(); |             } | ||||||
|         	} |  | ||||||
| 
 | 
 | ||||||
|             String response = get.getResponseBodyAsString(); |             String response = get.getResponseBodyAsString(); | ||||||
|             if (status == HttpStatus.SC_OK) { |             if (status == HttpStatus.SC_OK) { | ||||||
|                 JSONObject json = new JSONObject(response); |                 JSONObject json = new JSONObject(response); | ||||||
|                 if (!json.getBoolean(NODE_INSTALLED)) { |                 if (!json.getBoolean(NODE_INSTALLED)) { | ||||||
|                     mLatestResult = new RemoteOperationResult( |                     mLatestResult = new RemoteOperationResult( | ||||||
|                     		RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); |                         RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); | ||||||
|                 } else { |                 } else { | ||||||
|                     String version = json.getString(NODE_VERSION); |                     String version = json.getString(NODE_VERSION); | ||||||
| 					OwnCloudVersion ocVersion = new OwnCloudVersion(version); |                     OwnCloudVersion ocVersion = new OwnCloudVersion(version); | ||||||
|                     if (!ocVersion.isVersionValid()) { |                     if (!ocVersion.isVersionValid()) { | ||||||
|                         mLatestResult = new RemoteOperationResult( |                         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 |  | ||||||
| 							); |  | ||||||
|                 		} |  | ||||||
| 
 | 
 | ||||||
| 						ArrayList<Object> data = new ArrayList<Object>(); |                     } else { | ||||||
| 						data.add(ocVersion); |                         // success | ||||||
| 						mLatestResult.setData(data); |                         if (isRedirectToNonSecureConnection) { | ||||||
| 						retval = true; |                             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; | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                  | 
 | ||||||
|             } else { |             } else { | ||||||
|                 mLatestResult = new RemoteOperationResult(false, status, get.getResponseHeaders()); |                 mLatestResult = new RemoteOperationResult(false, get); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|         } catch (JSONException e) { |         } catch (JSONException e) { | ||||||
|             mLatestResult = new RemoteOperationResult( |             mLatestResult = new RemoteOperationResult( | ||||||
|             		RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); |                 RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED); | ||||||
|              | 
 | ||||||
|         } catch (Exception e) { |         } catch (Exception e) { | ||||||
|             mLatestResult = new RemoteOperationResult(e); |             mLatestResult = new RemoteOperationResult(e); | ||||||
|              | 
 | ||||||
|         } finally { |         } finally { | ||||||
|             if (get != null) |             if (get != null) | ||||||
|                 get.releaseConnection(); |                 get.releaseConnection(); | ||||||
|         } |         } | ||||||
|          | 
 | ||||||
|         if (mLatestResult.isSuccess()) { |         if (mLatestResult.isSuccess()) { | ||||||
|             Log_OC.i(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage()); |             Log_OC.i(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage()); | ||||||
|              | 
 | ||||||
|         } else if (mLatestResult.getException() != null) { |         } else if (mLatestResult.getException() != null) { | ||||||
|             Log_OC.e(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage(),  |             Log_OC.e(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage(), | ||||||
|             		mLatestResult.getException()); |                 mLatestResult.getException()); | ||||||
|              | 
 | ||||||
|         } else { |         } else { | ||||||
|             Log_OC.e(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage()); |             Log_OC.e(TAG, "Connection check at " + baseUrlSt + ": " + mLatestResult.getLogMessage()); | ||||||
|         } |         } | ||||||
| @ -179,30 +173,30 @@ public class GetRemoteStatusOperation extends RemoteOperation { | |||||||
| 
 | 
 | ||||||
|     private boolean isOnline() { |     private boolean isOnline() { | ||||||
|         ConnectivityManager cm = (ConnectivityManager) mContext |         ConnectivityManager cm = (ConnectivityManager) mContext | ||||||
|                 .getSystemService(Context.CONNECTIVITY_SERVICE); |             .getSystemService(Context.CONNECTIVITY_SERVICE); | ||||||
|         return cm != null && cm.getActiveNetworkInfo() != null |         return cm != null && cm.getActiveNetworkInfo() != null | ||||||
|                 && cm.getActiveNetworkInfo().isConnectedOrConnecting(); |             && cm.getActiveNetworkInfo().isConnectedOrConnecting(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 	@Override |     @Override | ||||||
| 	protected RemoteOperationResult run(OwnCloudClient client) { |     protected RemoteOperationResult run(OwnCloudClient client) { | ||||||
|         if (!isOnline()) { |         if (!isOnline()) { | ||||||
|         	return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION); |             return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION); | ||||||
|         } |         } | ||||||
|         String baseUriStr = client.getBaseUri().toString(); |         String baseUriStr = client.getBaseUri().toString(); | ||||||
|         if (baseUriStr.startsWith("http://") || baseUriStr.startsWith("https://")) { |         if (baseUriStr.startsWith("http://") || baseUriStr.startsWith("https://")) { | ||||||
|             tryConnection(client); |             tryConnection(client); | ||||||
|              | 
 | ||||||
|         } else { |         } else { | ||||||
|             client.setBaseUri(Uri.parse("https://" + baseUriStr)); |             client.setBaseUri(Uri.parse("https://" + baseUriStr)); | ||||||
|             boolean httpsSuccess = tryConnection(client);  |             boolean httpsSuccess = tryConnection(client); | ||||||
| 			if (!httpsSuccess && !mLatestResult.isSslRecoverableException()) { |             if (!httpsSuccess && !mLatestResult.isSslRecoverableException()) { | ||||||
|                 Log_OC.d(TAG, "establishing secure connection failed, trying non secure connection"); |                 Log_OC.d(TAG, "establishing secure connection failed, trying non secure connection"); | ||||||
|                 client.setBaseUri(Uri.parse("http://" + baseUriStr)); |                 client.setBaseUri(Uri.parse("http://" + baseUriStr)); | ||||||
|                 tryConnection(client); |                 tryConnection(client); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         return mLatestResult; |         return mLatestResult; | ||||||
| 	} |     } | ||||||
| 	 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -143,15 +143,15 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation { | |||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 // Result |                 // Result | ||||||
|                 result = new RemoteOperationResult(true, status, get.getResponseHeaders()); |                 result = new RemoteOperationResult(true, get); | ||||||
|                 ResultData resultData = new ResultData(bos.toByteArray(), mimeType, etag); |                 ResultData resultData = new ResultData(bos.toByteArray(), mimeType, etag); | ||||||
|                 ArrayList<Object> data = new ArrayList<Object>(); |                 ArrayList<Object> data = new ArrayList<Object>(); | ||||||
|                 data.add(resultData); |                 data.add(resultData); | ||||||
|                 result.setData(data); |                 result.setData(data); | ||||||
| 
 | 
 | ||||||
|             } else { |             } else { | ||||||
|  |                 result = new RemoteOperationResult(false, get); | ||||||
|                 client.exhaustResponse(get.getResponseBodyAsStream()); |                 client.exhaustResponse(get.getResponseBodyAsStream()); | ||||||
|                 result = new RemoteOperationResult(false, status, get.getResponseHeaders()); |  | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|         } catch (Exception e) { |         } catch (Exception e) { | ||||||
|  | |||||||
| @ -86,14 +86,14 @@ public class GetRemoteUserInfoOperation extends RemoteOperation { | |||||||
|                 userInfo.mEmail = respData.getString(NODE_EMAIL); |                 userInfo.mEmail = respData.getString(NODE_EMAIL); | ||||||
| 
 | 
 | ||||||
|                 // Result |                 // Result | ||||||
|                 result = new RemoteOperationResult(true, status, get.getResponseHeaders()); |                 result = new RemoteOperationResult(true, get); | ||||||
|                 // Username in result.data |                 // Username in result.data | ||||||
|                 ArrayList<Object> data = new ArrayList<Object>(); |                 ArrayList<Object> data = new ArrayList<Object>(); | ||||||
|                 data.add(userInfo); |                 data.add(userInfo); | ||||||
|                 result.setData(data); |                 result.setData(data); | ||||||
| 
 | 
 | ||||||
|             } else { |             } else { | ||||||
|                 result = new RemoteOperationResult(false, status, get.getResponseHeaders()); |                 result = new RemoteOperationResult(false, get); | ||||||
|                 String response = get.getResponseBodyAsString(); |                 String response = get.getResponseBodyAsString(); | ||||||
|                 Log_OC.e(TAG, "Failed response while getting user information "); |                 Log_OC.e(TAG, "Failed response while getting user information "); | ||||||
|                 if (response != null) { |                 if (response != null) { | ||||||
|  | |||||||
| @ -107,14 +107,14 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation { | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|                 // Result |                 // Result | ||||||
|                 result = new RemoteOperationResult(true, status, get.getResponseHeaders()); |                 result = new RemoteOperationResult(true, get); | ||||||
|                 //Quota data in data collection |                 //Quota data in data collection | ||||||
|                 ArrayList<Object> data = new ArrayList<Object>(); |                 ArrayList<Object> data = new ArrayList<Object>(); | ||||||
|                 data.add(new Quota(quotaFree, quotaUsed, quotaTotal, quotaRelative)); |                 data.add(new Quota(quotaFree, quotaUsed, quotaTotal, quotaRelative)); | ||||||
|                 result.setData(data); |                 result.setData(data); | ||||||
| 
 | 
 | ||||||
|             } else { |             } else { | ||||||
|                 result = new RemoteOperationResult(false, status, get.getResponseHeaders()); |                 result = new RemoteOperationResult(false, get); | ||||||
|                 String response = get.getResponseBodyAsString(); |                 String response = get.getResponseBodyAsString(); | ||||||
|                 Log_OC.e(TAG, "Failed response while getting user quota information "); |                 Log_OC.e(TAG, "Failed response while getting user quota information "); | ||||||
|                 if (response != null) { |                 if (response != null) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user