From: David A. Velasco Date: Tue, 17 Jul 2012 12:26:18 +0000 (+0200) Subject: Fixed problem with some special characters when opening files; renamed WebdavUtils... X-Git-Tag: oc-android-1.4.3~269 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/45f89711be3eda7e677ed5e8fdc9c13daca6dcc9 Fixed problem with some special characters when opening files; renamed WebdavUtils.encode to WebdavUtils.encodePath; fixed null pointer exception in preview --- diff --git a/AndroidManifest.xml b/AndroidManifest.xml index a547234a..362a6018 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -18,7 +18,7 @@ --> + android:versionName="0.1.162B" xmlns:android="http://schemas.android.com/apk/res/android"> diff --git a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java index 61975dd7..9dfa8f6a 100644 --- a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java +++ b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java @@ -220,7 +220,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { for (int i=0; i < files.size() && !mCancellation; i++) { OCFile newFile = files.get(i); if (newFile.getMimetype().equals("DIR")) { - fetchData(getUri().toString() + WebdavUtils.encode(newFile.getRemotePath()), syncResult, newFile.getFileId()); + fetchData(getUri().toString() + WebdavUtils.encodePath(newFile.getRemotePath()), syncResult, newFile.getFileId()); } } if (mCancellation) Log.d(TAG, "Leaving " + uri + " because cancellation request"); diff --git a/src/eu/alefzero/owncloud/ui/adapter/FileListActionListAdapter.java b/src/eu/alefzero/owncloud/ui/adapter/FileListActionListAdapter.java index d0d5b5fe..1556e0d8 100644 --- a/src/eu/alefzero/owncloud/ui/adapter/FileListActionListAdapter.java +++ b/src/eu/alefzero/owncloud/ui/adapter/FileListActionListAdapter.java @@ -23,6 +23,7 @@ import java.io.File; import eu.alefzero.owncloud.R; import eu.alefzero.owncloud.authenticator.AccountAuthenticator; import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta; +import eu.alefzero.webdav.WebdavUtils; import android.accounts.Account; import android.accounts.AccountManager; import android.content.Context; @@ -84,7 +85,7 @@ public class FileListActionListAdapter implements ListAdapter { .getSystemService(Context.ACCOUNT_SERVICE); String ocurl = accm.getUserData(mAccount, AccountAuthenticator.KEY_OC_URL); - ocurl += mFilePath + Uri.encode(mFilename); + ocurl += WebdavUtils.encodePath(mFilePath + mFilename); intent.setData(Uri.parse(ocurl)); } else { intent.putExtra("toDownload", false); diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java index 7eb0c1b8..63d11bf6 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java @@ -197,6 +197,7 @@ public class FileDetailFragment extends SherlockFragment implements IntentFilter filter = new IntentFilter( FileDownloader.DOWNLOAD_FINISH_MESSAGE); getActivity().registerReceiver(mDownloadFinishReceiver, filter); + mPreview = (ImageView)mView.findViewById(R.id.fdPreview); } @Override @@ -340,9 +341,10 @@ public class FileDetailFragment extends SherlockFragment implements @Override public void onClick(View v) { String storagePath = mFile.getStoragePath(); + String encodedStoragePath = WebdavUtils.encodePath(storagePath); try { Intent i = new Intent(Intent.ACTION_VIEW); - i.setDataAndType(Uri.parse("file://"+ storagePath), mFile.getMimetype()); + i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mFile.getMimetype()); i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivity(i); @@ -354,7 +356,7 @@ public class FileDetailFragment extends SherlockFragment implements Intent i = new Intent(Intent.ACTION_VIEW); mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1)); if (mimeType != null && !mimeType.equals(mFile.getMimetype())) { - i.setDataAndType(Uri.parse("file://"+mFile.getStoragePath()), mimeType); + i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mimeType); i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); startActivity(i); toastIt = false; @@ -644,11 +646,11 @@ public class FileDetailFragment extends SherlockFragment implements String baseUrl = am.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL); OwnCloudVersion ocv = new OwnCloudVersion(am.getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION)); String webdav_path = AccountUtils.getWebdavPath(ocv); - Log.d("ASD", ""+baseUrl + webdav_path + WebdavUtils.encode(mOld.getRemotePath())); + Log.d("ASD", ""+baseUrl + webdav_path + WebdavUtils.encodePath(mOld.getRemotePath())); - Log.e("ASD", Uri.parse(baseUrl).getPath() == null ? "" : Uri.parse(baseUrl).getPath() + webdav_path + WebdavUtils.encode(mNew.getRemotePath())); - LocalMoveMethod move = new LocalMoveMethod(baseUrl + webdav_path + WebdavUtils.encode(mOld.getRemotePath()), - Uri.parse(baseUrl).getPath() == null ? "" : Uri.parse(baseUrl).getPath() + webdav_path + WebdavUtils.encode(mNew.getRemotePath())); + Log.e("ASD", Uri.parse(baseUrl).getPath() == null ? "" : Uri.parse(baseUrl).getPath() + webdav_path + WebdavUtils.encodePath(mNew.getRemotePath())); + LocalMoveMethod move = new LocalMoveMethod(baseUrl + webdav_path + WebdavUtils.encodePath(mOld.getRemotePath()), + Uri.parse(baseUrl).getPath() == null ? "" : Uri.parse(baseUrl).getPath() + webdav_path + WebdavUtils.encodePath(mNew.getRemotePath())); try { int status = wc.executeMethod(move); @@ -772,9 +774,9 @@ public class FileDetailFragment extends SherlockFragment implements String baseUrl = am.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL); OwnCloudVersion ocv = new OwnCloudVersion(am.getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION)); String webdav_path = AccountUtils.getWebdavPath(ocv); - Log.d("ASD", ""+baseUrl + webdav_path + WebdavUtils.encode(mFileToRemove.getRemotePath())); + Log.d("ASD", ""+baseUrl + webdav_path + WebdavUtils.encodePath(mFileToRemove.getRemotePath())); - DeleteMethod delete = new DeleteMethod(baseUrl + webdav_path + WebdavUtils.encode(mFileToRemove.getRemotePath())); + DeleteMethod delete = new DeleteMethod(baseUrl + webdav_path + WebdavUtils.encodePath(mFileToRemove.getRemotePath())); HttpMethodParams params = delete.getParams(); params.setSoTimeout(1000); delete.setParams(params); diff --git a/src/eu/alefzero/webdav/WebdavClient.java b/src/eu/alefzero/webdav/WebdavClient.java index 9eafddc1..e248eb84 100644 --- a/src/eu/alefzero/webdav/WebdavClient.java +++ b/src/eu/alefzero/webdav/WebdavClient.java @@ -122,7 +122,7 @@ public class WebdavClient extends HttpClient { */ public boolean downloadFile(String remoteFilepath, File targetPath) { boolean ret = false; - GetMethod get = new GetMethod(mUri.toString() + WebdavUtils.encode(remoteFilepath)); + GetMethod get = new GetMethod(mUri.toString() + WebdavUtils.encodePath(remoteFilepath)); HttpMethodParams params = get.getParams(); params.setSoTimeout(0); // that means "infinite timeout"; it's the default value, but let's make it explicit get.setParams(params); @@ -163,7 +163,7 @@ public class WebdavClient extends HttpClient { * @return */ public boolean deleteFile(String remoteFilePath){ - DavMethod delete = new DeleteMethod(mUri.toString() + WebdavUtils.encode(remoteFilePath)); + DavMethod delete = new DeleteMethod(mUri.toString() + WebdavUtils.encodePath(remoteFilePath)); try { executeMethod(delete); } catch (Throwable e) { @@ -196,7 +196,7 @@ public class WebdavClient extends HttpClient { FileRequestEntity entity = new FileRequestEntity(f, contentType); entity.setOnDatatransferProgressListener(mDataTransferListener); Log.e("ASD", f.exists() + " " + entity.getContentLength()); - PutMethod put = new PutMethod(mUri.toString() + WebdavUtils.encode(remoteTarget)); + PutMethod put = new PutMethod(mUri.toString() + WebdavUtils.encodePath(remoteTarget)); HttpMethodParams params = put.getParams(); params.setSoTimeout(0); // that means "infinite timeout"; it's the default value, but let's make it explicit put.setParams(params); @@ -242,7 +242,7 @@ public class WebdavClient extends HttpClient { */ public boolean createDirectory(String path) { try { - MkColMethod mkcol = new MkColMethod(mUri.toString() + WebdavUtils.encode(path)); + MkColMethod mkcol = new MkColMethod(mUri.toString() + WebdavUtils.encodePath(path)); int status = executeMethod(mkcol); Log.d(TAG, "Status returned " + status); Log.d(TAG, "uri: " + mkcol.getURI().toString()); diff --git a/src/eu/alefzero/webdav/WebdavUtils.java b/src/eu/alefzero/webdav/WebdavUtils.java index 8e7c07b6..b6c0f2e7 100644 --- a/src/eu/alefzero/webdav/WebdavUtils.java +++ b/src/eu/alefzero/webdav/WebdavUtils.java @@ -68,7 +68,7 @@ public class WebdavUtils { * @param remoteFilePath Path * @return Encoded path according to RFC 2396, always starting with "/" */ - public static String encode(String remoteFilePath) { + public static String encodePath(String remoteFilePath) { String encodedPath = Uri.encode(remoteFilePath, "/"); if (!encodedPath.startsWith("/")) encodedPath = "/" + encodedPath;