openEventsPlatformApp/plugins/cordova-plugin-file/src/android/LocalFilesystemURL.java
plugins/cordova-plugin-file/src/android/LocalFilesystemURL.javaRaw
1/*
2 Licensed to the Apache Software Foundation (ASF) under one
3 or more contributor license agreements. See the NOTICE file
4 distributed with this work for additional information
5 regarding copyright ownership. The ASF licenses this file
6 to you under the Apache License, Version 2.0 (the
7 "License"); you may not use this file except in compliance
8 with the License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing,
13 software distributed under the License is distributed on an
14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 KIND, either express or implied. See the License for the
16 specific language governing permissions and limitations
17 under the License.
18 */
19package org.apache.cordova.file;
20
21import android.net.Uri;
22
23public class LocalFilesystemURL {
24
25 public static final String FILESYSTEM_PROTOCOL = "cdvfile";
26
27 public final Uri uri;
28 public final String fsName;
29 public final String path;
30 public final boolean isDirectory;
31
32 private LocalFilesystemURL(Uri uri, String fsName, String fsPath, boolean isDirectory) {
33 this.uri = uri;
34 this.fsName = fsName;
35 this.path = fsPath;
36 this.isDirectory = isDirectory;
37 }
38
39 public static LocalFilesystemURL parse(Uri uri) {
40 if (!FILESYSTEM_PROTOCOL.equals(uri.getScheme())) {
41 return null;
42 }
43 String path = uri.getPath();
44 if (path.length() < 1) {
45 return null;
46 }
47 int firstSlashIdx = path.indexOf('/', 1);
48 if (firstSlashIdx < 0) {
49 return null;
50 }
51 String fsName = path.substring(1, firstSlashIdx);
52 path = path.substring(firstSlashIdx);
53 boolean isDirectory = path.charAt(path.length() - 1) == '/';
54 return new LocalFilesystemURL(uri, fsName, path, isDirectory);
55 }
56
57 public static LocalFilesystemURL parse(String uri) {
58 return parse(Uri.parse(uri));
59 }
60
61 public String toString() {
62 return uri.toString();
63 }
64}