1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

Remove deprecated methods for update to version 1.0

This commit is contained in:
David A. Velasco 2017-08-04 11:11:37 +02:00
parent a4386bb4fe
commit 02f35d5f5e
7 changed files with 36 additions and 171 deletions

View File

@ -144,28 +144,6 @@ public class OwnCloudClient extends HttpClient {
mCredentials.applyTo(this);
}
/**
* Check if a file exists in the OC server
*
* @return 'true' if the file exists; 'false' it doesn't exist
* @throws Exception When the existence could not be determined
* @deprecated Use ExistenceCheckOperation instead
*/
@Deprecated
public boolean existsFile(String path) throws IOException, HttpException {
HeadMethod head = new HeadMethod(getWebdavUri() + WebdavUtils.encodePath(path));
try {
int status = executeMethod(head);
Log_OC.d(TAG, "HEAD to " + path + " finished with HTTP status " + status +
((status != HttpStatus.SC_OK) ? "(FAIL)" : ""));
exhaustResponse(head.getResponseBodyAsStream());
return (status == HttpStatus.SC_OK);
} finally {
head.releaseConnection(); // let the connection available for other methods
}
}
/**
* Requests the received method with the received timeout (milliseconds).
*

View File

@ -58,11 +58,12 @@ public class OwnCloudClientFactory {
/**
* Creates a OwnCloudClient setup for an ownCloud account
*
*
* Do not call this method from the main thread.
*
*
* @param account The ownCloud account
* @param appContext Android application context
* @param currentActivity Caller {@link Activity}
* @return A OwnCloudClient object ready to be used
* @throws AuthenticatorException If the authenticator failed to get the authorization
* token for the account.
@ -72,69 +73,7 @@ public class OwnCloudClientFactory {
* authorization token for the account.
* @throws AccountNotFoundException If 'account' is unknown for the AccountManager
*
* @deprecated : Will be deleted in version 1.0.
* Use {@link #createOwnCloudClient(Account, Context, Activity)} instead.
*/
@Deprecated
public static OwnCloudClient createOwnCloudClient (Account account, Context appContext)
throws OperationCanceledException, AuthenticatorException, IOException,
AccountNotFoundException {
//Log_OC.d(TAG, "Creating OwnCloudClient associated to " + account.name);
Uri baseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(appContext, account));
AccountManager am = AccountManager.get(appContext);
// TODO avoid calling to getUserData here
boolean isOauth2 =
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2) != null;
boolean isSamlSso =
am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso);
String username = AccountUtils.getUsernameForAccount(account);
if (isOauth2) {
String accessToken = am.blockingGetAuthToken(
account,
AccountTypeUtils.getAuthTokenTypeAccessToken(account.type),
false);
client.setCredentials(
OwnCloudCredentialsFactory.newBearerCredentials(username, accessToken)
);
} else if (isSamlSso) { // TODO avoid a call to getUserData here
String accessToken = am.blockingGetAuthToken(
account,
AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type),
false);
client.setCredentials(
OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken)
);
} else {
//String password = am.getPassword(account);
String password = am.blockingGetAuthToken(
account,
AccountTypeUtils.getAuthTokenTypePass(account.type),
false);
OwnCloudVersion version = AccountUtils.getServerVersionForAccount(account, appContext);
client.setCredentials(
OwnCloudCredentialsFactory.newBasicCredentials(
username,
password,
(version != null && version.isPreemptiveAuthenticationPreferred())
)
);
}
// Restore cookies
AccountUtils.restoreCookies(account, client, appContext);
return client;
}
public static OwnCloudClient createOwnCloudClient (Account account, Context appContext,
Activity currentActivity)
throws OperationCanceledException, AuthenticatorException, IOException,
@ -157,7 +96,7 @@ public class OwnCloudClientFactory {
currentActivity,
null,
null);
Bundle result = future.getResult();
String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN);
if (accessToken == null) throw new AuthenticatorException("WTF!");
@ -173,7 +112,7 @@ public class OwnCloudClientFactory {
currentActivity,
null,
null);
Bundle result = future.getResult();
String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN);
if (accessToken == null) throw new AuthenticatorException("WTF!");
@ -194,7 +133,7 @@ public class OwnCloudClientFactory {
null,
null
);
Bundle result = future.getResult();
String password = result.getString(AccountManager.KEY_AUTHTOKEN);
OwnCloudVersion version = AccountUtils.getServerVersionForAccount(account, appContext);
@ -206,13 +145,13 @@ public class OwnCloudClientFactory {
)
);
}
// Restore cookies
AccountUtils.restoreCookies(account, client, appContext);
return client;
}
/**
* Creates a OwnCloudClient to access a URL and sets the desired parameters for ownCloud
* client connections.

View File

@ -51,51 +51,30 @@ public class AccountUtils {
private static final String TAG = AccountUtils.class.getSimpleName();
public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav";
public static final String ODAV_PATH = "/remote.php/webdav";
public static final String STATUS_PATH = "/status.php";
/**
* Constructs full url to host and webdav resource basing on host version
*
* @param context
* @param account
* @return url or null on failure
* @param context Valid Android {@link Context}, needed to access the {@link AccountManager}
* @param account A stored ownCloud {@link Account}
* @return Full URL to WebDAV endpoint in the server corresponding to 'account'.
* @throws AccountNotFoundException When 'account' is unknown for the AccountManager
* @deprecated To be removed in release 1.0.
*/
@Deprecated
public static String constructFullURLForAccount(Context context, Account account) throws AccountNotFoundException {
AccountManager ama = AccountManager.get(context);
String baseurl = ama.getUserData(account, Constants.KEY_OC_BASE_URL);
if (baseurl == null) {
throw new AccountNotFoundException(account, "Account not found", null);
}
return baseurl + WEBDAV_PATH_4_0;
}
/**
* Extracts url server from the account
*
* @param context
* @param account
* @return url server or null on failure
* @throws AccountNotFoundException When 'account' is unknown for the AccountManager
* @deprecated This method will be removed in version 1.0.
* Use {@link #getBaseUrlForAccount(Context, Account)}
* instead.
*/
@Deprecated
public static String constructBasicURLForAccount(Context context, Account account)
public static String getWebDavUrlForAccount(Context context, Account account)
throws AccountNotFoundException {
return getBaseUrlForAccount(context, account);
return getBaseUrlForAccount(context, account) + WEBDAV_PATH_4_0;
}
/**
* Extracts url server from the account
*
* @param context
* @param account
* @return url server or null on failure
* @param context Valid Android {@link Context}, needed to access the {@link AccountManager}
* @param account A stored ownCloud {@link Account}
* @return Full URL to the server corresponding to 'account', ending in the base path
* common to all API endpoints.
* @throws AccountNotFoundException When 'account' is unknown for the AccountManager
*/
public static String getBaseUrlForAccount(Context context, Account account)
@ -370,15 +349,6 @@ public class AccountUtils {
public static class Constants {
/**
* Value under this key should handle path to webdav php script. Will be
* removed and usage should be replaced by combining
* {@link #KEY_OC_BASE_URL } and
* {@link com.owncloud.android.lib.resources.status.OwnCloudVersion}
*
* @deprecated
*/
public static final String KEY_OC_URL = "oc_url";
/**
* Version should be 3 numbers separated by dot so it can be parsed by
* {@link com.owncloud.android.lib.resources.status.OwnCloudVersion}
@ -397,12 +367,6 @@ public class AccountUtils {
* Flag signaling if the ownCloud server can be accessed with session cookies from SAML-based web single-sign-on.
*/
public static final String KEY_SUPPORTS_SAML_WEB_SSO = "oc_supports_saml_web_sso";
/**
* Flag signaling if the ownCloud server supports Share API"
*
* @deprecated
*/
public static final String KEY_SUPPORTS_SHARE_API = "oc_supports_share_api";
/**
* OC account cookies
*/

View File

@ -71,8 +71,6 @@ public class BearerAuthScheme implements AuthScheme /*extends RFC2617Scheme*/ {
* @param challenge Authentication challenge
*
* @throws MalformedChallengeException Thrown if the authentication challenge is malformed
*
* @deprecated Use parameterless constructor and {@link AuthScheme#processChallenge(String)} method
*/
public BearerAuthScheme(final String challenge) throws MalformedChallengeException {
processChallenge(challenge);
@ -125,8 +123,6 @@ public class BearerAuthScheme implements AuthScheme /*extends RFC2617Scheme*/ {
* for this authentication scheme
* @throws AuthenticationException If authorization string cannot be generated due to an authentication failure
* @return A bearer authorization string
*
* @deprecated Use {@link #authenticate(Credentials, HttpMethod)}
*/
public String authenticate(Credentials credentials, String method, String uri) throws AuthenticationException {
Log_OC.d(TAG, "enter BearerScheme.authenticate(Credentials, String, String)");
@ -183,9 +179,7 @@ public class BearerAuthScheme implements AuthScheme /*extends RFC2617Scheme*/ {
}
/**
* @deprecated Use {@link #authenticate(BearerCredentials, String)}
*
* Returns a bearer Authorization header value for the given
* Returns a bearer Authorization header value for the given
* {@link BearerCredentials}.
*
* @param credentials The credentials to encode.
@ -245,8 +239,6 @@ public class BearerAuthScheme implements AuthScheme /*extends RFC2617Scheme*/ {
* This method simply returns the realm for the challenge.
*
* @return String a String identifying the authentication challenge.
*
* @deprecated no longer used
*/
@Override
public String getID() {

View File

@ -71,19 +71,6 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation {
mSuccessIfAbsent = successIfAbsent;
}
/**
* Full constructor. Success of the operation will depend upon the value of successIfAbsent.
*
* @param remotePath Path to append to the URL owned by the client instance.
* @param context Android application context.
* @param successIfAbsent When 'true', the operation finishes in success if the path does
* NOT exist in the remote server (HTTP 404).
* @deprecated
*/
public ExistenceCheckRemoteOperation(String remotePath, Context context, boolean successIfAbsent) {
this(remotePath, successIfAbsent);
}
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;

View File

@ -24,6 +24,8 @@
package com.owncloud.android.lib.resources.files;
import android.os.RemoteException;
import java.io.File;
import org.apache.jackrabbit.webdav.client.methods.DavMethodBase;
@ -101,8 +103,7 @@ public class RenameRemoteFileOperation extends RemoteOperation {
return new RemoteOperationResult(ResultCode.OK);
}
// check if a file with the new name already exists
if (client.existsFile(mNewRemotePath)) {
if (targetPathIsUsed(client)) {
return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
}
@ -134,6 +135,18 @@ public class RenameRemoteFileOperation extends RemoteOperation {
return result;
}
/**
* Checks if a file with the new name already exists.
*
* @return 'True' if the target path is already used by an existing file.
*/
private boolean targetPathIsUsed(OwnCloudClient client) {
ExistenceCheckRemoteOperation existenceCheckRemoteOperation =
new ExistenceCheckRemoteOperation(mNewRemotePath, false);
RemoteOperationResult exists = existenceCheckRemoteOperation.run(client);
return exists.isSuccess();
}
/**
* Move operation
*/

View File

@ -63,14 +63,6 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {
private int mVersion;
private boolean mIsValid;
/**
* @deprecated Will be removed in version 1.0 of the library.
*/
private OwnCloudVersion(int version) {
mVersion = version;
mIsValid = true;
}
public OwnCloudVersion(String version) {
mVersion = 0;
mIsValid = false;