mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-09 00:46:15 +00:00
Merge pull request #1 from owncloud/share_link__code_improvements
Code improvements in operation to get all the remote shares.
This commit is contained in:
commit
7126c73e63
@ -28,6 +28,7 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@ -212,7 +213,10 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
|
||||
|
||||
private void onSuccessfulRefresh(ReadRemoteFolderOperation operation, RemoteOperationResult result) {
|
||||
mFilesAdapter.clear();
|
||||
List<RemoteFile> files = result.getData();
|
||||
List<RemoteFile> files = new ArrayList<RemoteFile>();
|
||||
for(Object obj: result.getData()) {
|
||||
files.add((RemoteFile) obj);
|
||||
}
|
||||
if (files != null) {
|
||||
Iterator<RemoteFile> it = files.iterator();
|
||||
while (it.hasNext()) {
|
||||
|
@ -92,6 +92,23 @@ public class AccountUtils {
|
||||
return baseurl + webdavpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts url server from the account
|
||||
* @param context
|
||||
* @param account
|
||||
* @return url server or null on failure
|
||||
* @throws AccountNotFoundException When 'account' is unknown for the AccountManager
|
||||
*/
|
||||
public static String constructBasicURLForAccount(Context context, Account account) throws AccountNotFoundException {
|
||||
AccountManager ama = AccountManager.get(context);
|
||||
String baseurl = ama.getUserData(account, OwnCloudAccount.Constants.KEY_OC_BASE_URL);
|
||||
|
||||
if (baseurl == null )
|
||||
throw new AccountNotFoundException(account, "Account not found", null);
|
||||
|
||||
return baseurl;
|
||||
}
|
||||
|
||||
|
||||
public static class AccountNotFoundException extends AccountsException {
|
||||
|
||||
|
@ -57,6 +57,7 @@ public class OwnCloudClient extends HttpClient {
|
||||
private static final int MAX_REDIRECTIONS_COUNT = 3;
|
||||
|
||||
private Uri mUri;
|
||||
private Uri mWebdavUri;
|
||||
private Credentials mCredentials;
|
||||
private boolean mFollowRedirects;
|
||||
private String mSsoSessionCookie;
|
||||
@ -117,7 +118,7 @@ public class OwnCloudClient extends HttpClient {
|
||||
* @throws Exception When the existence could not be determined
|
||||
*/
|
||||
public boolean existsFile(String path) throws IOException, HttpException {
|
||||
HeadMethod head = new HeadMethod(mUri.toString() + WebdavUtils.encodePath(path));
|
||||
HeadMethod head = new HeadMethod(mWebdavUri.toString() + WebdavUtils.encodePath(path));
|
||||
try {
|
||||
int status = executeMethod(head);
|
||||
Log.d(TAG, "HEAD to " + path + " finished with HTTP status " + status + ((status != HttpStatus.SC_OK)?"(FAIL)":""));
|
||||
@ -224,6 +225,18 @@ public class OwnCloudClient extends HttpClient {
|
||||
getHttpConnectionManager().getParams().setConnectionTimeout(defaultConnectionTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Webdav URI for the helper methods that receive paths as parameters, instead of full URLs
|
||||
* @param uri
|
||||
*/
|
||||
public void setWebdavUri(Uri uri) {
|
||||
mWebdavUri = uri;
|
||||
}
|
||||
|
||||
public Uri getWebdavUri() {
|
||||
return mWebdavUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the base URI for the helper methods that receive paths as parameters, instead of full URLs
|
||||
* @param uri
|
||||
|
@ -70,11 +70,14 @@ public class OwnCloudClientFactory {
|
||||
public static OwnCloudClient createOwnCloudClient (Account account, Context appContext) throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException {
|
||||
//Log_OC.d(TAG, "Creating OwnCloudClient associated to " + account.name);
|
||||
|
||||
Uri uri = Uri.parse(AccountUtils.constructFullURLForAccount(appContext, account));
|
||||
Uri webdavUri = Uri.parse(AccountUtils.constructFullURLForAccount(appContext, account));
|
||||
Uri uri = Uri.parse(AccountUtils.constructBasicURLForAccount(appContext, account));
|
||||
AccountManager am = AccountManager.get(appContext);
|
||||
boolean isOauth2 = am.getUserData(account, OwnCloudAccount.Constants.KEY_SUPPORTS_OAUTH2) != null; // TODO avoid calling to getUserData here
|
||||
boolean isSamlSso = am.getUserData(account, OwnCloudAccount.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
|
||||
OwnCloudClient client = createOwnCloudClient(uri, appContext, !isSamlSso);
|
||||
OwnCloudClient client = createOwnCloudClient(webdavUri, appContext, !isSamlSso);
|
||||
client.setBaseUri(uri);
|
||||
|
||||
if (isOauth2) {
|
||||
String accessToken = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), false);
|
||||
client.setBearerCredentials(accessToken); // TODO not assume that the access token is a bearer token
|
||||
@ -95,11 +98,13 @@ public class OwnCloudClientFactory {
|
||||
|
||||
|
||||
public static OwnCloudClient createOwnCloudClient (Account account, Context appContext, Activity currentActivity) throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException {
|
||||
Uri uri = Uri.parse(AccountUtils.constructFullURLForAccount(appContext, account));
|
||||
Uri webdavUri = Uri.parse(AccountUtils.constructFullURLForAccount(appContext, account));
|
||||
Uri uri = Uri.parse(AccountUtils.constructBasicURLForAccount(appContext, account));
|
||||
AccountManager am = AccountManager.get(appContext);
|
||||
boolean isOauth2 = am.getUserData(account, OwnCloudAccount.Constants.KEY_SUPPORTS_OAUTH2) != null; // TODO avoid calling to getUserData here
|
||||
boolean isSamlSso = am.getUserData(account, OwnCloudAccount.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
|
||||
OwnCloudClient client = createOwnCloudClient(uri, appContext, !isSamlSso);
|
||||
OwnCloudClient client = createOwnCloudClient(webdavUri, appContext, !isSamlSso);
|
||||
client.setBaseUri(uri);
|
||||
|
||||
if (isOauth2) { // TODO avoid a call to getUserData here
|
||||
AccountManagerFuture<Bundle> future = am.getAuthToken(account, AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), null, currentActivity, null, null);
|
||||
@ -148,7 +153,7 @@ public class OwnCloudClientFactory {
|
||||
OwnCloudClient client = new OwnCloudClient(NetworkUtils.getMultiThreadedConnManager());
|
||||
|
||||
client.setDefaultTimeouts(DEFAULT_DATA_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT);
|
||||
client.setBaseUri(uri);
|
||||
client.setWebdavUri(uri);
|
||||
client.setFollowRedirects(followRedirects);
|
||||
|
||||
return client;
|
||||
|
@ -24,7 +24,6 @@
|
||||
|
||||
package com.owncloud.android.lib.operations.common;
|
||||
|
||||
import com.owncloud.android.lib.network.webdav.WebdavEntry;
|
||||
import com.owncloud.android.lib.utils.FileUtils;
|
||||
|
||||
import android.os.Parcel;
|
||||
@ -33,20 +32,16 @@ import android.util.Log;
|
||||
|
||||
|
||||
/**
|
||||
* Contains the data of a Share Remote File from the Share API
|
||||
* Contains the data of a Share from the Share API
|
||||
*
|
||||
* @author masensio
|
||||
*
|
||||
*/
|
||||
public class ShareRemoteFile extends RemoteFile {
|
||||
|
||||
/**
|
||||
* Generated - should be refreshed every time the class changes!!
|
||||
*/
|
||||
private static final long serialVersionUID = -5916376011588784325L;
|
||||
public class OCShare implements Parcelable{
|
||||
|
||||
private static final String TAG = ShareRemoteFile.class.getSimpleName();
|
||||
private static final String TAG = OCShare.class.getSimpleName();
|
||||
|
||||
private long mId;
|
||||
private long mFileSource;
|
||||
private long mItemSource;
|
||||
private ShareType mShareType;
|
||||
@ -61,13 +56,12 @@ public class ShareRemoteFile extends RemoteFile {
|
||||
private long mUserId;
|
||||
private long mIdRemoteShared;
|
||||
|
||||
public ShareRemoteFile() {
|
||||
public OCShare() {
|
||||
super();
|
||||
resetData();
|
||||
}
|
||||
|
||||
public ShareRemoteFile(String path) {
|
||||
super(path);
|
||||
public OCShare(String path) {
|
||||
resetData();
|
||||
if (path == null || path.length() <= 0 || !path.startsWith(FileUtils.PATH_SEPARATOR)) {
|
||||
Log.e(TAG, "Trying to create a OCShare with a non valid path");
|
||||
@ -76,15 +70,11 @@ public class ShareRemoteFile extends RemoteFile {
|
||||
mPath = path;
|
||||
}
|
||||
|
||||
public ShareRemoteFile(WebdavEntry we) {
|
||||
super(we);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/**
|
||||
* Used internally. Reset all file properties
|
||||
*/
|
||||
private void resetData() {
|
||||
mId = -1;
|
||||
mFileSource = 0;
|
||||
mItemSource = 0;
|
||||
mShareType = ShareType.NO_SHARED;
|
||||
@ -101,6 +91,15 @@ public class ShareRemoteFile extends RemoteFile {
|
||||
}
|
||||
|
||||
/// Getters and Setters
|
||||
|
||||
public long getId() {
|
||||
return mId;
|
||||
}
|
||||
|
||||
public void setId(long id){
|
||||
mId = id;
|
||||
}
|
||||
|
||||
public long getFileSource() {
|
||||
return mFileSource;
|
||||
}
|
||||
@ -208,15 +207,15 @@ public class ShareRemoteFile extends RemoteFile {
|
||||
/**
|
||||
* Parcelable Methods
|
||||
*/
|
||||
public static final Parcelable.Creator<ShareRemoteFile> CREATOR = new Parcelable.Creator<ShareRemoteFile>() {
|
||||
public static final Parcelable.Creator<OCShare> CREATOR = new Parcelable.Creator<OCShare>() {
|
||||
@Override
|
||||
public ShareRemoteFile createFromParcel(Parcel source) {
|
||||
return new ShareRemoteFile(source);
|
||||
public OCShare createFromParcel(Parcel source) {
|
||||
return new OCShare(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShareRemoteFile[] newArray(int size) {
|
||||
return new ShareRemoteFile[size];
|
||||
public OCShare[] newArray(int size) {
|
||||
return new OCShare[size];
|
||||
}
|
||||
};
|
||||
|
||||
@ -225,12 +224,12 @@ public class ShareRemoteFile extends RemoteFile {
|
||||
*
|
||||
* @param source The source parcel
|
||||
*/
|
||||
protected ShareRemoteFile(Parcel source) {
|
||||
super(source);
|
||||
protected OCShare(Parcel source) {
|
||||
readFromParcel(source);
|
||||
}
|
||||
|
||||
public void readFromParcel(Parcel source) {
|
||||
super.readFromParcel(source);
|
||||
mId = source.readLong();
|
||||
|
||||
mFileSource = source.readLong();
|
||||
mItemSource = source.readLong();
|
||||
@ -252,10 +251,15 @@ public class ShareRemoteFile extends RemoteFile {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return this.hashCode();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
|
||||
dest.writeLong(mId);
|
||||
dest.writeLong(mFileSource);
|
||||
dest.writeLong(mItemSource);
|
||||
dest.writeString((mShareType == null) ? "" : mShareType.name());
|
||||
@ -270,4 +274,5 @@ public class ShareRemoteFile extends RemoteFile {
|
||||
dest.writeLong(mUserId);
|
||||
dest.writeLong(mIdRemoteShared);
|
||||
}
|
||||
|
||||
}
|
@ -106,12 +106,12 @@ public class RemoteOperationResult implements Serializable {
|
||||
private ResultCode mCode = ResultCode.UNKNOWN_ERROR;
|
||||
private String mRedirectedLocation;
|
||||
|
||||
private ArrayList<RemoteFile> mFiles;
|
||||
private ArrayList<Object> mData;
|
||||
|
||||
public RemoteOperationResult(ResultCode code) {
|
||||
mCode = code;
|
||||
mSuccess = (code == ResultCode.OK || code == ResultCode.OK_SSL || code == ResultCode.OK_NO_SSL);
|
||||
mFiles = null;
|
||||
mData = null;
|
||||
}
|
||||
|
||||
private RemoteOperationResult(boolean success, int httpCode) {
|
||||
@ -207,12 +207,12 @@ public class RemoteOperationResult implements Serializable {
|
||||
}
|
||||
|
||||
|
||||
public void setData(ArrayList<RemoteFile> files){
|
||||
mFiles = files;
|
||||
public void setData(ArrayList<Object> files){
|
||||
mData = files;
|
||||
}
|
||||
|
||||
public ArrayList<RemoteFile> getData(){
|
||||
return mFiles;
|
||||
public ArrayList<Object> getData(){
|
||||
return mData;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
|
@ -70,7 +70,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
|
||||
}
|
||||
|
||||
long offset = 0;
|
||||
String uriPrefix = client.getBaseUri() + WebdavUtils.encodePath(mRemotePath) + "-chunking-" + Math.abs((new Random()).nextInt(9000)+1000) + "-" ;
|
||||
String uriPrefix = client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath) + "-chunking-" + Math.abs((new Random()).nextInt(9000)+1000) + "-" ;
|
||||
long chunkCount = (long) Math.ceil((double)file.length() / CHUNK_SIZE);
|
||||
for (int chunkIndex = 0; chunkIndex < chunkCount ; chunkIndex++, offset += CHUNK_SIZE) {
|
||||
if (mPutMethod != null) {
|
||||
|
@ -80,7 +80,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation {
|
||||
boolean noInvalidChars = FileUtils.isValidPath(mRemotePath);
|
||||
if (noInvalidChars) {
|
||||
try {
|
||||
mkcol = new MkColMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath));
|
||||
mkcol = new MkColMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
|
||||
int status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT);
|
||||
if (!mkcol.succeeded() && mkcol.getStatusCode() == HttpStatus.SC_CONFLICT && mCreateFullPath) {
|
||||
result = createParentFolder(FileUtils.getParentPath(mRemotePath), client);
|
||||
|
@ -98,7 +98,7 @@ public class DownloadRemoteFileOperation extends RemoteOperation {
|
||||
protected int downloadFile(OwnCloudClient client, File targetFile) throws HttpException, IOException, OperationCancelledException {
|
||||
int status = -1;
|
||||
boolean savedFile = false;
|
||||
mGet = new GetMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath));
|
||||
mGet = new GetMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
|
||||
Iterator<OnDatatransferProgressListener> it = null;
|
||||
|
||||
FileOutputStream fos = null;
|
||||
|
@ -75,16 +75,16 @@ public class ExistenceCheckRemoteOperation extends RemoteOperation {
|
||||
RemoteOperationResult result = null;
|
||||
HeadMethod head = null;
|
||||
try {
|
||||
head = new HeadMethod(client.getBaseUri() + WebdavUtils.encodePath(mPath));
|
||||
head = new HeadMethod(client.getWebdavUri() + WebdavUtils.encodePath(mPath));
|
||||
int status = client.executeMethod(head, TIMEOUT, TIMEOUT);
|
||||
client.exhaustResponse(head.getResponseBodyAsStream());
|
||||
boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) || (status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent);
|
||||
result = new RemoteOperationResult(success, status, head.getResponseHeaders());
|
||||
Log.d(TAG, "Existence check for " + client.getBaseUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + "finished with HTTP status " + status + (!success?"(FAIL)":""));
|
||||
Log.d(TAG, "Existence check for " + client.getWebdavUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + "finished with HTTP status " + status + (!success?"(FAIL)":""));
|
||||
|
||||
} catch (Exception e) {
|
||||
result = new RemoteOperationResult(e);
|
||||
Log.e(TAG, "Existence check for " + client.getBaseUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + ": " + result.getLogMessage(), result.getException());
|
||||
Log.e(TAG, "Existence check for " + client.getWebdavUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + ": " + result.getLogMessage(), result.getException());
|
||||
|
||||
} finally {
|
||||
if (head != null)
|
||||
|
@ -38,36 +38,30 @@ import com.owncloud.android.lib.network.OwnCloudClient;
|
||||
import com.owncloud.android.lib.operations.common.RemoteOperation;
|
||||
import com.owncloud.android.lib.operations.common.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;
|
||||
import com.owncloud.android.lib.operations.common.ShareRemoteFile;
|
||||
import com.owncloud.android.lib.operations.common.OCShare;
|
||||
import com.owncloud.android.lib.utils.ShareXMLParser;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
/**
|
||||
* Get the data from the server to know shared files/folders
|
||||
* Get the data from the server to know shares
|
||||
*
|
||||
* @author masensio
|
||||
*
|
||||
*/
|
||||
|
||||
public class GetRemoteSharedFilesOperation extends RemoteOperation {
|
||||
public class GetRemoteSharesOperation extends RemoteOperation {
|
||||
|
||||
private static final String TAG = GetRemoteSharedFilesOperation.class.getSimpleName();
|
||||
private static final String TAG = GetRemoteSharesOperation.class.getSimpleName();
|
||||
|
||||
// OCS Route
|
||||
private static final String SHAREAPI_ROUTE ="/ocs/v1.php/apps/files_sharing/api/v1/shares";
|
||||
|
||||
private ArrayList<ShareRemoteFile> mSharedFiles; // List of files for result
|
||||
private ArrayList<OCShare> mShares; // List of shares for result
|
||||
|
||||
private String mUrlServer;
|
||||
|
||||
public ArrayList<ShareRemoteFile> getSharedFiles() {
|
||||
return mSharedFiles;
|
||||
}
|
||||
|
||||
public GetRemoteSharedFilesOperation(String urlServer) {
|
||||
mUrlServer = urlServer;
|
||||
public GetRemoteSharesOperation() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -76,8 +70,8 @@ public class GetRemoteSharedFilesOperation extends RemoteOperation {
|
||||
int status = -1;
|
||||
|
||||
// Get Method
|
||||
GetMethod get = new GetMethod(mUrlServer + SHAREAPI_ROUTE);
|
||||
Log.d(TAG, "URL ------> " + mUrlServer + SHAREAPI_ROUTE);
|
||||
GetMethod get = new GetMethod(client.getBaseUri() + SHAREAPI_ROUTE);
|
||||
Log.d(TAG, "URL ------> " + client.getBaseUri() + SHAREAPI_ROUTE);
|
||||
|
||||
// Get the response
|
||||
try{
|
||||
@ -91,10 +85,15 @@ public class GetRemoteSharedFilesOperation extends RemoteOperation {
|
||||
// convert String into InputStream
|
||||
InputStream is = new ByteArrayInputStream(response.getBytes());
|
||||
ShareXMLParser xmlParser = new ShareXMLParser();
|
||||
mSharedFiles = xmlParser.parseXMLResponse(is);
|
||||
if (mSharedFiles != null) {
|
||||
Log.d(TAG, "Shared Files: " + mSharedFiles.size());
|
||||
mShares = xmlParser.parseXMLResponse(is);
|
||||
if (mShares != null) {
|
||||
Log.d(TAG, "Shares: " + mShares.size());
|
||||
result = new RemoteOperationResult(ResultCode.OK);
|
||||
ArrayList<Object> sharesObjects = new ArrayList<Object>();
|
||||
for (OCShare share: mShares) {
|
||||
sharesObjects.add(share);
|
||||
}
|
||||
result.setData(sharesObjects);
|
||||
}
|
||||
}
|
||||
} catch (HttpException e) {
|
@ -75,8 +75,8 @@ public class GetUserNameRemoteOperation extends RemoteOperation {
|
||||
int status = -1;
|
||||
|
||||
// Get Method
|
||||
GetMethod get = new GetMethod(client.getBaseUri() + OCS_ROUTE);
|
||||
Log.d(TAG, "URL ------> " + client.getBaseUri() + OCS_ROUTE);
|
||||
GetMethod get = new GetMethod(client.getWebdavUri() + OCS_ROUTE);
|
||||
Log.d(TAG, "URL ------> " + client.getWebdavUri() + OCS_ROUTE);
|
||||
// Add the Header
|
||||
get.addRequestHeader(HEADER_OCS_API, HEADER_OCS_API_VALUE);
|
||||
|
||||
|
@ -158,11 +158,11 @@ public class OwnCloudServerCheckOperation extends RemoteOperation {
|
||||
tryConnection(client, mUrl + AccountUtils.STATUS_PATH);
|
||||
|
||||
} else {
|
||||
client.setBaseUri(Uri.parse("https://" + mUrl + AccountUtils.STATUS_PATH));
|
||||
client.setWebdavUri(Uri.parse("https://" + mUrl + AccountUtils.STATUS_PATH));
|
||||
boolean httpsSuccess = tryConnection(client, "https://" + mUrl + AccountUtils.STATUS_PATH);
|
||||
if (!httpsSuccess && !mLatestResult.isSslRecoverableException()) {
|
||||
Log.d(TAG, "establishing secure connection failed, trying non secure connection");
|
||||
client.setBaseUri(Uri.parse("http://" + mUrl + AccountUtils.STATUS_PATH));
|
||||
client.setWebdavUri(Uri.parse("http://" + mUrl + AccountUtils.STATUS_PATH));
|
||||
tryConnection(client, "http://" + mUrl + AccountUtils.STATUS_PATH);
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class ReadRemoteFileOperation extends RemoteOperation {
|
||||
|
||||
/// take the duty of check the server for the current state of the file there
|
||||
try {
|
||||
propfind = new PropFindMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath),
|
||||
propfind = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath),
|
||||
DavConstants.PROPFIND_ALL_PROP,
|
||||
DavConstants.DEPTH_0);
|
||||
int status;
|
||||
@ -87,9 +87,9 @@ public class ReadRemoteFileOperation extends RemoteOperation {
|
||||
if (isMultiStatus) {
|
||||
// Parse response
|
||||
MultiStatus resp = propfind.getResponseBodyAsMultiStatus();
|
||||
WebdavEntry we = new WebdavEntry(resp.getResponses()[0], client.getBaseUri().getPath());
|
||||
WebdavEntry we = new WebdavEntry(resp.getResponses()[0], client.getWebdavUri().getPath());
|
||||
RemoteFile remoteFile = new RemoteFile(we);
|
||||
ArrayList<RemoteFile> files = new ArrayList<RemoteFile>();
|
||||
ArrayList<Object> files = new ArrayList<Object>();
|
||||
files.add(remoteFile);
|
||||
|
||||
// Result of the operation
|
||||
|
@ -52,7 +52,7 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
|
||||
private static final String TAG = ReadRemoteFolderOperation.class.getSimpleName();
|
||||
|
||||
private String mRemotePath;
|
||||
private ArrayList<RemoteFile> mFolderAndFiles;
|
||||
private ArrayList<Object> mFolderAndFiles;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -75,7 +75,7 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
|
||||
|
||||
try {
|
||||
// remote request
|
||||
query = new PropFindMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath),
|
||||
query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath),
|
||||
DavConstants.PROPFIND_ALL_PROP,
|
||||
DavConstants.DEPTH_1);
|
||||
int status = client.executeMethod(query);
|
||||
@ -134,17 +134,17 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
|
||||
* @return
|
||||
*/
|
||||
private void readData(MultiStatus dataInServer, OwnCloudClient client) {
|
||||
mFolderAndFiles = new ArrayList<RemoteFile>();
|
||||
mFolderAndFiles = new ArrayList<Object>();
|
||||
|
||||
// parse data from remote folder
|
||||
WebdavEntry we = new WebdavEntry(dataInServer.getResponses()[0], client.getBaseUri().getPath());
|
||||
WebdavEntry we = new WebdavEntry(dataInServer.getResponses()[0], client.getWebdavUri().getPath());
|
||||
mFolderAndFiles.add(fillOCFile(we));
|
||||
|
||||
// loop to update every child
|
||||
RemoteFile remoteFile = null;
|
||||
for (int i = 1; i < dataInServer.getResponses().length; ++i) {
|
||||
/// new OCFile instance with the data from the server
|
||||
we = new WebdavEntry(dataInServer.getResponses()[i], client.getBaseUri().getPath());
|
||||
we = new WebdavEntry(dataInServer.getResponses()[i], client.getWebdavUri().getPath());
|
||||
remoteFile = fillOCFile(we);
|
||||
mFolderAndFiles.add(remoteFile);
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public class RemoveRemoteFileOperation extends RemoteOperation {
|
||||
DeleteMethod delete = null;
|
||||
|
||||
try {
|
||||
delete = new DeleteMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath));
|
||||
delete = new DeleteMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
|
||||
int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT);
|
||||
|
||||
delete.getResponseBodyAsString(); // exhaust the response, although not interesting
|
||||
|
@ -104,8 +104,8 @@ public class RenameRemoteFileOperation extends RemoteOperation {
|
||||
return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
|
||||
}
|
||||
|
||||
move = new LocalMoveMethod( client.getBaseUri() + WebdavUtils.encodePath(mOldRemotePath),
|
||||
client.getBaseUri() + WebdavUtils.encodePath(mNewRemotePath));
|
||||
move = new LocalMoveMethod( client.getWebdavUri() + WebdavUtils.encodePath(mOldRemotePath),
|
||||
client.getWebdavUri() + WebdavUtils.encodePath(mNewRemotePath));
|
||||
int status = client.executeMethod(move, RENAME_READ_TIMEOUT, RENAME_CONNECTION_TIMEOUT);
|
||||
|
||||
move.getResponseBodyAsString(); // exhaust response, although not interesting
|
||||
|
@ -80,7 +80,7 @@ public class UploadRemoteFileOperation extends RemoteOperation {
|
||||
if (mCancellationRequested.get()) {
|
||||
throw new OperationCancelledException();
|
||||
} else {
|
||||
mPutMethod = new PutMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath));
|
||||
mPutMethod = new PutMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ import org.xmlpull.v1.XmlPullParserFactory;
|
||||
import android.util.Log;
|
||||
import android.util.Xml;
|
||||
|
||||
import com.owncloud.android.lib.operations.common.ShareRemoteFile;
|
||||
import com.owncloud.android.lib.operations.common.OCShare;
|
||||
import com.owncloud.android.lib.operations.common.ShareType;
|
||||
|
||||
/**
|
||||
@ -111,7 +111,7 @@ public class ShareXMLParser {
|
||||
* @throws XmlPullParserException
|
||||
* @throws IOException
|
||||
*/
|
||||
public ArrayList<ShareRemoteFile> parseXMLResponse(InputStream is) throws XmlPullParserException, IOException {
|
||||
public ArrayList<OCShare> parseXMLResponse(InputStream is) throws XmlPullParserException, IOException {
|
||||
|
||||
try {
|
||||
// XMLPullParser
|
||||
@ -136,8 +136,8 @@ public class ShareXMLParser {
|
||||
* @throws XmlPullParserException
|
||||
* @throws IOException
|
||||
*/
|
||||
private ArrayList<ShareRemoteFile> readOCS (XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
ArrayList<ShareRemoteFile> sharedFiles = new ArrayList<ShareRemoteFile>();
|
||||
private ArrayList<OCShare> readOCS (XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
ArrayList<OCShare> shares = new ArrayList<OCShare>();
|
||||
parser.require(XmlPullParser.START_TAG, ns , NODE_OCS);
|
||||
while (parser.next() != XmlPullParser.END_TAG) {
|
||||
if (parser.getEventType() != XmlPullParser.START_TAG) {
|
||||
@ -148,13 +148,13 @@ public class ShareXMLParser {
|
||||
if (name.equalsIgnoreCase(NODE_META)) {
|
||||
readMeta(parser);
|
||||
} else if (name.equalsIgnoreCase(NODE_DATA)) {
|
||||
sharedFiles = readData(parser);
|
||||
shares = readData(parser);
|
||||
} else {
|
||||
skip(parser);
|
||||
}
|
||||
|
||||
}
|
||||
return sharedFiles;
|
||||
return shares;
|
||||
|
||||
|
||||
}
|
||||
@ -194,8 +194,8 @@ public class ShareXMLParser {
|
||||
* @throws XmlPullParserException
|
||||
* @throws IOException
|
||||
*/
|
||||
private ArrayList<ShareRemoteFile> readData(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
ArrayList<ShareRemoteFile> sharedFiles = new ArrayList<ShareRemoteFile>();
|
||||
private ArrayList<OCShare> readData(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
ArrayList<OCShare> shares = new ArrayList<OCShare>();
|
||||
|
||||
parser.require(XmlPullParser.START_TAG, ns, NODE_DATA);
|
||||
Log.d(TAG, "---- NODE DATA ---");
|
||||
@ -205,13 +205,13 @@ public class ShareXMLParser {
|
||||
}
|
||||
String name = parser.getName();
|
||||
if (name.equalsIgnoreCase(NODE_ELEMENT)) {
|
||||
sharedFiles.add(readElement(parser));
|
||||
shares.add(readElement(parser));
|
||||
} else {
|
||||
skip(parser);
|
||||
}
|
||||
}
|
||||
|
||||
return sharedFiles;
|
||||
return shares;
|
||||
|
||||
}
|
||||
|
||||
@ -222,10 +222,10 @@ public class ShareXMLParser {
|
||||
* @throws XmlPullParserException
|
||||
* @throws IOException
|
||||
*/
|
||||
private ShareRemoteFile readElement(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
private OCShare readElement(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
parser.require(XmlPullParser.START_TAG, ns, NODE_ELEMENT);
|
||||
|
||||
ShareRemoteFile sharedFile = new ShareRemoteFile();
|
||||
OCShare share = new OCShare();
|
||||
|
||||
Log.d(TAG, "---- NODE ELEMENT ---");
|
||||
while (parser.next() != XmlPullParser.END_TAG) {
|
||||
@ -236,44 +236,44 @@ public class ShareXMLParser {
|
||||
String name = parser.getName();
|
||||
|
||||
if (name.equalsIgnoreCase(NODE_ID)) {
|
||||
sharedFile.setIdRemoteShared(Integer.parseInt(readNode(parser, NODE_ID)));
|
||||
share.setIdRemoteShared(Integer.parseInt(readNode(parser, NODE_ID)));
|
||||
|
||||
} else if (name.equalsIgnoreCase(NODE_ITEM_TYPE)) {
|
||||
sharedFile.setIsDirectory(readNode(parser, NODE_ITEM_TYPE).equalsIgnoreCase(TYPE_FOLDER));
|
||||
share.setIsDirectory(readNode(parser, NODE_ITEM_TYPE).equalsIgnoreCase(TYPE_FOLDER));
|
||||
|
||||
} else if (name.equalsIgnoreCase(NODE_ITEM_SOURCE)) {
|
||||
sharedFile.setItemSource(Long.parseLong(readNode(parser, NODE_ITEM_SOURCE)));
|
||||
share.setItemSource(Long.parseLong(readNode(parser, NODE_ITEM_SOURCE)));
|
||||
|
||||
} else if (name.equalsIgnoreCase(NODE_PARENT)) {
|
||||
readNode(parser, NODE_PARENT);
|
||||
|
||||
} else if (name.equalsIgnoreCase(NODE_SHARE_TYPE)) {
|
||||
int value = Integer.parseInt(readNode(parser, NODE_SHARE_TYPE));
|
||||
sharedFile.setShareType(ShareType.fromValue(value));
|
||||
share.setShareType(ShareType.fromValue(value));
|
||||
|
||||
} else if (name.equalsIgnoreCase(NODE_SHARE_WITH)) {
|
||||
sharedFile.setShareWith(readNode(parser, NODE_SHARE_WITH));
|
||||
share.setShareWith(readNode(parser, NODE_SHARE_WITH));
|
||||
|
||||
} else if (name.equalsIgnoreCase(NODE_FILE_SOURCE)) {
|
||||
sharedFile.setFileSource(Long.parseLong(readNode(parser, NODE_FILE_SOURCE)));
|
||||
share.setFileSource(Long.parseLong(readNode(parser, NODE_FILE_SOURCE)));
|
||||
|
||||
} else if (name.equalsIgnoreCase(NODE_PATH)) {
|
||||
sharedFile.setPath(readNode(parser, NODE_PATH));
|
||||
share.setPath(readNode(parser, NODE_PATH));
|
||||
|
||||
} else if (name.equalsIgnoreCase(NODE_PERMISSIONS)) {
|
||||
sharedFile.setPermissions(Integer.parseInt(readNode(parser, NODE_PERMISSIONS)));
|
||||
share.setPermissions(Integer.parseInt(readNode(parser, NODE_PERMISSIONS)));
|
||||
|
||||
} else if (name.equalsIgnoreCase(NODE_STIME)) {
|
||||
sharedFile.setSharedDate(Long.parseLong(readNode(parser, NODE_STIME)));
|
||||
share.setSharedDate(Long.parseLong(readNode(parser, NODE_STIME)));
|
||||
|
||||
} else if (name.equalsIgnoreCase(NODE_EXPIRATION)) {
|
||||
String value = readNode(parser, NODE_EXPIRATION);
|
||||
if (!value.isEmpty()) {
|
||||
sharedFile.setExpirationDate(Long.parseLong(readNode(parser, NODE_EXPIRATION))); // check if expiration is in long format or date format
|
||||
share.setExpirationDate(Long.parseLong(readNode(parser, NODE_EXPIRATION))); // check if expiration is in long format or date format
|
||||
}
|
||||
|
||||
} else if (name.equalsIgnoreCase(NODE_TOKEN)) {
|
||||
sharedFile.setToken(readNode(parser, NODE_TOKEN));
|
||||
share.setToken(readNode(parser, NODE_TOKEN));
|
||||
|
||||
} else if (name.equalsIgnoreCase(NODE_STORAGE)) {
|
||||
readNode(parser, NODE_STORAGE);
|
||||
@ -281,14 +281,14 @@ public class ShareXMLParser {
|
||||
readNode(parser, NODE_MAIL_SEND);
|
||||
|
||||
} else if (name.equalsIgnoreCase(NODE_SHARE_WITH_DISPLAY_NAME)) {
|
||||
sharedFile.setSharedWithDisplayName(readNode(parser, NODE_SHARE_WITH_DISPLAY_NAME));
|
||||
share.setSharedWithDisplayName(readNode(parser, NODE_SHARE_WITH_DISPLAY_NAME));
|
||||
|
||||
} else {
|
||||
skip(parser);
|
||||
}
|
||||
}
|
||||
|
||||
return sharedFile;
|
||||
return share;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user