mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Migrate webdav wrappers to kotlin
This commit is contained in:
		
							parent
							
								
									c5fd59c825
								
							
						
					
					
						commit
						7f2d94bc78
					
				| @ -21,12 +21,10 @@ | |||||||
|  *   THE SOFTWARE. |  *   THE SOFTWARE. | ||||||
|  * |  * | ||||||
|  */ |  */ | ||||||
|  | package com.owncloud.android.lib.common.http.methods.webdav | ||||||
| 
 | 
 | ||||||
| package com.owncloud.android.lib.common.http.methods.webdav; | import okhttp3.Response | ||||||
| 
 | import java.net.URL | ||||||
| import kotlin.Unit; |  | ||||||
| 
 |  | ||||||
| import java.net.URL; |  | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Copy calls wrapper |  * Copy calls wrapper | ||||||
| @ -34,24 +32,17 @@ import java.net.URL; | |||||||
|  * @author Christian Schabesberger |  * @author Christian Schabesberger | ||||||
|  * @author David González Verdugo |  * @author David González Verdugo | ||||||
|  */ |  */ | ||||||
| public class CopyMethod extends DavMethod { | class CopyMethod( | ||||||
| 
 |     val url: URL?, | ||||||
|     final String destinationUrl; |     private val destinationUrl: String, | ||||||
|     final boolean forceOverride; |     private val forceOverride: Boolean | ||||||
| 
 | ) : DavMethod(url) { | ||||||
|     public CopyMethod(URL url, String destinationUrl, boolean forceOverride) { |     @Throws(Exception::class) | ||||||
|         super(url); |     public override fun onExecute(): Int { | ||||||
|         this.destinationUrl = destinationUrl; |         mDavResource.copy(destinationUrl, forceOverride) { response: Response -> | ||||||
|         this.forceOverride = forceOverride; |             mResponse = response | ||||||
|  |         } | ||||||
|  |         return super.getStatusCode() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override | } | ||||||
|     public int onExecute() throws Exception { |  | ||||||
|         mDavResource.copy(destinationUrl, forceOverride, response -> { |  | ||||||
|             mResponse = response; |  | ||||||
|             return Unit.INSTANCE; |  | ||||||
|         }); |  | ||||||
| 
 |  | ||||||
|         return super.getStatusCode(); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -21,13 +21,12 @@ | |||||||
|  *   THE SOFTWARE. |  *   THE SOFTWARE. | ||||||
|  * |  * | ||||||
|  */ |  */ | ||||||
| 
 | package com.owncloud.android.lib.common.http.methods.webdav | ||||||
| package com.owncloud.android.lib.common.http.methods.webdav; |  | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * @author David González Verdugo |  * @author David González Verdugo | ||||||
|  */ |  */ | ||||||
| public class DavConstants { | object DavConstants { | ||||||
|     public static final int DEPTH_0 = 0; |     const val DEPTH_0 = 0 | ||||||
|     public static final int DEPTH_1 = 1; |     const val DEPTH_1 = 1 | ||||||
| } | } | ||||||
| @ -21,12 +21,10 @@ | |||||||
|  *   THE SOFTWARE. |  *   THE SOFTWARE. | ||||||
|  * |  * | ||||||
|  */ |  */ | ||||||
|  | package com.owncloud.android.lib.common.http.methods.webdav | ||||||
| 
 | 
 | ||||||
| package com.owncloud.android.lib.common.http.methods.webdav; | import okhttp3.Response | ||||||
| 
 | import java.net.URL | ||||||
| import kotlin.Unit; |  | ||||||
| 
 |  | ||||||
| import java.net.URL; |  | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * MkCol calls wrapper |  * MkCol calls wrapper | ||||||
| @ -34,18 +32,12 @@ import java.net.URL; | |||||||
|  * @author Christian Schabesberger |  * @author Christian Schabesberger | ||||||
|  * @author David González Verdugo |  * @author David González Verdugo | ||||||
|  */ |  */ | ||||||
| public class MkColMethod extends DavMethod { | class MkColMethod(url: URL?) : DavMethod(url) { | ||||||
|     public MkColMethod(URL url) { |     @Throws(Exception::class) | ||||||
|         super(url); |     public override fun onExecute(): Int { | ||||||
|  |         mDavResource.mkCol(null) { response: Response -> | ||||||
|  |             mResponse = response | ||||||
|  |         } | ||||||
|  |         return super.getStatusCode() | ||||||
|     } |     } | ||||||
| 
 | } | ||||||
|     @Override |  | ||||||
|     public int onExecute() throws Exception { |  | ||||||
|         mDavResource.mkCol(null, response -> { |  | ||||||
|             mResponse = response; |  | ||||||
|             return Unit.INSTANCE; |  | ||||||
|         }); |  | ||||||
| 
 |  | ||||||
|         return super.getStatusCode(); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -21,13 +21,11 @@ | |||||||
|  *   THE SOFTWARE. |  *   THE SOFTWARE. | ||||||
|  * |  * | ||||||
|  */ |  */ | ||||||
|  | package com.owncloud.android.lib.common.http.methods.webdav | ||||||
| 
 | 
 | ||||||
| package com.owncloud.android.lib.common.http.methods.webdav; | import com.owncloud.android.lib.common.http.HttpConstants | ||||||
| 
 | import okhttp3.Response | ||||||
| import com.owncloud.android.lib.common.http.HttpConstants; | import java.net.URL | ||||||
| import kotlin.Unit; |  | ||||||
| 
 |  | ||||||
| import java.net.URL; |  | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Move calls wrapper |  * Move calls wrapper | ||||||
| @ -35,27 +33,23 @@ import java.net.URL; | |||||||
|  * @author Christian Schabesberger |  * @author Christian Schabesberger | ||||||
|  * @author David González Verdugo |  * @author David González Verdugo | ||||||
|  */ |  */ | ||||||
| public class MoveMethod extends DavMethod { | class MoveMethod( | ||||||
|     final String destinationUrl; |     url: URL?, | ||||||
|     final boolean forceOverride; |     private val destinationUrl: String, | ||||||
| 
 |     private val forceOverride: Boolean | ||||||
|     public MoveMethod(URL url, String destinationUrl, boolean forceOverride) { | ) : | ||||||
|         super(url); |     DavMethod(url) { | ||||||
|         this.destinationUrl = destinationUrl; |     @Throws(Exception::class) | ||||||
|         this.forceOverride = forceOverride; |     public override fun onExecute(): Int { | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Override |  | ||||||
|     public int onExecute() throws Exception { |  | ||||||
|         mDavResource.move( |         mDavResource.move( | ||||||
|                 destinationUrl, |             destinationUrl, | ||||||
|                 forceOverride, |             forceOverride, | ||||||
|                 super.getRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER), |             super.getRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER), | ||||||
|                 super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER), response -> { |             super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER) | ||||||
|                     mResponse = response; |         ) { response: Response -> | ||||||
|                     return Unit.INSTANCE; |             mResponse = response | ||||||
|                 }); |         } | ||||||
| 
 |         return super.getStatusCode() | ||||||
|         return super.getStatusCode(); |  | ||||||
|     } |     } | ||||||
| } | 
 | ||||||
|  | } | ||||||
| @ -1,94 +0,0 @@ | |||||||
| /* ownCloud Android Library is available under MIT license |  | ||||||
|  *   Copyright (C) 2020 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 |  | ||||||
|  *   in the Software without restriction, including without limitation the rights |  | ||||||
|  *   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |  | ||||||
|  *   copies of the Software, and to permit persons to whom the Software is |  | ||||||
|  *   furnished to do so, subject to the following conditions: |  | ||||||
|  * |  | ||||||
|  *   The above copyright notice and this permission notice shall be included in |  | ||||||
|  *   all copies or substantial portions of the Software. |  | ||||||
|  * |  | ||||||
|  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |  | ||||||
|  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |  | ||||||
|  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |  | ||||||
|  *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |  | ||||||
|  *   BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |  | ||||||
|  *   ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |  | ||||||
|  *   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |  | ||||||
|  *   THE SOFTWARE. |  | ||||||
|  * |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| package com.owncloud.android.lib.common.http.methods.webdav; |  | ||||||
| 
 |  | ||||||
| import at.bitfire.dav4jvm.Property; |  | ||||||
| import at.bitfire.dav4jvm.Response; |  | ||||||
| import at.bitfire.dav4jvm.exception.DavException; |  | ||||||
| import kotlin.Unit; |  | ||||||
| 
 |  | ||||||
| import java.io.IOException; |  | ||||||
| import java.net.URL; |  | ||||||
| import java.util.ArrayList; |  | ||||||
| import java.util.List; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * Propfind calls wrapper |  | ||||||
|  * |  | ||||||
|  * @author David González Verdugo |  | ||||||
|  */ |  | ||||||
| public class PropfindMethod extends DavMethod { |  | ||||||
| 
 |  | ||||||
|     // request |  | ||||||
|     private final int mDepth; |  | ||||||
|     private final Property.Name[] mPropertiesToRequest; |  | ||||||
| 
 |  | ||||||
|     // response |  | ||||||
|     private final List<Response> mMembers; |  | ||||||
|     private Response mRoot; |  | ||||||
| 
 |  | ||||||
|     public PropfindMethod(URL url, int depth, Property.Name[] propertiesToRequest) { |  | ||||||
|         super(url); |  | ||||||
|         mDepth = depth; |  | ||||||
|         mPropertiesToRequest = propertiesToRequest; |  | ||||||
|         mMembers = new ArrayList<>(); |  | ||||||
|         mRoot = null; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Override |  | ||||||
|     public int onExecute() throws IOException, DavException { |  | ||||||
|         mDavResource.propfind(mDepth, mPropertiesToRequest, |  | ||||||
|                 (Response response, Response.HrefRelation hrefRelation) -> { |  | ||||||
|                     switch (hrefRelation) { |  | ||||||
|                         case MEMBER: |  | ||||||
|                             mMembers.add(response); |  | ||||||
|                             break; |  | ||||||
|                         case SELF: |  | ||||||
|                             mRoot = response; |  | ||||||
|                             break; |  | ||||||
|                         case OTHER: |  | ||||||
|                         default: |  | ||||||
|                     } |  | ||||||
|                     return Unit.INSTANCE; |  | ||||||
|                 }, response -> { |  | ||||||
|                     mResponse = response; |  | ||||||
|                     return Unit.INSTANCE; |  | ||||||
|                 }); |  | ||||||
| 
 |  | ||||||
|         return getStatusCode(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public int getDepth() { |  | ||||||
|         return mDepth; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public List<Response> getMembers() { |  | ||||||
|         return mMembers; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public Response getRoot() { |  | ||||||
|         return mRoot; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -0,0 +1,78 @@ | |||||||
|  | /* ownCloud Android Library is available under MIT license | ||||||
|  |  *   Copyright (C) 2020 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 | ||||||
|  |  *   in the Software without restriction, including without limitation the rights | ||||||
|  |  *   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||||
|  |  *   copies of the Software, and to permit persons to whom the Software is | ||||||
|  |  *   furnished to do so, subject to the following conditions: | ||||||
|  |  * | ||||||
|  |  *   The above copyright notice and this permission notice shall be included in | ||||||
|  |  *   all copies or substantial portions of the Software. | ||||||
|  |  * | ||||||
|  |  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||||||
|  |  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||||||
|  |  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||||||
|  |  *   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||||||
|  |  *   BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||||||
|  |  *   ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||||||
|  |  *   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||||
|  |  *   THE SOFTWARE. | ||||||
|  |  * | ||||||
|  |  */ | ||||||
|  | package com.owncloud.android.lib.common.http.methods.webdav | ||||||
|  | 
 | ||||||
|  | import at.bitfire.dav4android.Property | ||||||
|  | import at.bitfire.dav4android.Response | ||||||
|  | import at.bitfire.dav4android.Response.HrefRelation | ||||||
|  | import at.bitfire.dav4android.exception.DavException | ||||||
|  | import java.io.IOException | ||||||
|  | import java.net.URL | ||||||
|  | import java.util.ArrayList | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Propfind calls wrapper | ||||||
|  |  * | ||||||
|  |  * @author David González Verdugo | ||||||
|  |  */ | ||||||
|  | class PropfindMethod( | ||||||
|  |     url: URL?, | ||||||
|  |     // request | ||||||
|  |     val depth: Int, | ||||||
|  |     private val mPropertiesToRequest: Array<Property.Name> | ||||||
|  | ) : DavMethod(url) { | ||||||
|  | 
 | ||||||
|  |     // response | ||||||
|  |     private val mMembers: MutableList<Response> | ||||||
|  |     var root: Response? | ||||||
|  |         private set | ||||||
|  | 
 | ||||||
|  |     @Throws(IOException::class, DavException::class) | ||||||
|  |     public override fun onExecute(): Int { | ||||||
|  |         mDavResource.propfind( | ||||||
|  |             depth = depth, | ||||||
|  |             reqProp = *mPropertiesToRequest, | ||||||
|  |             callback = { response: Response, hrefRelation: HrefRelation? -> | ||||||
|  |                 when (hrefRelation) { | ||||||
|  |                     HrefRelation.MEMBER -> mMembers.add(response) | ||||||
|  |                     HrefRelation.SELF -> this.root = response | ||||||
|  |                     HrefRelation.OTHER -> { | ||||||
|  |                     } | ||||||
|  |                     else -> { | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             }, rawCallback = { response: okhttp3.Response -> | ||||||
|  |                 mResponse = response | ||||||
|  |             }) | ||||||
|  |         return statusCode | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     val members: List<Response> | ||||||
|  |         get() = mMembers | ||||||
|  | 
 | ||||||
|  |     init { | ||||||
|  |         mMembers = ArrayList() | ||||||
|  |         this.root = null | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -21,41 +21,30 @@ | |||||||
|  *   THE SOFTWARE. |  *   THE SOFTWARE. | ||||||
|  * |  * | ||||||
|  */ |  */ | ||||||
|  | package com.owncloud.android.lib.common.http.methods.webdav | ||||||
| 
 | 
 | ||||||
| package com.owncloud.android.lib.common.http.methods.webdav; | import at.bitfire.dav4android.exception.HttpException | ||||||
| 
 | import com.owncloud.android.lib.common.http.HttpConstants | ||||||
| import at.bitfire.dav4jvm.exception.HttpException; | import java.io.IOException | ||||||
| import com.owncloud.android.lib.common.http.HttpConstants; | import java.net.URL | ||||||
| import kotlin.Unit; |  | ||||||
| 
 |  | ||||||
| import java.io.IOException; |  | ||||||
| import java.net.URL; |  | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Put calls wrapper |  * Put calls wrapper | ||||||
|  * |  * | ||||||
|  * @author David González Verdugo |  * @author David González Verdugo | ||||||
|  */ |  */ | ||||||
| public class PutMethod extends DavMethod { | class PutMethod(url: URL?) : DavMethod(url) { | ||||||
| 
 |     @Throws(IOException::class, HttpException::class) | ||||||
|     public PutMethod(URL url) { |     public override fun onExecute(): Int { | ||||||
|         super(url); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     ; |  | ||||||
| 
 |  | ||||||
|     @Override |  | ||||||
|     public int onExecute() throws IOException, HttpException { |  | ||||||
|         mDavResource.put( |         mDavResource.put( | ||||||
|                 mRequestBody, |             mRequestBody, | ||||||
|                 super.getRequestHeader(HttpConstants.IF_MATCH_HEADER), |             super.getRequestHeader(HttpConstants.IF_MATCH_HEADER), | ||||||
|                 super.getRequestHeader(HttpConstants.CONTENT_TYPE_HEADER), |             super.getRequestHeader(HttpConstants.CONTENT_TYPE_HEADER), | ||||||
|                 super.getRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER), |             super.getRequestHeader(HttpConstants.OC_TOTAL_LENGTH_HEADER), | ||||||
|                 super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER), response -> { |             super.getRequestHeader(HttpConstants.OC_X_OC_MTIME_HEADER) | ||||||
|                     mResponse = response; |         ) { response: Response -> | ||||||
|                     return Unit.INSTANCE; |             mResponse = response | ||||||
|                 }); |         } | ||||||
| 
 |         return super.getStatusCode() | ||||||
|         return super.getStatusCode(); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -27,7 +27,6 @@ import com.owncloud.android.lib.common.OwnCloudClient; | |||||||
| import com.owncloud.android.lib.common.accounts.AccountUtils; | import com.owncloud.android.lib.common.accounts.AccountUtils; | ||||||
| import com.owncloud.android.lib.common.http.HttpConstants; | import com.owncloud.android.lib.common.http.HttpConstants; | ||||||
| import com.owncloud.android.lib.common.http.methods.webdav.DavUtils; | import com.owncloud.android.lib.common.http.methods.webdav.DavUtils; | ||||||
| import com.owncloud.android.lib.common.http.methods.webdav.PropfindMethod; |  | ||||||
| import com.owncloud.android.lib.common.network.WebdavUtils; | import com.owncloud.android.lib.common.network.WebdavUtils; | ||||||
| import com.owncloud.android.lib.common.operations.RemoteOperation; | import com.owncloud.android.lib.common.operations.RemoteOperation; | ||||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult; | import com.owncloud.android.lib.common.operations.RemoteOperationResult; | ||||||
|  | |||||||
| @ -30,7 +30,6 @@ import com.owncloud.android.lib.common.accounts.AccountUtils; | |||||||
| import com.owncloud.android.lib.common.http.HttpConstants; | import com.owncloud.android.lib.common.http.HttpConstants; | ||||||
| import com.owncloud.android.lib.common.http.methods.webdav.DavConstants; | import com.owncloud.android.lib.common.http.methods.webdav.DavConstants; | ||||||
| import com.owncloud.android.lib.common.http.methods.webdav.DavUtils; | import com.owncloud.android.lib.common.http.methods.webdav.DavUtils; | ||||||
| import com.owncloud.android.lib.common.http.methods.webdav.PropfindMethod; |  | ||||||
| import com.owncloud.android.lib.common.network.WebdavUtils; | import com.owncloud.android.lib.common.network.WebdavUtils; | ||||||
| import com.owncloud.android.lib.common.operations.RemoteOperation; | import com.owncloud.android.lib.common.operations.RemoteOperation; | ||||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult; | import com.owncloud.android.lib.common.operations.RemoteOperationResult; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user