Merge pull request #186 from owncloud/fixed_contradicted_messages_in_login_view
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / ExistenceCheckOperation.java
index 506636f..1093986 100644 (file)
@@ -2,9 +2,8 @@
  *   Copyright (C) 2012 ownCloud Inc.
  *
  *   This program is free software: you can redistribute it and/or modify
  *   Copyright (C) 2012 ownCloud Inc.
  *
  *   This program is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation, either version 3 of the License, or
- *   (at your option) any later version.
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
  *
  *   This program is distributed in the hope that it will be useful,
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  *
  *   This program is distributed in the hope that it will be useful,
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -21,10 +20,11 @@ package com.owncloud.android.operations;
 import org.apache.commons.httpclient.HttpStatus;
 import org.apache.commons.httpclient.methods.HeadMethod;
 
 import org.apache.commons.httpclient.HttpStatus;
 import org.apache.commons.httpclient.methods.HeadMethod;
 
+import com.owncloud.android.Log_OC;
+
 import eu.alefzero.webdav.WebdavClient;
 import android.content.Context;
 import android.net.ConnectivityManager;
 import eu.alefzero.webdav.WebdavClient;
 import android.content.Context;
 import android.net.ConnectivityManager;
-import android.util.Log;
 
 /**
  * Operation to check the existence or absence of a path in a remote server.
 
 /**
  * Operation to check the existence or absence of a path in a remote server.
@@ -41,20 +41,6 @@ public class ExistenceCheckOperation extends RemoteOperation {
     private String mPath;
     private Context mContext;
     private boolean mSuccessIfAbsent;
     private String mPath;
     private Context mContext;
     private boolean mSuccessIfAbsent;
-    private String mAccessToken;
-
-    
-    /**
-     * Simple constructor. Success when the path in the server exists.
-     * 
-     * @param path          Path to append to the URL owned by the client instance.
-     * @param context       Android application context.
-     * @param accessToken   Access token for Bearer Authentication -> TODO: move to other place
-     */
-    public ExistenceCheckOperation(String path, Context context, String accessToken) {
-        this(path, context, false);
-        mAccessToken = accessToken;
-    }
 
     
     /**
 
     
     /**
@@ -80,17 +66,15 @@ public class ExistenceCheckOperation extends RemoteOperation {
         HeadMethod head = null;
         try {
             head = new HeadMethod(client.getBaseUri() + mPath);
         HeadMethod head = null;
         try {
             head = new HeadMethod(client.getBaseUri() + mPath);
-            head.addRequestHeader("Authorization", "Bearer " + mAccessToken);   // TODO put in some general place
-            
             int status = client.executeMethod(head, TIMEOUT, TIMEOUT);
             client.exhaustResponse(head.getResponseBodyAsStream());
             boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) || (status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent);
             result = new RemoteOperationResult(success, status);
             int status = client.executeMethod(head, TIMEOUT, TIMEOUT);
             client.exhaustResponse(head.getResponseBodyAsStream());
             boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) || (status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent);
             result = new RemoteOperationResult(success, status);
-            Log.d(TAG, "Existence check for " + client.getBaseUri() + mPath + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + "finished with HTTP status " + status + (!success?"(FAIL)":""));
+            Log_OC.d(TAG, "Existence check for " + client.getBaseUri() + mPath + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + "finished with HTTP status " + status + (!success?"(FAIL)":""));
             
         } catch (Exception e) {
             result = new RemoteOperationResult(e);
             
         } catch (Exception e) {
             result = new RemoteOperationResult(e);
-            Log.e(TAG, "Existence check for " + client.getBaseUri() + mPath + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + ": " + result.getLogMessage(), result.getException());
+            Log_OC.e(TAG, "Existence check for " + client.getBaseUri() + mPath + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + ": " + result.getLogMessage(), result.getException());
             
         } finally {
             if (head != null)
             
         } finally {
             if (head != null)
@@ -106,4 +90,5 @@ public class ExistenceCheckOperation extends RemoteOperation {
                 && cm.getActiveNetworkInfo().isConnectedOrConnecting();
     }
 
                 && cm.getActiveNetworkInfo().isConnectedOrConnecting();
     }
 
+
 }
 }