X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/611fe1e4b5790a7a8034c34754366965faf36073..3e2d5f40b4cf14e7de2688eadb7ec0a6b8473329:/src/eu/alefzero/webdav/WebdavClient.java diff --git a/src/eu/alefzero/webdav/WebdavClient.java b/src/eu/alefzero/webdav/WebdavClient.java index 449cfffe..bd58fcc2 100644 --- a/src/eu/alefzero/webdav/WebdavClient.java +++ b/src/eu/alefzero/webdav/WebdavClient.java @@ -80,11 +80,11 @@ public class WebdavClient extends HttpClient { AccountAuthenticator.KEY_OC_VERSION)); String baseUrl = AccountManager.get(context).getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL); String webDavPath = AccountUtils.getWebdavPath(ownCloudVersion); - String username = account.name.substring(0, account.name.indexOf('@')); + String username = account.name.substring(0, account.name.lastIndexOf('@')); String password = AccountManager.get(context).getPassword(account); mUri = Uri.parse(baseUrl + webDavPath); - +Log.e("ASD", ""+username); setCredentials(username, password); } @@ -144,9 +144,9 @@ public class WebdavClient extends HttpClient { mDataTransferListener.transferProgress(readResult); fos.write(bytes, 0, readResult); } - + ret = true; } - ret = true; + } catch (Throwable e) { e.printStackTrace(); targetPath.delete(); @@ -186,7 +186,7 @@ public class WebdavClient extends HttpClient { */ public boolean putFile(String localFile, String remoteTarget, String contentType) { - boolean result = true; + boolean result = false; try { Log.e("ASD", contentType + ""); @@ -200,7 +200,11 @@ public class WebdavClient extends HttpClient { int status = executeMethod(put, 0); Log.d(TAG, "PUT method return with status " + status); - Log.i(TAG, "Uploading, done"); + if (status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT) { + result = true; + Log.i(TAG, "Uploading, done"); + } + } catch (final Exception e) { Log.i(TAG, "" + e.getMessage()); result = false; @@ -248,6 +252,23 @@ public class WebdavClient extends HttpClient { } return true; } + + + /** + * Check if a file exists in the OC server + * + * @return 'Boolean.TRUE' if the file exists; 'Boolean.FALSE' it doesn't exist; NULL if couldn't be checked + */ + public Boolean existsFile(String path) { + try { + HeadMethod head = new HeadMethod(mUri.toString() + WebdavUtils.encodePath(path)); + int status = executeMethod(head); + return (status == HttpStatus.SC_OK); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } /**