You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2015/03/11 16:35:14 UTC
[03/13] cordova-plugin-file git commit: android: Ensure
LocalFilesystemURL can only be created with "cdvfile" URLs
android: Ensure LocalFilesystemURL can only be created with "cdvfile" URLs
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/8f7b013b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/8f7b013b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/8f7b013b
Branch: refs/heads/master
Commit: 8f7b013baad2545eb7ed83e12ad924d354c5f1b2
Parents: bad4242
Author: Andrew Grieve <ag...@chromium.org>
Authored: Mon Mar 9 14:44:32 2015 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Mar 11 11:35:07 2015 -0400
----------------------------------------------------------------------
src/android/ContentFilesystem.java | 48 +++++++++-------------
src/android/FileUtils.java | 38 +++++++++---------
src/android/Filesystem.java | 22 +++++-----
src/android/LocalFilesystem.java | 20 ++++-----
src/android/LocalFilesystemURL.java | 69 ++++++++++++++------------------
5 files changed, 88 insertions(+), 109 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/8f7b013b/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index 3e967f3..a4a2227 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -53,28 +53,20 @@ public class ContentFilesystem extends Filesystem {
@Override
public JSONObject getEntryForLocalURL(LocalFilesystemURL inputURL) throws IOException {
- if ("/".equals(inputURL.fullPath)) {
- return LocalFilesystem.makeEntryForURL(inputURL, true, inputURL.URL.toString());
+ if ("/".equals(inputURL.uri.getPath())) {
+ return LocalFilesystem.makeEntryForURL(inputURL, true, inputURL.uri);
}
// Get the cursor to validate that the file exists
Cursor cursor = openCursorForURL(inputURL);
- String filePath = null;
- try {
- if (cursor == null || !cursor.moveToFirst()) {
- throw new FileNotFoundException();
- }
- filePath = filesystemPathForCursor(cursor);
- } finally {
- if (cursor != null)
- cursor.close();
- }
- if (filePath == null) {
- filePath = inputURL.URL.toString();
+ File file = resourceApi.mapUriToFile(inputURL.uri);
+ Uri nativeUrl;
+ if (file == null) {
+ nativeUrl = inputURL.uri;
} else {
- filePath = "file://" + filePath;
+ nativeUrl = Uri.fromFile(file);
}
- return makeEntryForPath(inputURL.fullPath, inputURL.filesystemName, false /*fp.isDirectory()*/, filePath);
+ return makeEntryForURL(inputURL, false /*fp.isDirectory()*/, nativeUrl);
}
@Override
@@ -85,7 +77,7 @@ public class ContentFilesystem extends Filesystem {
throw new IOException("Cannot create content url");
}
}
- LocalFilesystemURL requestedURL = new LocalFilesystemURL(Uri.withAppendedPath(inputURL.URL, fileName));
+ LocalFilesystemURL requestedURL = LocalFilesystemURL.parse(Uri.withAppendedPath(inputURL.uri, fileName));
File fp = new File(this.filesystemPathForURL(requestedURL));
if (!fp.exists()) {
throw new FileNotFoundException("path does not exist");
@@ -100,7 +92,7 @@ public class ContentFilesystem extends Filesystem {
}
}
// Return the directory
- return makeEntryForPath(requestedURL.fullPath, requestedURL.filesystemName, directory, Uri.fromFile(fp).toString());
+ return makeEntryForURL(requestedURL, directory, Uri.fromFile(fp));
}
@@ -155,9 +147,9 @@ public class ContentFilesystem extends Filesystem {
JSONObject metadata = new JSONObject();
try {
metadata.put("size", size);
- metadata.put("type", resourceApi.getMimeType(inputURL.URL));
- metadata.put("name", inputURL.filesystemName);
- metadata.put("fullPath", inputURL.fullPath);
+ metadata.put("type", resourceApi.getMimeType(inputURL.uri));
+ metadata.put("name", name);
+ metadata.put("fullPath", inputURL.pathAndQuery);
metadata.put("lastModifiedDate", lastModified);
} catch (JSONException e) {
return null;
@@ -175,8 +167,8 @@ public class ContentFilesystem extends Filesystem {
// Figure out where we should be copying to
final LocalFilesystemURL destinationURL = makeDestinationURL(newName, srcURL, destURL);
- OutputStream os = resourceApi.openOutputStream(destURL.URL);
- CordovaResourceApi.OpenForReadResult ofrr = resourceApi.openForRead(srcURL.URL);
+ OutputStream os = resourceApi.openOutputStream(destURL.uri);
+ CordovaResourceApi.OpenForReadResult ofrr = resourceApi.openForRead(srcURL.uri);
if (move && !srcFs.canRemoveFileAtLocalURL(srcURL)) {
throw new NoModificationAllowedException("Cannot move file at source URL");
}
@@ -188,7 +180,7 @@ public class ContentFilesystem extends Filesystem {
if (move) {
srcFs.removeFileAtLocalURL(srcURL);
}
- return makeEntryForURL(destinationURL, false, destinationURL.URL.toString());
+ return makeEntryForURL(destinationURL, false, destinationURL.uri);
} else {
// Need to copy the hard way
return super.copyFileToURL(destURL, newName, srcFs, srcURL, move);
@@ -199,7 +191,7 @@ public class ContentFilesystem extends Filesystem {
@Override
public void readFileAtURL(LocalFilesystemURL inputURL, long start, long end,
ReadFileCallback readFileCallback) throws IOException {
- CordovaResourceApi.OpenForReadResult ofrr = resourceApi.openForRead(inputURL.URL);
+ CordovaResourceApi.OpenForReadResult ofrr = resourceApi.openForRead(inputURL.uri);
if (end < 0) {
end = ofrr.length;
}
@@ -228,7 +220,7 @@ public class ContentFilesystem extends Filesystem {
protected Cursor openCursorForURL(LocalFilesystemURL url) {
ContentResolver contentResolver = context.getContentResolver();
- Cursor cursor = contentResolver.query(url.URL, null, null, null, null);
+ Cursor cursor = contentResolver.query(url.uri, null, null, null, null);
return cursor;
}
@@ -257,7 +249,7 @@ public class ContentFilesystem extends Filesystem {
@Override
public String filesystemPathForURL(LocalFilesystemURL url) {
- File f = resourceApi.mapUriToFile(url.URL);
+ File f = resourceApi.mapUriToFile(url.uri);
return f == null ? null : f.getAbsolutePath();
}
@@ -277,7 +269,7 @@ public class ContentFilesystem extends Filesystem {
@Override
OutputStream getOutputStreamForURL(LocalFilesystemURL inputURL)
throws IOException {
- OutputStream os = resourceApi.openOutputStream(inputURL.URL);
+ OutputStream os = resourceApi.openOutputStream(inputURL.uri);
return os;
}
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/8f7b013b/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 043bdca..2a1e965 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -214,7 +214,7 @@ public class FileUtils extends CordovaPlugin {
private Filesystem filesystemForURL(LocalFilesystemURL localURL) {
if (localURL == null) return null;
- return filesystemForName(localURL.filesystemName);
+ return filesystemForName(localURL.fsName);
}
@Override
@@ -224,7 +224,7 @@ public class FileUtils extends CordovaPlugin {
return null;
}
try {
- LocalFilesystemURL inputURL = new LocalFilesystemURL(uri);
+ LocalFilesystemURL inputURL = LocalFilesystemURL.parse(uri);
Filesystem fs = this.filesystemForURL(inputURL);
if (fs == null) {
return null;
@@ -511,7 +511,7 @@ public class FileUtils extends CordovaPlugin {
public String filesystemPathForURL(String localURLstr) throws MalformedURLException {
try {
- LocalFilesystemURL inputURL = new LocalFilesystemURL(localURLstr);
+ LocalFilesystemURL inputURL = LocalFilesystemURL.parse(localURLstr);
Filesystem fs = this.filesystemForURL(inputURL);
if (fs == null) {
throw new MalformedURLException("No installed handlers for this URL");
@@ -534,9 +534,9 @@ public class FileUtils extends CordovaPlugin {
if (url != null) {
// A shorter fullPath implies that the filesystem is a better
// match for the local path than the previous best.
- if (localURL == null || (url.fullPath.length() < shortestFullPath)) {
+ if (localURL == null || (url.pathAndQuery.length() < shortestFullPath)) {
localURL = url;
- shortestFullPath = url.fullPath.length();
+ shortestFullPath = url.pathAndQuery.length();
}
}
}
@@ -603,7 +603,7 @@ public class FileUtils extends CordovaPlugin {
String path = uri.getPath();
inputURL = this.filesystemURLforLocalPath(path);
} else {
- inputURL = new LocalFilesystemURL(uri);
+ inputURL = LocalFilesystemURL.parse(uri);
}
try {
@@ -627,7 +627,7 @@ public class FileUtils extends CordovaPlugin {
*/
private JSONArray readEntries(String baseURLstr) throws FileNotFoundException, JSONException, MalformedURLException {
try {
- LocalFilesystemURL inputURL = new LocalFilesystemURL(baseURLstr);
+ LocalFilesystemURL inputURL = LocalFilesystemURL.parse(baseURLstr);
Filesystem fs = this.filesystemForURL(inputURL);
if (fs == null) {
throw new MalformedURLException("No installed handlers for this URL");
@@ -658,8 +658,8 @@ public class FileUtils extends CordovaPlugin {
throw new FileNotFoundException();
}
- LocalFilesystemURL srcURL = new LocalFilesystemURL(srcURLstr);
- LocalFilesystemURL destURL = new LocalFilesystemURL(destURLstr);
+ LocalFilesystemURL srcURL = LocalFilesystemURL.parse(srcURLstr);
+ LocalFilesystemURL destURL = LocalFilesystemURL.parse(destURLstr);
Filesystem srcFs = this.filesystemForURL(srcURL);
Filesystem destFs = this.filesystemForURL(destURL);
@@ -685,9 +685,9 @@ public class FileUtils extends CordovaPlugin {
*/
private boolean removeRecursively(String baseURLstr) throws FileExistsException, NoModificationAllowedException, MalformedURLException {
try {
- LocalFilesystemURL inputURL = new LocalFilesystemURL(baseURLstr);
+ LocalFilesystemURL inputURL = LocalFilesystemURL.parse(baseURLstr);
// You can't delete the root directory.
- if ("".equals(inputURL.fullPath) || "/".equals(inputURL.fullPath)) {
+ if ("".equals(inputURL.pathAndQuery) || "/".equals(inputURL.pathAndQuery)) {
throw new NoModificationAllowedException("You can't delete the root directory");
}
@@ -714,9 +714,9 @@ public class FileUtils extends CordovaPlugin {
*/
private boolean remove(String baseURLstr) throws NoModificationAllowedException, InvalidModificationException, MalformedURLException {
try {
- LocalFilesystemURL inputURL = new LocalFilesystemURL(baseURLstr);
+ LocalFilesystemURL inputURL = LocalFilesystemURL.parse(baseURLstr);
// You can't delete the root directory.
- if ("".equals(inputURL.fullPath) || "/".equals(inputURL.fullPath)) {
+ if ("".equals(inputURL.pathAndQuery) || "/".equals(inputURL.pathAndQuery)) {
throw new NoModificationAllowedException("You can't delete the root directory");
}
@@ -748,7 +748,7 @@ public class FileUtils extends CordovaPlugin {
*/
private JSONObject getFile(String baseURLstr, String path, JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException {
try {
- LocalFilesystemURL inputURL = new LocalFilesystemURL(baseURLstr);
+ LocalFilesystemURL inputURL = LocalFilesystemURL.parse(baseURLstr);
Filesystem fs = this.filesystemForURL(inputURL);
if (fs == null) {
throw new MalformedURLException("No installed handlers for this URL");
@@ -767,7 +767,7 @@ public class FileUtils extends CordovaPlugin {
*/
private JSONObject getParent(String baseURLstr) throws JSONException, IOException {
try {
- LocalFilesystemURL inputURL = new LocalFilesystemURL(baseURLstr);
+ LocalFilesystemURL inputURL = LocalFilesystemURL.parse(baseURLstr);
Filesystem fs = this.filesystemForURL(inputURL);
if (fs == null) {
throw new MalformedURLException("No installed handlers for this URL");
@@ -786,7 +786,7 @@ public class FileUtils extends CordovaPlugin {
*/
private JSONObject getFileMetadata(String baseURLstr) throws FileNotFoundException, JSONException, MalformedURLException {
try {
- LocalFilesystemURL inputURL = new LocalFilesystemURL(baseURLstr);
+ LocalFilesystemURL inputURL = LocalFilesystemURL.parse(baseURLstr);
Filesystem fs = this.filesystemForURL(inputURL);
if (fs == null) {
throw new MalformedURLException("No installed handlers for this URL");
@@ -913,7 +913,7 @@ public class FileUtils extends CordovaPlugin {
*/
public void readFileAs(final String srcURLstr, final int start, final int end, final CallbackContext callbackContext, final String encoding, final int resultType) throws MalformedURLException {
try {
- LocalFilesystemURL inputURL = new LocalFilesystemURL(srcURLstr);
+ LocalFilesystemURL inputURL = LocalFilesystemURL.parse(srcURLstr);
Filesystem fs = this.filesystemForURL(inputURL);
if (fs == null) {
throw new MalformedURLException("No installed handlers for this URL");
@@ -982,7 +982,7 @@ public class FileUtils extends CordovaPlugin {
/**/
public long write(String srcURLstr, String data, int offset, boolean isBinary) throws FileNotFoundException, IOException, NoModificationAllowedException {
try {
- LocalFilesystemURL inputURL = new LocalFilesystemURL(srcURLstr);
+ LocalFilesystemURL inputURL = LocalFilesystemURL.parse(srcURLstr);
Filesystem fs = this.filesystemForURL(inputURL);
if (fs == null) {
throw new MalformedURLException("No installed handlers for this URL");
@@ -1000,7 +1000,7 @@ public class FileUtils extends CordovaPlugin {
*/
private long truncateFile(String srcURLstr, long size) throws FileNotFoundException, IOException, NoModificationAllowedException {
try {
- LocalFilesystemURL inputURL = new LocalFilesystemURL(srcURLstr);
+ LocalFilesystemURL inputURL = LocalFilesystemURL.parse(srcURLstr);
Filesystem fs = this.filesystemForURL(inputURL);
if (fs == null) {
throw new MalformedURLException("No installed handlers for this URL");
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/8f7b013b/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index d1cbc27..64b78b8 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -78,8 +78,8 @@ public abstract class Filesystem {
}
}
- public static JSONObject makeEntryForURL(LocalFilesystemURL inputURL, Boolean isDir, String nativeURL) {
- return makeEntryForPath(inputURL.fullPath, inputURL.filesystemName, isDir, nativeURL);
+ public static JSONObject makeEntryForURL(LocalFilesystemURL inputURL, Boolean isDir, Uri nativeURL) {
+ return makeEntryForPath(inputURL.pathAndQuery, inputURL.fsName, isDir, nativeURL.toString());
}
abstract JSONObject getEntryForLocalURL(LocalFilesystemURL inputURL) throws IOException;
@@ -104,29 +104,27 @@ public abstract class Filesystem {
}
public JSONObject getParentForLocalURL(LocalFilesystemURL inputURL) throws IOException {
- LocalFilesystemURL newURL = new LocalFilesystemURL(inputURL.URL);
-
- if (!("".equals(inputURL.fullPath) || "/".equals(inputURL.fullPath))) {
- String dirURL = inputURL.fullPath.replaceAll("/+$", "");
- int lastPathStartsAt = dirURL.lastIndexOf('/')+1;
- newURL.fullPath = newURL.fullPath.substring(0,lastPathStartsAt);
+ Uri parentUri = inputURL.uri;
+ String parentPath = new File(inputURL.uri.getPath()).getParent();
+ if (!"/".equals(parentPath)) {
+ parentUri = inputURL.uri.buildUpon().path(parentPath + '/').build();
}
- return getEntryForLocalURL(newURL);
+ return getEntryForLocalURL(LocalFilesystemURL.parse(parentUri));
}
protected LocalFilesystemURL makeDestinationURL(String newName, LocalFilesystemURL srcURL, LocalFilesystemURL destURL) {
// I know this looks weird but it is to work around a JSON bug.
if ("null".equals(newName) || "".equals(newName)) {
- newName = srcURL.URL.getLastPathSegment();;
+ newName = srcURL.uri.getLastPathSegment();;
}
- String newDest = destURL.URL.toString();
+ String newDest = destURL.uri.toString();
if (newDest.endsWith("/")) {
newDest = newDest + newName;
} else {
newDest = newDest + "/" + newName;
}
- return new LocalFilesystemURL(newDest);
+ return LocalFilesystemURL.parse(newDest);
}
/* Read a source URL (possibly from a different filesystem, srcFs,) and copy it to
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/8f7b013b/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 544663d..805eacd 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -68,7 +68,7 @@ public class LocalFilesystem extends Filesystem {
@Override
public String filesystemPathForURL(LocalFilesystemURL url) {
- return filesystemPathForFullPath(url.fullPath);
+ return filesystemPathForFullPath(url.pathAndQuery);
}
private String fullPathForFilesystemPath(String absolutePath) {
@@ -81,9 +81,9 @@ public class LocalFilesystem extends Filesystem {
protected LocalFilesystemURL URLforFullPath(String fullPath) {
if (fullPath != null) {
if (fullPath.startsWith("/")) {
- return new LocalFilesystemURL(LocalFilesystemURL.FILESYSTEM_PROTOCOL + "://localhost/"+this.name+fullPath);
+ return LocalFilesystemURL.parse(LocalFilesystemURL.FILESYSTEM_PROTOCOL + "://localhost/"+this.name+fullPath);
}
- return new LocalFilesystemURL(LocalFilesystemURL.FILESYSTEM_PROTOCOL + "://localhost/"+this.name+"/"+fullPath);
+ return LocalFilesystemURL.parse(LocalFilesystemURL.FILESYSTEM_PROTOCOL + "://localhost/"+this.name+"/"+fullPath);
}
return null;
@@ -144,7 +144,7 @@ public class LocalFilesystem extends Filesystem {
if (!fp.canRead()) {
throw new IOException();
}
- return LocalFilesystem.makeEntryForURL(inputURL, fp.isDirectory(), Uri.fromFile(fp).toString());
+ return LocalFilesystem.makeEntryForURL(inputURL, fp.isDirectory(), Uri.fromFile(fp));
}
@Override
@@ -171,7 +171,7 @@ public class LocalFilesystem extends Filesystem {
if (path.startsWith("/")) {
requestedURL = URLforFilesystemPath(path);
} else {
- requestedURL = URLforFullPath(normalizePath(inputURL.fullPath + "/" + path));
+ requestedURL = URLforFullPath(normalizePath(inputURL.pathAndQuery + "/" + path));
}
File fp = new File(this.filesystemPathForURL(requestedURL));
@@ -205,7 +205,7 @@ public class LocalFilesystem extends Filesystem {
}
// Return the directory
- return makeEntryForPath(requestedURL.fullPath, requestedURL.filesystemName, directory, Uri.fromFile(fp).toString());
+ return makeEntryForPath(requestedURL.pathAndQuery, requestedURL.fsName, directory, Uri.fromFile(fp).toString());
}
@Override
@@ -256,7 +256,7 @@ public class LocalFilesystem extends Filesystem {
File[] files = fp.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].canRead()) {
- entries.put(makeEntryForPath(fullPathForFilesystemPath(files[i].getAbsolutePath()), inputURL.filesystemName, files[i].isDirectory(), Uri.fromFile(files[i]).toString()));
+ entries.put(makeEntryForPath(fullPathForFilesystemPath(files[i].getAbsolutePath()), inputURL.fsName, files[i].isDirectory(), Uri.fromFile(files[i]).toString()));
}
}
}
@@ -269,7 +269,7 @@ public class LocalFilesystem extends Filesystem {
File file = new File(filesystemPathForURL(inputURL));
if (!file.exists()) {
- throw new FileNotFoundException("File at " + inputURL.URL + " does not exist.");
+ throw new FileNotFoundException("File at " + inputURL.uri + " does not exist.");
}
JSONObject metadata = new JSONObject();
@@ -278,7 +278,7 @@ public class LocalFilesystem extends Filesystem {
metadata.put("size", file.isDirectory() ? 0 : file.length());
metadata.put("type", resourceApi.getMimeType(Uri.fromFile(file)));
metadata.put("name", file.getName());
- metadata.put("fullPath", inputURL.fullPath);
+ metadata.put("fullPath", inputURL.pathAndQuery);
metadata.put("lastModifiedDate", file.lastModified());
} catch (JSONException e) {
return null;
@@ -599,7 +599,7 @@ public class LocalFilesystem extends Filesystem {
File file = new File(filesystemPathForURL(inputURL));
if (!file.exists()) {
- throw new FileNotFoundException("File at " + inputURL.URL + " does not exist.");
+ throw new FileNotFoundException("File at " + inputURL.uri + " does not exist.");
}
RandomAccessFile raf = new RandomAccessFile(filesystemPathForURL(inputURL), "rw");
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/8f7b013b/src/android/LocalFilesystemURL.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystemURL.java b/src/android/LocalFilesystemURL.java
index 2bf40c3..473b587 100644
--- a/src/android/LocalFilesystemURL.java
+++ b/src/android/LocalFilesystemURL.java
@@ -25,50 +25,39 @@ import android.net.Uri;
public class LocalFilesystemURL {
public static final String FILESYSTEM_PROTOCOL = "cdvfile";
-
- Uri URL;
- String filesystemName;
- String fullPath;
- public LocalFilesystemURL(Uri URL) {
- this.URL = URL;
- this.filesystemName = this.filesystemNameForLocalURL(URL);
- this.fullPath = this.fullPathForLocalURL(URL);
- }
-
- private String fullPathForLocalURL(Uri URL) {
- if (FILESYSTEM_PROTOCOL.equals(URL.getScheme()) && "localhost".equals(URL.getHost())) {
- String path = URL.getPath();
- if (URL.getQuery() != null) {
- path = path + "?" + URL.getQuery();
- }
- return path.substring(path.indexOf('/', 1));
- } else if ("content".equals(URL.getScheme())) {
- String path = '/' + URL.getHost() + URL.getPath();
- // Re-encode path component to handle Android 4.4+ Content URLs
- return Uri.encode(path,"/");
- }
- return null;
- }
+ public final Uri uri;
+ public final String fsName;
+ public final String pathAndQuery;
- private String filesystemNameForLocalURL(Uri URL) {
- if (FILESYSTEM_PROTOCOL.equals(URL.getScheme()) && "localhost".equals(URL.getHost())) {
- List<String> pathComponents = URL.getPathSegments();
- if (pathComponents != null && pathComponents.size() > 0) {
- return pathComponents.get(0);
- }
- return null;
- } else if ("content".equals(URL.getScheme())) {
- return "content";
- }
- return null;
+ private LocalFilesystemURL(Uri uri, String fsName, String fsPath) {
+ this.uri = uri;
+ this.fsName = fsName;
+ this.pathAndQuery = fsPath;
}
- public LocalFilesystemURL(String strURL) {
- this(Uri.parse(strURL));
- }
-
+ public static LocalFilesystemURL parse(Uri uri) {
+ if (!FILESYSTEM_PROTOCOL.equals(uri.getScheme())) {
+ return null;
+ }
+ List<String> pathComponents = uri.getPathSegments();
+ if (pathComponents == null || pathComponents.size() == 0) {
+ return null;
+ }
+ String fsName = pathComponents.get(0);
+ String pathAndQuery = uri.getPath();
+ pathAndQuery = pathAndQuery.substring(pathAndQuery.indexOf('/', 1));
+ if (uri.getQuery() != null) {
+ pathAndQuery = pathAndQuery + "?" + uri.getQuery();
+ }
+ return new LocalFilesystemURL(uri, fsName, pathAndQuery);
+ }
+
+ public static LocalFilesystemURL parse(String uri) {
+ return parse(Uri.parse(uri));
+ }
+
public String toString() {
- return "cdvfile://localhost/" + this.filesystemName + this.fullPath;
+ return uri.toString();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org