[tx-robot] updated from transifex
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / GetServerInfoOperation.java
index c210153..1b4b7a9 100644 (file)
@@ -1,24 +1,21 @@
-/* ownCloud Android Library is available under MIT license
- *   Copyright (C) 2014 ownCloud Inc.
- *   
- *   Permission is hereby granted, free of charge, to any person obtaining a copy
- *   of this software and associated documentation files (the "Software"), to deal
- *   in the Software without restriction, including without limitation the rights
- *   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- *   copies of the Software, and to permit persons to whom the Software is
- *   furnished to do so, subject to the following conditions:
- *   
- *   The above copyright notice and this permission notice shall be included in
- *   all copies or substantial portions of the Software.
- *   
- *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
- *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
- *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 
- *   BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
- *   ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
- *   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- *   THE SOFTWARE.
+/**
+ *   ownCloud Android client application
+ *
+ *   @author David A. Velasco
+ *   @author masensio
+ *   Copyright (C) 2015 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   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
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  */
 
@@ -31,10 +28,10 @@ import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.resources.status.GetRemoteStatusOperation;
 import com.owncloud.android.lib.resources.status.OwnCloudVersion;
 import com.owncloud.android.operations.DetectAuthenticationMethodOperation.AuthenticationMethod;
-import com.owncloud.android.utils.Log_OC;
 
 import android.content.Context;
 
@@ -43,9 +40,6 @@ import android.content.Context;
  * 
  * Checks the existence of a configured ownCloud server in the URL, gets its version 
  * and finds out what authentication method is needed to access files in it.
- * 
- * @author David A. Velasco
- * @author masensio
  */
 
 public class GetServerInfoOperation extends RemoteOperation {
@@ -53,7 +47,6 @@ public class GetServerInfoOperation extends RemoteOperation {
     private static final String TAG = GetServerInfoOperation.class.getSimpleName();
     
     private String mUrl;
-    private String mAuthTokenType;
     private Context mContext;
     
     private ServerInfo mResultData;
@@ -62,14 +55,11 @@ public class GetServerInfoOperation extends RemoteOperation {
      * Constructor.
      * 
      * @param url               URL to an ownCloud server.
-     * @param authTokenType     Identifies the authorization token supported by the caller;
-     *                          TODO ugly dependency, get rid of it. 
      * @param context           Android context; needed to check network state
      *                          TODO ugly dependency, get rid of it. 
      */
-    public GetServerInfoOperation(String url, String authTokenType, Context context) {
+    public GetServerInfoOperation(String url, Context context) {
         mUrl = trimWebdavSuffix(url);
-        mAuthTokenType = authTokenType;
         mContext = context;
         
         mResultData = new ServerInfo();
@@ -87,14 +77,14 @@ public class GetServerInfoOperation extends RemoteOperation {
        protected RemoteOperationResult run(OwnCloudClient client) {
            
            // first: check the status of the server (including its version)
-           GetRemoteStatusOperation getStatus = new GetRemoteStatusOperation(mUrl, mContext);
+           GetRemoteStatusOperation getStatus = new GetRemoteStatusOperation(mContext);
            RemoteOperationResult result = getStatus.execute(client);
-
+           
         if (result.isSuccess()) {
             // second: get authentication method required by the server
             mResultData.mVersion = (OwnCloudVersion)(result.getData().get(0));
-            boolean isSslConn = (result.getCode() == ResultCode.OK_SSL);
-            mResultData.mBaseUrl = normalizeProtocolPrefix(mUrl, isSslConn);
+            mResultData.mIsSslConn = (result.getCode() == ResultCode.OK_SSL);
+            mResultData.mBaseUrl = normalizeProtocolPrefix(mUrl, mResultData.mIsSslConn);
             RemoteOperationResult detectAuthResult = detectAuthorizationMethod(client);
             
             // third: merge results
@@ -114,10 +104,8 @@ public class GetServerInfoOperation extends RemoteOperation {
        
     private RemoteOperationResult detectAuthorizationMethod(OwnCloudClient client) {
         Log_OC.d(TAG, "Trying empty authorization to detect authentication method");
-        String webdav_path = AccountUtils.getWebdavPath(mResultData.mVersion, mAuthTokenType);
-        String webdav_url = mResultData.mBaseUrl + webdav_path;
         DetectAuthenticationMethodOperation operation = 
-                new DetectAuthenticationMethodOperation(mContext, webdav_url);
+                new DetectAuthenticationMethodOperation(mContext);
         return operation.execute(client);
     }
     
@@ -129,12 +117,8 @@ public class GetServerInfoOperation extends RemoteOperation {
             if (url.endsWith("/")) {
                 url = url.substring(0, url.length() - 1);
             }
-            if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_4_0)){
-                url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_4_0.length());
-            } else if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_2_0)){
-                url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_2_0.length());
-            } else if (url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_1_2)){
-                url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_1_2.length());
+            if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_4_0_AND_LATER)){
+                url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_4_0_AND_LATER.length());
             }
         }
         return url;
@@ -155,9 +139,10 @@ public class GetServerInfoOperation extends RemoteOperation {
     
     
     public static class ServerInfo {
-        public OwnCloudVersion mVersion;
-        public String mBaseUrl;
-        public AuthenticationMethod mAuthMethod;
+        public OwnCloudVersion mVersion = null;
+        public String mBaseUrl = "";
+        public AuthenticationMethod mAuthMethod = AuthenticationMethod.UNKNOWN;
+        public boolean mIsSslConn = false;
     }
        
 }