Loading build.gradle +1 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ repositories { dependencies { api 'com.squareup.moshi:moshi:1.8.0' api 'org.apache.jackrabbit:jackrabbit-webdav:2.12.6' api 'org.apache.jackrabbit:jackrabbit-webdav:2.12.6+' implementation 'org.parceler:parceler-api:1.1.12' annotationProcessor 'org.parceler:parceler:1.1.12' Loading src/com/owncloud/android/lib/common/network/WebdavUtils.java +18 −8 Original line number Diff line number Diff line Loading @@ -101,18 +101,31 @@ public class WebdavUtils { propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_PERMISSIONS, 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); return propSet; } /** * Builds a DavPropertyNameSet with a minimum of property prop * For using instead of DavConstants.PROPFIND_ALL_PROP * @return */ public static DavPropertyNameSet getMinimumPropSet() { 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.GETETAG); return propSet; } /** * Builds a DavPropertyNameSet with properties for files * @return Loading Loading @@ -205,11 +218,8 @@ public class WebdavUtils { if (eTag == null) { eTag = method.getResponseHeader("etag"); } String result = ""; if (eTag != null) { result = parseEtag(eTag.getValue()); } return result; return (eTag != null) ? parseEtag(eTag.getValue()) : ""; } } src/com/owncloud/android/lib/resources/files/CreateFolderRemoteOperation.java +2 −4 Original line number Diff line number Diff line Loading @@ -86,7 +86,6 @@ public class CreateFolderRemoteOperation extends RemoteOperation { return result; } private RemoteOperationResult createFolder(OwnCloudClient client) { RemoteOperationResult result; MkColMethod mkCol = null; Loading @@ -94,10 +93,10 @@ public class CreateFolderRemoteOperation extends RemoteOperation { mkCol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); Log.d("CreateFolderRemoteOp", "Query string: "+mkCol.getQueryString()); client.setUseNextcloudUserAgent(true); client.executeMethod(mkCol, READ_TIMEOUT, CONNECTION_TIMEOUT); Log.d("CreateFolderRemoteOp", "Query string: "+mkCol.getQueryString()); if (HttpStatus.SC_METHOD_NOT_ALLOWED == mkCol.getStatusCode()) { result = new RemoteOperationResult(RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS); } else { Loading @@ -108,8 +107,7 @@ public class CreateFolderRemoteOperation extends RemoteOperation { client.exhaustResponse(mkCol.getResponseBodyAsStream()); } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e); Log.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e); } finally { if (mkCol != null) mkCol.releaseConnection(); Loading src/com/owncloud/android/lib/resources/files/LightReadFolderRemoteOperation.java 0 → 100644 +197 −0 Original line number Diff line number Diff line /* ownCloud Android Library is available under MIT license * Copyright (C) 2015 ownCloud Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ package com.owncloud.android.lib.resources.files; import android.util.Log; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.network.WebdavEntry; import com.owncloud.android.lib.common.network.WebdavUtils; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.files.model.RemoteFile; import org.apache.commons.httpclient.HttpStatus; import org.apache.jackrabbit.webdav.DavConstants; import org.apache.jackrabbit.webdav.MultiStatus; import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; import java.util.ArrayList; /** * Remote operation performing the read of remote file or folder in the ownCloud server. * * @author David A. Velasco * @author masensio */ public class LightReadFolderRemoteOperation extends RemoteOperation { private static final String TAG = LightReadFolderRemoteOperation.class.getSimpleName(); private String mRemotePath; private ArrayList<Object> mFolderAndFiles; private int depth; /** * Constructor * * @param remotePath Remote path of the file. */ public LightReadFolderRemoteOperation(String remotePath) { this(remotePath, DavConstants.DEPTH_1); } /** * Constructor * @param remotePath remothe path of folder * @param depth depth to reach. Value should be in DavConstants (DEPTH_0, DEPTH_1 or DEPTH_INFINITY). DEPTH_0 by default */ public LightReadFolderRemoteOperation(String remotePath, int depth){ mRemotePath = remotePath; if(depth == DavConstants.DEPTH_0 || depth == DavConstants.DEPTH_1 || depth == DavConstants.DEPTH_INFINITY) { this.depth = depth; }else{ this.depth = DavConstants.DEPTH_0; } } /** * Performs the read operation. * * @param client Client object to communicate with the remote ownCloud server. */ @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; PropFindMethod query = null; try { // remote request query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath), WebdavUtils.getMinimumPropSet(), // PropFind Properties this.depth); Log.d("ReadFolderRemoteOp", "Display query: "+query.getQueryString() ); int status = client.executeMethod(query); // check and process response boolean isSuccess = (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK); if (isSuccess) { // get data from remote folder MultiStatus dataInServer = query.getResponseBodyAsMultiStatus(); readData(dataInServer, client); // Result of the operation result = new RemoteOperationResult(true, query); // Add data to the result if (result.isSuccess()) { result.setData(mFolderAndFiles); } } else { // synchronization failed client.exhaustResponse(query.getResponseBodyAsStream()); result = new RemoteOperationResult(false, query); } } catch (Exception e) { result = new RemoteOperationResult(e); } finally { if (query != null) query.releaseConnection(); // let the connection available for other methods if (result == null) { result = new RemoteOperationResult(new Exception("unknown error")); Log_OC.e(TAG, "Synchronized " + mRemotePath + ": failed"); } else { if (result.isSuccess()) { Log_OC.i(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage()); } else { if (result.isException()) { Log_OC.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage(), result.getException()); } else { Log_OC.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage()); } } } } return result; } public boolean isMultiStatus(int status) { return (status == HttpStatus.SC_MULTI_STATUS); } /** * 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 */ private void readData(MultiStatus remoteData, OwnCloudClient client) { mFolderAndFiles = new ArrayList<>(); // parse data from remote folder WebdavEntry we = new WebdavEntry(remoteData.getResponses()[0], client.getWebdavUri().getPath()); mFolderAndFiles.add(fillOCFile(we)); // loop to update every child RemoteFile remoteFile; for (int i = 1; i < remoteData.getResponses().length; ++i) { /// new OCFile instance with the data from the server we = new WebdavEntry(remoteData.getResponses()[i], client.getWebdavUri().getPath()); remoteFile = fillOCFile(we); mFolderAndFiles.add(remoteFile); } } /** * 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.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()); return file; } } Loading
build.gradle +1 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ repositories { dependencies { api 'com.squareup.moshi:moshi:1.8.0' api 'org.apache.jackrabbit:jackrabbit-webdav:2.12.6' api 'org.apache.jackrabbit:jackrabbit-webdav:2.12.6+' implementation 'org.parceler:parceler-api:1.1.12' annotationProcessor 'org.parceler:parceler:1.1.12' Loading
src/com/owncloud/android/lib/common/network/WebdavUtils.java +18 −8 Original line number Diff line number Diff line Loading @@ -101,18 +101,31 @@ public class WebdavUtils { propSet.add(WebdavEntry.EXTENDED_PROPERTY_NAME_PERMISSIONS, 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); return propSet; } /** * Builds a DavPropertyNameSet with a minimum of property prop * For using instead of DavConstants.PROPFIND_ALL_PROP * @return */ public static DavPropertyNameSet getMinimumPropSet() { 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.GETETAG); return propSet; } /** * Builds a DavPropertyNameSet with properties for files * @return Loading Loading @@ -205,11 +218,8 @@ public class WebdavUtils { if (eTag == null) { eTag = method.getResponseHeader("etag"); } String result = ""; if (eTag != null) { result = parseEtag(eTag.getValue()); } return result; return (eTag != null) ? parseEtag(eTag.getValue()) : ""; } }
src/com/owncloud/android/lib/resources/files/CreateFolderRemoteOperation.java +2 −4 Original line number Diff line number Diff line Loading @@ -86,7 +86,6 @@ public class CreateFolderRemoteOperation extends RemoteOperation { return result; } private RemoteOperationResult createFolder(OwnCloudClient client) { RemoteOperationResult result; MkColMethod mkCol = null; Loading @@ -94,10 +93,10 @@ public class CreateFolderRemoteOperation extends RemoteOperation { mkCol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); Log.d("CreateFolderRemoteOp", "Query string: "+mkCol.getQueryString()); client.setUseNextcloudUserAgent(true); client.executeMethod(mkCol, READ_TIMEOUT, CONNECTION_TIMEOUT); Log.d("CreateFolderRemoteOp", "Query string: "+mkCol.getQueryString()); if (HttpStatus.SC_METHOD_NOT_ALLOWED == mkCol.getStatusCode()) { result = new RemoteOperationResult(RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS); } else { Loading @@ -108,8 +107,7 @@ public class CreateFolderRemoteOperation extends RemoteOperation { client.exhaustResponse(mkCol.getResponseBodyAsStream()); } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e); Log.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e); } finally { if (mkCol != null) mkCol.releaseConnection(); Loading
src/com/owncloud/android/lib/resources/files/LightReadFolderRemoteOperation.java 0 → 100644 +197 −0 Original line number Diff line number Diff line /* ownCloud Android Library is available under MIT license * Copyright (C) 2015 ownCloud Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ package com.owncloud.android.lib.resources.files; import android.util.Log; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.network.WebdavEntry; import com.owncloud.android.lib.common.network.WebdavUtils; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.files.model.RemoteFile; import org.apache.commons.httpclient.HttpStatus; import org.apache.jackrabbit.webdav.DavConstants; import org.apache.jackrabbit.webdav.MultiStatus; import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; import java.util.ArrayList; /** * Remote operation performing the read of remote file or folder in the ownCloud server. * * @author David A. Velasco * @author masensio */ public class LightReadFolderRemoteOperation extends RemoteOperation { private static final String TAG = LightReadFolderRemoteOperation.class.getSimpleName(); private String mRemotePath; private ArrayList<Object> mFolderAndFiles; private int depth; /** * Constructor * * @param remotePath Remote path of the file. */ public LightReadFolderRemoteOperation(String remotePath) { this(remotePath, DavConstants.DEPTH_1); } /** * Constructor * @param remotePath remothe path of folder * @param depth depth to reach. Value should be in DavConstants (DEPTH_0, DEPTH_1 or DEPTH_INFINITY). DEPTH_0 by default */ public LightReadFolderRemoteOperation(String remotePath, int depth){ mRemotePath = remotePath; if(depth == DavConstants.DEPTH_0 || depth == DavConstants.DEPTH_1 || depth == DavConstants.DEPTH_INFINITY) { this.depth = depth; }else{ this.depth = DavConstants.DEPTH_0; } } /** * Performs the read operation. * * @param client Client object to communicate with the remote ownCloud server. */ @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; PropFindMethod query = null; try { // remote request query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath), WebdavUtils.getMinimumPropSet(), // PropFind Properties this.depth); Log.d("ReadFolderRemoteOp", "Display query: "+query.getQueryString() ); int status = client.executeMethod(query); // check and process response boolean isSuccess = (status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK); if (isSuccess) { // get data from remote folder MultiStatus dataInServer = query.getResponseBodyAsMultiStatus(); readData(dataInServer, client); // Result of the operation result = new RemoteOperationResult(true, query); // Add data to the result if (result.isSuccess()) { result.setData(mFolderAndFiles); } } else { // synchronization failed client.exhaustResponse(query.getResponseBodyAsStream()); result = new RemoteOperationResult(false, query); } } catch (Exception e) { result = new RemoteOperationResult(e); } finally { if (query != null) query.releaseConnection(); // let the connection available for other methods if (result == null) { result = new RemoteOperationResult(new Exception("unknown error")); Log_OC.e(TAG, "Synchronized " + mRemotePath + ": failed"); } else { if (result.isSuccess()) { Log_OC.i(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage()); } else { if (result.isException()) { Log_OC.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage(), result.getException()); } else { Log_OC.e(TAG, "Synchronized " + mRemotePath + ": " + result.getLogMessage()); } } } } return result; } public boolean isMultiStatus(int status) { return (status == HttpStatus.SC_MULTI_STATUS); } /** * 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 */ private void readData(MultiStatus remoteData, OwnCloudClient client) { mFolderAndFiles = new ArrayList<>(); // parse data from remote folder WebdavEntry we = new WebdavEntry(remoteData.getResponses()[0], client.getWebdavUri().getPath()); mFolderAndFiles.add(fillOCFile(we)); // loop to update every child RemoteFile remoteFile; for (int i = 1; i < remoteData.getResponses().length; ++i) { /// new OCFile instance with the data from the server we = new WebdavEntry(remoteData.getResponses()[i], client.getWebdavUri().getPath()); remoteFile = fillOCFile(we); mFolderAndFiles.add(remoteFile); } } /** * 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.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()); return file; } }