arnaucube
arnaucube/openEventsPlatformAppPublic Self-hosted repository
openEventsPlatformApp/plugins/cordova-plugin-file/www/blackberry10/createEntryFromNative.js
plugins/cordova-plugin-file/www/blackberry10/createEntryFromNative.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
22/*
23 * createEntryFromNative
24 * 
25 * IN
26 *  native - webkit Entry
27 * OUT
28 *  returns Cordova entry
29 */
30
31var info = require('cordova-plugin-file.bb10FileSystemInfo'),
32    fileSystems = require('cordova-plugin-file.fileSystems');
33
34module.exports = function (native) {
35    var entry = {
36            nativeEntry: native,
37            isDirectory: !!native.isDirectory,
38            isFile: !!native.isFile,
39            name: native.name,
40            fullPath: native.fullPath,
41            filesystemName: native.filesystem.name,
42            nativeURL: native.toURL()
43        },
44        persistentPath = info.persistentPath.substring(7),
45        temporaryPath = info.temporaryPath.substring(7);
46    //fix bb10 webkit incorrect nativeURL
47    if (native.filesystem.name === 'root') {
48        entry.nativeURL = 'file:///' + FileSystem.encodeURIPath(native.fullPath);
49    } else if (entry.nativeURL.indexOf('filesystem:local:///persistent/') === 0) {
50        entry.nativeURL = info.persistentPath + FileSystem.encodeURIPath(native.fullPath);
51    } else if (entry.nativeURL.indexOf('filesystem:local:///temporary') === 0) {
52        entry.nativeURL = info.temporaryPath + FileSystem.encodeURIPath(native.fullPath);
53    }
54    //translate file system name from bb10 webkit
55    if (entry.filesystemName === 'local__0:Persistent' || entry.fullPath.indexOf(persistentPath) !== -1) {
56        entry.filesystemName = 'persistent';
57    } else if (entry.filesystemName === 'local__0:Temporary' || entry.fullPath.indexOf(temporaryPath) !== -1) {
58        entry.filesystemName = 'temporary';
59    }
60    //add file system property (will be called sync)
61    fileSystems.getFs(entry.filesystemName, function (fs) {
62        entry.filesystem = fs;
63    });
64    //set root on fullPath for persistent / temporary locations
65    entry.fullPath = entry.fullPath.replace(persistentPath, "");
66    entry.fullPath = entry.fullPath.replace(temporaryPath, "");
67    //set trailing slash on directory
68    if (entry.isDirectory && entry.fullPath.substring(entry.fullPath.length - 1) !== '/') {
69        entry.fullPath += '/';
70    }
71    if (entry.isDirectory && entry.nativeURL.substring(entry.nativeURL.length - 1) !== '/') {
72        entry.nativeURL += '/';
73    }
74    return entry;
75};