/[cvs]/api/Classes/Program/WebServer/Directory.cpp
ViewVC logotype

Contents of /api/Classes/Program/WebServer/Directory.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Sun Jul 1 20:47:58 2001 UTC (23 years, 4 months ago) by bearsoft
Branch: lazy, MAIN
CVS Tags: start, HEAD
Changes since 1.1: +0 -0 lines
First import

1 #include "Directory.h"
2 #include "../../String/StringInput.h"
3 #include "../../System/System.h"
4 #include "../../DateTime/DateTime.h"
5 #include "../../System/SystemDefine.h"
6 #include "../../Html/Table.h"
7 #include "../../Html/Link.h"
8 #include "../../Files/FileHandler.h"
9 #include "../../Files/FileInfo.h"
10
11
12 Directory::Directory(Header *iHeader)
13 {
14 columnToSort=0;
15 fileMatris=null;
16 buttonMatris=null;
17 header=iHeader;
18 readPermission=true;
19
20 linkFileName = new Link();
21 linkFileSize = new Link();
22 linkFileType = new Link();
23 linkLastModified = new Link();
24
25 linkFileName->info->setString("Name");
26 linkFileSize->info->setString("Size");
27 linkFileType->info->setString("Type");
28 linkLastModified->info->setString("LastModified");
29 }
30
31 Directory::~Directory()
32 {
33 if (linkFileName!=null)
34 {
35 delete linkFileName;
36 }
37
38 if (linkFileSize!=null)
39 {
40 delete linkFileSize;
41 }
42
43 if (linkFileType!=null)
44 {
45 delete linkFileType;
46 }
47
48 if (linkLastModified!=null)
49 {
50 delete linkLastModified;
51 }
52 }
53
54 void Directory::createFileMatris()
55 {
56 fileMatris = new HtmlMatrisList<String>(4);
57
58 String filePath=header->filePath;
59 String path=header->filePathWithoutRootPath;
60
61 FileHandler fileHandler;
62
63 ObjectLinkedList<FileInfo> *fileList=fileHandler.listDirectory(filePath);
64
65 int size=fileList->size();
66
67 for ( int i=0; i<size ; i++ )
68 {
69 FileInfo *fileInfo=fileList->getElement(i);
70
71 Link link;
72
73 String fileName;
74
75 if (!filePath.isBackPartEqualTo("/"))
76 {
77 fileName+=path;
78 fileName+="/";
79 }
80
81 fileName+=fileInfo->name;
82
83 if (fileInfo->directory)
84 {
85 link.filePath->setString(fileName + "/");
86 }
87 else
88 {
89 link.filePath->setString(fileName);
90 }
91
92 link.info->setString(fileInfo->name);
93 link.create();
94
95 fileMatris->addColumnInRow(link, fileInfo->name, 0);
96
97 if (fileInfo->directory)
98 {
99 fileMatris->addColumnInRow("***", 1);
100 fileMatris->addColumnInRow("Directory", 2);
101 }
102 else
103 {
104 String fileSize=fileInfo->size;
105 // String fileSize="10000";
106 fileMatris->addColumnInRow(fileSize, 1);
107 fileMatris->addColumnInRow("File", 2);
108 }
109
110 fileMatris->addColumnInRow(fileInfo->lastModified, 3);
111
112 fileMatris->addRow();
113 }
114
115 delete fileList;
116
117 if(linkFileName->filePath->equals("?NameUp"))
118 {
119 columnToSort=0;
120 fileMatris->sortColumnInLargestOrder(columnToSort);
121 return;
122 }
123
124 if(linkFileName->filePath->equals("?NameDown"))
125 {
126 columnToSort=0;
127 fileMatris->sortColumnInSmallestOrder(columnToSort);
128 return;
129 }
130
131 if(linkFileSize->filePath->equals("?SizeUp"))
132 {
133 columnToSort=1;
134 fileMatris->sortColumnInLargestValueOrder(columnToSort);
135 return;
136 }
137
138 if(linkFileSize->filePath->equals("?SizeDown"))
139 {
140 columnToSort=1;
141 fileMatris->sortColumnInSmallestValueOrder(columnToSort);
142 return;
143 }
144
145 if(linkFileType->filePath->equals("?TypeUp"))
146 {
147 columnToSort=2;
148 fileMatris->sortColumnInLargestOrder(columnToSort);
149 return;
150 }
151
152 if(linkFileType->filePath->equals("?TypeDown"))
153 {
154 columnToSort=2;
155 fileMatris->sortColumnInSmallestOrder(columnToSort);
156 return;
157 }
158
159 if(linkLastModified->filePath->equals("?LastModifiedUp"))
160 {
161 columnToSort=3;
162 fileMatris->sortColumnInLargestOrder(columnToSort);
163 return;
164 }
165
166 if(linkLastModified->filePath->equals("?LastModifiedDown"))
167 {
168 columnToSort=3;
169 fileMatris->sortColumnInSmallestOrder(columnToSort);
170 return;
171 }
172
173 }
174
175 void Directory::createButtonMatris()
176 {
177 linkFileName->create();
178 linkFileSize->create();
179 linkFileType->create();
180 linkLastModified->create();
181
182 buttonMatris = new HtmlMatrisList<String>(4);
183
184 buttonMatris->addColumnInRow(linkFileName, "1", 0);
185 buttonMatris->addColumnInRow(linkFileSize, "1", 1);
186 buttonMatris->addColumnInRow(linkFileType, "1", 2);
187 buttonMatris->addColumnInRow(linkLastModified, "1", 3);
188
189
190 buttonMatris->addRow();
191 }
192
193 bool Directory::init()
194 {
195 bool connectionStatus=true;
196
197 createFileMatris();
198 createButtonMatris();
199
200 String start;
201
202 // start.readFile("Html/Start.txt");
203
204 Table table;
205 table.border=1;
206 table.width=400;
207 table.createMatris(buttonMatris);
208 table.createMatris(fileMatris, columnToSort);
209 table.create();
210
211
212 String data=start + "<html><body><form>" + table.data + "</form></body></html>";
213 // System::println(data);
214
215 connectionStatus=header->makeAndSendHeaderWithStringData(data);
216
217 if (fileMatris != null)
218 {
219 delete fileMatris;
220 }
221
222 if (buttonMatris != null)
223 {
224 delete buttonMatris;
225 }
226
227 return connectionStatus;
228 }
229
230
231 bool Directory::check()
232 {
233 String filePath=header->filePath;
234
235 //part 1
236
237 if (filePath.isBackPartEqualTo("/?Name"))
238 {
239 linkFileName->filePath->setString("?NameDown");
240 linkFileSize->filePath->setString("?Size");
241 linkFileType->filePath->setString("?Type");
242 linkLastModified->filePath->setString("?LastModified");
243
244 return checkIfThatIsADirectory(filePath);
245 }
246
247 if (filePath.isBackPartEqualTo("/?Size"))
248 {
249 linkFileName->filePath->setString("?Name");
250 linkFileSize->filePath->setString("?SizeDown");
251 linkFileType->filePath->setString("?Type");
252 linkLastModified->filePath->setString("?LastModified");
253
254 return checkIfThatIsADirectory(filePath);
255 }
256
257 if (filePath.isBackPartEqualTo("/?Type"))
258 {
259 linkFileName->filePath->setString("?Name");
260 linkFileSize->filePath->setString("?Size");
261 linkFileType->filePath->setString("?TypeDown");
262 linkLastModified->filePath->setString("?LastModified");
263
264 return checkIfThatIsADirectory(filePath);
265 }
266
267 if (filePath.isBackPartEqualTo("/?LastModified"))
268 {
269 linkFileName->filePath->setString("?Name");
270 linkFileSize->filePath->setString("?Size");
271 linkFileType->filePath->setString("?Type");
272 linkLastModified->filePath->setString("?LastModifiedDown");
273
274 return checkIfThatIsADirectory(filePath);
275 }
276
277 //part 2
278
279 if (filePath.isBackPartEqualTo("/?NameDown"))
280 {
281 linkFileName->filePath->setString("?NameUp");
282 linkFileSize->filePath->setString("?Size");
283 linkFileType->filePath->setString("?Type");
284 linkLastModified->filePath->setString("?LastModified");
285
286 return checkIfThatIsADirectory(filePath);
287 }
288
289 if (filePath.isBackPartEqualTo("/?SizeDown"))
290 {
291 linkFileName->filePath->setString("?Name");
292 linkFileSize->filePath->setString("?SizeUp");
293 linkFileType->filePath->setString("?Type");
294 linkLastModified->filePath->setString("?LastModified");
295
296 return checkIfThatIsADirectory(filePath);
297 }
298
299 if (filePath.isBackPartEqualTo("/?TypeDown"))
300 {
301 linkFileName->filePath->setString("?Name");
302 linkFileSize->filePath->setString("?Size");
303 linkFileType->filePath->setString("?TypeUp");
304 linkLastModified->filePath->setString("?LastModified");
305
306 return checkIfThatIsADirectory(filePath);
307 }
308
309 if (filePath.isBackPartEqualTo("/?LastModifiedDown"))
310 {
311 linkFileName->filePath->setString("?Name");
312 linkFileSize->filePath->setString("?Size");
313 linkFileType->filePath->setString("?Type");
314 linkLastModified->filePath->setString("?LastModifiedUp");
315
316 return checkIfThatIsADirectory(filePath);
317 }
318
319 //part 3
320
321 if (filePath.isBackPartEqualTo("/?NameUp"))
322 {
323 linkFileName->filePath->setString("?NameDown");
324 linkFileSize->filePath->setString("?Size");
325 linkFileType->filePath->setString("?Type");
326 linkLastModified->filePath->setString("?LastModified");
327
328 return checkIfThatIsADirectory(filePath);
329 }
330
331 if (filePath.isBackPartEqualTo("/?SizeUp"))
332 {
333 linkFileName->filePath->setString("?Name");
334 linkFileSize->filePath->setString("?SizeDown");
335 linkFileType->filePath->setString("?Type");
336 linkLastModified->filePath->setString("?LastModified");
337
338 return checkIfThatIsADirectory(filePath);
339 }
340
341 if (filePath.isBackPartEqualTo("/?TypeUp"))
342 {
343 linkFileName->filePath->setString("?Name");
344 linkFileSize->filePath->setString("?Size");
345 linkFileType->filePath->setString("?TypeDown");
346 linkLastModified->filePath->setString("?LastModified");
347
348 return checkIfThatIsADirectory(filePath);
349 }
350
351 if (filePath.isBackPartEqualTo("/?LastModifiedUp"))
352 {
353 linkFileName->filePath->setString("?Name");
354 linkFileSize->filePath->setString("?Size");
355 linkFileType->filePath->setString("?Type");
356 linkLastModified->filePath->setString("?LastModifiedDown");
357
358 return checkIfThatIsADirectory(filePath);
359 }
360
361 FileHandler fileHandler;
362 FileInfo *fileInfo=fileHandler.getFileInfo(filePath);
363
364 if (fileInfo->directory)
365 {
366 String path;
367
368 if (!filePath.isBackPartEqualTo("/"))
369 {
370 path+=header->filePathWithoutRootPath;
371 path+="/";
372 }
373
374 linkFileName->filePath->setString(path + "?Name");
375 linkFileSize->filePath->setString(path + "?Size");
376 linkFileType->filePath->setString(path + "?Type");
377 linkLastModified->filePath->setString(path + "?LastModified");
378
379 readPermission=fileInfo->readPermission;
380 // System::println("directory");
381 return true;
382 }
383 else
384 {
385 // System::println("not a directory");
386 return false;
387 }
388
389 return false;
390 }
391
392
393 bool Directory::checkIfThatIsADirectory(String &filePath)
394 {
395 filePath.cutTheBegining('/');
396 filePath+="/";
397 header->filePath->setString(filePath);
398
399 FileHandler fileHandler;
400 FileInfo *fileInfo=fileHandler.getFileInfo(filePath);
401
402 if (fileInfo->directory)
403 {
404 readPermission=fileInfo->readPermission;
405 return true;
406 }
407 else
408 {
409 readPermission=fileInfo->readPermission;
410 return false;
411 }
412
413 return false;
414 }

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26