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

Merge pull request #85 from owncloud/update_share_link_for_OC_8.2

Update share link for oc 8.2
This commit is contained in:
David A. Velasco 2015-09-14 14:58:13 +02:00
commit 5985ba9a9f
4 changed files with 60 additions and 20 deletions

View File

@ -37,6 +37,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
/** /**
* Provide a list shares for a specific file. * Provide a list shares for a specific file.
@ -65,12 +66,14 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation {
* Constructor * Constructor
* *
* @param remoteFilePath Path to file or folder * @param remoteFilePath Path to file or folder
* @param reshares If set to false (default), only shares from the current user are returned * @param reshares If set to false (default), only shares from the current user are
* returned
* If set to true, all shares from the given file are returned * If set to true, all shares from the given file are returned
* @param subfiles If set to false (default), lists only the folder being shared * @param subfiles If set to false (default), lists only the folder being shared
* If set to true, all shared files within the folder are returned. * If set to true, all shared files within the folder are returned.
*/ */
public GetRemoteSharesForFileOperation(String remoteFilePath, boolean reshares, boolean subfiles) { public GetRemoteSharesForFileOperation(String remoteFilePath, boolean reshares,
boolean subfiles) {
mRemoteFilePath = remoteFilePath; mRemoteFilePath = remoteFilePath;
mReshares = reshares; mReshares = reshares;
mSubfiles = subfiles; mSubfiles = subfiles;
@ -88,11 +91,11 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation {
get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH);
// Add Parameters to Get Method // Add Parameters to Get Method
get.setQueryString(new NameValuePair[] { get.setQueryString(new NameValuePair[]{
new NameValuePair(PARAM_PATH, mRemoteFilePath), new NameValuePair(PARAM_PATH, mRemoteFilePath),
new NameValuePair(PARAM_RESHARES, String.valueOf(mReshares)), new NameValuePair(PARAM_RESHARES, String.valueOf(mReshares)),
new NameValuePair(PARAM_SUBFILES, String.valueOf(mSubfiles)) new NameValuePair(PARAM_SUBFILES, String.valueOf(mSubfiles))
}); });
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
@ -113,9 +116,13 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation {
result = new RemoteOperationResult(ResultCode.OK); result = new RemoteOperationResult(ResultCode.OK);
ArrayList<Object> sharesObjects = new ArrayList<Object>(); ArrayList<Object> sharesObjects = new ArrayList<Object>();
for (OCShare share: mShares) { for (OCShare share: mShares) {
// Build the link // Build the link
if (share.getToken().length() > 0) { if (( share.getShareLink() == null) &&
share.setShareLink(client.getBaseUri() + ShareUtils.SHARING_LINK_TOKEN + share.getToken()); (share.getToken().length() > 0)) {
String linkToken = ShareUtils.getSharingToken(
client.getOwnCloudVersion());
share.setShareLink(client.getBaseUri() + linkToken +
share.getToken());
} }
sharesObjects.add(share); sharesObjects.add(share);
} }

View File

@ -24,6 +24,8 @@
package com.owncloud.android.lib.resources.shares; package com.owncloud.android.lib.resources.shares;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
/** /**
* Contains Constants for Share Operation * Contains Constants for Share Operation
* *
@ -36,7 +38,18 @@ public class ShareUtils {
// OCS Route // OCS Route
public static final String SHARING_API_PATH ="/ocs/v1.php/apps/files_sharing/api/v1/shares"; public static final String SHARING_API_PATH ="/ocs/v1.php/apps/files_sharing/api/v1/shares";
// String to build the link with the token of a share: server address + "/public.php?service=files&t=" + token // String to build the link with the token of a share:
public static final String SHARING_LINK_TOKEN = "/public.php?service=files&t="; // server address + "/public.php?service=files&t=" + token
public static final String SHARING_LINK_TOKEN_BEFORE_VERSION_8 = "/public.php?service=files&t=";
public static final String SHARING_LINK_TOKEN_AFTER_VERSION_8= "/index.php/s/";
public static String getSharingToken(OwnCloudVersion version){
if (version!= null && version.isAfter8Version()){
return SHARING_LINK_TOKEN_AFTER_VERSION_8;
} else {
return SHARING_LINK_TOKEN_BEFORE_VERSION_8;
}
}
} }

View File

@ -126,7 +126,8 @@ public class ShareXMLParser {
* @throws XmlPullParserException * @throws XmlPullParserException
* @throws IOException * @throws IOException
*/ */
public ArrayList<OCShare> parseXMLResponse(InputStream is) throws XmlPullParserException, IOException { public ArrayList<OCShare> parseXMLResponse(InputStream is) throws XmlPullParserException,
IOException {
try { try {
// XMLPullParser // XMLPullParser
@ -151,7 +152,8 @@ public class ShareXMLParser {
* @throws XmlPullParserException * @throws XmlPullParserException
* @throws IOException * @throws IOException
*/ */
private ArrayList<OCShare> readOCS (XmlPullParser parser) throws XmlPullParserException, IOException { private ArrayList<OCShare> readOCS (XmlPullParser parser) throws XmlPullParserException,
IOException {
ArrayList<OCShare> shares = new ArrayList<OCShare>(); ArrayList<OCShare> shares = new ArrayList<OCShare>();
parser.require(XmlPullParser.START_TAG, ns , NODE_OCS); parser.require(XmlPullParser.START_TAG, ns , NODE_OCS);
while (parser.next() != XmlPullParser.END_TAG) { while (parser.next() != XmlPullParser.END_TAG) {
@ -209,7 +211,8 @@ public class ShareXMLParser {
* @throws XmlPullParserException * @throws XmlPullParserException
* @throws IOException * @throws IOException
*/ */
private ArrayList<OCShare> readData(XmlPullParser parser) throws XmlPullParserException, IOException { private ArrayList<OCShare> readData(XmlPullParser parser) throws XmlPullParserException,
IOException {
ArrayList<OCShare> shares = new ArrayList<OCShare>(); ArrayList<OCShare> shares = new ArrayList<OCShare>();
OCShare share = null; OCShare share = null;
@ -259,7 +262,8 @@ public class ShareXMLParser {
* @throws XmlPullParserException * @throws XmlPullParserException
* @throws IOException * @throws IOException
*/ */
private void readElement(XmlPullParser parser, ArrayList<OCShare> shares) throws XmlPullParserException, IOException { private void readElement(XmlPullParser parser, ArrayList<OCShare> shares)
throws XmlPullParserException, IOException {
parser.require(XmlPullParser.START_TAG, ns, NODE_ELEMENT); parser.require(XmlPullParser.START_TAG, ns, NODE_ELEMENT);
OCShare share = new OCShare(); OCShare share = new OCShare();
@ -273,7 +277,8 @@ public class ShareXMLParser {
String name = parser.getName(); String name = parser.getName();
if (name.equalsIgnoreCase(NODE_ELEMENT)) { if (name.equalsIgnoreCase(NODE_ELEMENT)) {
// patch to work around servers responding with extra <element> surrounding all the shares on the same file before // 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 // https://github.com/owncloud/core/issues/6992 was fixed
readElement(parser, shares); readElement(parser, shares);
@ -327,6 +332,11 @@ public class ShareXMLParser {
} else if (name.equalsIgnoreCase(NODE_SHARE_WITH_DISPLAY_NAME)) { } else if (name.equalsIgnoreCase(NODE_SHARE_WITH_DISPLAY_NAME)) {
share.setSharedWithDisplayName(readNode(parser, NODE_SHARE_WITH_DISPLAY_NAME)); share.setSharedWithDisplayName(readNode(parser, NODE_SHARE_WITH_DISPLAY_NAME));
} else if (name.equalsIgnoreCase(NODE_URL)) {
share.setShareType(ShareType.PUBLIC_LINK);
String value = readNode(parser, NODE_URL);
share.setShareLink(value);
} else { } else {
skip(parser); skip(parser);
} }
@ -344,7 +354,8 @@ public class ShareXMLParser {
} }
private void fixPathForFolder(OCShare share) { private void fixPathForFolder(OCShare share) {
if (share.isFolder() && share.getPath() != null && share.getPath().length() > 0 && !share.getPath().endsWith(FileUtils.PATH_SEPARATOR)) { if (share.isFolder() && share.getPath() != null && share.getPath().length() > 0 &&
!share.getPath().endsWith(FileUtils.PATH_SEPARATOR)) {
share.setPath(share.getPath() + FileUtils.PATH_SEPARATOR); share.setPath(share.getPath() + FileUtils.PATH_SEPARATOR);
} }
} }
@ -357,7 +368,8 @@ public class ShareXMLParser {
* @throws XmlPullParserException * @throws XmlPullParserException
* @throws IOException * @throws IOException
*/ */
private String readNode (XmlPullParser parser, String node) throws XmlPullParserException, IOException{ private String readNode (XmlPullParser parser, String node) throws XmlPullParserException,
IOException{
parser.require(XmlPullParser.START_TAG, ns, node); parser.require(XmlPullParser.START_TAG, ns, node);
String value = readText(parser); String value = readText(parser);
//Log_OC.d(TAG, "node= " + node + ", value= " + value); //Log_OC.d(TAG, "node= " + node + ", value= " + value);

View File

@ -42,6 +42,8 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {
public static final int MINIMUM_VERSION_WITH_FORBIDDEN_CHARS = 0x08010000; // 8.1 public static final int MINIMUM_VERSION_WITH_FORBIDDEN_CHARS = 0x08010000; // 8.1
public static final int MINIMUM_SERVER_VERSION_FOR_REMOTE_THUMBNAILS = 0x07080000; // 7.8.0 public static final int MINIMUM_SERVER_VERSION_FOR_REMOTE_THUMBNAILS = 0x07080000; // 7.8.0
public static final int VERSION_8 = 0x08000000; // 8.0
private static final int MAX_DOTS = 3; private static final int MAX_DOTS = 3;
@ -129,7 +131,13 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {
return (mVersion >= MINIMUM_VERSION_WITH_FORBIDDEN_CHARS); return (mVersion >= MINIMUM_VERSION_WITH_FORBIDDEN_CHARS);
} }
public boolean supportsRemoteThumbnails() { return (mVersion >= MINIMUM_SERVER_VERSION_FOR_REMOTE_THUMBNAILS); } public boolean supportsRemoteThumbnails() {
return (mVersion >= MINIMUM_SERVER_VERSION_FOR_REMOTE_THUMBNAILS);
}
public boolean isAfter8Version(){
return (mVersion >= VERSION_8);
}
} }