mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Apply code review changes
This commit is contained in:
parent
261e7a762d
commit
af6b18e042
@ -68,90 +68,27 @@ class CreateRemoteShareOperation
|
|||||||
* For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27.
|
* For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27.
|
||||||
*/
|
*/
|
||||||
(
|
(
|
||||||
private val mRemoteFilePath: String,
|
private val remoteFilePath: String,
|
||||||
private val mShareType: ShareType,
|
private val shareType: ShareType,
|
||||||
private val mShareWith: String,
|
private val shareWith: String,
|
||||||
/**
|
var publicUpload: Boolean?, // Upload permissions for the public link (only folders)
|
||||||
* Upload permissions for the public link (only folders)
|
var password: String?, // Password to set for the public link
|
||||||
*/
|
var permissions: Int // Access permissions for the file bound to the share
|
||||||
private var mPublicUpload: Boolean?,
|
|
||||||
/**
|
|
||||||
* Password to set for the public link
|
|
||||||
*/
|
|
||||||
private var mPassword: String?,
|
|
||||||
/**
|
|
||||||
* Access permissions for the file bound to the share
|
|
||||||
*/
|
|
||||||
private var mPermissions: Int
|
|
||||||
) : RemoteOperation<ShareParserResult>() {
|
) : RemoteOperation<ShareParserResult>() {
|
||||||
private var mGetShareDetails: Boolean = false
|
var getShareDetails: Boolean = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name to set for the public link
|
* Name to set for the public link
|
||||||
*/
|
*/
|
||||||
private var mName = ""
|
var name = ""
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expiration date to set for the public link
|
* Expiration date to set for the public link
|
||||||
*/
|
*/
|
||||||
private var mExpirationDateInMillis: Long = 0
|
var expirationDateInMillis: Long = INITIAL_EXPIRATION_DATE_IN_MILLIS
|
||||||
|
|
||||||
init {
|
init {
|
||||||
mGetShareDetails = false // defaults to false for backwards compatibility
|
getShareDetails = 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.
|
|
||||||
*/
|
|
||||||
fun setName(name: String?) {
|
|
||||||
this.mName = 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.
|
|
||||||
*/
|
|
||||||
fun setPassword(password: String) {
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
fun setExpirationDate(expirationDateInMillis: Long) {
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
fun setPermissions(permissions: Int) {
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
fun setPublicUpload(publicUpload: Boolean?) {
|
|
||||||
mPublicUpload = publicUpload
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setGetShareDetails(set: Boolean) {
|
|
||||||
mGetShareDetails = set
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareParserResult> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareParserResult> {
|
||||||
@ -159,30 +96,30 @@ class CreateRemoteShareOperation
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
val formBodyBuilder = FormBody.Builder()
|
val formBodyBuilder = FormBody.Builder()
|
||||||
.add(PARAM_PATH, mRemoteFilePath)
|
.add(PARAM_PATH, remoteFilePath)
|
||||||
.add(PARAM_SHARE_TYPE, Integer.toString(mShareType.value))
|
.add(PARAM_SHARE_TYPE, Integer.toString(shareType.value))
|
||||||
.add(PARAM_SHARE_WITH, mShareWith)
|
.add(PARAM_SHARE_WITH, shareWith)
|
||||||
|
|
||||||
if (mName.length > 0) {
|
if (name.isNotEmpty()) {
|
||||||
formBodyBuilder.add(PARAM_NAME, mName)
|
formBodyBuilder.add(PARAM_NAME, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mExpirationDateInMillis > 0) {
|
if (expirationDateInMillis > INITIAL_EXPIRATION_DATE_IN_MILLIS) {
|
||||||
val dateFormat = SimpleDateFormat(FORMAT_EXPIRATION_DATE, Locale.getDefault())
|
val dateFormat = SimpleDateFormat(FORMAT_EXPIRATION_DATE, Locale.getDefault())
|
||||||
val expirationDate = Calendar.getInstance()
|
val expirationDate = Calendar.getInstance()
|
||||||
expirationDate.timeInMillis = mExpirationDateInMillis
|
expirationDate.timeInMillis = expirationDateInMillis
|
||||||
val formattedExpirationDate = dateFormat.format(expirationDate.time)
|
val formattedExpirationDate = dateFormat.format(expirationDate.time)
|
||||||
formBodyBuilder.add(PARAM_EXPIRATION_DATE, formattedExpirationDate)
|
formBodyBuilder.add(PARAM_EXPIRATION_DATE, formattedExpirationDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mPublicUpload!!) {
|
if (publicUpload == true) {
|
||||||
formBodyBuilder.add(PARAM_PUBLIC_UPLOAD, java.lang.Boolean.toString(true))
|
formBodyBuilder.add(PARAM_PUBLIC_UPLOAD, publicUpload.toString())
|
||||||
}
|
}
|
||||||
if (mPassword != null && mPassword!!.length > 0) {
|
if (!password.isNullOrEmpty()) {
|
||||||
formBodyBuilder.add(PARAM_PASSWORD, mPassword!!)
|
formBodyBuilder.add(PARAM_PASSWORD, password!!)
|
||||||
}
|
}
|
||||||
if (RemoteShare.DEFAULT_PERMISSION != mPermissions) {
|
if (RemoteShare.DEFAULT_PERMISSION != permissions) {
|
||||||
formBodyBuilder.add(PARAM_PERMISSIONS, Integer.toString(mPermissions))
|
formBodyBuilder.add(PARAM_PERMISSIONS, Integer.toString(permissions))
|
||||||
}
|
}
|
||||||
|
|
||||||
val requestUri = client.baseUri
|
val requestUri = client.baseUri
|
||||||
@ -203,12 +140,12 @@ class CreateRemoteShareOperation
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (isSuccess(status)) {
|
if (isSuccess(status)) {
|
||||||
parser.setOneOrMoreSharesRequired(true)
|
parser.oneOrMoreSharesRequired = true
|
||||||
parser.setOwnCloudVersion(client.ownCloudVersion)
|
parser.ownCloudVersion = client.ownCloudVersion
|
||||||
parser.setServerBaseUri(client.baseUri)
|
parser.serverBaseUri = client.baseUri
|
||||||
result = parser.parse(postMethod.responseBodyAsString)
|
result = parser.parse(postMethod.responseBodyAsString)
|
||||||
|
|
||||||
if (result.isSuccess && mGetShareDetails) {
|
if (result.isSuccess && getShareDetails) {
|
||||||
|
|
||||||
// TODO Use executeHttpMethod
|
// TODO Use executeHttpMethod
|
||||||
// retrieve more info - POST only returns the index of the new share
|
// retrieve more info - POST only returns the index of the new share
|
||||||
@ -248,5 +185,7 @@ class CreateRemoteShareOperation
|
|||||||
private val PARAM_SHARE_WITH = "shareWith"
|
private val PARAM_SHARE_WITH = "shareWith"
|
||||||
private val PARAM_PERMISSIONS = "permissions"
|
private val PARAM_PERMISSIONS = "permissions"
|
||||||
private val FORMAT_EXPIRATION_DATE = "yyyy-MM-dd"
|
private val FORMAT_EXPIRATION_DATE = "yyyy-MM-dd"
|
||||||
|
|
||||||
|
const val INITIAL_EXPIRATION_DATE_IN_MILLIS : Long = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -38,64 +38,26 @@ import java.io.Serializable
|
|||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
class RemoteShare : Parcelable, Serializable {
|
class RemoteShare : Parcelable, Serializable {
|
||||||
|
var shareWith: String = ""
|
||||||
/// Getters and Setters
|
var path: String = ""
|
||||||
|
var token: String = ""
|
||||||
|
var sharedWithDisplayName: String = ""
|
||||||
|
var sharedWithAdditionalInfo: String = ""
|
||||||
|
var name: String = ""
|
||||||
|
var shareLink: String = ""
|
||||||
var fileSource: Long = 0
|
var fileSource: Long = 0
|
||||||
var itemSource: Long = 0
|
var itemSource: Long = 0
|
||||||
var shareType: ShareType? = null
|
var shareType: ShareType? = null
|
||||||
private var mShareWith: String? = null
|
|
||||||
private var mPath: String? = null
|
|
||||||
var permissions: Int = 0
|
var permissions: Int = 0
|
||||||
var sharedDate: Long = 0
|
var sharedDate: Long = 0
|
||||||
var expirationDate: Long = 0
|
var expirationDate: Long = 0
|
||||||
private var mToken: String? = null
|
|
||||||
private var mSharedWithDisplayName: String? = null
|
|
||||||
var sharedWithAdditionalInfo: String? = null
|
|
||||||
private var mName: String? = null
|
|
||||||
var isFolder: Boolean = false
|
var isFolder: Boolean = false
|
||||||
var userId: Long = 0
|
var userId: Long = 0
|
||||||
var remoteId: Long = 0
|
var remoteId: Long = 0
|
||||||
private set
|
private set
|
||||||
private var mShareLink: String? = null
|
|
||||||
|
|
||||||
var shareWith: String?
|
|
||||||
get() = mShareWith
|
|
||||||
set(shareWith) {
|
|
||||||
this.mShareWith = shareWith ?: ""
|
|
||||||
}
|
|
||||||
|
|
||||||
var path: String?
|
|
||||||
get() = mPath
|
|
||||||
set(path) {
|
|
||||||
this.mPath = path ?: ""
|
|
||||||
}
|
|
||||||
|
|
||||||
var token: String?
|
|
||||||
get() = mToken
|
|
||||||
set(token) {
|
|
||||||
this.mToken = token ?: ""
|
|
||||||
}
|
|
||||||
|
|
||||||
var sharedWithDisplayName: String?
|
|
||||||
get() = mSharedWithDisplayName
|
|
||||||
set(sharedWithDisplayName) {
|
|
||||||
this.mSharedWithDisplayName = sharedWithDisplayName ?: ""
|
|
||||||
}
|
|
||||||
|
|
||||||
var name: String?
|
|
||||||
get() = mName
|
|
||||||
set(name) {
|
|
||||||
mName = name ?: ""
|
|
||||||
}
|
|
||||||
|
|
||||||
var shareLink: String?
|
|
||||||
get() = this.mShareLink
|
|
||||||
set(shareLink) {
|
|
||||||
this.mShareLink = shareLink ?: ""
|
|
||||||
}
|
|
||||||
|
|
||||||
val isPasswordProtected: Boolean
|
val isPasswordProtected: Boolean
|
||||||
get() = ShareType.PUBLIC_LINK == shareType && mShareWith!!.length > 0
|
get() = ShareType.PUBLIC_LINK == shareType && shareWith.isNotEmpty()
|
||||||
|
|
||||||
constructor() : super() {
|
constructor() : super() {
|
||||||
resetData()
|
resetData()
|
||||||
@ -103,33 +65,34 @@ class RemoteShare : Parcelable, Serializable {
|
|||||||
|
|
||||||
constructor(path: String?) {
|
constructor(path: String?) {
|
||||||
resetData()
|
resetData()
|
||||||
if (path == null || path.length <= 0 || !path.startsWith(FileUtils.PATH_SEPARATOR)) {
|
if (path == null || path.isEmpty() || !path.startsWith(FileUtils.PATH_SEPARATOR)) {
|
||||||
Log_OC.e(TAG, "Trying to create a RemoteShare with a non valid path")
|
Log_OC.e(TAG, "Trying to create a RemoteShare with a non valid path")
|
||||||
throw IllegalArgumentException("Trying to create a RemoteShare with a non valid path: " + path!!)
|
throw IllegalArgumentException("Trying to create a RemoteShare with a non valid path: " + path!!)
|
||||||
}
|
}
|
||||||
mPath = path
|
this.path = path
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used internally. Reset all file properties
|
* Used internally. Reset all file properties
|
||||||
*/
|
*/
|
||||||
private fun resetData() {
|
private fun resetData() {
|
||||||
|
shareWith = ""
|
||||||
|
path = ""
|
||||||
|
token = ""
|
||||||
|
sharedWithDisplayName = ""
|
||||||
|
sharedWithAdditionalInfo = ""
|
||||||
|
name = ""
|
||||||
|
shareLink = ""
|
||||||
fileSource = 0
|
fileSource = 0
|
||||||
itemSource = 0
|
itemSource = 0
|
||||||
shareType = ShareType.NO_SHARED
|
shareType = ShareType.NO_SHARED
|
||||||
mShareWith = ""
|
permissions = DEFAULT_PERMISSION
|
||||||
mPath = ""
|
|
||||||
permissions = -1
|
|
||||||
sharedDate = 0
|
sharedDate = 0
|
||||||
expirationDate = 0
|
expirationDate = 0
|
||||||
mToken = ""
|
|
||||||
mSharedWithDisplayName = ""
|
|
||||||
sharedWithAdditionalInfo = ""
|
sharedWithAdditionalInfo = ""
|
||||||
isFolder = false
|
isFolder = false
|
||||||
userId = -1
|
userId = -1
|
||||||
remoteId = -1
|
remoteId = -1
|
||||||
mShareLink = ""
|
|
||||||
mName = ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setIdRemoteShared(remoteId: Long) {
|
fun setIdRemoteShared(remoteId: Long) {
|
||||||
@ -146,6 +109,13 @@ class RemoteShare : Parcelable, Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun readFromParcel(source: Parcel) {
|
fun readFromParcel(source: Parcel) {
|
||||||
|
shareWith = source.readString()
|
||||||
|
path = source.readString()
|
||||||
|
token = source.readString()
|
||||||
|
sharedWithDisplayName = source.readString()
|
||||||
|
sharedWithAdditionalInfo = source.readString()
|
||||||
|
name = source.readString()
|
||||||
|
shareLink = source.readString()
|
||||||
fileSource = source.readLong()
|
fileSource = source.readLong()
|
||||||
itemSource = source.readLong()
|
itemSource = source.readLong()
|
||||||
try {
|
try {
|
||||||
@ -153,20 +123,12 @@ class RemoteShare : Parcelable, Serializable {
|
|||||||
} catch (x: IllegalArgumentException) {
|
} catch (x: IllegalArgumentException) {
|
||||||
shareType = ShareType.NO_SHARED
|
shareType = ShareType.NO_SHARED
|
||||||
}
|
}
|
||||||
|
|
||||||
mShareWith = source.readString()
|
|
||||||
mPath = source.readString()
|
|
||||||
permissions = source.readInt()
|
permissions = source.readInt()
|
||||||
sharedDate = source.readLong()
|
sharedDate = source.readLong()
|
||||||
expirationDate = source.readLong()
|
expirationDate = source.readLong()
|
||||||
mToken = source.readString()
|
|
||||||
mSharedWithDisplayName = source.readString()
|
|
||||||
sharedWithAdditionalInfo = source.readString()
|
|
||||||
isFolder = source.readInt() == 0
|
isFolder = source.readInt() == 0
|
||||||
userId = source.readLong()
|
userId = source.readLong()
|
||||||
remoteId = source.readLong()
|
remoteId = source.readLong()
|
||||||
mShareLink = source.readString()
|
|
||||||
mName = source.readString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun describeContents(): Int {
|
override fun describeContents(): Int {
|
||||||
@ -174,22 +136,22 @@ class RemoteShare : Parcelable, Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
override fun writeToParcel(dest: Parcel, flags: Int) {
|
||||||
|
dest.writeString(shareWith)
|
||||||
|
dest.writeString(path)
|
||||||
|
dest.writeString(token)
|
||||||
|
dest.writeString(sharedWithDisplayName)
|
||||||
|
dest.writeString(sharedWithAdditionalInfo)
|
||||||
|
dest.writeString(name)
|
||||||
|
dest.writeString(shareLink)
|
||||||
dest.writeLong(fileSource)
|
dest.writeLong(fileSource)
|
||||||
dest.writeLong(itemSource)
|
dest.writeLong(itemSource)
|
||||||
dest.writeString(if (shareType == null) "" else shareType!!.name)
|
dest.writeString(if (shareType == null) "" else shareType!!.name)
|
||||||
dest.writeString(mShareWith)
|
|
||||||
dest.writeString(mPath)
|
|
||||||
dest.writeInt(permissions)
|
dest.writeInt(permissions)
|
||||||
dest.writeLong(sharedDate)
|
dest.writeLong(sharedDate)
|
||||||
dest.writeLong(expirationDate)
|
dest.writeLong(expirationDate)
|
||||||
dest.writeString(mToken)
|
|
||||||
dest.writeString(mSharedWithDisplayName)
|
|
||||||
dest.writeString(sharedWithAdditionalInfo)
|
|
||||||
dest.writeInt(if (isFolder) 1 else 0)
|
dest.writeInt(if (isFolder) 1 else 0)
|
||||||
dest.writeLong(userId)
|
dest.writeLong(userId)
|
||||||
dest.writeLong(remoteId)
|
dest.writeLong(remoteId)
|
||||||
dest.writeString(mShareLink)
|
|
||||||
dest.writeString(mName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -90,9 +90,7 @@ class RemoveRemoteShareOperation
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isSuccess(status: Int): Boolean {
|
private fun isSuccess(status: Int): Boolean = status == HttpConstants.HTTP_OK
|
||||||
return status == HttpConstants.HTTP_OK
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
@ -28,42 +28,21 @@
|
|||||||
package com.owncloud.android.lib.resources.shares
|
package com.owncloud.android.lib.resources.shares
|
||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||||
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
|
import com.owncloud.android.lib.resources.status.OwnCloudVersion
|
||||||
import org.xmlpull.v1.XmlPullParserException
|
import org.xmlpull.v1.XmlPullParserException
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream
|
import java.io.ByteArrayInputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.InputStream
|
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
|
|
||||||
class ShareToRemoteOperationResultParser(shareXmlParser: ShareXMLParser) {
|
class ShareToRemoteOperationResultParser(private var shareXmlParser: ShareXMLParser?) {
|
||||||
|
var oneOrMoreSharesRequired = false
|
||||||
private var mShareXmlParser: ShareXMLParser? = null
|
var ownCloudVersion: OwnCloudVersion? = null
|
||||||
private var mOneOrMoreSharesRequired = false
|
var serverBaseUri: Uri? = null
|
||||||
private var mOwnCloudVersion: OwnCloudVersion? = null
|
|
||||||
private var mServerBaseUri: Uri? = null
|
|
||||||
|
|
||||||
init {
|
|
||||||
mShareXmlParser = shareXmlParser
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setOneOrMoreSharesRequired(oneOrMoreSharesRequired: Boolean) {
|
|
||||||
mOneOrMoreSharesRequired = oneOrMoreSharesRequired
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setOwnCloudVersion(ownCloudVersion: OwnCloudVersion?) {
|
|
||||||
mOwnCloudVersion = ownCloudVersion
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setServerBaseUri(serverBaseURi: Uri) {
|
|
||||||
mServerBaseUri = serverBaseURi
|
|
||||||
}
|
|
||||||
|
|
||||||
fun parse(serverResponse: String?): RemoteOperationResult<ShareParserResult> {
|
fun parse(serverResponse: String?): RemoteOperationResult<ShareParserResult> {
|
||||||
if (serverResponse == null || serverResponse.length == 0) {
|
if (serverResponse.isNullOrEmpty()) {
|
||||||
return RemoteOperationResult(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE)
|
return RemoteOperationResult(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,15 +51,15 @@ class ShareToRemoteOperationResultParser(shareXmlParser: ShareXMLParser) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Parse xml response and obtain the list of shares
|
// Parse xml response and obtain the list of shares
|
||||||
val `is` = ByteArrayInputStream(serverResponse.toByteArray())
|
val byteArrayServerResponse = ByteArrayInputStream(serverResponse.toByteArray())
|
||||||
if (mShareXmlParser == null) {
|
if (shareXmlParser == null) {
|
||||||
Log_OC.w(TAG, "No ShareXmlParser provided, creating new instance ")
|
Log_OC.w(TAG, "No ShareXmlParser provided, creating new instance ")
|
||||||
mShareXmlParser = ShareXMLParser()
|
shareXmlParser = ShareXMLParser()
|
||||||
}
|
}
|
||||||
val shares = mShareXmlParser!!.parseXMLResponse(`is`)
|
val shares = shareXmlParser?.parseXMLResponse(byteArrayServerResponse)
|
||||||
|
|
||||||
if (mShareXmlParser!!.isSuccess) {
|
if (shareXmlParser?.isSuccess!!) {
|
||||||
if (shares != null && shares.size > 0 || !mOneOrMoreSharesRequired) {
|
if (!shares.isNullOrEmpty() || !oneOrMoreSharesRequired) {
|
||||||
result = RemoteOperationResult(RemoteOperationResult.ResultCode.OK)
|
result = RemoteOperationResult(RemoteOperationResult.ResultCode.OK)
|
||||||
if (shares != null) {
|
if (shares != null) {
|
||||||
for (share in shares) {
|
for (share in shares) {
|
||||||
@ -88,12 +67,12 @@ class ShareToRemoteOperationResultParser(shareXmlParser: ShareXMLParser) {
|
|||||||
// build the share link if not in the response
|
// build the share link if not in the response
|
||||||
// (needed for OC servers < 9.0.0, see ShareXMLParser.java#line256)
|
// (needed for OC servers < 9.0.0, see ShareXMLParser.java#line256)
|
||||||
if (share.shareType == ShareType.PUBLIC_LINK
|
if (share.shareType == ShareType.PUBLIC_LINK
|
||||||
&& (share.shareLink == null || share.shareLink!!.length <= 0)
|
&& share.shareLink.isEmpty()
|
||||||
&& share.token!!.length > 0
|
&& share.token.isNotEmpty()
|
||||||
) {
|
) {
|
||||||
if (mServerBaseUri != null) {
|
if (serverBaseUri != null) {
|
||||||
val sharingLinkPath = ShareUtils.getSharingLinkPath(mOwnCloudVersion)
|
val sharingLinkPath = ShareUtils.getSharingLinkPath(ownCloudVersion)
|
||||||
share.shareLink = mServerBaseUri.toString() + sharingLinkPath + share.token
|
share.shareLink = serverBaseUri.toString() + sharingLinkPath + share.token
|
||||||
} else {
|
} else {
|
||||||
Log_OC.e(TAG, "Couldn't build link for public share :(")
|
Log_OC.e(TAG, "Couldn't build link for public share :(")
|
||||||
}
|
}
|
||||||
@ -107,18 +86,15 @@ class ShareToRemoteOperationResultParser(shareXmlParser: ShareXMLParser) {
|
|||||||
Log_OC.e(TAG, "Successful status with no share in the response")
|
Log_OC.e(TAG, "Successful status with no share in the response")
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (mShareXmlParser!!.isWrongParameter) {
|
} else if (shareXmlParser?.isWrongParameter!!) {
|
||||||
result = RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_WRONG_PARAMETER)
|
result = RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_WRONG_PARAMETER)
|
||||||
result.setData(ShareParserResult(null!!, mShareXmlParser!!.message!!))
|
result.data = ShareParserResult(arrayListOf(), shareXmlParser?.message!!)
|
||||||
|
} else if (shareXmlParser?.isNotFound!!) {
|
||||||
} else if (mShareXmlParser!!.isNotFound) {
|
|
||||||
result = RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND)
|
result = RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND)
|
||||||
result.setData(ShareParserResult(null!!, mShareXmlParser!!.message!!))
|
result.data = ShareParserResult(arrayListOf(), shareXmlParser?.message!!)
|
||||||
|
} else if (shareXmlParser?.isForbidden!!) {
|
||||||
} else if (mShareXmlParser!!.isForbidden) {
|
|
||||||
result = RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_FORBIDDEN)
|
result = RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_FORBIDDEN)
|
||||||
result.setData(ShareParserResult(null!!, mShareXmlParser!!.message!!))
|
result.data = ShareParserResult(arrayListOf(), shareXmlParser?.message!!)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = RemoteOperationResult(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE)
|
result = RemoteOperationResult(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE)
|
||||||
}
|
}
|
||||||
@ -136,7 +112,6 @@ class ShareToRemoteOperationResultParser(shareXmlParser: ShareXMLParser) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private val TAG = ShareToRemoteOperationResultParser::class.java.simpleName
|
private val TAG = ShareToRemoteOperationResultParser::class.java.simpleName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,6 @@ import java.util.ArrayList
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class ShareXMLParser {
|
class ShareXMLParser {
|
||||||
|
|
||||||
// Getters and Setters
|
// Getters and Setters
|
||||||
var status: String? = null
|
var status: String? = null
|
||||||
var statusCode: Int = 0
|
var statusCode: Int = 0
|
||||||
@ -65,18 +64,18 @@ class ShareXMLParser {
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
init {
|
init {
|
||||||
statusCode = -1
|
statusCode = INIT
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse is as response of Share API
|
* Parse is as response of Share API
|
||||||
* @param is
|
* @param inputStream
|
||||||
* @return List of ShareRemoteFiles
|
* @return List of ShareRemoteFiles
|
||||||
* @throws XmlPullParserException
|
* @throws XmlPullParserException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
@Throws(XmlPullParserException::class, IOException::class)
|
@Throws(XmlPullParserException::class, IOException::class)
|
||||||
fun parseXMLResponse(`is`: InputStream): ArrayList<RemoteShare> {
|
fun parseXMLResponse(inputStream: InputStream): ArrayList<RemoteShare> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// XMLPullParser
|
// XMLPullParser
|
||||||
@ -85,12 +84,12 @@ class ShareXMLParser {
|
|||||||
|
|
||||||
val parser = Xml.newPullParser()
|
val parser = Xml.newPullParser()
|
||||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false)
|
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false)
|
||||||
parser.setInput(`is`, null)
|
parser.setInput(inputStream, null)
|
||||||
parser.nextTag()
|
parser.nextTag()
|
||||||
return readOCS(parser)
|
return readOCS(parser)
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
`is`.close()
|
inputStream.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,10 +306,10 @@ class ShareXMLParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun fixPathForFolder(share: RemoteShare) {
|
private fun fixPathForFolder(share: RemoteShare) {
|
||||||
if (share.isFolder && share.path != null && share.path!!.length > 0 &&
|
if (share.isFolder && share.path.isNotEmpty() &&
|
||||||
!share.path!!.endsWith(FileUtils.PATH_SEPARATOR)
|
!share.path.endsWith(FileUtils.PATH_SEPARATOR)
|
||||||
) {
|
) {
|
||||||
share.path = share.path!! + FileUtils.PATH_SEPARATOR
|
share.path = share.path + FileUtils.PATH_SEPARATOR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,40 +375,41 @@ class ShareXMLParser {
|
|||||||
private val ns: String? = null
|
private val ns: String? = null
|
||||||
|
|
||||||
// NODES for XML Parser
|
// NODES for XML Parser
|
||||||
private val NODE_OCS = "ocs"
|
private const val NODE_OCS = "ocs"
|
||||||
|
|
||||||
private val NODE_META = "meta"
|
private const val NODE_META = "meta"
|
||||||
private val NODE_STATUS = "status"
|
private const val NODE_STATUS = "status"
|
||||||
private val NODE_STATUS_CODE = "statuscode"
|
private const val NODE_STATUS_CODE = "statuscode"
|
||||||
private val NODE_MESSAGE = "message"
|
private const val NODE_MESSAGE = "message"
|
||||||
|
|
||||||
private val NODE_DATA = "data"
|
private const val NODE_DATA = "data"
|
||||||
private val NODE_ELEMENT = "element"
|
private const val NODE_ELEMENT = "element"
|
||||||
private val NODE_ID = "id"
|
private const val NODE_ID = "id"
|
||||||
private val NODE_ITEM_TYPE = "item_type"
|
private const val NODE_ITEM_TYPE = "item_type"
|
||||||
private val NODE_ITEM_SOURCE = "item_source"
|
private const val NODE_ITEM_SOURCE = "item_source"
|
||||||
private val NODE_PARENT = "parent"
|
private const val NODE_PARENT = "parent"
|
||||||
private val NODE_SHARE_TYPE = "share_type"
|
private const val NODE_SHARE_TYPE = "share_type"
|
||||||
private val NODE_SHARE_WITH = "share_with"
|
private const val NODE_SHARE_WITH = "share_with"
|
||||||
private val NODE_FILE_SOURCE = "file_source"
|
private const val NODE_FILE_SOURCE = "file_source"
|
||||||
private val NODE_PATH = "path"
|
private const val NODE_PATH = "path"
|
||||||
private val NODE_PERMISSIONS = "permissions"
|
private const val NODE_PERMISSIONS = "permissions"
|
||||||
private val NODE_STIME = "stime"
|
private const val NODE_STIME = "stime"
|
||||||
private val NODE_EXPIRATION = "expiration"
|
private const val NODE_EXPIRATION = "expiration"
|
||||||
private val NODE_TOKEN = "token"
|
private const val NODE_TOKEN = "token"
|
||||||
private val NODE_STORAGE = "storage"
|
private const val NODE_STORAGE = "storage"
|
||||||
private val NODE_MAIL_SEND = "mail_send"
|
private const val NODE_MAIL_SEND = "mail_send"
|
||||||
private val NODE_SHARE_WITH_DISPLAY_NAME = "share_with_displayname"
|
private const val NODE_SHARE_WITH_DISPLAY_NAME = "share_with_displayname"
|
||||||
private val NODE_SHARE_WITH_ADDITIONAL_INFO = "share_with_additional_info"
|
private const val NODE_SHARE_WITH_ADDITIONAL_INFO = "share_with_additional_info"
|
||||||
private val NODE_NAME = "name"
|
private const val NODE_NAME = "name"
|
||||||
|
|
||||||
private val NODE_URL = "url"
|
private const val NODE_URL = "url"
|
||||||
|
|
||||||
private val TYPE_FOLDER = "folder"
|
private const val TYPE_FOLDER = "folder"
|
||||||
|
|
||||||
private val SUCCESS = 200
|
private const val SUCCESS = 200
|
||||||
private val ERROR_WRONG_PARAMETER = 400
|
private const val ERROR_WRONG_PARAMETER = 400
|
||||||
private val ERROR_FORBIDDEN = 403
|
private const val ERROR_FORBIDDEN = 403
|
||||||
private val ERROR_NOT_FOUND = 404
|
private const val ERROR_NOT_FOUND = 404
|
||||||
|
private const val INIT = -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,35 +57,35 @@ class UpdateRemoteShareOperation
|
|||||||
/**
|
/**
|
||||||
* Identifier of the share to update
|
* Identifier of the share to update
|
||||||
*/
|
*/
|
||||||
private val mRemoteId: Long
|
private val remoteId: Long
|
||||||
) : RemoteOperation<ShareParserResult>() {
|
) : RemoteOperation<ShareParserResult>() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Password to set for the public link
|
* Password to set for the public link
|
||||||
*/
|
*/
|
||||||
private var mPassword: String? = null
|
private var password: String? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expiration date to set for the public link
|
* Expiration date to set for the public link
|
||||||
*/
|
*/
|
||||||
private var mExpirationDateInMillis: Long = 0
|
private var expirationDateInMillis: Long = 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access permissions for the file bound to the share
|
* Access permissions for the file bound to the share
|
||||||
*/
|
*/
|
||||||
private var mPermissions: Int = 0
|
private var permissions: Int = 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload permissions for the public link (only folders)
|
* Upload permissions for the public link (only folders)
|
||||||
*/
|
*/
|
||||||
private var mPublicUpload: Boolean? = null
|
private var publicUpload: Boolean? = null
|
||||||
private var mName: String? = null
|
private var name: String? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
mPassword = null // no update
|
password = null // no update
|
||||||
mExpirationDateInMillis = 0 // no update
|
expirationDateInMillis = 0 // no update
|
||||||
mPublicUpload = null
|
publicUpload = null
|
||||||
mPermissions = RemoteShare.DEFAULT_PERMISSION
|
permissions = RemoteShare.DEFAULT_PERMISSION
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,7 +96,7 @@ class UpdateRemoteShareOperation
|
|||||||
* Null results in no update applied to the name.
|
* Null results in no update applied to the name.
|
||||||
*/
|
*/
|
||||||
fun setName(name: String) {
|
fun setName(name: String) {
|
||||||
this.mName = name
|
this.name = name
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,7 +107,7 @@ class UpdateRemoteShareOperation
|
|||||||
* Null results in no update applied to the password.
|
* Null results in no update applied to the password.
|
||||||
*/
|
*/
|
||||||
fun setPassword(password: String) {
|
fun setPassword(password: String) {
|
||||||
mPassword = password
|
this.password = password
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -119,7 +119,7 @@ class UpdateRemoteShareOperation
|
|||||||
* the expiration date.
|
* the expiration date.
|
||||||
*/
|
*/
|
||||||
fun setExpirationDate(expirationDateInMillis: Long) {
|
fun setExpirationDate(expirationDateInMillis: Long) {
|
||||||
mExpirationDateInMillis = expirationDateInMillis
|
this.expirationDateInMillis = expirationDateInMillis
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -129,7 +129,7 @@ class UpdateRemoteShareOperation
|
|||||||
* Values <= 0 result in no update applied to the permissions.
|
* Values <= 0 result in no update applied to the permissions.
|
||||||
*/
|
*/
|
||||||
fun setPermissions(permissions: Int) {
|
fun setPermissions(permissions: Int) {
|
||||||
mPermissions = permissions
|
this.permissions = permissions
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,7 +139,7 @@ class UpdateRemoteShareOperation
|
|||||||
* Null results in no update applied to the upload permission.
|
* Null results in no update applied to the upload permission.
|
||||||
*/
|
*/
|
||||||
fun setPublicUpload(publicUpload: Boolean?) {
|
fun setPublicUpload(publicUpload: Boolean?) {
|
||||||
mPublicUpload = publicUpload
|
this.publicUpload = publicUpload
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareParserResult> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<ShareParserResult> {
|
||||||
@ -149,38 +149,38 @@ class UpdateRemoteShareOperation
|
|||||||
val formBodyBuilder = FormBody.Builder()
|
val formBodyBuilder = FormBody.Builder()
|
||||||
|
|
||||||
// Parameters to update
|
// Parameters to update
|
||||||
if (mName != null) {
|
if (name != null) {
|
||||||
formBodyBuilder.add(PARAM_NAME, mName!!)
|
formBodyBuilder.add(PARAM_NAME, name!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mExpirationDateInMillis < 0) {
|
if (expirationDateInMillis < 0) {
|
||||||
// clear expiration date
|
// clear expiration date
|
||||||
formBodyBuilder.add(PARAM_EXPIRATION_DATE, "")
|
formBodyBuilder.add(PARAM_EXPIRATION_DATE, "")
|
||||||
|
|
||||||
} else if (mExpirationDateInMillis > 0) {
|
} else if (expirationDateInMillis > 0) {
|
||||||
// set expiration date
|
// set expiration date
|
||||||
val dateFormat = SimpleDateFormat(FORMAT_EXPIRATION_DATE, Locale.GERMAN)
|
val dateFormat = SimpleDateFormat(FORMAT_EXPIRATION_DATE, Locale.getDefault())
|
||||||
val expirationDate = Calendar.getInstance()
|
val expirationDate = Calendar.getInstance()
|
||||||
expirationDate.timeInMillis = mExpirationDateInMillis
|
expirationDate.timeInMillis = expirationDateInMillis
|
||||||
val formattedExpirationDate = dateFormat.format(expirationDate.time)
|
val formattedExpirationDate = dateFormat.format(expirationDate.time)
|
||||||
formBodyBuilder.add(PARAM_EXPIRATION_DATE, formattedExpirationDate)
|
formBodyBuilder.add(PARAM_EXPIRATION_DATE, formattedExpirationDate)
|
||||||
} // else, ignore - no update
|
} // else, ignore - no update
|
||||||
|
|
||||||
if (mPublicUpload != null) {
|
if (publicUpload != null) {
|
||||||
formBodyBuilder.add(PARAM_PUBLIC_UPLOAD, java.lang.Boolean.toString(mPublicUpload!!))
|
formBodyBuilder.add(PARAM_PUBLIC_UPLOAD, publicUpload.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
// IMPORTANT: permissions parameter needs to be updated after mPublicUpload parameter,
|
// IMPORTANT: permissions parameter needs to be updated after mPublicUpload parameter,
|
||||||
// otherwise they would be set always as 1 (READ) in the server when mPublicUpload was updated
|
// otherwise they would be set always as 1 (READ) in the server when mPublicUpload was updated
|
||||||
if (mPermissions > 0) {
|
if (permissions > 0) {
|
||||||
// set permissions
|
// set permissions
|
||||||
formBodyBuilder.add(PARAM_PERMISSIONS, Integer.toString(mPermissions))
|
formBodyBuilder.add(PARAM_PERMISSIONS, permissions.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
val requestUri = client.baseUri
|
val requestUri = client.baseUri
|
||||||
val uriBuilder = requestUri.buildUpon()
|
val uriBuilder = requestUri.buildUpon()
|
||||||
uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH)
|
uriBuilder.appendEncodedPath(ShareUtils.SHARING_API_PATH)
|
||||||
uriBuilder.appendEncodedPath(java.lang.Long.toString(mRemoteId))
|
uriBuilder.appendEncodedPath(remoteId.toString())
|
||||||
|
|
||||||
val putMethod = PutMethod(URL(uriBuilder.build().toString()))
|
val putMethod = PutMethod(URL(uriBuilder.build().toString()))
|
||||||
|
|
||||||
@ -196,8 +196,8 @@ class UpdateRemoteShareOperation
|
|||||||
val parser = ShareToRemoteOperationResultParser(
|
val parser = ShareToRemoteOperationResultParser(
|
||||||
ShareXMLParser()
|
ShareXMLParser()
|
||||||
)
|
)
|
||||||
parser.setOwnCloudVersion(client.ownCloudVersion)
|
parser.ownCloudVersion = client.ownCloudVersion
|
||||||
parser.setServerBaseUri(client.baseUri)
|
parser.serverBaseUri = client.baseUri
|
||||||
result = parser.parse(putMethod.responseBodyAsString)
|
result = parser.parse(putMethod.responseBodyAsString)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user