mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Support for usernames with character +
This commit is contained in:
		
							parent
							
								
									f7a54a8218
								
							
						
					
					
						commit
						8d5524da75
					
				| @ -1,5 +1,5 @@ | |||||||
| /* ownCloud Android Library is available under MIT license | /* ownCloud Android Library is available under MIT license | ||||||
|  *   Copyright (C) 2019 ownCloud GmbH. |  *   Copyright (C) 2020 ownCloud GmbH. | ||||||
|  * |  * | ||||||
|  *   Permission is hereby granted, free of charge, to any person obtaining a copy |  *   Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
|  *   of this software and associated documentation files (the "Software"), to deal |  *   of this software and associated documentation files (the "Software"), to deal | ||||||
| @ -24,7 +24,6 @@ | |||||||
| 
 | 
 | ||||||
| package com.owncloud.android.lib.resources.files; | package com.owncloud.android.lib.resources.files; | ||||||
| 
 | 
 | ||||||
| import android.net.Uri; |  | ||||||
| import android.os.Parcel; | import android.os.Parcel; | ||||||
| import android.os.Parcelable; | import android.os.Parcelable; | ||||||
| 
 | 
 | ||||||
| @ -41,14 +40,11 @@ import at.bitfire.dav4android.property.owncloud.OCId; | |||||||
| import at.bitfire.dav4android.property.owncloud.OCPermissions; | import at.bitfire.dav4android.property.owncloud.OCPermissions; | ||||||
| import at.bitfire.dav4android.property.owncloud.OCPrivatelink; | import at.bitfire.dav4android.property.owncloud.OCPrivatelink; | ||||||
| import at.bitfire.dav4android.property.owncloud.OCSize; | import at.bitfire.dav4android.property.owncloud.OCSize; | ||||||
| import okhttp3.HttpUrl; |  | ||||||
| 
 | 
 | ||||||
| import java.io.Serializable; | import java.io.Serializable; | ||||||
| import java.math.BigDecimal; | import java.math.BigDecimal; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| 
 | 
 | ||||||
| import static com.owncloud.android.lib.common.OwnCloudClient.WEBDAV_FILES_PATH_4_0; |  | ||||||
| 
 |  | ||||||
| /** | /** | ||||||
|  * Contains the data of a Remote File from a WebDavEntry |  * Contains the data of a Remote File from a WebDavEntry | ||||||
|  * |  * | ||||||
| @ -115,7 +111,7 @@ public class RemoteFile implements Parcelable, Serializable { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public RemoteFile(final Response davResource, String userId) { |     public RemoteFile(final Response davResource, String userId) { | ||||||
|         this(getRemotePathFromUrl(davResource.getHref(), userId)); |         this(RemoteFileUtil.Companion.getRemotePathFromUrl(davResource.getHref(), userId)); | ||||||
|         final List<Property> properties = davResource.getProperties(); |         final List<Property> properties = davResource.getProperties(); | ||||||
| 
 | 
 | ||||||
|         for (Property property : properties) { |         for (Property property : properties) { | ||||||
| @ -167,21 +163,6 @@ public class RemoteFile implements Parcelable, Serializable { | |||||||
|         readFromParcel(source); |         readFromParcel(source); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Retrieves a relative path from a remote file url |  | ||||||
|      * <p> |  | ||||||
|      * Example: url:port/remote.php/dav/files/username/Documents/text.txt => /Documents/text.txt |  | ||||||
|      * |  | ||||||
|      * @param url    remote file url |  | ||||||
|      * @param userId file owner |  | ||||||
|      * @return remote relative path of the file |  | ||||||
|      */ |  | ||||||
|     private static String getRemotePathFromUrl(HttpUrl url, String userId) { |  | ||||||
|         final String davFilesPath = WEBDAV_FILES_PATH_4_0 + userId; |  | ||||||
|         final String absoluteDavPath = Uri.decode(url.encodedPath()); |  | ||||||
|         final String pathToOc = absoluteDavPath.split(davFilesPath)[0]; |  | ||||||
|         return absoluteDavPath.replace(pathToOc + davFilesPath, ""); |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Getters and Setters |      * Getters and Setters | ||||||
|  | |||||||
| @ -0,0 +1,49 @@ | |||||||
|  | /* 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.resources.files | ||||||
|  | 
 | ||||||
|  | import android.net.Uri | ||||||
|  | import com.owncloud.android.lib.common.OwnCloudClient | ||||||
|  | import okhttp3.HttpUrl | ||||||
|  | 
 | ||||||
|  | class RemoteFileUtil { | ||||||
|  |     companion object { | ||||||
|  |         /** | ||||||
|  |          * Retrieves a relative path from a remote file url | ||||||
|  |          * | ||||||
|  |          * | ||||||
|  |          * Example: url:port/remote.php/dav/files/username/Documents/text.txt => /Documents/text.txt | ||||||
|  |          * | ||||||
|  |          * @param url    remote file url | ||||||
|  |          * @param userId file owner | ||||||
|  |          * @return remote relative path of the file | ||||||
|  |          */ | ||||||
|  |         fun getRemotePathFromUrl(url: HttpUrl, userId: String): String? { | ||||||
|  |             val davFilesPath = OwnCloudClient.WEBDAV_FILES_PATH_4_0 + userId | ||||||
|  |             val absoluteDavPath = Uri.decode(url.encodedPath()) | ||||||
|  |             val pathToOc = absoluteDavPath.split(davFilesPath)[0] | ||||||
|  |             return absoluteDavPath.replace(pathToOc + davFilesPath, "") | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user