diff --git a/library/src/androidTest/java/com/owncloud/android/Dav4JVM.kt b/library/src/androidTest/java/com/owncloud/android/Dav4JVM.kt deleted file mode 100644 index f194a4a0bc..0000000000 --- a/library/src/androidTest/java/com/owncloud/android/Dav4JVM.kt +++ /dev/null @@ -1,285 +0,0 @@ -/* Nextcloud Android Library is available under MIT license - * - * @author Tobias Kaminsky - * Copyright (C) 2022 Tobias Kaminsky - * Copyright (C) 2022 Nextcloud 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 - -import at.bitfire.dav4jvm.DavResource -import at.bitfire.dav4jvm.Response -import com.nextcloud.common.NextcloudAuthenticator -import com.nextcloud.operations.PropFindMethod -import com.nextcloud.test.RandomStringGenerator -import com.owncloud.android.lib.common.network.WebdavUtils -import com.owncloud.android.lib.common.utils.WebDavFileUtils -import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation -import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation -import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperationIT -import com.owncloud.android.lib.resources.files.SearchRemoteOperation -import com.owncloud.android.lib.resources.files.ToggleFavoriteRemoteOperation -import com.owncloud.android.lib.resources.files.UploadFileRemoteOperation -import com.owncloud.android.lib.resources.files.model.RemoteFile -import com.owncloud.android.lib.resources.shares.CreateShareRemoteOperation -import com.owncloud.android.lib.resources.shares.OCShare -import com.owncloud.android.lib.resources.shares.ShareType -import com.owncloud.android.lib.resources.status.OCCapability -import com.owncloud.android.lib.resources.tags.CreateTagRemoteOperation -import com.owncloud.android.lib.resources.tags.GetTagsRemoteOperation -import com.owncloud.android.lib.resources.tags.PutTagRemoteOperation -import okhttp3.HttpUrl.Companion.toHttpUrl -import org.apache.jackrabbit.webdav.DavConstants -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue -import org.junit.Test -import java.io.IOException - -/* -can be removed after fully switching to dav4jvm as other tests should cover it - */ -class Dav4JVM : AbstractIT() { - @Test - @Throws(IOException::class) - fun singlePropfind() { - val path = "/testFolder/" - val subFolder = path + "subfolder/" - - // create folder - CreateFolderRemoteOperation( - path, - true - ).execute(client).isSuccess - - // verify folder - assertTrue(ReadFolderRemoteOperation(path).execute(client).isSuccess) - - // add favorite - assertTrue(ToggleFavoriteRemoteOperation(true, path).execute(client).isSuccess) - - // share it - assertTrue( - CreateShareRemoteOperation( - path, - ShareType.USER, - "admin", - false, - "", - OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER, - true - ).execute(client) - .isSuccess - ) - - // add one child - // create folder - CreateFolderRemoteOperation( - subFolder, - true - ).execute(client).isSuccess - - // verify folder - assertTrue(ReadFolderRemoteOperation(subFolder).execute(client).isSuccess) - - // do old read folder operation to compare data against it - var result = ReadFolderRemoteOperation(path).execute(client).data as List - assertEquals(2, result.size) - var oldRemoteFile = result[0] - var oldSubFolderFile = result[1] - - assertEquals(path, oldRemoteFile.remotePath) - assertEquals(subFolder, oldSubFolderFile.remotePath) - - // create tag - val tag1 = "a" + RandomStringGenerator.make(ReadFolderRemoteOperationIT.TAG_LENGTH) - assertTrue(CreateTagRemoteOperation(tag1).execute(nextcloudClient).isSuccess) - - // list tags - val tags = GetTagsRemoteOperation().execute(client).resultData - - // add tag - assertTrue( - PutTagRemoteOperation( - tags[0].id, - oldRemoteFile.localId - ).execute(nextcloudClient).isSuccess - ) - - // do old read folder operation to compare data against it - result = ReadFolderRemoteOperation(path).execute(client).data as List - assertEquals(2, result.size) - oldRemoteFile = result[0] - oldSubFolderFile = result[1] - - // new - val httpUrl = (nextcloudClient.filesDavUri.toString() + path).toHttpUrl() - - var davResponse: Response? = null - - val memberElements: MutableList = ArrayList() - var rootElement: Response? = null - - // disable redirect - val client = nextcloudClient.client - .newBuilder() - .followRedirects(false) - .authenticator(NextcloudAuthenticator(nextcloudClient.credentials)) - .build() - - // register custom property - // TODO check how to do it in a central way - WebdavUtils.registerCustomFactories() - - // TODO use DavResource().propfind in ReadFileRemoteOperation/ReadFolderRemoteOperation - // TODO test all properties on server! - DavResource(client, httpUrl) - .propfind( - DavConstants.DEPTH_1, - *WebdavUtils.getAllPropertiesList() - ) { response: Response, hrefRelation: Response.HrefRelation? -> - davResponse = response - when (hrefRelation) { - Response.HrefRelation.MEMBER -> memberElements.add(response) - Response.HrefRelation.SELF -> rootElement = response - Response.HrefRelation.OTHER -> {} - else -> {} - } - } - - assertTrue(davResponse?.isSuccess() == true) - assertTrue(rootElement != null) - assertEquals(1, memberElements.size) - - val remoteFile = WebDavFileUtils().parseResponse(rootElement, nextcloudClient.filesDavUri) - assertTrue(oldRemoteFile == remoteFile) - - val subfolderFile = - WebDavFileUtils().parseResponse(memberElements[0], nextcloudClient.filesDavUri) - assertTrue(oldSubFolderFile == subfolderFile) - - // new propfind - val newResult = nextcloudClient.execute(PropFindMethod(httpUrl)) - - assertTrue(newResult.success) - assertTrue(oldRemoteFile == newResult.root) - - assertEquals(1, newResult.children.size) - assertTrue(oldSubFolderFile == newResult.children[0]) - } - - @Test - fun search() { - val path = "/testFolder/" - - // create folder - assertTrue( - CreateFolderRemoteOperation( - path, - true - ).execute(client).isSuccess - ) - - // create file - val filePath = createFile("text") - val remotePath = "/test.md" - - assertTrue( - UploadFileRemoteOperation( - filePath, - remotePath, - "text/markdown", - "", - RANDOM_MTIME, - System.currentTimeMillis(), - true - ).execute(client).isSuccess - ) - - WebdavUtils.registerCustomFactories() - - var ror = SearchRemoteOperation( - "test", - SearchRemoteOperation.SearchType.FILE_SEARCH, - false, - OCCapability().apply { - versionMayor = 23 - versionMinor = 0 - versionMicro = 0 - } - ).execute( - client - ) - - assertTrue(ror.isSuccess) - assertEquals(2, ror.resultData.size) - - val oldRemoteFile = ror.resultData[0] - - assertTrue( - path == ror.resultData[0].remotePath || - path == ror.resultData[1].remotePath - ) - - ror = SearchRemoteOperation( - "test", - SearchRemoteOperation.SearchType.FILE_SEARCH, - false, - OCCapability().apply { - versionMayor = 23 - versionMinor = 0 - versionMicro = 0 - } - ).execute( - nextcloudClient - ) - - assertTrue(ror.isSuccess) - assertEquals(2, ror.resultData.size) - - val remoteFile = ror.resultData[0] - assertTrue( - path == ror.resultData[0].remotePath || - path == ror.resultData[1].remotePath - ) - - assertEquals(oldRemoteFile.remoteId, remoteFile.remoteId) - } - - @Test - fun propPatch() { - val path = "/testFolder/" - - // create folder - assertTrue(CreateFolderRemoteOperation(path, true).execute(client).isSuccess) - - // make it favorite - assertTrue( - ToggleFavoriteRemoteOperation(true, path).execute(nextcloudClient).isSuccess - ) - - val result = ReadFolderRemoteOperation(path).execute(client) - assertTrue(result.isSuccess) - val list = result.data as List - assertTrue(list[0].isFavorite) - } -} diff --git a/library/src/main/java/com/nextcloud/operations/PropFindMethod.kt b/library/src/main/java/com/nextcloud/operations/PropFindMethod.kt index f4e69fb1e7..5333db2a1e 100644 --- a/library/src/main/java/com/nextcloud/operations/PropFindMethod.kt +++ b/library/src/main/java/com/nextcloud/operations/PropFindMethod.kt @@ -1,60 +1,70 @@ -/* - * - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2023 Tobias Kaminsky - * Copyright (C) 2023 Nextcloud GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ +/* Nextcloud Android Library is available under MIT license +* +* @author Tobias Kaminsky +* Copyright (C) 2023 Tobias Kaminsky +* Copyright (C) 2023 Nextcloud 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.nextcloud.operations import android.net.Uri import at.bitfire.dav4jvm.DavResource +import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.Response import com.nextcloud.common.DavMethod import com.owncloud.android.lib.common.network.WebdavUtils import com.owncloud.android.lib.common.utils.WebDavFileUtils import okhttp3.HttpUrl import okhttp3.OkHttpClient -import org.apache.jackrabbit.webdav.DavConstants -class PropFindMethod(httpUrl: HttpUrl) : DavMethod(httpUrl) { +class PropFindMethod +@JvmOverloads constructor( + httpUrl: HttpUrl, + private val propertySet: Array = WebdavUtils.PROPERTYSETS.ALL, + private val depth: Int = 1 +) : DavMethod(httpUrl) { + override fun apply(client: OkHttpClient, httpUrl: HttpUrl, filesDavUri: Uri): PropFindResult { val webDavFileUtils = WebDavFileUtils() val result = PropFindResult() - DavResource(client, httpUrl) - .propfind( - DavConstants.DEPTH_1, - *WebdavUtils.getAllPropertiesList() - ) { response: Response, hrefRelation: Response.HrefRelation? -> - result.success = response.isSuccess() + DavResource(client, httpUrl).propfind( + depth, *propertySet + ) { response: Response, hrefRelation: Response.HrefRelation? -> + result.success = response.isSuccess() - when (hrefRelation) { - Response.HrefRelation.MEMBER -> result.children.add( - webDavFileUtils.parseResponse(response, filesDavUri) - ) + when (hrefRelation) { + Response.HrefRelation.MEMBER -> result.children.add( + webDavFileUtils.parseResponse(response, filesDavUri) + ) - Response.HrefRelation.SELF -> result.root = - webDavFileUtils.parseResponse(response, filesDavUri) + Response.HrefRelation.SELF -> result.root = + webDavFileUtils.parseResponse(response, filesDavUri) - Response.HrefRelation.OTHER -> {} - else -> {} - } + Response.HrefRelation.OTHER -> {} + else -> {} } + } return result } diff --git a/library/src/main/java/com/owncloud/android/lib/common/network/ExtendedProperties.kt b/library/src/main/java/com/owncloud/android/lib/common/network/ExtendedProperties.kt new file mode 100644 index 0000000000..90e1c4d47c --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/common/network/ExtendedProperties.kt @@ -0,0 +1,74 @@ +/* Nextcloud Android Library is available under MIT license +* +* @author ZetaZom +* Copyright (C) 2024 ZetaTom +* Copyright (C) 2024 Nextcloud 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.network + +import at.bitfire.dav4jvm.Property + +enum class ExtendedProperties(val value: String, val namespace: String) { + CREATION_TIME("creation_time", WebdavUtils.NAMESPACE_NC), + FAVORITE("favorite", WebdavUtils.NAMESPACE_OC), + HAS_PREVIEW("has-preview", WebdavUtils.NAMESPACE_NC), + HIDDEN("hidden", WebdavUtils.NAMESPACE_NC), + IS_ENCRYPTED("is-encrypted", WebdavUtils.NAMESPACE_NC), + LOCK("lock", WebdavUtils.NAMESPACE_NC), + LOCK_OWNER("lock-owner", WebdavUtils.NAMESPACE_NC), + LOCK_OWNER_DISPLAY_NAME("lock-owner-displayname", WebdavUtils.NAMESPACE_NC), + LOCK_OWNER_EDITOR("lock-owner-editor", WebdavUtils.NAMESPACE_NC), + LOCK_OWNER_TYPE("lock-owner-type", WebdavUtils.NAMESPACE_NC), + LOCK_TIME("lock-time", WebdavUtils.NAMESPACE_NC), + LOCK_TIMEOUT("lock-timeout", WebdavUtils.NAMESPACE_NC), + LOCK_TOKEN("lock-token", WebdavUtils.NAMESPACE_NC), + METADATA_GPS("file-metadata-gps", WebdavUtils.NAMESPACE_NC), + METADATA_LIVE_PHOTO("metadata-files-live-photo", WebdavUtils.NAMESPACE_NC), + METADATA_PHOTOS_GPS("metadata-photos-gps", WebdavUtils.NAMESPACE_NC), + METADATA_PHOTOS_SIZE("metadata-photos-size", WebdavUtils.NAMESPACE_NC), + METADATA_SIZE("file-metadata-size", WebdavUtils.NAMESPACE_NC), + MOUNT_TYPE("mount-type", WebdavUtils.NAMESPACE_NC), + NAME_LOCAL_ID("fileid", WebdavUtils.NAMESPACE_OC), + NAME_PERMISSIONS("permissions", WebdavUtils.NAMESPACE_OC), + NAME_REMOTE_ID("id", WebdavUtils.NAMESPACE_OC), + NAME_SIZE("size", WebdavUtils.NAMESPACE_OC), + NOTE("note", WebdavUtils.NAMESPACE_NC), + OWNER_DISPLAY_NAME("owner-display-name", WebdavUtils.NAMESPACE_OC), + OWNER_ID("owner-id", WebdavUtils.NAMESPACE_OC), + RICH_WORKSPACE("rich-workspace", WebdavUtils.NAMESPACE_NC), + SHAREES("sharees", WebdavUtils.NAMESPACE_NC), + SHAREES_DISPLAY_NAME("display-name", WebdavUtils.NAMESPACE_NC), + SHAREES_ID("id", WebdavUtils.NAMESPACE_NC), + SHAREES_SHARE_TYPE("type", WebdavUtils.NAMESPACE_NC), + SYSTEM_TAGS("system-tags", WebdavUtils.NAMESPACE_NC), + TRASHBIN_DELETION_TIME("trashbin-deletion-time", WebdavUtils.NAMESPACE_NC), + TRASHBIN_FILENAME("trashbin-filename", WebdavUtils.NAMESPACE_NC), + TRASHBIN_ORIGINAL_LOCATION("trashbin-original-location", WebdavUtils.NAMESPACE_NC), + UNREAD_COMMENTS("comments-unread", WebdavUtils.NAMESPACE_OC), + UPLOAD_TIME("upload_time", WebdavUtils.NAMESPACE_NC); + + fun toPropertyName(): Property.Name { + return Property.Name(namespace, value) + } +} \ No newline at end of file diff --git a/library/src/main/java/com/owncloud/android/lib/common/network/WebdavEntry.java b/library/src/main/java/com/owncloud/android/lib/common/network/WebdavEntry.java deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/library/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java b/library/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java deleted file mode 100644 index a3051b0dc3..0000000000 --- a/library/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.java +++ /dev/null @@ -1,363 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2015 ownCloud Inc. - * Copyright (C) 2012 Bartek Przybylski - * - * 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.network; - -import android.net.Uri; - -import androidx.annotation.Nullable; - -import com.owncloud.android.lib.resources.files.webdav.NCEtag; -import com.owncloud.android.lib.resources.files.webdav.NCFavorite; -import com.owncloud.android.lib.resources.files.webdav.NCGetLastModified; -import com.owncloud.android.lib.resources.files.webdav.NCMountType; -import com.owncloud.android.lib.resources.files.webdav.NCPermissions; -import com.owncloud.android.lib.resources.files.webdav.NCRichWorkspace; -import com.owncloud.android.lib.resources.files.webdav.NCSharee; -import com.owncloud.android.lib.resources.files.webdav.NCTags; -import com.owncloud.android.lib.resources.files.webdav.OCId; -import com.owncloud.android.lib.resources.files.webdav.OCLocalId; -import com.owncloud.android.lib.resources.files.webdav.OCOwnerDisplayName; -import com.owncloud.android.lib.resources.files.webdav.OCOwnerId; -import com.owncloud.android.lib.resources.files.webdav.OCSize; - -import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.HttpMethod; -import org.apache.jackrabbit.webdav.property.DavPropertyName; -import org.apache.jackrabbit.webdav.property.DavPropertyNameSet; -import org.apache.jackrabbit.webdav.xml.Namespace; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -import at.bitfire.dav4jvm.Property; -import at.bitfire.dav4jvm.PropertyFactory; -import at.bitfire.dav4jvm.PropertyRegistry; -import at.bitfire.dav4jvm.property.CreationDate; -import at.bitfire.dav4jvm.property.DisplayName; -import at.bitfire.dav4jvm.property.GetContentLength; -import at.bitfire.dav4jvm.property.GetContentType; -import at.bitfire.dav4jvm.property.GetETag; -import at.bitfire.dav4jvm.property.ResourceType; - -public class WebdavUtils { - private static final SimpleDateFormat DATETIME_FORMATS[] = { - new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US), - new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US), - new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sss'Z'", Locale.US), - new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US), - new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US), - new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US), - new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US), - new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.US) - }; - - public static @Nullable - Date parseResponseDate(String date) { - Date returnDate; - SimpleDateFormat format; - for (int i = 0; i < DATETIME_FORMATS.length; ++i) { - try { - format = DATETIME_FORMATS[i]; - synchronized (format) { - returnDate = format.parse(date); - } - return returnDate; - } catch (ParseException e) { - // this is not the format - } - } - return null; - } - - /** - * Encodes a path according to URI RFC 2396. - *

- * If the received path doesn't start with "/", the method adds it. - * - * @param remoteFilePath Path - * @return Encoded path according to RFC 2396, always starting with "/" - */ - public static String encodePath(String remoteFilePath) { - String encodedPath = Uri.encode(remoteFilePath, "/"); - if (!encodedPath.startsWith("/")) { - encodedPath = "/" + encodedPath; - } - return encodedPath; - } - - /** - * Builds a DavPropertyNameSet with all prop For using instead of DavConstants.PROPFIND_ALL_PROP - * - * @return - */ - public static DavPropertyNameSet getAllPropSet() { - Namespace ocNamespace = Namespace.getNamespace(WebdavEntry.NAMESPACE_OC); - Namespace ncNamespace = Namespace.getNamespace(WebdavEntry.NAMESPACE_NC); - DavPropertyNameSet propSet = new DavPropertyNameSet(); - - propSet.add(DavPropertyName.DISPLAYNAME); - propSet.add(DavPropertyName.GETCONTENTTYPE); - propSet.add(DavPropertyName.RESOURCETYPE); - propSet.add(DavPropertyName.GETCONTENTLENGTH); - propSet.add(DavPropertyName.GETLASTMODIFIED); - propSet.add(DavPropertyName.CREATIONDATE); - propSet.add(DavPropertyName.GETETAG); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_PERMISSIONS, ocNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_LOCAL_ID, ocNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_REMOTE_ID, ocNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, ocNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_FAVORITE, ocNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_IS_ENCRYPTED, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_MOUNT_TYPE, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_OWNER_ID, ocNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_OWNER_DISPLAY_NAME, ocNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_UNREAD_COMMENTS, ocNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_HAS_PREVIEW, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_NOTE, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_SHAREES, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_RICH_WORKSPACE, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_CREATION_TIME, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_UPLOAD_TIME, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_OWNER_TYPE, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_OWNER, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_OWNER_DISPLAY_NAME, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_OWNER_EDITOR, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TIME, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TIMEOUT, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TOKEN, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_SYSTEM_TAGS, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_METADATA_SIZE, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_METADATA_GPS, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_METADATA_PHOTOS_SIZE, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_METADATA_PHOTOS_GPS, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_METADATA_LIVE_PHOTO, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_HIDDEN, ncNamespace); - - return propSet; - } - - public static Property.Name[] getAllPropertiesList() { - // TODO re-enable all - List list = new ArrayList<>(); - - list.add(DisplayName.NAME); - list.add(GetContentType.NAME); - list.add(ResourceType.NAME); - list.add(GetContentLength.NAME); - list.add(NCGetLastModified.NAME); - list.add(CreationDate.NAME); - list.add(GetETag.NAME); // list.add(NCEtag.NAME); - list.add(NCPermissions.NAME); - list.add(OCLocalId.NAME); -// propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_REMOTE_ID, ocNamespace); - list.add(OCSize.NAME); - list.add(NCFavorite.NAME); -// list.add(NCEncrypted.NAME); - list.add(NCMountType.NAME); - list.add(OCOwnerId.NAME); - list.add(OCOwnerDisplayName.NAME); -// list.add(new Property.Name(OC_NAMESPACE, EXTENDED_PROPERTY_UNREAD_COMMENTS)); -// list.add(NCPreview.NAME); -// list.add(new Property.Name(NC_NAMESPACE, EXTENDED_PROPERTY_NOTE)); - list.add(NCSharee.NAME); - list.add(NCRichWorkspace.NAME); - list.add(CreationDate.NAME); -// propSet.add(WebdavEntry.EXTENDED_PROPERTY_UPLOAD_TIME, ncNamespace); -// propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK, ncNamespace); -// propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_OWNER_TYPE, ncNamespace); -// propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_OWNER, ncNamespace); -// propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_OWNER_DISPLAY_NAME, ncNamespace); -// propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_OWNER_EDITOR, ncNamespace); -// propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TIME, ncNamespace); -// propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TIMEOUT, ncNamespace); -// propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TOKEN, ncNamespace); - list.add(NCTags.NAME); - // metadata size - // metadata gps - list.add(OCId.NAME); // what about this? - - return list.toArray(new Property.Name[0]); - } - - /** - * Builds a DavPropertyNameSet with properties for files - * - * @return - */ - public static DavPropertyNameSet getFilePropSet() { - Namespace ocNamespace = Namespace.getNamespace(WebdavEntry.NAMESPACE_OC); - Namespace ncNamespace = Namespace.getNamespace(WebdavEntry.NAMESPACE_NC); - DavPropertyNameSet propSet = new DavPropertyNameSet(); - - propSet.add(DavPropertyName.DISPLAYNAME); - propSet.add(DavPropertyName.GETCONTENTTYPE); - propSet.add(DavPropertyName.RESOURCETYPE); - propSet.add(DavPropertyName.GETCONTENTLENGTH); - propSet.add(DavPropertyName.GETLASTMODIFIED); - propSet.add(DavPropertyName.CREATIONDATE); - propSet.add(DavPropertyName.GETETAG); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_PERMISSIONS, ocNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_LOCAL_ID, ocNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_REMOTE_ID, ocNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, ocNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_FAVORITE, ocNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_HAS_PREVIEW, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_SHAREES, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_CREATION_TIME, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_UPLOAD_TIME, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_OWNER_TYPE, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_OWNER, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_OWNER_DISPLAY_NAME, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_OWNER_EDITOR, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TIME, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TIMEOUT, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_LOCK_TOKEN, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_IS_ENCRYPTED, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_SYSTEM_TAGS, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_METADATA_SIZE, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_METADATA_GPS, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_METADATA_PHOTOS_SIZE, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_METADATA_PHOTOS_GPS, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_METADATA_LIVE_PHOTO, ncNamespace); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_HIDDEN, ncNamespace); - - return propSet; - } - - /** - * Builds a DavPropertyNameSet with properties for trashbin - * - * @return - */ - public static DavPropertyNameSet getTrashbinPropSet() { - DavPropertyNameSet propSet = new DavPropertyNameSet(); - propSet.add(DavPropertyName.RESOURCETYPE); - propSet.add(DavPropertyName.GETCONTENTTYPE); - propSet.add(DavPropertyName.GETCONTENTLENGTH); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_REMOTE_ID, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); - propSet.add(WebdavEntry.TRASHBIN_FILENAME, Namespace.getNamespace(WebdavEntry.NAMESPACE_NC)); - propSet.add(WebdavEntry.TRASHBIN_ORIGINAL_LOCATION, Namespace.getNamespace(WebdavEntry.NAMESPACE_NC)); - propSet.add(WebdavEntry.TRASHBIN_DELETION_TIME, Namespace.getNamespace(WebdavEntry.NAMESPACE_NC)); - - return propSet; - } - - /** - * Builds a DavPropertyNameSet with properties for versions - * - * @return - */ - public static DavPropertyNameSet getFileVersionPropSet() { - DavPropertyNameSet propSet = new DavPropertyNameSet(); - propSet.add(DavPropertyName.GETCONTENTTYPE); - propSet.add(DavPropertyName.RESOURCETYPE); - propSet.add(DavPropertyName.GETCONTENTLENGTH); - propSet.add(DavPropertyName.GETLASTMODIFIED); - propSet.add(DavPropertyName.CREATIONDATE); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_REMOTE_ID, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); - propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); - - return propSet; - } - - /** - * Builds a DavPropertyNameSet with properties for chunks - */ - public static DavPropertyNameSet getChunksPropSet() { - DavPropertyNameSet propSet = new DavPropertyNameSet(); - propSet.add(DavPropertyName.GETCONTENTTYPE); - propSet.add(DavPropertyName.RESOURCETYPE); - propSet.add(DavPropertyName.GETCONTENTLENGTH); - - return propSet; - } - - /** - * @param rawEtag - * @return - */ - public static String parseEtag(String rawEtag) { - if (rawEtag == null || rawEtag.length() == 0) { - return ""; - } - if (rawEtag.endsWith("-gzip")) { - rawEtag = rawEtag.substring(0, rawEtag.length() - 5); - } - if (rawEtag.length() >= 2 && rawEtag.startsWith("\"") && rawEtag.endsWith("\"")) { - rawEtag = rawEtag.substring(1, rawEtag.length() - 1); - } - return rawEtag; - } - - - /** - * @param method - * @return - */ - public static String getEtagFromResponse(HttpMethod method) { - Header eTag = method.getResponseHeader("OC-ETag"); - if (eTag == null) { - eTag = method.getResponseHeader("oc-etag"); - } - if (eTag == null) { - eTag = method.getResponseHeader("ETag"); - } - if (eTag == null) { - eTag = method.getResponseHeader("etag"); - } - String result = ""; - if (eTag != null) { - result = parseEtag(eTag.getValue()); - } - return result; - } - - public static void registerCustomFactories() { - List list = new ArrayList<>(); - list.add(new NCFavorite.Factory()); - list.add(new NCGetLastModified.Factory()); - list.add(new NCEtag.Factory()); - list.add(new NCPermissions.Factory()); - list.add(new OCId.Factory()); - list.add(new OCSize.Factory()); - list.add(new NCMountType.Factory()); - list.add(new OCOwnerId.Factory()); - list.add(new OCOwnerDisplayName.Factory()); - list.add(new NCRichWorkspace.Factory()); - list.add(new NCSharee.Factory()); - list.add(new NCTags.Factory()); - list.add(new OCLocalId.Factory()); - - PropertyRegistry.INSTANCE.register(list); - } -} diff --git a/library/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.kt b/library/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.kt new file mode 100644 index 0000000000..67d250e392 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/common/network/WebdavUtils.kt @@ -0,0 +1,273 @@ +/* Nextcloud Android Library is available under MIT license +* +* @author ZetaZom +* Copyright (C) 2024 ZetaTom +* Copyright (C) 2024 Nextcloud 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.network + +import android.net.Uri +import at.bitfire.dav4jvm.PropertyRegistry.register +import at.bitfire.dav4jvm.property.CreationDate +import at.bitfire.dav4jvm.property.DisplayName +import at.bitfire.dav4jvm.property.GetContentLength +import at.bitfire.dav4jvm.property.GetContentType +import at.bitfire.dav4jvm.property.ResourceType +import com.google.gson.Gson +import com.owncloud.android.lib.resources.files.webdav.NCCreationTime +import com.owncloud.android.lib.resources.files.webdav.NCEncrypted +import com.owncloud.android.lib.resources.files.webdav.NCEtag +import com.owncloud.android.lib.resources.files.webdav.NCFavorite +import com.owncloud.android.lib.resources.files.webdav.NCGetLastModified +import com.owncloud.android.lib.resources.files.webdav.NCHidden +import com.owncloud.android.lib.resources.files.webdav.NCLock +import com.owncloud.android.lib.resources.files.webdav.NCLockOwner +import com.owncloud.android.lib.resources.files.webdav.NCLockOwnerDisplayName +import com.owncloud.android.lib.resources.files.webdav.NCLockOwnerEditor +import com.owncloud.android.lib.resources.files.webdav.NCLockOwnerType +import com.owncloud.android.lib.resources.files.webdav.NCLockTime +import com.owncloud.android.lib.resources.files.webdav.NCLockTimeout +import com.owncloud.android.lib.resources.files.webdav.NCLockToken +import com.owncloud.android.lib.resources.files.webdav.NCMetadataGPS +import com.owncloud.android.lib.resources.files.webdav.NCMetadataLivePhoto +import com.owncloud.android.lib.resources.files.webdav.NCMetadataPhotosGPS +import com.owncloud.android.lib.resources.files.webdav.NCMetadataPhotosSize +import com.owncloud.android.lib.resources.files.webdav.NCMetadataSize +import com.owncloud.android.lib.resources.files.webdav.NCMountType +import com.owncloud.android.lib.resources.files.webdav.NCNote +import com.owncloud.android.lib.resources.files.webdav.NCPermissions +import com.owncloud.android.lib.resources.files.webdav.NCPreview +import com.owncloud.android.lib.resources.files.webdav.NCRichWorkspace +import com.owncloud.android.lib.resources.files.webdav.NCSharees +import com.owncloud.android.lib.resources.files.webdav.NCTags +import com.owncloud.android.lib.resources.files.webdav.NCTrashbinDeletionTime +import com.owncloud.android.lib.resources.files.webdav.NCTrashbinFilename +import com.owncloud.android.lib.resources.files.webdav.NCTrashbinLocation +import com.owncloud.android.lib.resources.files.webdav.NCUploadTime +import com.owncloud.android.lib.resources.files.webdav.OCCommentsUnread +import com.owncloud.android.lib.resources.files.webdav.OCId +import com.owncloud.android.lib.resources.files.webdav.OCLocalId +import com.owncloud.android.lib.resources.files.webdav.OCOwnerDisplayName +import com.owncloud.android.lib.resources.files.webdav.OCOwnerId +import com.owncloud.android.lib.resources.files.webdav.OCSize +import org.apache.commons.httpclient.HttpMethod +import java.text.ParseException +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale + +object WebdavUtils { + const val NAMESPACE_OC = "http://owncloud.org/ns" + const val NAMESPACE_NC = "http://nextcloud.org/ns" + + internal val gson = Gson() + + private val DATETIME_FORMATS = arrayOf( + SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US), + SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US), + SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sss'Z'", Locale.US), + SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US), + SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US), + SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US), + SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US), + SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.US) + ) + + object PROPERTYSETS { + val ALL = arrayOf( + DisplayName.NAME, + GetContentType.NAME, + ResourceType.NAME, + GetContentLength.NAME, + NCGetLastModified.NAME, + CreationDate.NAME, + NCEtag.NAME, + NCPermissions.NAME, + OCLocalId.NAME, + OCId.NAME, + OCSize.NAME, + NCFavorite.NAME, + NCEncrypted.NAME, + NCMountType.NAME, + OCOwnerId.NAME, + OCOwnerDisplayName.NAME, + OCCommentsUnread.NAME, + NCPreview.NAME, + NCNote.NAME, + NCSharees.NAME, + NCRichWorkspace.NAME, + NCCreationTime.NAME, + NCUploadTime.NAME, + NCLock.NAME, + NCLockOwnerType.NAME, + NCLockOwner.NAME, + NCLockOwnerDisplayName.NAME, + NCLockOwnerEditor.NAME, + NCLockTime.NAME, + NCLockTimeout.NAME, + NCLockToken.NAME, + NCTags.NAME, + NCMetadataSize.NAME, + NCMetadataGPS.NAME, + NCMetadataSize.NAME, + NCMetadataPhotosSize.NAME, + NCMetadataPhotosGPS.NAME, + NCMetadataLivePhoto.NAME, + NCHidden.NAME + ) + + val FILE = arrayOf( + DisplayName.NAME, + GetContentType.NAME, + ResourceType.NAME, + GetContentLength.NAME, + NCGetLastModified.NAME, + CreationDate.NAME, + NCEtag.NAME, + NCPermissions.NAME, + OCLocalId.NAME, + OCId.NAME, + OCSize.NAME, + NCFavorite.NAME, + NCPreview.NAME, + NCSharees.NAME, + NCCreationTime.NAME, + NCUploadTime.NAME, + NCLock.NAME, + NCLockOwnerType.NAME, + NCLockOwner.NAME, + NCLockOwnerDisplayName.NAME, + NCLockOwnerEditor.NAME, + NCLockTime.NAME, + NCLockTimeout.NAME, + NCLockToken.NAME, + NCEncrypted.NAME, + NCTags.NAME, + NCMetadataSize.NAME, + NCMetadataGPS.NAME, + NCMetadataPhotosSize.NAME, + NCMetadataPhotosGPS.NAME, + NCMetadataLivePhoto.NAME, + NCHidden.NAME + ) + + val TRASHBIN = arrayOf( + ResourceType.NAME, + GetContentType.NAME, + GetContentLength.NAME, + OCSize.NAME, + OCId.NAME, + NCTrashbinFilename.NAME, + NCTrashbinLocation.NAME, + NCTrashbinDeletionTime.NAME + ) + + val FILE_VERSION = arrayOf( + GetContentType.NAME, + ResourceType.NAME, + GetContentLength.NAME, + NCGetLastModified.NAME, + CreationDate.NAME, + OCId.NAME, + OCSize.NAME + ) + + val CHUNK = arrayOf( + GetContentType.NAME, + ResourceType.NAME, + GetContentLength.NAME + ) + } + + fun parseResponseDate(date: String?): Date? { + for (format in DATETIME_FORMATS) { + try { + date?.let { return format.parse(it) } + } catch (e: ParseException) { + // this is not the format + } + } + return null + } + + /** + * Encodes a path according to URI RFC 2396. + * + * + * If the received path doesn't start with "/", the method adds it. + * + * @param remoteFilePath Path + * @return Encoded path according to RFC 2396, always starting with "/" + */ + fun encodePath(remoteFilePath: String?): String { + val encodedPath = Uri.encode(remoteFilePath, "/") + if (!encodedPath.startsWith("/")) { + return "/$encodedPath" + } + return encodedPath + } + + fun parseEtag(etag: String?): String { + if (etag.isNullOrEmpty()) { + return "" + } + return etag.removeSuffix("-gzip").removeSurrounding("\"") + } + + fun getEtagFromResponse(method: HttpMethod): String { + var eTag = method.getResponseHeader("OC-ETag") + if (eTag == null) { + eTag = method.getResponseHeader("oc-etag") + } + if (eTag == null) { + eTag = method.getResponseHeader("ETag") + } + if (eTag == null) { + eTag = method.getResponseHeader("etag") + } + if (eTag != null) { + return parseEtag(eTag.value) + } + return "" + } + + fun registerCustomFactories() { + val list = listOf( + NCFavorite.Factory(), + NCGetLastModified.Factory(), + NCEtag.Factory(), + NCPermissions.Factory(), + OCId.Factory(), + OCSize.Factory(), + NCMountType.Factory(), + OCOwnerId.Factory(), + OCOwnerDisplayName.Factory(), + NCRichWorkspace.Factory(), + NCSharees.Factory(), + NCTags.Factory(), + OCLocalId.Factory() + ) + register(list) + } +} \ No newline at end of file diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/model/FileLockType.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/model/FileLockType.kt index cb40b26263..790a0e54ad 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/model/FileLockType.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/model/FileLockType.kt @@ -14,6 +14,6 @@ enum class FileLockType(val value: Int) { companion object { @JvmStatic - fun fromValue(v: Int): FileLockType? = values().firstOrNull { it.value == v } + fun fromValue(v: Int): FileLockType? = entries.firstOrNull { it.value == v } } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCCreationTime.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCCreationTime.kt new file mode 100644 index 0000000000..8a86c4dfa9 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCCreationTime.kt @@ -0,0 +1,52 @@ +/* Nextcloud Android Library is available under MIT license +* +* @author ZetaZom +* Copyright (C) 2024 ZetaTom +* Copyright (C) 2024 Nextcloud 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.webdav + +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils +import com.owncloud.android.lib.common.network.ExtendedProperties +import org.xmlpull.v1.XmlPullParser + +class NCCreationTime private constructor(val creationTime: Long) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + XmlUtils.readText(parser)?.let { date -> + return NCCreationTime(date.toLong()) + } + return NCCreationTime(0) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.CREATION_TIME.toPropertyName() + } +} \ No newline at end of file diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCEncrypted.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCEncrypted.kt index af73fbd145..1698c4febf 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCEncrypted.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCEncrypted.kt @@ -1,22 +1,49 @@ +/* Nextcloud Android Library is available under MIT license +* +* @author Tobias Kaminsky +* Copyright (C) 2022 Tobias Kaminsky +* Copyright (C) 2022 Nextcloud 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.webdav -import android.text.TextUtils import android.util.Log import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.PropertyFactory import at.bitfire.dav4jvm.XmlUtils -import com.owncloud.android.lib.common.network.WebdavEntry +import com.owncloud.android.lib.common.network.ExtendedProperties import org.xmlpull.v1.XmlPullParser import org.xmlpull.v1.XmlPullParserException import java.io.IOException -class NCEncrypted private constructor(var isNcEncrypted: Boolean) : Property { - +class NCEncrypted private constructor(val encrypted: Boolean) : Property { class Factory : PropertyFactory { + override fun getName() = NAME + override fun create(parser: XmlPullParser): Property { try { val text = XmlUtils.readText(parser) - if (!TextUtils.isEmpty(text)) { + if (!text.isNullOrEmpty()) { return NCEncrypted("1" == text) } } catch (e: IOException) { @@ -26,15 +53,10 @@ class NCEncrypted private constructor(var isNcEncrypted: Boolean) : Property { } return NCEncrypted(false) } - - override fun getName(): Property.Name { - return NAME - } } companion object { @JvmField - val NAME: Property.Name = - Property.Name(WebdavEntry.NAMESPACE_NC, WebdavEntry.EXTENDED_PROPERTY_IS_ENCRYPTED) + val NAME = ExtendedProperties.IS_ENCRYPTED.toPropertyName() } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCEtag.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCEtag.kt index ba81292cd8..c4184fe3ff 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCEtag.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCEtag.kt @@ -1,24 +1,29 @@ -/* - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2022 Tobias Kaminsky - * Copyright (C) 2022 Nextcloud GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ +/* Nextcloud Android Library is available under MIT license +* +* @author Tobias Kaminsky +* Copyright (C) 2022 Tobias Kaminsky +* Copyright (C) 2022 Nextcloud 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.webdav @@ -28,23 +33,21 @@ import at.bitfire.dav4jvm.XmlUtils import com.owncloud.android.lib.common.network.WebdavUtils import org.xmlpull.v1.XmlPullParser -class NCEtag internal constructor(var etag: String) : Property { - - companion object { - @JvmField - val NAME = Property.Name(XmlUtils.NS_WEBDAV, "getetag") - } - +class NCEtag private constructor(val etag: String?) : Property { class Factory : PropertyFactory { - override fun getName() = NAME - override fun create(parser: XmlPullParser): NCEtag? { + override fun create(parser: XmlPullParser): NCEtag { // XmlUtils.readText(parser)?.let { rawEtag -> return NCEtag(WebdavUtils.parseEtag(rawEtag)) } - return null + return NCEtag(null) } } + + companion object { + @JvmField + val NAME = Property.Name(XmlUtils.NS_WEBDAV, "getetag") + } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCFavorite.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCFavorite.kt index 429ef5e878..1369c79cdc 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCFavorite.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCFavorite.kt @@ -1,44 +1,49 @@ -/* - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2022 Tobias Kaminsky - * Copyright (C) 2022 Nextcloud GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ +/* Nextcloud Android Library is available under MIT license +* +* @author Tobias Kaminsky +* Copyright (C) 2022 Tobias Kaminsky +* Copyright (C) 2022 Nextcloud 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.webdav -import android.text.TextUtils import android.util.Log import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.PropertyFactory import at.bitfire.dav4jvm.XmlUtils.readText -import com.owncloud.android.lib.common.network.WebdavEntry +import com.owncloud.android.lib.common.network.ExtendedProperties import org.xmlpull.v1.XmlPullParser import org.xmlpull.v1.XmlPullParserException import java.io.IOException -class NCFavorite internal constructor(var isOcFavorite: Boolean) : Property { - +class NCFavorite private constructor(val favorite: Boolean) : Property { class Factory : PropertyFactory { + override fun getName() = NAME + override fun create(parser: XmlPullParser): Property { try { val text = readText(parser) - if (!TextUtils.isEmpty(text)) { + if (!text.isNullOrEmpty()) { return NCFavorite("1" == text) } } catch (e: IOException) { @@ -48,13 +53,10 @@ class NCFavorite internal constructor(var isOcFavorite: Boolean) : Property { } return NCFavorite(false) } - - override fun getName() = NAME } companion object { @JvmField - val NAME: Property.Name = - Property.Name(WebdavEntry.NAMESPACE_OC, WebdavEntry.EXTENDED_PROPERTY_FAVORITE) + val NAME = ExtendedProperties.FAVORITE.toPropertyName() } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCGetLastModified.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCGetLastModified.kt index 5d761a9ab6..46b7f9d046 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCGetLastModified.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCGetLastModified.kt @@ -1,24 +1,29 @@ -/* - * - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2023 Tobias Kaminsky - * Copyright (C) 2023 Nextcloud GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ +/* Nextcloud Android Library is available under MIT license +* +* @author Tobias Kaminsky +* Copyright (C) 2023 Tobias Kaminsky +* Copyright (C) 2023 Nextcloud 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.webdav @@ -28,23 +33,19 @@ import at.bitfire.dav4jvm.XmlUtils import com.owncloud.android.lib.common.network.WebdavUtils import org.xmlpull.v1.XmlPullParser -class NCGetLastModified internal constructor(var lastModified: Long) : Property { - +class NCGetLastModified private constructor(val lastModified: Long) : Property { class Factory : PropertyFactory { - override fun getName() = NAME - override fun create(parser: XmlPullParser): NCGetLastModified? { + override fun create(parser: XmlPullParser): NCGetLastModified { // XmlUtils.readText(parser)?.let { rawDate -> val date = WebdavUtils.parseResponseDate(rawDate) if (date != null) { return NCGetLastModified(date.time) - } else { - 0 } } - return null + return NCGetLastModified(0) } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCHidden.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCHidden.kt new file mode 100644 index 0000000000..c806438791 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCHidden.kt @@ -0,0 +1,62 @@ +/* Nextcloud Android Library is available under MIT license +* +* @author ZetaZom +* Copyright (C) 2024 ZetaTom +* Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils +import com.owncloud.android.lib.common.network.ExtendedProperties +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCHidden private constructor(val hidden: Boolean) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + try { + val text = XmlUtils.readText(parser) + if (!text.isNullOrEmpty()) { + return NCHidden("1" == text) + } + } catch (e: IOException) { + Log.e("NCEncrypted", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCEncrypted", "failed to create property", e) + } + return NCHidden(false) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.HIDDEN.toPropertyName() + } +} \ No newline at end of file diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLock.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLock.kt new file mode 100644 index 0000000000..914cf95e53 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLock.kt @@ -0,0 +1,62 @@ +/* Nextcloud Android Library is available under MIT license +* +* @author ZetaZom +* Copyright (C) 2024 ZetaTom +* Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils +import com.owncloud.android.lib.common.network.ExtendedProperties +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCLock private constructor(val locked: Boolean) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + try { + val text = XmlUtils.readText(parser) + if (!text.isNullOrEmpty()) { + return NCLock("1" == text) + } + } catch (e: IOException) { + Log.e("NCEncrypted", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCEncrypted", "failed to create property", e) + } + return NCLock(false) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.LOCK.toPropertyName() + } +} \ No newline at end of file diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockOwner.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockOwner.kt new file mode 100644 index 0000000000..db8763cd1f --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockOwner.kt @@ -0,0 +1,62 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author ZetaTom + * Copyright (C) 2024 ZetaTom + * Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils.readText +import com.owncloud.android.lib.common.network.ExtendedProperties +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCLockOwner private constructor(val lockOwner: String?) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + try { + val text = readText(parser) + if (!text.isNullOrEmpty()) { + return NCLockOwner(text) + } + } catch (e: IOException) { + Log.e("NCLockOwner", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCLockOwner", "failed to create property", e) + } + return NCLockOwner(null) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.LOCK_OWNER.toPropertyName() + } +} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockOwnerDisplayName.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockOwnerDisplayName.kt new file mode 100644 index 0000000000..f1064fd697 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockOwnerDisplayName.kt @@ -0,0 +1,62 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author ZetaTom + * Copyright (C) 2024 ZetaTom + * Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils.readText +import com.owncloud.android.lib.common.network.ExtendedProperties +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCLockOwnerDisplayName private constructor(val lockOwnerDisplayName: String) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + try { + val text = readText(parser) + if (!text.isNullOrEmpty()) { + return NCLockOwnerDisplayName(text) + } + } catch (e: IOException) { + Log.e("NCOwnerDisplayName", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCOwnerDisplayName", "failed to create property", e) + } + return NCLockOwnerDisplayName("") + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.LOCK_OWNER_DISPLAY_NAME.toPropertyName() + } +} \ No newline at end of file diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockOwnerEditor.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockOwnerEditor.kt new file mode 100644 index 0000000000..528bef6d1b --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockOwnerEditor.kt @@ -0,0 +1,62 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author ZetaTom + * Copyright (C) 2024 ZetaTom + * Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils.readText +import com.owncloud.android.lib.common.network.ExtendedProperties +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCLockOwnerEditor private constructor(val lockOwnerEditor: String?) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + try { + val text = readText(parser) + if (!text.isNullOrEmpty()) { + return NCLockOwnerEditor(text) + } + } catch (e: IOException) { + Log.e("NCLockOwnerEditor", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCLockOwnerEditor", "failed to create property", e) + } + return NCLockOwnerEditor(null) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.LOCK_OWNER_EDITOR.toPropertyName() + } +} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockOwnerType.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockOwnerType.kt new file mode 100644 index 0000000000..8fed656dff --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockOwnerType.kt @@ -0,0 +1,63 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author ZetaTom + * Copyright (C) 2024 ZetaTom + * Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils.readText +import com.owncloud.android.lib.common.network.ExtendedProperties +import com.owncloud.android.lib.resources.files.model.FileLockType +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCLockOwnerType private constructor(val lockOwnerType: FileLockType?) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + try { + val text = readText(parser) + if (!text.isNullOrEmpty()) { + return NCLockOwnerType(FileLockType.fromValue(text.toInt())) + } + } catch (e: IOException) { + Log.e("NCLockOwnerType", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCLockOwnerType", "failed to create property", e) + } + return NCLockOwnerType(null) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.LOCK_OWNER_TYPE.toPropertyName() + } +} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockTime.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockTime.kt new file mode 100644 index 0000000000..8f27e79533 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockTime.kt @@ -0,0 +1,52 @@ +/* Nextcloud Android Library is available under MIT license +* +* @author ZetaZom +* Copyright (C) 2024 ZetaTom +* Copyright (C) 2024 Nextcloud 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.webdav + +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils +import com.owncloud.android.lib.common.network.ExtendedProperties +import org.xmlpull.v1.XmlPullParser + +class NCLockTime private constructor(val lockTime: Long) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + XmlUtils.readText(parser)?.let { date -> + return NCLockTime(date.toLong()) + } + return NCLockTime(0) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.LOCK_TIME.toPropertyName() + } +} \ No newline at end of file diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockTimeout.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockTimeout.kt new file mode 100644 index 0000000000..d3a384633d --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockTimeout.kt @@ -0,0 +1,62 @@ +/* Nextcloud Android Library is available under MIT license +* +* @author ZetaZom +* Copyright (C) 2024 ZetaTom +* Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils.readText +import com.owncloud.android.lib.common.network.ExtendedProperties +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCLockTimeout private constructor(val lockTimeout: Long) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + try { + val text = readText(parser) + if (!text.isNullOrEmpty()) { + return NCLockTimeout(text.toLong()) + } + } catch (e: IOException) { + Log.e("NCLockTimeout", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCLockTimeout", "failed to create property", e) + } + return NCLockTimeout(0) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.LOCK_TIMEOUT.toPropertyName() + } +} \ No newline at end of file diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockToken.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockToken.kt new file mode 100644 index 0000000000..cdcc9e38c2 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCLockToken.kt @@ -0,0 +1,62 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author ZetaTom + * Copyright (C) 2024 ZetaTom + * Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils.readText +import com.owncloud.android.lib.common.network.ExtendedProperties +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCLockToken private constructor(val lockToken: String?) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + try { + val text = readText(parser) + if (!text.isNullOrEmpty()) { + return NCLockToken(text) + } + } catch (e: IOException) { + Log.e("NCLockToken", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCLockToken", "failed to create property", e) + } + return NCLockToken(null) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.LOCK_TOKEN.toPropertyName() + } +} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMetadataGPS.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMetadataGPS.kt new file mode 100644 index 0000000000..6cae54efaf --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMetadataGPS.kt @@ -0,0 +1,65 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author ZetaTom + * Copyright (C) 2024 ZetaTom + * Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils +import com.google.gson.Gson +import com.owncloud.android.lib.common.network.ExtendedProperties +import com.owncloud.android.lib.resources.files.model.GeoLocation +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCMetadataGPS private constructor(val geoLocation: GeoLocation?) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + try { + val text = XmlUtils.readText(parser) + if (!text.isNullOrEmpty()) { + val geoLocation = Gson().fromJson(text, GeoLocation::class.java) + return NCMetadataGPS(geoLocation) + } + } catch (e: IOException) { + Log.e("NCMetadataGPS", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCMetadataGPS", "failed to create property", e) + } + return NCMetadataGPS(null) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.METADATA_GPS.toPropertyName() + } +} \ No newline at end of file diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMetadataLivePhoto.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMetadataLivePhoto.kt new file mode 100644 index 0000000000..fc129599c6 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMetadataLivePhoto.kt @@ -0,0 +1,62 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author ZetaTom + * Copyright (C) 2024 ZetaTom + * Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils.readText +import com.owncloud.android.lib.common.network.ExtendedProperties +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCMetadataLivePhoto private constructor(val livePhoto: String?) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + try { + val text = readText(parser) + if (!text.isNullOrEmpty()) { + return NCMetadataLivePhoto(text) + } + } catch (e: IOException) { + Log.e("NCOwnerDisplayName", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCOwnerDisplayName", "failed to create property", e) + } + return NCMetadataLivePhoto(null) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.METADATA_LIVE_PHOTO.toPropertyName() + } +} \ No newline at end of file diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMetadataPhotosGPS.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMetadataPhotosGPS.kt new file mode 100644 index 0000000000..bdcc99b0d2 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMetadataPhotosGPS.kt @@ -0,0 +1,81 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author ZetaTom + * Copyright (C) 2024 ZetaTom + * Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils.propertyName +import at.bitfire.dav4jvm.XmlUtils.readText +import com.owncloud.android.lib.common.network.ExtendedProperties +import com.owncloud.android.lib.resources.files.model.GeoLocation +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCMetadataPhotosGPS private constructor(val geoLocation: GeoLocation) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + return NCMetadataPhotosGPS(parseText(parser)) + } + + private fun parseText(parser: XmlPullParser): GeoLocation { + var latitude = 0.0 + var longitude = 0.0 + + val depth = parser.depth + var eventType = parser.eventType + + try { + while (eventType != XmlPullParser.END_TAG || parser.depth != depth) { + if (eventType != XmlPullParser.TEXT) { + when (parser.propertyName().name) { + "latitude" -> readText(parser)?.let { latitude = it.toDouble() } + "longitude" -> readText(parser)?.let { longitude = it.toDouble() } + } + } + + eventType = parser.next() + } + } catch (e: IOException) { + Log.e("NCMetadataPhotosGPS", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCMetadataPhotosGPS", "failed to create property", e) + } + + return GeoLocation(latitude, longitude) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.METADATA_PHOTOS_GPS.toPropertyName() + } +} \ No newline at end of file diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMetadataPhotosSize.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMetadataPhotosSize.kt new file mode 100644 index 0000000000..68dffbc77a --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMetadataPhotosSize.kt @@ -0,0 +1,81 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author ZetaTom + * Copyright (C) 2024 ZetaTom + * Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils.propertyName +import at.bitfire.dav4jvm.XmlUtils.readText +import com.owncloud.android.lib.common.network.ExtendedProperties +import com.owncloud.android.lib.resources.files.model.ImageDimension +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCMetadataPhotosSize private constructor(val imageDimension: ImageDimension) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + return NCMetadataPhotosSize(parseText(parser)) + } + + private fun parseText(parser: XmlPullParser): ImageDimension { + var width = 0.0f + var height = 0.0f + + val depth = parser.depth + var eventType = parser.eventType + + try { + while (eventType != XmlPullParser.END_TAG || parser.depth != depth) { + if (eventType != XmlPullParser.TEXT) { + when (parser.propertyName().name) { + "width" -> readText(parser)?.let { width = it.toFloat() } + "height" -> readText(parser)?.let { height = it.toFloat() } + } + } + + eventType = parser.next() + } + } catch (e: IOException) { + Log.e("NCMetadataPhotosSize", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCMetadataPhotosSize", "failed to create property", e) + } + + return ImageDimension(width, height) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.METADATA_PHOTOS_SIZE.toPropertyName() + } +} \ No newline at end of file diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMetadataSize.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMetadataSize.kt new file mode 100644 index 0000000000..f1a81149a7 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMetadataSize.kt @@ -0,0 +1,65 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author ZetaTom + * Copyright (C) 2024 ZetaTom + * Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils +import com.google.gson.Gson +import com.owncloud.android.lib.common.network.ExtendedProperties +import com.owncloud.android.lib.resources.files.model.ImageDimension +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCMetadataSize private constructor(val imageDimension: ImageDimension?) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + try { + val text = XmlUtils.readText(parser) + if (!text.isNullOrEmpty()) { + val imageDimension = Gson().fromJson(text, ImageDimension::class.java) + return NCMetadataSize(imageDimension) + } + } catch (e: IOException) { + Log.e("NCMetadataSize", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCMetadataSize", "failed to create property", e) + } + return NCMetadataSize(null) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.METADATA_SIZE.toPropertyName() + } +} \ No newline at end of file diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMountType.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMountType.kt index b075431774..45cfb3a09f 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMountType.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCMountType.kt @@ -1,54 +1,58 @@ -/* - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2022 Tobias Kaminsky - * Copyright (C) 2022 Nextcloud GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ +/* Nextcloud Android Library is available under MIT license +* +* @author Tobias Kaminsky +* Copyright (C) 2022 Tobias Kaminsky +* Copyright (C) 2022 Nextcloud 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.webdav import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.PropertyFactory import at.bitfire.dav4jvm.XmlUtils +import com.owncloud.android.lib.common.network.ExtendedProperties import com.owncloud.android.lib.common.network.WebdavEntry import org.xmlpull.v1.XmlPullParser -class NCMountType internal constructor(var type: WebdavEntry.MountType) : Property { - - companion object { - @JvmField - val NAME = Property.Name(WebdavEntry.NAMESPACE_NC, WebdavEntry.EXTENDED_PROPERTY_MOUNT_TYPE) - } - +class NCMountType private constructor(val mountType: WebdavEntry.MountType) : Property { class Factory : PropertyFactory { - override fun getName() = NAME override fun create(parser: XmlPullParser): NCMountType { // (#PCDATA) > - val r = XmlUtils.readText(parser)?.let { type -> + val type = XmlUtils.readText(parser) + return NCMountType( when (type) { "external" -> WebdavEntry.MountType.EXTERNAL "group" -> WebdavEntry.MountType.GROUP else -> WebdavEntry.MountType.INTERNAL } - } ?: WebdavEntry.MountType.INTERNAL - return NCMountType(r) + ) } } + + companion object { + @JvmField + val NAME = ExtendedProperties.MOUNT_TYPE.toPropertyName() + } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCNote.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCNote.kt new file mode 100644 index 0000000000..0c37968f3e --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCNote.kt @@ -0,0 +1,62 @@ +/* Nextcloud Android Library is available under MIT license +* +* @author ZetaZom +* Copyright (C) 2024 ZetaTom +* Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils.readText +import com.owncloud.android.lib.common.network.ExtendedProperties +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCNote private constructor(val note: String) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + try { + val text = readText(parser) + if (!text.isNullOrEmpty()) { + return NCNote(text) + } + } catch (e: IOException) { + Log.e("NCNote", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCNote", "failed to create property", e) + } + return NCNote("") + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.NOTE.toPropertyName() + } +} \ No newline at end of file diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCPermissions.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCPermissions.kt index c6a0493a5f..438198f888 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCPermissions.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCPermissions.kt @@ -1,47 +1,62 @@ -/* - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2022 Tobias Kaminsky - * Copyright (C) 2022 Nextcloud GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ +/* Nextcloud Android Library is available under MIT license +* +* @author ZetaTom +* Copyright (C) 2024 ZetaTom +* Copyright (C) 2024 Nextcloud 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.webdav +import android.util.Log import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.PropertyFactory import at.bitfire.dav4jvm.XmlUtils -import com.owncloud.android.lib.common.network.WebdavEntry +import com.owncloud.android.lib.common.network.ExtendedProperties import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException -class NCPermissions internal constructor(var permissions: String) : Property { - - companion object { - @JvmField - val NAME = - Property.Name(WebdavEntry.NAMESPACE_OC, WebdavEntry.EXTENDED_PROPERTY_NAME_PERMISSIONS) - } - +class NCPermissions private constructor(val permissions: String?) : Property { class Factory : PropertyFactory { - override fun getName() = NAME - override fun create(parser: XmlPullParser) = - // - NCPermissions(XmlUtils.readText(parser) ?: "") + override fun create(parser: XmlPullParser) : Property { + try { + val text = XmlUtils.readText(parser) + if (!text.isNullOrEmpty()) { + return NCPermissions(text) + } + } catch (e: IOException) { + Log.e("NCPermissions", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCPermissions", "failed to create property", e) + } + return NCPermissions(null) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.NAME_PERMISSIONS.toPropertyName() } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCPreview.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCPreview.kt index b7579c8c01..4b7448f8a5 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCPreview.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCPreview.kt @@ -27,24 +27,24 @@ package com.owncloud.android.lib.resources.files.webdav -import android.text.TextUtils import android.util.Log import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.PropertyFactory import at.bitfire.dav4jvm.XmlUtils.readText -import com.owncloud.android.lib.common.network.WebdavEntry +import com.owncloud.android.lib.common.network.ExtendedProperties import org.xmlpull.v1.XmlPullParser import org.xmlpull.v1.XmlPullParserException import java.io.IOException -class NCPreview private constructor(var isNcPreview: Boolean) : Property { - +class NCPreview private constructor(val preview: Boolean) : Property { class Factory : PropertyFactory { + override fun getName() = NAME + override fun create(parser: XmlPullParser): Property { try { val text = readText(parser) - if (!TextUtils.isEmpty(text)) { - return NCPreview(java.lang.Boolean.parseBoolean(text)) + if (!text.isNullOrEmpty()) { + return NCPreview(text.toBoolean()) } } catch (e: IOException) { Log.e("NCPreview", "failed to create property", e) @@ -53,15 +53,10 @@ class NCPreview private constructor(var isNcPreview: Boolean) : Property { } return NCPreview(false) } - - override fun getName(): Property.Name { - return NAME - } } companion object { @JvmField - val NAME: Property.Name = - Property.Name(WebdavEntry.NAMESPACE_NC, WebdavEntry.EXTENDED_PROPERTY_HAS_PREVIEW) + val NAME = ExtendedProperties.HAS_PREVIEW.toPropertyName() } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCRichWorkspace.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCRichWorkspace.kt index c335a4220c..036b79bb9e 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCRichWorkspace.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCRichWorkspace.kt @@ -1,52 +1,62 @@ -/* - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2022 Tobias Kaminsky - * Copyright (C) 2022 Nextcloud GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ +/* Nextcloud Android Library is available under MIT license +* +* @author Tobias Kaminsky +* Copyright (C) 2022 Tobias Kaminsky +* Copyright (C) 2022 Nextcloud 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.webdav +import android.util.Log import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.PropertyFactory import at.bitfire.dav4jvm.XmlUtils -import com.owncloud.android.lib.common.network.WebdavEntry +import com.owncloud.android.lib.common.network.ExtendedProperties import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException -class NCRichWorkspace internal constructor(var richWorkspace: String) : Property { - - companion object { - @JvmField - val NAME = - Property.Name(WebdavEntry.NAMESPACE_NC, WebdavEntry.EXTENDED_PROPERTY_RICH_WORKSPACE) - } - +class NCRichWorkspace private constructor(val richWorkspace: String?) : Property { class Factory : PropertyFactory { - override fun getName() = NAME - override fun create(parser: XmlPullParser): NCRichWorkspace? { - // NC rich-workspace property - // can be null if rich-workspace is disabled for this user - XmlUtils.readText(parser)?.let { string -> - return NCRichWorkspace(string) + override fun create(parser: XmlPullParser): NCRichWorkspace { + try { + val text = XmlUtils.readText(parser) + if (!text.isNullOrEmpty()) { + return NCRichWorkspace(text) + } + } catch (e: IOException) { + Log.e("NCRichWorkspace", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCRichWorkspace", "failed to create property", e) } - return NCRichWorkspace("") + return NCRichWorkspace(null) } } + + companion object { + @JvmField + val NAME = ExtendedProperties.RICH_WORKSPACE.toPropertyName() + } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCSharee.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCSharees.kt similarity index 54% rename from library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCSharee.kt rename to library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCSharees.kt index cea5e1f3ba..365b66c016 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCSharee.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCSharees.kt @@ -1,22 +1,27 @@ -/* - * Nextcloud Android client application +/* Nextcloud Android Library is available under MIT license * - * @author Tobias Kaminsky - * Copyright (C) 2022 Tobias Kaminsky - * Copyright (C) 2022 Nextcloud GmbH + * @author Tobias Kaminsky + * Copyright (C) 2022 Tobias Kaminsky + * Copyright (C) 2022 Nextcloud GmbH * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * 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: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * 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. * */ @@ -27,29 +32,21 @@ import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.PropertyFactory import at.bitfire.dav4jvm.XmlUtils.propertyName import at.bitfire.dav4jvm.XmlUtils.readText -import com.owncloud.android.lib.common.network.WebdavEntry +import com.owncloud.android.lib.common.network.ExtendedProperties import com.owncloud.android.lib.resources.shares.ShareType import com.owncloud.android.lib.resources.shares.ShareeUser import org.xmlpull.v1.XmlPullParser import org.xmlpull.v1.XmlPullParserException import java.io.IOException -class NCSharee internal constructor(var sharees: Array) : Property { - - companion object { - @JvmField - val NAME = - Property.Name(WebdavEntry.NAMESPACE_NC, WebdavEntry.EXTENDED_PROPERTY_SHAREES) - } - +class NCSharees private constructor(val sharees: Array) : Property { class Factory : PropertyFactory { - override fun getName() = NAME - override fun create(parser: XmlPullParser): NCSharee { + override fun create(parser: XmlPullParser): NCSharees { // NC sharees property readArrayNode(parser).let { sharees -> - return NCSharee(sharees.toTypedArray()) + return NCSharees(sharees.toTypedArray()) } } @@ -60,7 +57,7 @@ class NCSharee internal constructor(var sharees: Array) : Property { val depth = parser.depth var eventType = parser.eventType - while (!(eventType == XmlPullParser.END_TAG && parser.depth == depth)) { + while (eventType != XmlPullParser.END_TAG || parser.depth != depth) { if (eventType != XmlPullParser.TEXT) { list = readNCSharees(parser) } @@ -79,7 +76,7 @@ class NCSharee internal constructor(var sharees: Array) : Property { val depth = parser.depth var eventType = parser.eventType - while (!(eventType == XmlPullParser.END_TAG && parser.depth == depth)) { + while (eventType != XmlPullParser.END_TAG || parser.depth != depth) { if (eventType == XmlPullParser.START_TAG && parser.depth == depth + 1) { list.add(readNCSharee(parser)) } @@ -98,19 +95,19 @@ class NCSharee internal constructor(var sharees: Array) : Property { var displayName: String? = null var shareType: ShareType? = null - while (!(eventType == XmlPullParser.END_TAG && parser.depth == depth)) { + while (eventType != XmlPullParser.END_TAG || parser.depth != depth) { if (eventType != XmlPullParser.TEXT) { - when (parser.propertyName().toString()) { - "http://nextcloud.org/ns:id" -> { + when (parser.propertyName().name) { + ExtendedProperties.SHAREES_ID.name -> { userId = readText(parser) } - "http://nextcloud.org/ns:display-name" -> { + ExtendedProperties.SHAREES_DISPLAY_NAME.name -> { displayName = readText(parser) } - "http://nextcloud.org/ns:type" -> { - shareType = - ShareType.fromValue(readText(parser)?.toInt() ?: 0) + + ExtendedProperties.SHAREES_SHARE_TYPE.name -> { + shareType = ShareType.fromValue(readText(parser)?.toInt() ?: 0) } } } @@ -121,4 +118,9 @@ class NCSharee internal constructor(var sharees: Array) : Property { return ShareeUser(userId, displayName, shareType) } } + + companion object { + @JvmField + val NAME = ExtendedProperties.SHAREES.toPropertyName() + } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCTags.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCTags.kt index df7a017615..3e303df349 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCTags.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCTags.kt @@ -1,22 +1,27 @@ -/* - * Nextcloud Android client application +/* Nextcloud Android Library is available under MIT license * - * @author Tobias Kaminsky - * Copyright (C) 2022 Tobias Kaminsky - * Copyright (C) 2022 Nextcloud GmbH + * @author Tobias Kaminsky + * Copyright (C) 2022 Tobias Kaminsky + * Copyright (C) 2022 Nextcloud GmbH * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * 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: * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . + * 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. * */ @@ -28,22 +33,14 @@ import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.PropertyFactory import at.bitfire.dav4jvm.XmlUtils.propertyName import at.bitfire.dav4jvm.XmlUtils.readText -import com.owncloud.android.lib.common.network.WebdavEntry +import com.owncloud.android.lib.common.network.ExtendedProperties import com.owncloud.android.lib.resources.shares.ShareType import org.xmlpull.v1.XmlPullParser import org.xmlpull.v1.XmlPullParserException import java.io.IOException -class NCTags internal constructor(var tags: Array) : Property { - - companion object { - @JvmField - val NAME = - Property.Name(WebdavEntry.NAMESPACE_NC, WebdavEntry.EXTENDED_PROPERTY_SYSTEM_TAGS) - } - +class NCTags private constructor(val tags: Array) : Property { class Factory : PropertyFactory { - override fun getName() = NAME override fun create(parser: XmlPullParser): NCTags { @@ -125,4 +122,9 @@ class NCTags internal constructor(var tags: Array) : Property { return "" } } + + companion object { + @JvmField + val NAME = ExtendedProperties.SYSTEM_TAGS.toPropertyName() + } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCTrashbinDeletionTime.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCTrashbinDeletionTime.kt new file mode 100644 index 0000000000..c4d1527857 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCTrashbinDeletionTime.kt @@ -0,0 +1,62 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author ZetaTom + * Copyright (C) 2024 ZetaTom + * Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils +import com.owncloud.android.lib.common.network.ExtendedProperties +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCTrashbinDeletionTime private constructor(val deletionTime: Long) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + try { + val text = XmlUtils.readText(parser) + if (!text.isNullOrEmpty()) { + return NCTrashbinDeletionTime(text.toLong()) + } + } catch (e: IOException) { + Log.e("NCTrashbinDeletionTime", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCTrashbinDeletionTime", "failed to create property", e) + } + return NCTrashbinDeletionTime(0) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.TRASHBIN_DELETION_TIME.toPropertyName() + } +} \ No newline at end of file diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCTrashbinFilename.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCTrashbinFilename.kt new file mode 100644 index 0000000000..f6e52a6759 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCTrashbinFilename.kt @@ -0,0 +1,62 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author ZetaTom + * Copyright (C) 2024 ZetaTom + * Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils.readText +import com.owncloud.android.lib.common.network.ExtendedProperties +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCTrashbinFilename private constructor(val originalLocation: String?) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + try { + val text = readText(parser) + if (!text.isNullOrEmpty()) { + return NCTrashbinFilename(text) + } + } catch (e: IOException) { + Log.e("NCTrashbinFilename", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCTrashbinFilename", "failed to create property", e) + } + return NCTrashbinFilename(null) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.TRASHBIN_FILENAME.toPropertyName() + } +} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCTrashbinLocation.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCTrashbinLocation.kt new file mode 100644 index 0000000000..8d865b0653 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCTrashbinLocation.kt @@ -0,0 +1,62 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author ZetaTom + * Copyright (C) 2024 ZetaTom + * Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils.readText +import com.owncloud.android.lib.common.network.ExtendedProperties +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCTrashbinLocation private constructor(val originalLocation: String?) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + try { + val text = readText(parser) + if (!text.isNullOrEmpty()) { + return NCTrashbinLocation(text) + } + } catch (e: IOException) { + Log.e("NCTrashbinLocation", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCTrashbinLocation", "failed to create property", e) + } + return NCTrashbinLocation(null) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.TRASHBIN_ORIGINAL_LOCATION.toPropertyName() + } +} diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCUploadTime.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCUploadTime.kt new file mode 100644 index 0000000000..37bdaba9f7 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/NCUploadTime.kt @@ -0,0 +1,62 @@ +/* Nextcloud Android Library is available under MIT license +* +* @author ZetaZom +* Copyright (C) 2024 ZetaTom +* Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils +import com.owncloud.android.lib.common.network.ExtendedProperties +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class NCUploadTime private constructor(val uploadTime: Long) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + try { + val text = XmlUtils.readText(parser) + if (!text.isNullOrEmpty()) { + return NCUploadTime(text.toLong()) + } + } catch (e: IOException) { + Log.e("NCUploadTime", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("NCUploadTime", "failed to create property", e) + } + return NCUploadTime(0) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.UPLOAD_TIME.toPropertyName() + } +} \ No newline at end of file diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCCommentsUnread.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCCommentsUnread.kt new file mode 100644 index 0000000000..b80bbc2df9 --- /dev/null +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCCommentsUnread.kt @@ -0,0 +1,62 @@ +/* Nextcloud Android Library is available under MIT license +* +* @author ZetaZom +* Copyright (C) 2024 ZetaTom +* Copyright (C) 2024 Nextcloud 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.webdav + +import android.util.Log +import at.bitfire.dav4jvm.Property +import at.bitfire.dav4jvm.PropertyFactory +import at.bitfire.dav4jvm.XmlUtils.readText +import com.owncloud.android.lib.common.network.ExtendedProperties +import org.xmlpull.v1.XmlPullParser +import org.xmlpull.v1.XmlPullParserException +import java.io.IOException + +class OCCommentsUnread private constructor(val commentsCount: Long) : Property { + class Factory : PropertyFactory { + override fun getName() = NAME + + override fun create(parser: XmlPullParser): Property { + try { + val text = readText(parser) + if (!text.isNullOrEmpty()) { + return OCCommentsUnread(text.toLong()) + } + } catch (e: IOException) { + Log.e("OCCommentsUnread", "failed to create property", e) + } catch (e: XmlPullParserException) { + Log.e("OCCommentsUnread", "failed to create property", e) + } + return OCCommentsUnread(0) + } + } + + companion object { + @JvmField + val NAME = ExtendedProperties.UNREAD_COMMENTS.toPropertyName() + } +} \ No newline at end of file diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCId.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCId.kt index 49573295b3..ce6efb9045 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCId.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCId.kt @@ -27,23 +27,23 @@ package com.owncloud.android.lib.resources.files.webdav -import android.text.TextUtils import android.util.Log import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.PropertyFactory import at.bitfire.dav4jvm.XmlUtils.readText -import com.owncloud.android.lib.common.network.WebdavEntry +import com.owncloud.android.lib.common.network.ExtendedProperties import org.xmlpull.v1.XmlPullParser import org.xmlpull.v1.XmlPullParserException import java.io.IOException -class OCId private constructor(var ocId: String?) : Property { - +class OCId private constructor(val id: String?) : Property { class Factory : PropertyFactory { + override fun getName() = NAME + override fun create(parser: XmlPullParser): Property { try { val text = readText(parser) - if (!TextUtils.isEmpty(text)) { + if (!text.isNullOrEmpty()) { return OCId(text) } } catch (e: IOException) { @@ -51,17 +51,12 @@ class OCId private constructor(var ocId: String?) : Property { } catch (e: XmlPullParserException) { Log.e("OCId", "failed to create property", e) } - return OCId("") - } - - override fun getName(): Property.Name { - return NAME + return OCId(null) } } companion object { @JvmField - val NAME: Property.Name = - Property.Name(WebdavEntry.NAMESPACE_OC, WebdavEntry.EXTENDED_PROPERTY_NAME_REMOTE_ID) + val NAME = ExtendedProperties.NAME_REMOTE_ID.toPropertyName() } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCLocalId.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCLocalId.kt index 3d7efc32a8..0abea6213e 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCLocalId.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCLocalId.kt @@ -27,41 +27,36 @@ package com.owncloud.android.lib.resources.files.webdav -import android.text.TextUtils import android.util.Log import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.PropertyFactory import at.bitfire.dav4jvm.XmlUtils.readText -import com.owncloud.android.lib.common.network.WebdavEntry +import com.owncloud.android.lib.common.network.ExtendedProperties import org.xmlpull.v1.XmlPullParser import org.xmlpull.v1.XmlPullParserException import java.io.IOException -class OCLocalId private constructor(var localId: Long) : Property { - +class OCLocalId private constructor(val localId: Long) : Property { class Factory : PropertyFactory { + override fun getName() = NAME + override fun create(parser: XmlPullParser): Property { try { val text = readText(parser) - if (!TextUtils.isEmpty(text)) { - return OCLocalId(text!!.toLong()) + if (!text.isNullOrEmpty()) { + return OCLocalId(text.toLong()) } } catch (e: IOException) { Log.e("OCLocalId", "failed to create property", e) } catch (e: XmlPullParserException) { Log.e("OCLocalId", "failed to create property", e) } - return OCLocalId(-1) - } - - override fun getName(): Property.Name { - return NAME + return OCLocalId(0) } } companion object { @JvmField - val NAME: Property.Name = - Property.Name(WebdavEntry.NAMESPACE_OC, WebdavEntry.EXTENDED_PROPERTY_NAME_LOCAL_ID) + val NAME = ExtendedProperties.NAME_LOCAL_ID.toPropertyName() } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCOwnerDisplayName.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCOwnerDisplayName.kt index 1292f9a1a7..76b58e2e94 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCOwnerDisplayName.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCOwnerDisplayName.kt @@ -27,23 +27,23 @@ package com.owncloud.android.lib.resources.files.webdav -import android.text.TextUtils import android.util.Log import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.PropertyFactory import at.bitfire.dav4jvm.XmlUtils.readText -import com.owncloud.android.lib.common.network.WebdavEntry +import com.owncloud.android.lib.common.network.ExtendedProperties import org.xmlpull.v1.XmlPullParser import org.xmlpull.v1.XmlPullParserException import java.io.IOException -class OCOwnerDisplayName private constructor(var string: String?) : Property { - +class OCOwnerDisplayName private constructor(val ownerDisplayName: String?) : Property { class Factory : PropertyFactory { + override fun getName() = NAME + override fun create(parser: XmlPullParser): Property { try { val text = readText(parser) - if (!TextUtils.isEmpty(text)) { + if (!text.isNullOrEmpty()) { return OCOwnerDisplayName(text) } } catch (e: IOException) { @@ -51,19 +51,12 @@ class OCOwnerDisplayName private constructor(var string: String?) : Property { } catch (e: XmlPullParserException) { Log.e("OCOwnerDisplayName", "failed to create property", e) } - return OCOwnerDisplayName("") - } - - override fun getName(): Property.Name { - return NAME + return OCOwnerDisplayName(null) } } companion object { @JvmField - val NAME: Property.Name = Property.Name( - WebdavEntry.NAMESPACE_OC, - WebdavEntry.EXTENDED_PROPERTY_OWNER_DISPLAY_NAME - ) + val NAME = ExtendedProperties.OWNER_DISPLAY_NAME.toPropertyName() } -} +} \ No newline at end of file diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCOwnerId.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCOwnerId.kt index 398ee7ee6b..6304090d73 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCOwnerId.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCOwnerId.kt @@ -27,41 +27,36 @@ package com.owncloud.android.lib.resources.files.webdav -import android.text.TextUtils import android.util.Log import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.PropertyFactory import at.bitfire.dav4jvm.XmlUtils.readText -import com.owncloud.android.lib.common.network.WebdavEntry +import com.owncloud.android.lib.common.network.ExtendedProperties import org.xmlpull.v1.XmlPullParser import org.xmlpull.v1.XmlPullParserException import java.io.IOException -class OCOwnerId private constructor(var ownerId: String?) : Property { - +class OCOwnerId private constructor(val ownerId: String?) : Property { class Factory : PropertyFactory { + override fun getName() = NAME + override fun create(parser: XmlPullParser): Property { try { val text = readText(parser) - if (!TextUtils.isEmpty(text)) { + if (!text.isNullOrEmpty()) { return OCOwnerId(text) } } catch (e: IOException) { - Log.e("OCId", "failed to create property", e) + Log.e("OCOwnerId", "failed to create property", e) } catch (e: XmlPullParserException) { - Log.e("OCId", "failed to create property", e) + Log.e("OCOwnerId", "failed to create property", e) } - return OCOwnerId("") - } - - override fun getName(): Property.Name { - return NAME + return OCOwnerId(null) } } companion object { @JvmField - val NAME: Property.Name = - Property.Name(WebdavEntry.NAMESPACE_OC, WebdavEntry.EXTENDED_PROPERTY_OWNER_ID) + val NAME = ExtendedProperties.OWNER_ID.toPropertyName() } } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCSize.kt b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCSize.kt index ed235c88ab..d892db4748 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCSize.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/files/webdav/OCSize.kt @@ -27,41 +27,36 @@ package com.owncloud.android.lib.resources.files.webdav -import android.text.TextUtils import android.util.Log import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.PropertyFactory import at.bitfire.dav4jvm.XmlUtils.readText -import com.owncloud.android.lib.common.network.WebdavEntry +import com.owncloud.android.lib.common.network.ExtendedProperties import org.xmlpull.v1.XmlPullParser import org.xmlpull.v1.XmlPullParserException import java.io.IOException -class OCSize private constructor(var ocSize: Long) : Property { - +class OCSize private constructor(val size: Long) : Property { class Factory : PropertyFactory { + override fun getName() = NAME + override fun create(parser: XmlPullParser): Property { try { val text = readText(parser) - if (!TextUtils.isEmpty(text)) { - return OCSize(text!!.toLong()) + if (!text.isNullOrEmpty()) { + return OCSize(text.toLong()) } } catch (e: IOException) { Log.e("OCSize", "failed to create property", e) } catch (e: XmlPullParserException) { Log.e("OCSize", "failed to create property", e) } - return OCSize(-1) - } - - override fun getName(): Property.Name { - return NAME + return OCSize(0) } } companion object { @JvmField - val NAME: Property.Name = - Property.Name(WebdavEntry.NAMESPACE_OC, WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE) + val NAME = ExtendedProperties.NAME_SIZE.toPropertyName() } -} +} \ No newline at end of file