1803f4cf1425ea27cda9e40cedaca7bdc3a26201
1 package com
.owncloud
.android
.operations
;
3 import java
.net
.MalformedURLException
;
4 import java
.net
.SocketException
;
5 import java
.net
.SocketTimeoutException
;
6 import java
.net
.UnknownHostException
;
8 import javax
.net
.ssl
.SSLException
;
10 import org
.apache
.commons
.httpclient
.ConnectTimeoutException
;
11 import org
.apache
.commons
.httpclient
.HttpStatus
;
14 public class RemoteOperationResult
{
16 public enum ResultCode
{ // TODO leave alone our own errors
22 INSTANCE_NOT_CONFIGURED
,
28 NO_NETWORK_CONNECTION
,
33 private boolean mSuccess
= false
;
34 private int mHttpCode
= -1;
35 private Exception mException
= null
;
36 private ResultCode mCode
= ResultCode
.UNKNOWN_ERROR
;
38 public RemoteOperationResult(ResultCode code
) {
40 mSuccess
= (code
== ResultCode
.OK
|| code
== ResultCode
.OK_SSL
|| code
== ResultCode
.OK_NO_SSL
);
43 public RemoteOperationResult(boolean success
, int httpCode
) {
48 mCode
= ResultCode
.OK
;
50 } else if (httpCode
> 0) {
52 case HttpStatus
.SC_NOT_FOUND
:
53 mCode
= ResultCode
.FILE_NOT_FOUND
;
55 case HttpStatus
.SC_INTERNAL_SERVER_ERROR
:
56 mCode
= ResultCode
.INSTANCE_NOT_CONFIGURED
;
59 mCode
= ResultCode
.UNHANDLED_HTTP_CODE
;
64 public RemoteOperationResult(Exception e
) {
67 if (e
instanceof SocketException
) {
68 mCode
= ResultCode
.WRONG_CONNECTION
;
69 //Log.e(TAG, "Socket exception while trying connection", e);
71 } else if (e
instanceof SocketTimeoutException
) {
72 mCode
= ResultCode
.TIMEOUT
;
73 //Log.e(TAG, "Socket timeout exception while trying connection", e);
75 } else if (e
instanceof ConnectTimeoutException
) {
76 mCode
= ResultCode
.TIMEOUT
;
77 //Log.e(TAG, "Socket timeout exception while trying connection", e);
79 } else if (e
instanceof MalformedURLException
) {
80 mCode
= ResultCode
.INCORRECT_ADDRESS
;
81 //Log.e(TAG, "Connect exception while trying connection", e);
83 } else if (e
instanceof UnknownHostException
) {
84 mCode
= ResultCode
.HOST_NOT_AVAILABLE
;
85 //Log.e(TAG, "Unknown host exception while trying connection", e);
87 } else if (e
instanceof SSLException
) {
88 mCode
= ResultCode
.SSL_ERROR
;
89 //Log.e(TAG, "SSL exception while trying connection", e);
92 mCode
= ResultCode
.UNKNOWN_ERROR
;
95 /* } catch (HttpException e) { // other specific exceptions from org.apache.commons.httpclient
96 Log.e(TAG, "HTTP exception while trying connection", e);
97 } catch (IOException e) { // UnkownsServiceException, and any other transport exceptions that could occur
98 Log.e(TAG, "I/O exception while trying connection", e);
99 } catch (Exception e) {
100 Log.e(TAG, "Unexpected exception while trying connection", e);
105 public boolean isSuccess() {
109 public int getHttpCode() {
113 public ResultCode
getCode() {
117 public Exception
getException() {