Loading src/com/owncloud/android/lib/common/OwnCloudClient.java +22 −10 Original line number Diff line number Diff line Loading @@ -25,8 +25,14 @@ package com.owncloud.android.lib.common; import java.io.IOException; import java.io.InputStream; import android.net.Uri; import com.owncloud.android.lib.common.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials; import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.network.RedirectionPath; import com.owncloud.android.lib.common.network.WebdavUtils; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.status.OwnCloudVersion; import org.apache.commons.httpclient.Cookie; import org.apache.commons.httpclient.Header; Loading @@ -44,14 +50,8 @@ import org.apache.commons.httpclient.methods.HeadMethod; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.commons.httpclient.params.HttpParams; import android.net.Uri; import com.owncloud.android.lib.common.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials; import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.network.RedirectionPath; import com.owncloud.android.lib.common.network.WebdavUtils; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.status.OwnCloudVersion; import java.io.IOException; import java.io.InputStream; public class OwnCloudClient extends HttpClient { Loading Loading @@ -335,6 +335,18 @@ public class OwnCloudClient extends HttpClient { } } public Uri getNewWebdavUri(boolean filesUri) { if (mCredentials instanceof OwnCloudBearerCredentials) { return Uri.parse(mBaseUri + AccountUtils.ODAV_PATH); } else { if (filesUri) { return Uri.parse(mBaseUri + AccountUtils.WEBDAV_PATH_4_0); } else { return Uri.parse(mBaseUri + AccountUtils.WEBDAV_PATH_9_0); } } } /** * Sets the root URI to the ownCloud server. * Loading src/com/owncloud/android/lib/common/accounts/AccountUtils.java +2 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ public class AccountUtils { public static final String WEBDAV_PATH_1_2 = "/webdav/owncloud.php"; public static final String WEBDAV_PATH_2_0 = "/files/webdav.php"; public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav"; public static final String WEBDAV_PATH_9_0 = "/remote.php/dav"; public static final String ODAV_PATH = "/remote.php/odav"; private static final String SAML_SSO_PATH = "/remote.php/webdav"; public static final String CARDDAV_PATH_2_0 = "/apps/contacts/carddav.php"; Loading @@ -73,6 +74,7 @@ public class AccountUtils { if (supportsSamlSso) { return SAML_SSO_PATH; } if (version.compareTo(OwnCloudVersion.owncloud_v4) >= 0) return WEBDAV_PATH_4_0; if (version.compareTo(OwnCloudVersion.owncloud_v3) >= 0 Loading src/com/owncloud/android/lib/common/network/WebdavEntry.java +39 −10 Original line number Diff line number Diff line Loading @@ -24,8 +24,9 @@ package com.owncloud.android.lib.common.network; import java.math.BigDecimal; import java.util.Date; import android.net.Uri; import com.owncloud.android.lib.common.utils.Log_OC; import org.apache.jackrabbit.webdav.MultiStatusResponse; import org.apache.jackrabbit.webdav.property.DavProperty; Loading @@ -33,9 +34,8 @@ import org.apache.jackrabbit.webdav.property.DavPropertyName; import org.apache.jackrabbit.webdav.property.DavPropertySet; import org.apache.jackrabbit.webdav.xml.Namespace; import android.net.Uri; import com.owncloud.android.lib.common.utils.Log_OC; import java.math.BigDecimal; import java.util.Date; public class WebdavEntry { Loading @@ -45,13 +45,21 @@ public class WebdavEntry { public static final String EXTENDED_PROPERTY_NAME_PERMISSIONS = "permissions"; public static final String EXTENDED_PROPERTY_NAME_REMOTE_ID = "id"; public static final String EXTENDED_PROPERTY_NAME_SIZE = "size"; public static final String EXTENDED_PROPERTY_FAVORITE = "favorite"; public static final String PROPERTY_QUOTA_USED_BYTES = "quota-used-bytes"; public static final String PROPERTY_QUOTA_AVAILABLE_BYTES = "quota-available-bytes"; private static final int CODE_PROP_NOT_FOUND = 404; private String mName, mPath, mUri, mContentType, mEtag, mPermissions, mRemoteId; private String mName; private String mPath; private String mUri; private String mContentType; private String mEtag; private String mPermissions; private String mRemoteId; private boolean mIsFavorite; private long mContentLength, mCreateTimestamp, mModifiedTimestamp, mSize; private BigDecimal mQuotaUsedBytes, mQuotaAvailableBytes; Loading Loading @@ -185,10 +193,30 @@ public class WebdavEntry { mSize = Long.parseLong((String) prop.getValue()); } // OC favorite property <oc:favorite> prop = propSet.get(EXTENDED_PROPERTY_FAVORITE, Namespace.getNamespace(NAMESPACE_OC)); if (prop != null) { String favoriteValue = (String) prop.getValue(); if ("1".equals(favoriteValue)) { mIsFavorite = true; } else { mIsFavorite = false; } } else { mIsFavorite = false; } } else { Log_OC.e("WebdavEntry", "General fuckup, no status for webdav response"); Log_OC.e("WebdavEntry", "General fuckup, no status for webdav response"); } } public boolean isFavorite() { return mIsFavorite; } public void setIsFavorite(boolean mIsFavorite) { this.mIsFavorite = mIsFavorite; } public String path() { Loading Loading @@ -257,5 +285,6 @@ public class WebdavEntry { mSize = 0; mQuotaUsedBytes = null; mQuotaAvailableBytes = null; mIsFavorite = false; } } src/com/owncloud/android/lib/common/network/WebdavUtils.java +9 −5 Original line number Diff line number Diff line Loading @@ -25,11 +25,6 @@ package com.owncloud.android.lib.common.network; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.net.Uri; import org.apache.commons.httpclient.Header; Loading @@ -38,6 +33,11 @@ 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.Date; import java.util.Locale; public class WebdavUtils { public static final SimpleDateFormat DISPLAY_DATE_FORMAT = new SimpleDateFormat( "dd.MM.yyyy hh:mm"); Loading Loading @@ -107,6 +107,8 @@ public class WebdavUtils { Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_FAVORITE, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); return propSet; } Loading @@ -130,6 +132,8 @@ public class WebdavUtils { Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_FAVORITE, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); return propSet; } Loading src/com/owncloud/android/lib/common/utils/WebDavFileUtils.java 0 → 100644 +102 −0 Original line number Diff line number Diff line /** * Nextcloud Android client application * * @author Mario Danic * Copyright (C) 2017 Mario Danic * * 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 <http://www.gnu.org/licenses/>. */ package com.owncloud.android.lib.common.utils; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.network.WebdavEntry; import com.owncloud.android.lib.resources.files.RemoteFile; import org.apache.jackrabbit.webdav.MultiStatus; import org.apache.jackrabbit.webdav.MultiStatusResponse; import java.util.ArrayList; /** * WebDav helper. */ public class WebDavFileUtils { /** * Read the data retrieved from the server about the contents of the target folder * * @param remoteData Full response got from the server with the data of the target * folder and its direct children. * @param client Client instance to the remote server where the data were * retrieved. * @return content of the target folder */ public ArrayList<Object> readData(MultiStatus remoteData, OwnCloudClient client, boolean isReadFolderOperation, boolean isSearchOperation, String username) { ArrayList<Object> mFolderAndFiles = new ArrayList<>(); WebdavEntry we; int start = 1; if (isReadFolderOperation) { we = new WebdavEntry(remoteData.getResponses()[0], client.getWebdavUri().getPath()); mFolderAndFiles.add(fillOCFile(we)); } else { start = 0; } String stripString = client.getWebdavUri().getPath(); if (isSearchOperation && username != null) { stripString = stripString.substring(0, stripString.lastIndexOf("/")) + "/dav/files/" + username; } // loop to update every child RemoteFile remoteFile = null; MultiStatusResponse[] responses = remoteData.getResponses(); for (int i = start; i < responses.length; i++) { /// new OCFile instance with the data from the server we = new WebdavEntry(responses[i], stripString); remoteFile = fillOCFile(we); mFolderAndFiles.add(remoteFile); } return mFolderAndFiles; } /** * Creates and populates a new {@link RemoteFile} object with the data read from the server. * * @param we WebDAV entry read from the server for a WebDAV resource (remote file or folder). * @return New OCFile instance representing the remote resource described by we. */ private RemoteFile fillOCFile(WebdavEntry we) { RemoteFile file = new RemoteFile(we.decodedPath()); file.setCreationTimestamp(we.createTimestamp()); file.setLength(we.contentLength()); file.setMimeType(we.contentType()); file.setModifiedTimestamp(we.modifiedTimestamp()); file.setEtag(we.etag()); file.setPermissions(we.permissions()); file.setRemoteId(we.remoteId()); file.setSize(we.size()); file.setQuotaUsedBytes(we.quotaUsedBytes()); file.setQuotaAvailableBytes(we.quotaAvailableBytes()); file.setFavorite(we.isFavorite()); return file; } } Loading
src/com/owncloud/android/lib/common/OwnCloudClient.java +22 −10 Original line number Diff line number Diff line Loading @@ -25,8 +25,14 @@ package com.owncloud.android.lib.common; import java.io.IOException; import java.io.InputStream; import android.net.Uri; import com.owncloud.android.lib.common.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials; import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.network.RedirectionPath; import com.owncloud.android.lib.common.network.WebdavUtils; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.status.OwnCloudVersion; import org.apache.commons.httpclient.Cookie; import org.apache.commons.httpclient.Header; Loading @@ -44,14 +50,8 @@ import org.apache.commons.httpclient.methods.HeadMethod; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.commons.httpclient.params.HttpParams; import android.net.Uri; import com.owncloud.android.lib.common.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials; import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.network.RedirectionPath; import com.owncloud.android.lib.common.network.WebdavUtils; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.status.OwnCloudVersion; import java.io.IOException; import java.io.InputStream; public class OwnCloudClient extends HttpClient { Loading Loading @@ -335,6 +335,18 @@ public class OwnCloudClient extends HttpClient { } } public Uri getNewWebdavUri(boolean filesUri) { if (mCredentials instanceof OwnCloudBearerCredentials) { return Uri.parse(mBaseUri + AccountUtils.ODAV_PATH); } else { if (filesUri) { return Uri.parse(mBaseUri + AccountUtils.WEBDAV_PATH_4_0); } else { return Uri.parse(mBaseUri + AccountUtils.WEBDAV_PATH_9_0); } } } /** * Sets the root URI to the ownCloud server. * Loading
src/com/owncloud/android/lib/common/accounts/AccountUtils.java +2 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ public class AccountUtils { public static final String WEBDAV_PATH_1_2 = "/webdav/owncloud.php"; public static final String WEBDAV_PATH_2_0 = "/files/webdav.php"; public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav"; public static final String WEBDAV_PATH_9_0 = "/remote.php/dav"; public static final String ODAV_PATH = "/remote.php/odav"; private static final String SAML_SSO_PATH = "/remote.php/webdav"; public static final String CARDDAV_PATH_2_0 = "/apps/contacts/carddav.php"; Loading @@ -73,6 +74,7 @@ public class AccountUtils { if (supportsSamlSso) { return SAML_SSO_PATH; } if (version.compareTo(OwnCloudVersion.owncloud_v4) >= 0) return WEBDAV_PATH_4_0; if (version.compareTo(OwnCloudVersion.owncloud_v3) >= 0 Loading
src/com/owncloud/android/lib/common/network/WebdavEntry.java +39 −10 Original line number Diff line number Diff line Loading @@ -24,8 +24,9 @@ package com.owncloud.android.lib.common.network; import java.math.BigDecimal; import java.util.Date; import android.net.Uri; import com.owncloud.android.lib.common.utils.Log_OC; import org.apache.jackrabbit.webdav.MultiStatusResponse; import org.apache.jackrabbit.webdav.property.DavProperty; Loading @@ -33,9 +34,8 @@ import org.apache.jackrabbit.webdav.property.DavPropertyName; import org.apache.jackrabbit.webdav.property.DavPropertySet; import org.apache.jackrabbit.webdav.xml.Namespace; import android.net.Uri; import com.owncloud.android.lib.common.utils.Log_OC; import java.math.BigDecimal; import java.util.Date; public class WebdavEntry { Loading @@ -45,13 +45,21 @@ public class WebdavEntry { public static final String EXTENDED_PROPERTY_NAME_PERMISSIONS = "permissions"; public static final String EXTENDED_PROPERTY_NAME_REMOTE_ID = "id"; public static final String EXTENDED_PROPERTY_NAME_SIZE = "size"; public static final String EXTENDED_PROPERTY_FAVORITE = "favorite"; public static final String PROPERTY_QUOTA_USED_BYTES = "quota-used-bytes"; public static final String PROPERTY_QUOTA_AVAILABLE_BYTES = "quota-available-bytes"; private static final int CODE_PROP_NOT_FOUND = 404; private String mName, mPath, mUri, mContentType, mEtag, mPermissions, mRemoteId; private String mName; private String mPath; private String mUri; private String mContentType; private String mEtag; private String mPermissions; private String mRemoteId; private boolean mIsFavorite; private long mContentLength, mCreateTimestamp, mModifiedTimestamp, mSize; private BigDecimal mQuotaUsedBytes, mQuotaAvailableBytes; Loading Loading @@ -185,10 +193,30 @@ public class WebdavEntry { mSize = Long.parseLong((String) prop.getValue()); } // OC favorite property <oc:favorite> prop = propSet.get(EXTENDED_PROPERTY_FAVORITE, Namespace.getNamespace(NAMESPACE_OC)); if (prop != null) { String favoriteValue = (String) prop.getValue(); if ("1".equals(favoriteValue)) { mIsFavorite = true; } else { mIsFavorite = false; } } else { mIsFavorite = false; } } else { Log_OC.e("WebdavEntry", "General fuckup, no status for webdav response"); Log_OC.e("WebdavEntry", "General fuckup, no status for webdav response"); } } public boolean isFavorite() { return mIsFavorite; } public void setIsFavorite(boolean mIsFavorite) { this.mIsFavorite = mIsFavorite; } public String path() { Loading Loading @@ -257,5 +285,6 @@ public class WebdavEntry { mSize = 0; mQuotaUsedBytes = null; mQuotaAvailableBytes = null; mIsFavorite = false; } }
src/com/owncloud/android/lib/common/network/WebdavUtils.java +9 −5 Original line number Diff line number Diff line Loading @@ -25,11 +25,6 @@ package com.owncloud.android.lib.common.network; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import android.net.Uri; import org.apache.commons.httpclient.Header; Loading @@ -38,6 +33,11 @@ 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.Date; import java.util.Locale; public class WebdavUtils { public static final SimpleDateFormat DISPLAY_DATE_FORMAT = new SimpleDateFormat( "dd.MM.yyyy hh:mm"); Loading Loading @@ -107,6 +107,8 @@ public class WebdavUtils { Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_FAVORITE, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); return propSet; } Loading @@ -130,6 +132,8 @@ public class WebdavUtils { Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_SIZE, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); propSet.add(WebdavEntry.EXTENDED_PROPERTY_FAVORITE, Namespace.getNamespace(WebdavEntry.NAMESPACE_OC)); return propSet; } Loading
src/com/owncloud/android/lib/common/utils/WebDavFileUtils.java 0 → 100644 +102 −0 Original line number Diff line number Diff line /** * Nextcloud Android client application * * @author Mario Danic * Copyright (C) 2017 Mario Danic * * 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 <http://www.gnu.org/licenses/>. */ package com.owncloud.android.lib.common.utils; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.network.WebdavEntry; import com.owncloud.android.lib.resources.files.RemoteFile; import org.apache.jackrabbit.webdav.MultiStatus; import org.apache.jackrabbit.webdav.MultiStatusResponse; import java.util.ArrayList; /** * WebDav helper. */ public class WebDavFileUtils { /** * Read the data retrieved from the server about the contents of the target folder * * @param remoteData Full response got from the server with the data of the target * folder and its direct children. * @param client Client instance to the remote server where the data were * retrieved. * @return content of the target folder */ public ArrayList<Object> readData(MultiStatus remoteData, OwnCloudClient client, boolean isReadFolderOperation, boolean isSearchOperation, String username) { ArrayList<Object> mFolderAndFiles = new ArrayList<>(); WebdavEntry we; int start = 1; if (isReadFolderOperation) { we = new WebdavEntry(remoteData.getResponses()[0], client.getWebdavUri().getPath()); mFolderAndFiles.add(fillOCFile(we)); } else { start = 0; } String stripString = client.getWebdavUri().getPath(); if (isSearchOperation && username != null) { stripString = stripString.substring(0, stripString.lastIndexOf("/")) + "/dav/files/" + username; } // loop to update every child RemoteFile remoteFile = null; MultiStatusResponse[] responses = remoteData.getResponses(); for (int i = start; i < responses.length; i++) { /// new OCFile instance with the data from the server we = new WebdavEntry(responses[i], stripString); remoteFile = fillOCFile(we); mFolderAndFiles.add(remoteFile); } return mFolderAndFiles; } /** * Creates and populates a new {@link RemoteFile} object with the data read from the server. * * @param we WebDAV entry read from the server for a WebDAV resource (remote file or folder). * @return New OCFile instance representing the remote resource described by we. */ private RemoteFile fillOCFile(WebdavEntry we) { RemoteFile file = new RemoteFile(we.decodedPath()); file.setCreationTimestamp(we.createTimestamp()); file.setLength(we.contentLength()); file.setMimeType(we.contentType()); file.setModifiedTimestamp(we.modifiedTimestamp()); file.setEtag(we.etag()); file.setPermissions(we.permissions()); file.setRemoteId(we.remoteId()); file.setSize(we.size()); file.setQuotaUsedBytes(we.quotaUsedBytes()); file.setQuotaAvailableBytes(we.quotaAvailableBytes()); file.setFavorite(we.isFavorite()); return file; } }