This repository has been archived by the owner on Apr 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdevelopment_javascript_File.html
238 lines (188 loc) · 6.35 KB
/
development_javascript_File.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mobile Widgets</title>
<link rel="stylesheet" href="style/style.css" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
<script type="text/javascript" src="js/StructureElts.js"></script>
<script type="text/javascript" src="js/Structure.js"></script>
<script type="text/javascript" src="js/DocElements.js"></script>
</head>
<body>
<script type="text/javascript">
<!--
idCurrentPage = "development_javascript_File";
beginPage();
//-->
</script>
<h1 class="title">File Javascript library</h1>
<script type="text/javascript">
<!--
addIndex();
//-->
</script>
<script type="text/javascript">addTitle("Description", 1);</script>
<p>
The File class provides means to read data from the file system and from an HTTP connection.
</p>
<br/>
<script type="text/javascript">addTitle("Methods", 1);</script>
<p>
<b>int list (String path)</b>:<br/>
Returns the number of files residing in the phone local file system and located
at <b>path</b>, considered as a directory. Path must start with "file://".<br/>
The file system often define root partitions to differentiate the phone memory
from an extension card.<br/>
These roots are automatically managed by this function and are treated as sub
directories of "file://".
</p>
<p>
<b>String getName (int n)</b>:<br/>
Returns the name of the file at position <b>n</b> inside path (list() must have
been called before).
</p>
<p>
<b>bool isDir (int n)</b>:<br/>
Returns true if the entry at position <b>n</b> in the directory referenced by
the last list command is also a directory (so list() must have been obviously
called before).
</p>
<p>
<b>String getFullPath (int n)</b>:<br/>
Returns the full path of the entry <b>n</b>.
</p>
<p>
<b>int open (String path, bool async)</b>:<br/>
Open the file referenced by the path parameter for reading and return an
identifier for future reference (close, getLine, oef, getStatus, ...).<br/>
If path starts with "http://" an HTTP connection is opened.<br/>
If path starts with "file:///" a file connection with the file system is created.<br/>
Otherwise, the content is read from the midlet resource.<br/>
If async is true the function returns immediately and the script must call
getStatus periodically to check whether getLine or getData can be called.
</p>
<p>
<b>void close (int i)</b>:<br/>
Close the stream associated with identifier <b>i</b>.
</p>
<p>
<b>String getLine (int i)</b>:<br/>
Returns the next line (chars up to "\n") in stream associated with identifier <b>i</b>.
</p>
<p>
<b>bool eof (int i)</b>:<br/>
Returns whether the stream associated with <b>i</b> reached end of file.
</p>
<p>
<b>int getData (int i, bool async, String encoding)</b>:<br/>
Starts reading data. If <b>async</b> is true returns immediately "", otherwise
returns all available data. <b>encoding</b> is optional (Default: UTF-8).
</p>
<p>
<b>int getStatus (int i)</b>:<br/>
Returns the current status, see Constants below.
</p>
<p>
<b>bool isAvailable ()</b>:<br/>
Returns true (1) if the device supports file system methods (<b>list, getName,
isDir, getFullPath</b>).
</p>
<p>
<b>void clean ()</b>:<br/>
Close all opened at once files.
</p>
<br/>
<script type="text/javascript">addTitle("Constants", 1);</script>
<p>
<b>ERROR</b>:<br/>
An error occurred (e.g. file does not exists).
</p>
<p>
<b>READY</b>:<br/>
File is open and ready for starting data transfer.
</p>
<p>
<b>OPENING</b>:<br/>
File is being open (i.e. communication in progress) .
</p>
<p>
<b>LOADING</b>:<br/>
Data is loading (transferring).
</p>
<p>
<b>LOADED</b>:<br/>
Data is fully loaded but not read yet.
</p>
<p>
<b>CLOSED</b>:<br/>
Data has been read.
</p>
<br/>
<script type="text/javascript">addTitle("Widget SDK", 1);</script>
<p>
In a widget context, the access to files on the file system is not available and
the following methods will not work : <b>list, getName, isDir, getFullPath</b>.<br/>
The 'file://' scheme is not supported in the <b>open()</b> method.
</p>
<br/>
<script type="text/javascript">addTitle("Examples", 1);</script>
<textarea wrap="off" readonly="readonly" rows="15" cols="80">
function path (p) {
downloadFile = File.open (url, true);
Browser.setTimeout (downloadData, 200);
}
function downloadData () {
if (downloadFile != -1) {
switch (File.getStatus (downloadFile)) {
case File.LOADING:
// most frequent state (prevents useless tests)
break;
case File.OPENING:
Browser.sendMessage ('Board', 'PROGRESS', -1);
break;
case File.READY:
// connection is ready, trigger async download to cache
if (showProgress) {
Browser.sendMessage ('Board', 'PROGRESS', 10);
}
File.getData (downloadFile, true);
break;
case File.LOADED:
cleanDownload ();
XML.open ('cache://'+ident+dataRecord, XML.URL+XML.BML_ENCODING, onNewDataParsed);
return;
case File.ERROR:
cleanDownload ();
// try to reuse previous data if any
onNewDataParsed ('', 400, -1);
return;
}
Browser.setTimeout (downloadData, 500); // Call this method again in 500ms
}
}
function cleanDownload () {
if (downloadFile != -1) {
File.close (downloadFile);
downloadFile = -1;
}
}
</textarea>
<p>
Find the entire source code into the DataLoader prototype.
</p>
<br/>
<script type="text/javascript">
<!--
addBackPageNavigator('widgets_development_javascript_ref', '');
//-->
</script>
<script type="text/javascript">
<!--
endPage();
//-->
</script>
</body>
</html>