mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Merge pull request #163 from owncloud/multiple_public_shares
Support in library for multiple public shares per file
This commit is contained in:
		
						commit
						bac38d13ef
					
				| @ -255,7 +255,7 @@ public class RemoteOperationResult implements Serializable { | ||||
|                 ErrorMessageParser xmlParser = new ErrorMessageParser(); | ||||
|                 try { | ||||
|                     String errorMessage = xmlParser.parseXMLResponse(is); | ||||
|                     if (errorMessage != null && errorMessage != "") { | ||||
|                     if (errorMessage != null && errorMessage.length() > 0) { | ||||
|                         mCode = ResultCode.SPECIFIC_FORBIDDEN; | ||||
|                         mHttpPhrase = errorMessage; | ||||
|                     } | ||||
|  | ||||
| @ -34,6 +34,11 @@ import com.owncloud.android.lib.common.operations.RemoteOperation; | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult; | ||||
| import com.owncloud.android.lib.common.utils.Log_OC; | ||||
| 
 | ||||
| import java.text.DateFormat; | ||||
| import java.text.SimpleDateFormat; | ||||
| import java.util.Calendar; | ||||
| import java.util.Locale; | ||||
| 
 | ||||
| /** | ||||
|  * Creates a new share.  This allows sharing with a user or group or as a link. | ||||
|  */ | ||||
| @ -41,21 +46,46 @@ public class CreateRemoteShareOperation extends RemoteOperation { | ||||
| 
 | ||||
|     private static final String TAG = CreateRemoteShareOperation.class.getSimpleName(); | ||||
| 
 | ||||
|     private static final String PARAM_NAME = "name"; | ||||
|     private static final String PARAM_PASSWORD = "password"; | ||||
|     private static final String PARAM_EXPIRATION_DATE = "expireDate"; | ||||
|     private static final String PARAM_PUBLIC_UPLOAD = "publicUpload"; | ||||
|     private static final String PARAM_PATH = "path"; | ||||
|     private static final String PARAM_SHARE_TYPE = "shareType"; | ||||
|     private static final String PARAM_SHARE_WITH = "shareWith"; | ||||
|     private static final String PARAM_PUBLIC_UPLOAD = "publicUpload"; | ||||
|     private static final String PARAM_PASSWORD = "password"; | ||||
|     private static final String PARAM_PERMISSIONS = "permissions"; | ||||
|     private static final String FORMAT_EXPIRATION_DATE = "yyyy-MM-dd"; | ||||
| 
 | ||||
|     private String mRemoteFilePath; | ||||
|     private ShareType mShareType; | ||||
|     private String mShareWith; | ||||
|     private boolean mPublicUpload; | ||||
|     private String mPassword; | ||||
|     private int mPermissions; | ||||
|     private boolean mGetShareDetails; | ||||
| 
 | ||||
|     /** | ||||
|      * Name to set for the public link | ||||
|      */ | ||||
|     private String mName = ""; | ||||
| 
 | ||||
|     /** | ||||
|      * Password to set for the public link | ||||
|      */ | ||||
|     private String mPassword; | ||||
| 
 | ||||
|     /** | ||||
|      * Expiration date to set for the public link | ||||
|      */ | ||||
|     private long mExpirationDateInMillis = 0; | ||||
| 
 | ||||
|     /** | ||||
|      * Access permissions for the file bound to the share | ||||
|      */ | ||||
|     private int mPermissions; | ||||
| 
 | ||||
|     /** | ||||
|      * Upload permissions for the public link (only folders) | ||||
|      */ | ||||
|     private Boolean mPublicUpload; | ||||
| 
 | ||||
|     /** | ||||
|      * Constructor | ||||
|      * | ||||
| @ -77,12 +107,12 @@ public class CreateRemoteShareOperation extends RemoteOperation { | ||||
|      *                       For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27. | ||||
|      */ | ||||
|     public CreateRemoteShareOperation( | ||||
|         String remoteFilePath, | ||||
|         ShareType shareType, | ||||
|         String shareWith, | ||||
|         boolean publicUpload, | ||||
|         String password, | ||||
|         int permissions | ||||
|             String remoteFilePath, | ||||
|             ShareType shareType, | ||||
|             String shareWith, | ||||
|             boolean publicUpload, | ||||
|             String password, | ||||
|             int permissions | ||||
|     ) { | ||||
| 
 | ||||
|         mRemoteFilePath = remoteFilePath; | ||||
| @ -94,6 +124,59 @@ public class CreateRemoteShareOperation extends RemoteOperation { | ||||
|         mGetShareDetails = false;        // defaults to false for backwards compatibility | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|      * Set name to create in Share resource. Ignored by servers previous to version 10.0.0 | ||||
|      * | ||||
|      * @param name     Name to set to the target share. | ||||
|      *                 Null or empty string result in no value set for the name. | ||||
|      */ | ||||
|     public void setName(String name) { | ||||
|         this.mName = (name == null) ? "" : name; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Set password to create in Share resource. | ||||
|      * | ||||
|      * @param password Password to set to the target share. | ||||
|      *                 Null or empty string result in no value set for the password. | ||||
|      */ | ||||
|     public void setPassword(String password) { | ||||
|         mPassword = password; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|      * Set expiration date to create in Share resource. | ||||
|      * | ||||
|      * @param expirationDateInMillis Expiration date to set to the target share. | ||||
|      *                               Zero or negative value results in no value sent for expiration date. | ||||
|      */ | ||||
|     public void setExpirationDate(long expirationDateInMillis) { | ||||
|         mExpirationDateInMillis = expirationDateInMillis; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|      * Set permissions to create in Share resource. | ||||
|      * | ||||
|      * @param permissions Permissions to set to the target share. | ||||
|      *                    Values <= 0 result in value set  to the permissions. | ||||
|      */ | ||||
|     public void setPermissions(int permissions) { | ||||
|         mPermissions = permissions; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * * Enable upload permissions to create in Share resource. | ||||
|      * * | ||||
|      * * @param publicUpload  Upload permission to set to the target share. | ||||
|      * *                      Null results in no update applied to the upload permission. | ||||
|      */ | ||||
|     public void setPublicUpload(Boolean publicUpload) { | ||||
|         mPublicUpload = publicUpload; | ||||
|     } | ||||
| 
 | ||||
|     public boolean isGettingShareDetails() { | ||||
|         return mGetShareDetails; | ||||
|     } | ||||
| @ -114,11 +197,24 @@ public class CreateRemoteShareOperation extends RemoteOperation { | ||||
|             post = new PostMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); | ||||
| 
 | ||||
|             post.setRequestHeader("Content-Type", | ||||
|                 "application/x-www-form-urlencoded; charset=utf-8"); // necessary for special characters | ||||
|                     "application/x-www-form-urlencoded; charset=utf-8"); // necessary for special characters | ||||
| 
 | ||||
|             post.addParameter(PARAM_PATH, mRemoteFilePath); | ||||
|             post.addParameter(PARAM_SHARE_TYPE, Integer.toString(mShareType.getValue())); | ||||
|             post.addParameter(PARAM_SHARE_WITH, mShareWith); | ||||
| 
 | ||||
|             if (mName.length() > 0) { | ||||
|                 post.addParameter(PARAM_NAME, mName); | ||||
|             } | ||||
| 
 | ||||
|             if (mExpirationDateInMillis > 0) { | ||||
|                 DateFormat dateFormat = new SimpleDateFormat(FORMAT_EXPIRATION_DATE, Locale.getDefault()); | ||||
|                 Calendar expirationDate = Calendar.getInstance(); | ||||
|                 expirationDate.setTimeInMillis(mExpirationDateInMillis); | ||||
|                 String formattedExpirationDate = dateFormat.format(expirationDate.getTime()); | ||||
|                 post.addParameter(PARAM_EXPIRATION_DATE, formattedExpirationDate); | ||||
|             } | ||||
| 
 | ||||
|             if (mPublicUpload) { | ||||
|                 post.addParameter(PARAM_PUBLIC_UPLOAD, Boolean.toString(true)); | ||||
|             } | ||||
| @ -137,7 +233,7 @@ public class CreateRemoteShareOperation extends RemoteOperation { | ||||
|                 String response = post.getResponseBodyAsString(); | ||||
| 
 | ||||
|                 ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser( | ||||
|                     new ShareXMLParser() | ||||
|                         new ShareXMLParser() | ||||
|                 ); | ||||
|                 parser.setOneOrMoreSharesRequired(true); | ||||
|                 parser.setOwnCloudVersion(client.getOwnCloudVersion()); | ||||
| @ -148,7 +244,7 @@ public class CreateRemoteShareOperation extends RemoteOperation { | ||||
|                     // retrieve more info - POST only returns the index of the new share | ||||
|                     OCShare emptyShare = (OCShare) result.getData().get(0); | ||||
|                     GetRemoteShareOperation getInfo = new GetRemoteShareOperation( | ||||
|                         emptyShare.getRemoteId() | ||||
|                             emptyShare.getRemoteId() | ||||
|                     ); | ||||
|                     result = getInfo.execute(client); | ||||
|                 } | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| /* ownCloud Android Library is available under MIT license | ||||
|  *   Copyright (C) 2016 ownCloud GmbH. | ||||
|  *   Copyright (C) 2017 ownCloud GmbH. | ||||
|  *    | ||||
|  *   Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
|  *   of this software and associated documentation files (the "Software"), to deal | ||||
| @ -24,6 +24,7 @@ | ||||
| 
 | ||||
| package com.owncloud.android.lib.resources.shares; | ||||
| 
 | ||||
| import java.io.File; | ||||
| import java.io.Serializable; | ||||
| 
 | ||||
| import android.os.Parcel; | ||||
| @ -35,9 +36,9 @@ import com.owncloud.android.lib.resources.files.FileUtils; | ||||
| 
 | ||||
| /** | ||||
|  * Contains the data of a Share from the Share API | ||||
|  *  | ||||
|  * @author masensio | ||||
|  * | ||||
|  * @author masensio | ||||
|  * @author David A. Velasco | ||||
|  */ | ||||
| public class OCShare implements Parcelable, Serializable { | ||||
| 
 | ||||
| @ -56,33 +57,27 @@ public class OCShare implements Parcelable, Serializable { | ||||
|     public static final int SHARE_PERMISSION_FLAG = 16; | ||||
|     public static final int MAXIMUM_PERMISSIONS_FOR_FILE = | ||||
|         READ_PERMISSION_FLAG + | ||||
|         UPDATE_PERMISSION_FLAG + | ||||
|         SHARE_PERMISSION_FLAG | ||||
|     ; | ||||
|             UPDATE_PERMISSION_FLAG + | ||||
|             SHARE_PERMISSION_FLAG; | ||||
|     public static final int MAXIMUM_PERMISSIONS_FOR_FOLDER = | ||||
|         MAXIMUM_PERMISSIONS_FOR_FILE + | ||||
|         CREATE_PERMISSION_FLAG + | ||||
|         DELETE_PERMISSION_FLAG | ||||
|     ; | ||||
|             CREATE_PERMISSION_FLAG + | ||||
|             DELETE_PERMISSION_FLAG; | ||||
|     public static final int FEDERATED_PERMISSIONS_FOR_FILE_UP_TO_OC9 = | ||||
|         READ_PERMISSION_FLAG + | ||||
|         UPDATE_PERMISSION_FLAG | ||||
|     ; | ||||
|             UPDATE_PERMISSION_FLAG; | ||||
|     public static final int FEDERATED_PERMISSIONS_FOR_FILE_AFTER_OC9 = | ||||
|         READ_PERMISSION_FLAG + | ||||
|         UPDATE_PERMISSION_FLAG + | ||||
|         SHARE_PERMISSION_FLAG | ||||
|     ; | ||||
|             UPDATE_PERMISSION_FLAG + | ||||
|             SHARE_PERMISSION_FLAG; | ||||
|     public static final int FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 = | ||||
|         READ_PERMISSION_FLAG + | ||||
|         UPDATE_PERMISSION_FLAG + | ||||
|         CREATE_PERMISSION_FLAG + | ||||
|         DELETE_PERMISSION_FLAG | ||||
|     ; | ||||
|             UPDATE_PERMISSION_FLAG + | ||||
|             CREATE_PERMISSION_FLAG + | ||||
|             DELETE_PERMISSION_FLAG; | ||||
|     public static final int FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9 = | ||||
|         FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 + | ||||
|         SHARE_PERMISSION_FLAG | ||||
|     ; | ||||
|             SHARE_PERMISSION_FLAG; | ||||
| 
 | ||||
|     private long mId; | ||||
|     private long mFileSource; | ||||
| @ -95,33 +90,34 @@ public class OCShare implements Parcelable, Serializable { | ||||
|     private long mExpirationDate; | ||||
|     private String mToken; | ||||
|     private String mSharedWithDisplayName; | ||||
|     private String mName; | ||||
|     private boolean mIsFolder; | ||||
|     private long mUserId; | ||||
|     private long mRemoteId; | ||||
|     private String mShareLink; | ||||
|      | ||||
| 
 | ||||
|     public OCShare() { | ||||
|     	super(); | ||||
|     	resetData(); | ||||
|         super(); | ||||
|         resetData(); | ||||
|     } | ||||
|      | ||||
| 	public OCShare(String path) { | ||||
| 		resetData(); | ||||
| 
 | ||||
|     public OCShare(String path) { | ||||
|         resetData(); | ||||
|         if (path == null || path.length() <= 0 || !path.startsWith(FileUtils.PATH_SEPARATOR)) { | ||||
|             Log_OC.e(TAG, "Trying to create a OCShare with a non valid path"); | ||||
|             throw new IllegalArgumentException("Trying to create a OCShare with a non valid path: " + path); | ||||
|         } | ||||
|         mPath = path; | ||||
| 	} | ||||
|     } | ||||
| 
 | ||||
| 	/** | ||||
|     /** | ||||
|      * Used internally. Reset all file properties | ||||
|      */ | ||||
|     private void resetData() { | ||||
|     	mId = -1; | ||||
|         mId = -1; | ||||
|         mFileSource = 0; | ||||
|         mItemSource = 0; | ||||
|         mShareType = ShareType.NO_SHARED;  | ||||
|         mShareType = ShareType.NO_SHARED; | ||||
|         mShareWith = ""; | ||||
|         mPath = ""; | ||||
|         mPermissions = -1; | ||||
| @ -133,18 +129,19 @@ public class OCShare implements Parcelable, Serializable { | ||||
|         mUserId = -1; | ||||
|         mRemoteId = -1; | ||||
|         mShareLink = ""; | ||||
|     }	 | ||||
|      | ||||
|         mName = ""; | ||||
|     } | ||||
| 
 | ||||
|     /// Getters and Setters | ||||
|      | ||||
| 
 | ||||
|     public long getId() { | ||||
|         return mId; | ||||
|     } | ||||
|      | ||||
|     public void setId(long id){ | ||||
| 
 | ||||
|     public void setId(long id) { | ||||
|         mId = id; | ||||
|     } | ||||
|      | ||||
| 
 | ||||
|     public long getFileSource() { | ||||
|         return mFileSource; | ||||
|     } | ||||
| @ -225,6 +222,14 @@ public class OCShare implements Parcelable, Serializable { | ||||
|         this.mSharedWithDisplayName = (sharedWithDisplayName != null) ? sharedWithDisplayName : ""; | ||||
|     } | ||||
| 
 | ||||
|     public String getName() { | ||||
|         return mName; | ||||
|     } | ||||
| 
 | ||||
|     public void setName(String name) { | ||||
|         mName = (name != null) ? name : ""; | ||||
|     } | ||||
| 
 | ||||
|     public boolean isFolder() { | ||||
|         return mIsFolder; | ||||
|     } | ||||
| @ -248,11 +253,11 @@ public class OCShare implements Parcelable, Serializable { | ||||
|     public void setIdRemoteShared(long remoteId) { | ||||
|         this.mRemoteId = remoteId; | ||||
|     } | ||||
|      | ||||
| 
 | ||||
|     public String getShareLink() { | ||||
|     	return this.mShareLink; | ||||
|         return this.mShareLink; | ||||
|     } | ||||
|      | ||||
| 
 | ||||
|     public void setShareLink(String shareLink) { | ||||
|         this.mShareLink = (shareLink != null) ? shareLink : ""; | ||||
|     } | ||||
| @ -260,8 +265,8 @@ public class OCShare implements Parcelable, Serializable { | ||||
|     public boolean isPasswordProtected() { | ||||
|         return ShareType.PUBLIC_LINK.equals(mShareType) && mShareWith.length() > 0; | ||||
|     } | ||||
|      | ||||
|     /**  | ||||
| 
 | ||||
|     /** | ||||
|      * Parcelable Methods | ||||
|      */ | ||||
|     public static final Parcelable.Creator<OCShare> CREATOR = new Parcelable.Creator<OCShare>() { | ||||
| @ -275,19 +280,19 @@ public class OCShare implements Parcelable, Serializable { | ||||
|             return new OCShare[size]; | ||||
|         } | ||||
|     }; | ||||
|      | ||||
| 
 | ||||
|     /** | ||||
|      * Reconstruct from parcel | ||||
|      *  | ||||
|      * | ||||
|      * @param source The source parcel | ||||
|      */     | ||||
|      */ | ||||
|     protected OCShare(Parcel source) { | ||||
|     	readFromParcel(source); | ||||
|         readFromParcel(source); | ||||
|     } | ||||
|      | ||||
| 
 | ||||
|     public void readFromParcel(Parcel source) { | ||||
|         mId = source.readLong(); | ||||
|     	 | ||||
| 
 | ||||
|         mFileSource = source.readLong(); | ||||
|         mItemSource = source.readLong(); | ||||
|         try { | ||||
| @ -306,18 +311,19 @@ public class OCShare implements Parcelable, Serializable { | ||||
|         mUserId = source.readLong(); | ||||
|         mRemoteId = source.readLong(); | ||||
|         mShareLink = source.readString(); | ||||
|         mName = source.readString(); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     @Override | ||||
|     public int describeContents() { | ||||
|         return this.hashCode(); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 	@Override | ||||
| 	public int describeContents() { | ||||
| 		return this.hashCode(); | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
|     @Override | ||||
|     public void writeToParcel(Parcel dest, int flags) { | ||||
|     	dest.writeLong(mId); | ||||
|         dest.writeLong(mId); | ||||
|         dest.writeLong(mFileSource); | ||||
|         dest.writeLong(mItemSource); | ||||
|         dest.writeString((mShareType == null) ? "" : mShareType.name()); | ||||
| @ -332,6 +338,7 @@ public class OCShare implements Parcelable, Serializable { | ||||
|         dest.writeLong(mUserId); | ||||
|         dest.writeLong(mRemoteId); | ||||
|         dest.writeString(mShareLink); | ||||
|         dest.writeString(mName); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -88,7 +88,8 @@ public class ShareToRemoteOperationResultParser { | ||||
|                     if (shares != null) { | ||||
|                         for (OCShare share : shares) { | ||||
|                             resultData.add(share); | ||||
|                             // build the share link if not in the response (only received when the share is created) | ||||
|                             // build the share link if not in the response | ||||
|                             // (needed for OC servers < 9.0.0, see ShareXMLParser.java#line256) | ||||
|                             if (share.getShareType() == ShareType.PUBLIC_LINK && | ||||
|                                     (share.getShareLink() == null || | ||||
|                                             share.getShareLink().length() <= 0) && | ||||
| @ -98,7 +99,7 @@ public class ShareToRemoteOperationResultParser { | ||||
|                                     String sharingLinkPath = ShareUtils.getSharingLinkPath(mOwnCloudVersion); | ||||
|                                     share.setShareLink(mServerBaseUri + sharingLinkPath + share.getToken()); | ||||
|                                 } else { | ||||
|                                     Log_OC.e(TAG, "Couldn't build link for public share"); | ||||
|                                     Log_OC.e(TAG, "Couldn't build link for public share :("); | ||||
|                                 } | ||||
|                             } | ||||
|                         } | ||||
|  | ||||
| @ -76,6 +76,7 @@ public class ShareXMLParser { | ||||
| 	private static final String NODE_STORAGE = "storage"; | ||||
| 	private static final String NODE_MAIL_SEND = "mail_send"; | ||||
| 	private static final String NODE_SHARE_WITH_DISPLAY_NAME = "share_with_displayname"; | ||||
|     private static final String NODE_NAME = "name"; | ||||
| 	 | ||||
| 	private static final String NODE_URL = "url"; | ||||
| 
 | ||||
| @ -252,6 +253,9 @@ public class ShareXMLParser { | ||||
| 				share.setIdRemoteShared(Integer.parseInt(value)); | ||||
| 
 | ||||
| 			} else if (name.equalsIgnoreCase(NODE_URL)) { | ||||
| 				// NOTE: this field is received in all the public shares from OC 9.0.0 | ||||
| 				// in previous versions, it's received in the result of POST requests, but not | ||||
| 				// in GET requests | ||||
| 				share.setShareType(ShareType.PUBLIC_LINK); | ||||
| 				String value = readNode(parser, NODE_URL); | ||||
| 				share.setShareLink(value); | ||||
| @ -356,7 +360,10 @@ public class ShareXMLParser { | ||||
| 				String value = readNode(parser, NODE_URL); | ||||
| 				share.setShareLink(value); | ||||
| 
 | ||||
| 			} else { | ||||
|             } else if (name.equalsIgnoreCase(NODE_NAME)) { | ||||
|                 share.setName(readNode(parser, NODE_NAME)); | ||||
| 
 | ||||
|             } else { | ||||
| 				skip(parser); | ||||
| 			}  | ||||
| 		}		 | ||||
|  | ||||
| @ -42,6 +42,7 @@ import java.text.SimpleDateFormat; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Calendar; | ||||
| import java.util.List; | ||||
| import java.util.Locale; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
| @ -54,6 +55,7 @@ public class UpdateRemoteShareOperation extends RemoteOperation { | ||||
| 
 | ||||
|     private static final String TAG = GetRemoteShareOperation.class.getSimpleName(); | ||||
| 
 | ||||
|     private static final String PARAM_NAME = "name"; | ||||
|     private static final String PARAM_PASSWORD = "password"; | ||||
|     private static final String PARAM_EXPIRATION_DATE = "expireDate"; | ||||
|     private static final String PARAM_PERMISSIONS = "permissions"; | ||||
| @ -87,6 +89,7 @@ public class UpdateRemoteShareOperation extends RemoteOperation { | ||||
|      * Upload permissions for the public link (only folders) | ||||
|      */ | ||||
|     private Boolean mPublicUpload; | ||||
|     private String mName; | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
| @ -102,6 +105,17 @@ public class UpdateRemoteShareOperation extends RemoteOperation { | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|      * Set name to update in Share resource. Ignored by servers previous to version 10.0.0 | ||||
|      * | ||||
|      * @param name     Name to set to the target share. | ||||
|      *                 Empty string clears the current name. | ||||
|      *                 Null results in no update applied to the name. | ||||
|      */ | ||||
|     public void setName(String name) { | ||||
|         this.mName = name; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Set password to update in Share resource. | ||||
|      * | ||||
| @ -150,38 +164,42 @@ public class UpdateRemoteShareOperation extends RemoteOperation { | ||||
|     @Override | ||||
|     protected RemoteOperationResult run(OwnCloudClient client) { | ||||
|         RemoteOperationResult result = null; | ||||
|         int status = -1; | ||||
|         int status; | ||||
| 
 | ||||
|         /// prepare array of parameters to update | ||||
|         List<Pair<String, String>> parametersToUpdate = new ArrayList<Pair<String, String>>(); | ||||
|         List<Pair<String, String>> parametersToUpdate = new ArrayList<>(); | ||||
|         if (mName != null) { | ||||
|             parametersToUpdate.add(new Pair<>(PARAM_NAME, mName)); | ||||
|         } | ||||
|          | ||||
|         if (mPassword != null) { | ||||
|             parametersToUpdate.add(new Pair<String, String>(PARAM_PASSWORD, mPassword)); | ||||
|             parametersToUpdate.add(new Pair<>(PARAM_PASSWORD, mPassword)); | ||||
|         } | ||||
|         if (mExpirationDateInMillis < 0) { | ||||
|             // clear expiration date | ||||
|             parametersToUpdate.add(new Pair(PARAM_EXPIRATION_DATE, "")); | ||||
|             parametersToUpdate.add(new Pair<>(PARAM_EXPIRATION_DATE, "")); | ||||
| 
 | ||||
|         } else if (mExpirationDateInMillis > 0) { | ||||
|             // set expiration date | ||||
|             DateFormat dateFormat = new SimpleDateFormat(FORMAT_EXPIRATION_DATE); | ||||
|             DateFormat dateFormat = new SimpleDateFormat(FORMAT_EXPIRATION_DATE, Locale.GERMAN); | ||||
|             Calendar expirationDate = Calendar.getInstance(); | ||||
|             expirationDate.setTimeInMillis(mExpirationDateInMillis); | ||||
|             String formattedExpirationDate = dateFormat.format(expirationDate.getTime()); | ||||
|             parametersToUpdate.add(new Pair(PARAM_EXPIRATION_DATE, formattedExpirationDate)); | ||||
|             parametersToUpdate.add(new Pair<>(PARAM_EXPIRATION_DATE, formattedExpirationDate)); | ||||
| 
 | ||||
|         } // else, ignore - no update | ||||
|         if (mPermissions > 0) { | ||||
|             // set permissions | ||||
|             parametersToUpdate.add(new Pair(PARAM_PERMISSIONS, Integer.toString(mPermissions))); | ||||
|             parametersToUpdate.add(new Pair<>(PARAM_PERMISSIONS, Integer.toString(mPermissions))); | ||||
|         } | ||||
| 
 | ||||
|         if (mPublicUpload != null) { | ||||
|             parametersToUpdate.add(new Pair(PARAM_PUBLIC_UPLOAD, Boolean.toString(mPublicUpload))); | ||||
|             parametersToUpdate.add(new Pair<>(PARAM_PUBLIC_UPLOAD, Boolean.toString(mPublicUpload))); | ||||
|         } | ||||
| 
 | ||||
|         /// perform required PUT requests | ||||
|         PutMethod put = null; | ||||
|         String uriString = null; | ||||
|         String uriString; | ||||
| 
 | ||||
|         try { | ||||
|             Uri requestUri = client.getBaseUri(); | ||||
| @ -218,7 +236,11 @@ public class UpdateRemoteShareOperation extends RemoteOperation { | ||||
|                 } else { | ||||
|                     result = new RemoteOperationResult(false, put); | ||||
|                 } | ||||
|                 if (!result.isSuccess()) { | ||||
|                 if (!result.isSuccess() && | ||||
|                     !PARAM_NAME.equals(parameter.first) | ||||
|                         // fail in "name" parameter will be ignored; requires OCX, will fail | ||||
|                         // fails in previous versions | ||||
|                     ) { | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
| @ -237,5 +259,4 @@ public class UpdateRemoteShareOperation extends RemoteOperation { | ||||
|         } | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -94,6 +94,7 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation { | ||||
|     private static final String PROPERTY_DAYS = "days"; | ||||
|     private static final String PROPERTY_SEND_MAIL = "send_mail"; | ||||
|     private static final String PROPERTY_UPLOAD = "upload"; | ||||
|     private static final String PROPERTY_MULTIPLE = "multiple"; | ||||
|     private static final String PROPERTY_RESHARING = "resharing"; | ||||
|     private static final String PROPERTY_OUTGOING = "outgoing"; | ||||
|     private static final String PROPERTY_INCOMING = "incoming"; | ||||
| @ -205,6 +206,10 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation { | ||||
|                                     capability.setFilesSharingPublicUpload(CapabilityBooleanType.fromBooleanValue( | ||||
|                                             respPublic.getBoolean(PROPERTY_UPLOAD))); | ||||
|                                 } | ||||
|                                 if (respPublic.has(PROPERTY_MULTIPLE)) { | ||||
|                                     capability.setFilesSharingPublicMultiple(CapabilityBooleanType.fromBooleanValue( | ||||
|                                             respPublic.getBoolean(PROPERTY_MULTIPLE))); | ||||
|                                 } | ||||
|                             } | ||||
| 
 | ||||
|                             if (respFilesSharing.has(NODE_USER)) { | ||||
|  | ||||
| @ -54,6 +54,7 @@ public class OCCapability { | ||||
|     private CapabilityBooleanType mFilesSharingPublicExpireDateEnforced; | ||||
|     private CapabilityBooleanType mFilesSharingPublicSendMail; | ||||
|     private CapabilityBooleanType mFilesSharingPublicUpload; | ||||
|     private CapabilityBooleanType mFilesSharingPublicMultiple; | ||||
| 
 | ||||
|     private CapabilityBooleanType mFilesSharingUserSendMail; | ||||
| 
 | ||||
| @ -67,7 +68,7 @@ public class OCCapability { | ||||
|     private CapabilityBooleanType mFilesUndelete; | ||||
|     private CapabilityBooleanType mFilesVersioning; | ||||
| 
 | ||||
|     public OCCapability(){ | ||||
|     public OCCapability() { | ||||
|         mId = 0; | ||||
|         mAccountName = ""; | ||||
| 
 | ||||
| @ -87,6 +88,7 @@ public class OCCapability { | ||||
|         mFilesSharingPublicExpireDateEnforced = CapabilityBooleanType.UNKNOWN; | ||||
|         mFilesSharingPublicSendMail = CapabilityBooleanType.UNKNOWN; | ||||
|         mFilesSharingPublicUpload = CapabilityBooleanType.UNKNOWN; | ||||
|         mFilesSharingPublicMultiple = CapabilityBooleanType.UNKNOWN; | ||||
|         mFilesSharingUserSendMail = CapabilityBooleanType.UNKNOWN; | ||||
|         mFilesSharingResharing = CapabilityBooleanType.UNKNOWN; | ||||
|         mFilesSharingFederationOutgoing = CapabilityBooleanType.UNKNOWN; | ||||
| @ -229,6 +231,14 @@ public class OCCapability { | ||||
|         this.mFilesSharingPublicUpload = filesSharingPublicUpload; | ||||
|     } | ||||
| 
 | ||||
|     public CapabilityBooleanType getFilesSharingPublicMultiple() { | ||||
|         return mFilesSharingPublicMultiple; | ||||
|     } | ||||
| 
 | ||||
|     public void setFilesSharingPublicMultiple(CapabilityBooleanType filesSharingPublicMultiple) { | ||||
|         this.mFilesSharingPublicMultiple = filesSharingPublicMultiple; | ||||
|     } | ||||
| 
 | ||||
|     public CapabilityBooleanType getFilesSharingUserSendMail() { | ||||
|         return mFilesSharingUserSendMail; | ||||
|     } | ||||
| @ -244,7 +254,7 @@ public class OCCapability { | ||||
|     public void setFilesSharingResharing(CapabilityBooleanType filesSharingResharing) { | ||||
|         this.mFilesSharingResharing = filesSharingResharing; | ||||
|     } | ||||
|      | ||||
| 
 | ||||
|     public CapabilityBooleanType getFilesSharingFederationOutgoing() { | ||||
|         return mFilesSharingFederationOutgoing; | ||||
|     } | ||||
| @ -284,8 +294,4 @@ public class OCCapability { | ||||
|     public void setFilesVersioning(CapabilityBooleanType filesVersioning) { | ||||
|         this.mFilesVersioning = filesVersioning; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -48,6 +48,8 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> { | ||||
|     private static final int MINIMUM_VERSION_WITH_SESSION_MONITORING_WORKING_IN_PREEMPTIVE_MODE = 0x09010301; | ||||
|     // 9.1.3.1, final 9.1.3: https://github.com/owncloud/core/commit/f9a867b70c217463289a741d4d26079eb2a80dfd | ||||
| 
 | ||||
|     private static final int MINIMUM_VERSION_WITH_MULTIPLE_PUBLIC_SHARING = 0xA000000; | ||||
| 
 | ||||
|     private static final String INVALID_ZERO_VERSION = "0.0.0"; | ||||
| 
 | ||||
|     private static final int MAX_DOTS = 3; | ||||
| @ -193,4 +195,8 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> { | ||||
|                 (mVersion >= MINIMUM_VERSION_WITH_SESSION_MONITORING_WORKING_IN_PREEMPTIVE_MODE) | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
|     public boolean isMultiplePublicSharingSupported() { | ||||
|         return (mVersion >= MINIMUM_VERSION_WITH_MULTIPLE_PUBLIC_SHARING); | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user