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

Merge branch 'master' into develop

This commit is contained in:
masensio 2014-02-24 12:56:22 +01:00
commit cd4414a7bd
5 changed files with 94 additions and 76 deletions

View File

@ -80,10 +80,11 @@ public class AccountUtils {
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);
String strver = ama.getUserData(account, Constants.KEY_OC_VERSION);
String version = ama.getUserData(account, Constants.KEY_OC_VERSION);
String versionString = ama.getUserData(account, Constants.KEY_OC_VERSION_STRING);
boolean supportsOAuth = (ama.getUserData(account, Constants.KEY_SUPPORTS_OAUTH2) != null);
boolean supportsSamlSso = (ama.getUserData(account, Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null);
OwnCloudVersion ver = new OwnCloudVersion(strver);
OwnCloudVersion ver = new OwnCloudVersion(version, versionString);
String webdavpath = getWebdavPath(ver, supportsOAuth, supportsSamlSso);
if (baseurl == null || webdavpath == null)
@ -148,6 +149,10 @@ public class AccountUtils {
* http://server/path or https://owncloud.server
*/
public static final String KEY_OC_BASE_URL = "oc_base_url";
/**
* Version string as shown in the status.php resource in the server side
*/
public static final String KEY_OC_VERSION_STRING = "oc_version_string";
/**
* Flag signaling if the ownCloud server can be accessed with OAuth2 access tokens.
*/

View File

@ -220,7 +220,8 @@ public class ShareXMLParser {
}
String name = parser.getName();
if (name.equalsIgnoreCase(NODE_ELEMENT)) {
shares.add(readElement(parser));
readElement(parser, shares);
} else if (name.equalsIgnoreCase(NODE_ID)) {// Parse Create XML Response
share = new OCShare();
String value = readNode(parser, NODE_ID);
@ -241,10 +242,10 @@ public class ShareXMLParser {
}
if (share != null) {
// this is the response of a request for creation; don't pass to isValidShare()
shares.add(share);
}
return shares;
}
@ -257,7 +258,7 @@ public class ShareXMLParser {
* @throws XmlPullParserException
* @throws IOException
*/
private OCShare readElement(XmlPullParser parser) throws XmlPullParserException, IOException {
private void readElement(XmlPullParser parser, ArrayList<OCShare> shares) throws XmlPullParserException, IOException {
parser.require(XmlPullParser.START_TAG, ns, NODE_ELEMENT);
OCShare share = new OCShare();
@ -270,7 +271,12 @@ public class ShareXMLParser {
String name = parser.getName();
if (name.equalsIgnoreCase(NODE_ID)) {
if (name.equalsIgnoreCase(NODE_ELEMENT)) {
// patch to work around servers responding with extra <element> surrounding all the shares on the same file before
// https://github.com/owncloud/core/issues/6992 was fixed
readElement(parser, shares);
} else if (name.equalsIgnoreCase(NODE_ID)) {
share.setIdRemoteShared(Integer.parseInt(readNode(parser, NODE_ID)));
} else if (name.equalsIgnoreCase(NODE_ITEM_TYPE)) {
@ -325,7 +331,15 @@ public class ShareXMLParser {
}
}
return share;
if (isValidShare(share)) {
shares.add(share);
}
}
private boolean isValidShare(OCShare share) {
return ((share.getIdRemoteShared() > -1) &&
(share.getShareType() == ShareType.PUBLIC_LINK) // at this moment we only care about public shares
);
}
private void fixPathForFolder(OCShare share) {

View File

@ -54,8 +54,6 @@ public class GetRemoteStatusOperation extends RemoteOperation {
private static final String TAG = GetRemoteStatusOperation.class.getSimpleName();
private static final String OCVERSION_SHARED_SUPPORTED = "5.0.13";
private static final String NODE_INSTALLED = "installed";
private static final String NODE_VERSION = "version";
private static final String NODE_VERSIONSTRING = "versionstring";
@ -64,27 +62,16 @@ public class GetRemoteStatusOperation extends RemoteOperation {
private RemoteOperationResult mLatestResult;
private Context mContext;
private OwnCloudVersion mOCVersion;
private OwnCloudVersion mOCVersionString;
public GetRemoteStatusOperation(String url, Context context) {
mUrl = url;
mContext = context;
mOCVersion = null;
mOCVersionString = null;
}
public OwnCloudVersion getDiscoveredVersion() {
return mOCVersion;
}
public boolean isSharedSupported() {
OwnCloudVersion shareServer = new OwnCloudVersion(OCVERSION_SHARED_SUPPORTED);
if (mOCVersionString != null) {
return mOCVersionString.compareTo(shareServer) >= 0;
}
return false;
}
private boolean tryConnection(OwnCloudClient wc, String urlSt) {
boolean retval = false;
@ -98,8 +85,9 @@ public class GetRemoteStatusOperation extends RemoteOperation {
if (!json.getBoolean(NODE_INSTALLED)) {
mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
} else {
mOCVersion = new OwnCloudVersion(json.getString(NODE_VERSION));
mOCVersionString = new OwnCloudVersion(json.getString(NODE_VERSIONSTRING), true);
String version = json.getString(NODE_VERSION);
String versionString = json.getString(NODE_VERSIONSTRING);
mOCVersion = new OwnCloudVersion(version, versionString);
if (!mOCVersion.isVersionValid()) {
mLatestResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.BAD_OC_VERSION);

View File

@ -37,33 +37,33 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {
public static final OwnCloudVersion owncloud_v4_5 = new OwnCloudVersion(
0x040500);
public static final int MINIMUM_VERSION_STRING_FOR_SHARING_API = 0x05000D;
// format is in version
// 0xAABBCC
// for version AA.BB.CC
// ie version 2.0.3 will be stored as 0x030003
// ie version 2.0.3 will be stored as 0x020003
private int mVersion;
private boolean mIsValid;
// not parsed, saved same value offered by the server
private String mVersionString;
public OwnCloudVersion(int version) {
protected OwnCloudVersion(int version) {
mVersion = version;
mIsValid = true;
mVersionString = "";
}
public OwnCloudVersion(String version) {
public OwnCloudVersion(String version, String versionString) {
mVersion = 0;
mIsValid = false;
parseVersionString(version);
}
public OwnCloudVersion(String versionstring, boolean isVersionString) {
mVersion = 0;
mIsValid = false;
if (isVersionString) {
parseVersionString(versionstring);
} else {
parseVersion(versionstring);
}
if (versionString != null && versionString.length() > 0) {
mVersionString = versionString;
} else if (mIsValid) {
mVersionString = version;
}
}
public String toString() {
@ -71,6 +71,14 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {
+ ((mVersion) % 256);
}
public String getVersion() {
return toString();
}
public String getVersionString() {
return mVersionString;
}
public boolean isVersionValid() {
return mIsValid;
}
@ -81,45 +89,48 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {
: another.mVersion < mVersion ? 1 : -1;
}
private void parseVersion(String version) {
try {
String[] nums = version.split("\\.");
if (nums.length > 0) {
mVersion += Integer.parseInt(nums[0]);
}
mVersion = mVersion << 8;
if (nums.length > 1) {
mVersion += Integer.parseInt(nums[1]);
}
mVersion = mVersion << 8;
if (nums.length > 2) {
mVersion += Integer.parseInt(nums[2]);
}
mIsValid = true;
} catch (Exception e) {
mIsValid = false;
}
}
private void parseVersionString(String versionstring) {
private void parseVersionString(String versionString) {
try {
versionstring = versionstring.replaceAll("[^\\d.]", "");
String[] nums = versionstring.split("\\.");
if (nums.length > 0) {
mVersion += Integer.parseInt(nums[0]);
}
mVersion = mVersion << 8;
if (nums.length > 1) {
mVersion += Integer.parseInt(nums[1]);
}
mVersion = mVersion << 8;
if (nums.length > 2) {
mVersion += Integer.parseInt(nums[2]);
}
mVersion = getParsedVersionString(versionString);
mIsValid = true;
} catch (Exception e) {
mIsValid = false;
}
}
private int getParsedVersionString(String versionString) throws NumberFormatException {
int version = 0;
// get only numeric part
versionString = versionString.replaceAll("[^\\d.]", "");
String[] nums = versionString.split("\\.");
if (nums.length > 0) {
version += Integer.parseInt(nums[0]);
}
version = version << 8;
if (nums.length > 1) {
version += Integer.parseInt(nums[1]);
}
version = version << 8;
if (nums.length > 2) {
version += Integer.parseInt(nums[2]);
}
return version;
}
public boolean isSharedSupported() {
int versionString = 0;
try {
versionString = getParsedVersionString(mVersionString);
} catch (Exception e) {
// nothing to do here
}
return (versionString >= MINIMUM_VERSION_STRING_FOR_SHARING_API);
}
}

View File

@ -80,10 +80,10 @@ public class GetRemoteUserNameOperation extends RemoteOperation {
//Get the user
try {
//GetMethod get = new GetMethod(client.getWebdavUri() + OCS_ROUTE);
get = new GetMethod(client.getBaseUri() + OCS_ROUTE);
Log.e(TAG, "Getting OC user information from " + client.getBaseUri() + OCS_ROUTE);
Log.e(TAG, "Getting OC user information from " + client.getWebdavUri() + OCS_ROUTE);
get = new GetMethod(client.getWebdavUri() + OCS_ROUTE);
//get = new GetMethod(client.getBaseUri() + OCS_ROUTE); // need to fix the semantics of getBaseUri and getWebdavUri
//Log.e(TAG, "Getting OC user information from " + client.getBaseUri() + OCS_ROUTE);
//Log.e(TAG, "Getting OC user information from " + client.getWebdavUri() + OCS_ROUTE);
// Add the Header
get.addRequestHeader(HEADER_OCS_API, HEADER_OCS_API_VALUE);
status = client.executeMethod(get);