From: David A. Velasco Date: Mon, 25 Jun 2012 13:18:27 +0000 (+0200) Subject: Changed OCFile to keep mRemotePath as a valid URL; CLEAR YOUR CACHE AFTER INSTALLING X-Git-Tag: oc-android-1.4.3~337^2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/ec38629eca5cf20c1e05a6e1562011b6d47798b5 Changed OCFile to keep mRemotePath as a valid URL; CLEAR YOUR CACHE AFTER INSTALLING --- diff --git a/AndroidManifest.xml b/AndroidManifest.xml index a6b5e6ad..b056899c 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -18,7 +18,7 @@ --> + android:versionName="0.1.132B" xmlns:android="http://schemas.android.com/apk/res/android"> diff --git a/src/eu/alefzero/owncloud/Uploader.java b/src/eu/alefzero/owncloud/Uploader.java index 35995799..757f8030 100644 --- a/src/eu/alefzero/owncloud/Uploader.java +++ b/src/eu/alefzero/owncloud/Uploader.java @@ -18,7 +18,6 @@ package eu.alefzero.owncloud; import java.io.File; -import java.net.URLEncoder; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; @@ -215,7 +214,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro EditText mDirname; public a(String path, EditText dirname) { - mPath = path; + mPath = path; mDirname = dirname; } @@ -239,6 +238,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro } public void onItemClick(AdapterView parent, View view, int position, long id) { + // click on folder in the list Log.d(TAG, "on item click"); Vector tmpfiles = mStorageManager.getDirectoryContent(mFile); if (tmpfiles == null) return; @@ -255,11 +255,13 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro } public void onClick(View v) { + // click on button switch (v.getId()) { case R.id.uploader_choose_folder: - mUploadPath = ""; + mUploadPath = "/"; for (String p : mParents) - mUploadPath += URLEncoder.encode(p) + "/"; + mUploadPath += p + "/"; + mUploadPath = Uri.encode(mUploadPath, "/"); Log.d(TAG, "Uploading file to dir " + mUploadPath); uploadFiles(); @@ -408,11 +410,11 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro final String display_name = c.getString(c.getColumnIndex(Media.DISPLAY_NAME)), data = c.getString(c.getColumnIndex(Media.DATA)); local[i] = data; - remote[i] = mUploadPath + display_name; + remote[i] = mUploadPath + Uri.encode(display_name); } else if (uri.getScheme().equals("file")) { final File file = new File(Uri.decode(uri.toString()).replace(uri.getScheme() + "://", "")); local[i] = file.getAbsolutePath(); - remote[i] = mUploadPath + file.getName(); + remote[i] = mUploadPath + Uri.encode(file.getName()); } } diff --git a/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java b/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java index ed22d3e2..0ad0d1bb 100644 --- a/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java +++ b/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java @@ -288,9 +288,9 @@ public class FileDataStorageManager implements DataStorageManager { file.setStoragePath(c.getString(c .getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH))); if (file.getStoragePath() == null) { - // try to find exisiting file and bind it with current account + // try to find existing file and bind it with current account File sdCard = Environment.getExternalStorageDirectory(); - File f = new File(sdCard.getAbsolutePath() + "/owncloud/" + mAccount.name + file.getRemotePath()); + File f = new File(sdCard.getAbsolutePath() + "/owncloud/" + mAccount.name + file.getURLDecodedRemotePath()); if (f.exists()) file.setStoragePath(f.getAbsolutePath()); } diff --git a/src/eu/alefzero/owncloud/datamodel/OCFile.java b/src/eu/alefzero/owncloud/datamodel/OCFile.java index 68619337..3a720b97 100644 --- a/src/eu/alefzero/owncloud/datamodel/OCFile.java +++ b/src/eu/alefzero/owncloud/datamodel/OCFile.java @@ -19,7 +19,10 @@ package eu.alefzero.owncloud.datamodel; import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; @@ -52,10 +55,19 @@ public class OCFile implements Parcelable, Comparable { * Create new {@link OCFile} with given path * * @param path The remote path of the file + * @throws MalformedURLException */ public OCFile(String path) { resetData(); mNeedsUpdating = false; + // dvelasco: let's make mandatory that mRemotePath is a valid URL always; this will make our life easier with the URL-encoding/decoding + if (path != null && path.length() > 0) { + try { + new URL("http://silly.test.com:8888" + path); + } catch (MalformedURLException e) { + throw new RuntimeException("Trying to create a OCFile with a non valid remote path: " + path , e); + } + } else throw new RuntimeException("Trying to create a OCFile with a non valid remote path: " + path); mRemotePath = path; } @@ -95,6 +107,15 @@ public class OCFile implements Parcelable, Comparable { } /** + * Returns the remote path of the file on ownCloud + * + * @return The remote path to the file + */ + public String getURLDecodedRemotePath() { + return Uri.decode(mRemotePath); + } + + /** * Can be used to check, whether or not this file exists in the database * already * @@ -182,11 +203,8 @@ public class OCFile implements Parcelable, Comparable { * @return The name of the file */ public String getFileName() { - if (mRemotePath != null) { - File f = new File(mRemotePath); - return f.getName().equals("") ? "/" : f.getName(); - } - return null; + File f = new File(getURLDecodedRemotePath()); + return f.getName().length() == 0 ? "/" : f.getName(); } /** @@ -324,13 +342,13 @@ public class OCFile implements Parcelable, Comparable { @Override public int compareTo(OCFile another) { if (isDirectory() && another.isDirectory()) { - return getFileName().toLowerCase().compareTo(another.getFileName().toLowerCase()); + return getRemotePath().toLowerCase().compareTo(another.getRemotePath().toLowerCase()); } else if (isDirectory()) { return -1; } else if (another.isDirectory()) { return 1; } - return getFileName().toLowerCase().compareTo(another.getFileName().toLowerCase()); + return getRemotePath().toLowerCase().compareTo(another.getRemotePath().toLowerCase()); } public boolean equals(Object o) { diff --git a/src/eu/alefzero/owncloud/files/services/FileDownloader.java b/src/eu/alefzero/owncloud/files/services/FileDownloader.java index c051fc19..323faf46 100644 --- a/src/eu/alefzero/owncloud/files/services/FileDownloader.java +++ b/src/eu/alefzero/owncloud/files/services/FileDownloader.java @@ -35,6 +35,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis public static final String DOWNLOAD_FINISH_MESSAGE = "DOWNLOAD_FINISH"; public static final String EXTRA_ACCOUNT = "ACCOUNT"; public static final String EXTRA_FILE_PATH = "FILE_PATH"; + public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH"; public static final String EXTRA_FILE_SIZE = "FILE_SIZE"; private static final String TAG = "FileDownloader"; @@ -43,6 +44,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis private ServiceHandler mServiceHandler; private Account mAccount; private String mFilePath; + private String mRemotePath; private int mLastPercent; private long mTotalDownloadSize; private long mCurrentDownlodSize; @@ -85,6 +87,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis } mAccount = intent.getParcelableExtra(EXTRA_ACCOUNT); mFilePath = intent.getStringExtra(EXTRA_FILE_PATH); + mRemotePath = intent.getStringExtra(EXTRA_REMOTE_PATH); Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; mServiceHandler.sendMessage(msg); @@ -141,7 +144,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis Log.e(TAG, file.getAbsolutePath() + " " + oc_url.toString()); Log.e(TAG, mFilePath+""); - if (wdc.downloadFile(mFilePath, file)) { + if (wdc.downloadFile(mRemotePath, file)) { ContentValues cv = new ContentValues(); cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getAbsolutePath()); getContentResolver().update( diff --git a/src/eu/alefzero/owncloud/files/services/FileUploader.java b/src/eu/alefzero/owncloud/files/services/FileUploader.java index c34e79ce..5d748c96 100644 --- a/src/eu/alefzero/owncloud/files/services/FileUploader.java +++ b/src/eu/alefzero/owncloud/files/services/FileUploader.java @@ -1,7 +1,6 @@ package eu.alefzero.owncloud.files.services; import java.io.File; -import java.net.URLDecoder; import eu.alefzero.owncloud.AccountUtils; import eu.alefzero.owncloud.R; @@ -124,7 +123,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe Toast.makeText(this, "Upload successfull", Toast.LENGTH_SHORT) .show(); } else { - Toast.makeText(this, "No i kupa", Toast.LENGTH_SHORT).show(); + Toast.makeText(this, "Upload could not be completed", Toast.LENGTH_SHORT).show(); } } @@ -176,14 +175,13 @@ public class FileUploader extends Service implements OnDatatransferProgressListe mCurrentIndexUpload = i; if (wc.putFile(mLocalPaths[i], mRemotePaths[i], mimeType)) { mResult |= true; - String decRemotePath = URLDecoder.decode(mRemotePaths[i]); - OCFile new_file = new OCFile(decRemotePath); // FyleSyncAdapter and this MUST use the same encoding when creating a new OCFile + OCFile new_file = new OCFile(mRemotePaths[i]); new_file.setMimetype(mimeType); new_file.setFileLength(new File(mLocalPaths[i]).length()); new_file.setModificationTimestamp(System.currentTimeMillis()); new_file.setLastSyncDate(0); new_file.setStoragePath(mLocalPaths[i]); - File f = new File(URLDecoder.decode(mRemotePaths[i])); + File f = new File(mRemotePaths[i]); new_file.setParentId(storageManager.getFileByPath(f.getParent().endsWith("/")?f.getParent():f.getParent()+"/").getFileId()); storageManager.saveFile(new_file); } diff --git a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java index 85f9cbb3..d5512a18 100644 --- a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java +++ b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java @@ -19,7 +19,6 @@ package eu.alefzero.owncloud.syncadapter; import java.io.IOException; -import java.net.URLDecoder; import java.util.Vector; import org.apache.jackrabbit.webdav.DavException; @@ -140,7 +139,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { } private OCFile fillOCFile(WebdavEntry we) { - OCFile file = new OCFile(URLDecoder.decode(we.path())); + OCFile file = new OCFile(we.path()); file.setCreationTimestamp(we.createTimestamp()); file.setFileLength(we.contentLength()); file.setMimetype(we.contentType()); diff --git a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java index b08c3ab6..25cb714d 100644 --- a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java +++ b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java @@ -22,7 +22,6 @@ import java.io.BufferedReader; import java.io.File; import java.io.InputStreamReader; import java.lang.Thread.UncaughtExceptionHandler; -import java.net.URLEncoder; import java.util.ArrayList; import android.accounts.Account; @@ -223,11 +222,12 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements AccountUtils.getCurrentOwnCloudAccount(this)); String remotepath = new String(); for (int j = mDirectories.getCount() - 2; j >= 0; --j) { - remotepath += "/" + URLEncoder.encode(mDirectories.getItem(j)); + remotepath += "/" + mDirectories.getItem(j); } if (!remotepath.endsWith("/")) remotepath += "/"; - remotepath += URLEncoder.encode(new File(filepath).getName()); + remotepath += new File(filepath).getName(); + remotepath = Uri.encode(remotepath, "/"); i.putExtra(FileUploader.KEY_LOCAL_FILE, filepath); i.putExtra(FileUploader.KEY_REMOTE_FILE, remotepath); @@ -309,9 +309,10 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements // Clear intent extra, so rotating the screen will not return us to this directory getIntent().removeExtra(FileDetailFragment.EXTRA_FILE); - } else { - mCurrentDir = mStorageManager.getFileByPath("/"); } + + if (mCurrentDir == null) + mCurrentDir = mStorageManager.getFileByPath("/"); // Drop-Down navigation and file list restore mDirectories = new CustomArrayAdapter(this, R.layout.sherlock_spinner_dropdown_item); @@ -428,7 +429,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements path = FileDisplayActivity.this.mCurrentDir.getRemotePath(); // Create directory - path += directoryName + "/"; + path += Uri.encode(directoryName) + "/"; Thread thread = new Thread(new DirectoryCreator(path, a)); thread.start(); diff --git a/src/eu/alefzero/owncloud/ui/adapter/FileListActionListAdapter.java b/src/eu/alefzero/owncloud/ui/adapter/FileListActionListAdapter.java index 3673155d..d0d5b5fe 100644 --- a/src/eu/alefzero/owncloud/ui/adapter/FileListActionListAdapter.java +++ b/src/eu/alefzero/owncloud/ui/adapter/FileListActionListAdapter.java @@ -84,7 +84,7 @@ public class FileListActionListAdapter implements ListAdapter { .getSystemService(Context.ACCOUNT_SERVICE); String ocurl = accm.getUserData(mAccount, AccountAuthenticator.KEY_OC_URL); - ocurl += mFilePath + mFilename; + ocurl += mFilePath + Uri.encode(mFilename); intent.setData(Uri.parse(ocurl)); } else { intent.putExtra("toDownload", false); diff --git a/src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java b/src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java index 7e102659..fc28e1ff 100644 --- a/src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java +++ b/src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java @@ -17,7 +17,6 @@ */ package eu.alefzero.owncloud.ui.adapter; -import java.net.URLDecoder; import java.util.Vector; import eu.alefzero.owncloud.DisplayUtils; diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java index 932fa513..21d12413 100644 --- a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java +++ b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java @@ -144,7 +144,8 @@ public class FileDetailFragment extends SherlockFragment implements Intent i = new Intent(getActivity(), FileDownloader.class); i.putExtra(FileDownloader.EXTRA_ACCOUNT, mIntent.getParcelableExtra(FileDownloader.EXTRA_ACCOUNT)); - i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getRemotePath()); + i.putExtra(FileDownloader.EXTRA_REMOTE_PATH, mFile.getRemotePath()); + i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getURLDecodedRemotePath()); i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength()); getActivity().startService(i); } diff --git a/src/eu/alefzero/webdav/WebdavClient.java b/src/eu/alefzero/webdav/WebdavClient.java index a8d22ce8..907de67c 100644 --- a/src/eu/alefzero/webdav/WebdavClient.java +++ b/src/eu/alefzero/webdav/WebdavClient.java @@ -21,7 +21,6 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.net.URLEncoder; import org.apache.commons.httpclient.Credentials; import org.apache.commons.httpclient.HttpClient; @@ -71,19 +70,23 @@ public class WebdavClient extends HttpClient { new EasySSLSocketFactory(), 443)); } - public boolean downloadFile(String filepath, File targetPath) { + public boolean downloadFile(String remoteFilepath, File targetPath) { // HttpGet get = new HttpGet(mUri.toString() + filepath.replace(" ", // "%20")); - String[] splitted_filepath = filepath.split("/"); - filepath = ""; + /* dvelasco - this is not necessary anymore; OCFile.mRemotePath (the origin of remoteFielPath) keeps valid URL strings + String[] splitted_filepath = remoteFilepath.split("/"); + remoteFilepath = ""; for (String s : splitted_filepath) { if (s.equals("")) continue; - filepath += "/" + URLEncoder.encode(s); + remoteFilepath += "/" + URLEncoder.encode(s); } - Log.e("ASD", mUri.toString() + filepath.replace(" ", "%20") + ""); + Log.e("ASD", mUri.toString() + remoteFilepath.replace(" ", "%20") + ""); GetMethod get = new GetMethod(mUri.toString() - + filepath.replace(" ", "%20")); + + remoteFilepath.replace(" ", "%20")); + */ + + GetMethod get = new GetMethod(mUri.toString() + remoteFilepath); // get.setHeader("Host", mUri.getHost()); // get.setHeader("User-Agent", "Android-ownCloud"); @@ -155,8 +158,7 @@ public class WebdavClient extends HttpClient { public boolean createDirectory(String path) { try { - MkColMethod mkcol = new MkColMethod(mUri.toString() + "/" + path - + "/"); + MkColMethod mkcol = new MkColMethod(mUri.toString() + path); int status = executeMethod(mkcol); Log.d(TAG, "Status returned " + status); Log.d(TAG, "uri: " + mkcol.getURI().toString());