Loading build.gradle +1 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ repositories { } dependencies { compile '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' implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5' Loading src/com/owncloud/android/lib/resources/files/GetFolderFullTreeRemoteOperation.javadeleted 100644 → 0 +0 −176 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 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 org.apache.jackrabbit.webdav.property.DavPropertyName; import org.apache.jackrabbit.webdav.property.DavPropertyNameSet; 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 GetFolderFullTreeRemoteOperation extends RemoteOperation { private static final String TAG = GetFolderFullTreeRemoteOperation.class.getSimpleName(); private String mRemotePath; private ArrayList<Object> mFolderAndFiles; /** * Constructor * * @param remotePath Remote path of the file. */ public GetFolderFullTreeRemoteOperation(String remotePath) { mRemotePath = remotePath; } /** * 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.getAllPropSet(), // PropFind Properties DavConstants.DEPTH_INFINITY); 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.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; } } src/com/owncloud/android/lib/resources/files/ReadFolderRemoteOperation.java +17 −2 Original line number Diff line number Diff line Loading @@ -52,15 +52,30 @@ public class ReadFolderRemoteOperation extends RemoteOperation { private String mRemotePath; private ArrayList<Object> mFolderAndFiles; private int depth; /** * Constructor * * @param remotePath Remote path of the file. */ public ReadFolderRemoteOperation(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 ReadFolderRemoteOperation(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. Loading @@ -76,7 +91,7 @@ public class ReadFolderRemoteOperation extends RemoteOperation { // remote request query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath), WebdavUtils.getAllPropSet(), // PropFind Properties DavConstants.DEPTH_1); this.depth); int status = client.executeMethod(query); // check and process response Loading Loading
build.gradle +1 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ repositories { } dependencies { compile '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' implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5' Loading
src/com/owncloud/android/lib/resources/files/GetFolderFullTreeRemoteOperation.javadeleted 100644 → 0 +0 −176 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 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 org.apache.jackrabbit.webdav.property.DavPropertyName; import org.apache.jackrabbit.webdav.property.DavPropertyNameSet; 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 GetFolderFullTreeRemoteOperation extends RemoteOperation { private static final String TAG = GetFolderFullTreeRemoteOperation.class.getSimpleName(); private String mRemotePath; private ArrayList<Object> mFolderAndFiles; /** * Constructor * * @param remotePath Remote path of the file. */ public GetFolderFullTreeRemoteOperation(String remotePath) { mRemotePath = remotePath; } /** * 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.getAllPropSet(), // PropFind Properties DavConstants.DEPTH_INFINITY); 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.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; } }
src/com/owncloud/android/lib/resources/files/ReadFolderRemoteOperation.java +17 −2 Original line number Diff line number Diff line Loading @@ -52,15 +52,30 @@ public class ReadFolderRemoteOperation extends RemoteOperation { private String mRemotePath; private ArrayList<Object> mFolderAndFiles; private int depth; /** * Constructor * * @param remotePath Remote path of the file. */ public ReadFolderRemoteOperation(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 ReadFolderRemoteOperation(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. Loading @@ -76,7 +91,7 @@ public class ReadFolderRemoteOperation extends RemoteOperation { // remote request query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath), WebdavUtils.getAllPropSet(), // PropFind Properties DavConstants.DEPTH_1); this.depth); int status = client.executeMethod(query); // check and process response Loading