arnaucube
arnaucube/openEventsPlatformAppPublic Self-hosted repository
openEventsPlatformApp/plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js
plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.jsRaw
 1/*
 2 *
 3 * Licensed to the Apache Software Foundation (ASF) under one
 4 * or more contributor license agreements.  See the NOTICE file
 5 * distributed with this work for additional information
 6 * regarding copyright ownership.  The ASF licenses this file
 7 * to you under the Apache License, Version 2.0 (the
 8 * "License"); you may not use this file except in compliance
 9 * with the License.  You may obtain a copy of the License at
10 *
11 *   http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied.  See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20*/
21(function() {
22    //For browser platform: not all browsers use overrided `resolveLocalFileSystemURL`.
23    function checkBrowser() {
24        if (cordova.platformId === "browser" && require('./isChrome')()) {
25            module.exports.resolveLocalFileSystemURL = window.resolveLocalFileSystemURL || window.webkitResolveLocalFileSystemURL;
26            return true;
27        }
28        return false;
29    }
30    if (checkBrowser()) {
31        return;
32    }
33
34    var argscheck = require('cordova/argscheck'),
35        DirectoryEntry = require('./DirectoryEntry'),
36        FileEntry = require('./FileEntry'),
37        FileError = require('./FileError'),
38        exec = require('cordova/exec');
39    var fileSystems = require('./fileSystems');
40
41    /**
42     * Look up file system Entry referred to by local URI.
43     * @param {DOMString} uri  URI referring to a local file or directory
44     * @param successCallback  invoked with Entry object corresponding to URI
45     * @param errorCallback    invoked if error occurs retrieving file system entry
46     */
47    module.exports.resolveLocalFileSystemURL = module.exports.resolveLocalFileSystemURL || function(uri, successCallback, errorCallback) {
48        argscheck.checkArgs('sFF', 'resolveLocalFileSystemURI', arguments);
49        // error callback
50        var fail = function(error) {
51            if (errorCallback) {
52                errorCallback(new FileError(error));
53            }
54        };
55        // sanity check for 'not:valid:filename' or '/not:valid:filename'
56        // file.spec.12 window.resolveLocalFileSystemURI should error (ENCODING_ERR) when resolving invalid URI with leading /.
57        if(!uri || uri.split(":").length > 2) {
58            setTimeout( function() {
59                fail(FileError.ENCODING_ERR);
60            },0);
61            return;
62        }
63        // if successful, return either a file or directory entry
64        var success = function(entry) {
65            if (entry) {
66                if (successCallback) {
67                    // create appropriate Entry object
68                    var fsName = entry.filesystemName || (entry.filesystem && entry.filesystem.name) || (entry.filesystem == window.PERSISTENT ? 'persistent' : 'temporary');
69                    fileSystems.getFs(fsName, function(fs) {
70                        // This should happen only on platforms that haven't implemented requestAllFileSystems (windows)
71                        if (!fs) {
72                            fs = new FileSystem(fsName, {name:"", fullPath:"/"});
73                        }
74                        var result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath, fs, entry.nativeURL) : new FileEntry(entry.name, entry.fullPath, fs, entry.nativeURL);
75                        successCallback(result);
76                    });
77                }
78            }
79            else {
80                // no Entry object returned
81                fail(FileError.NOT_FOUND_ERR);
82            }
83        };
84
85        exec(success, fail, "File", "resolveLocalFileSystemURI", [uri]);
86    };
87
88    module.exports.resolveLocalFileSystemURI = function() {
89        console.log("resolveLocalFileSystemURI is deprecated. Please call resolveLocalFileSystemURL instead.");
90        module.exports.resolveLocalFileSystemURL.apply(this, arguments);
91    };
92})();