00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00031
00032 #ifdef HAVE_CONFIG_H
00033 #include "autoconfig.h"
00034 #endif
00035
00036 #include "common.h"
00037 #include "pages.h"
00038 #include "tools.h"
00039 #include "storage.h"
00040 #include "filesystem.h"
00041 #include "string_converter.h"
00042
00043 using namespace zmm;
00044 using namespace mxml;
00045
00046 web::directories::directories() : WebRequestHandler()
00047 {
00048 }
00049
00050 void web::directories::process()
00051 {
00052 check_request();
00053
00054 String path;
00055 String parentID = param(_("parent_id"));
00056 if (parentID == nil || parentID == "0")
00057 path = _(FS_ROOT_DIRECTORY);
00058 else
00059 path = hex_decode_string(parentID);
00060
00061 Ref<Element> containers (new Element(_("containers")));
00062 containers->setArrayName(_("container"));
00063 containers->setAttribute(_("parent_id"), parentID);
00064 if (string_ok(param(_("select_it"))))
00065 containers->setAttribute(_("select_it"), param(_("select_it")));
00066 containers->setAttribute(_("type"), _("filesystem"));
00067 root->appendElementChild(containers);
00068
00069 Ref<Filesystem> fs(new Filesystem());
00070
00071 Ref<Array<FsObject> > arr;
00072 arr = fs->readDirectory(path, FS_MASK_DIRECTORIES,
00073 FS_MASK_DIRECTORIES);
00074
00075 for (int i = 0; i < arr->size(); i++)
00076 {
00077 Ref<FsObject> obj = arr->get(i);
00078
00079 Ref<Element> ce(new Element(_("container")));
00080 String filename = obj->filename;
00081 String filepath;
00082 if (path.c_str()[path.length() - 1] == '/')
00083 filepath = path + filename;
00084 else
00085 filepath = path + '/' + filename;
00086
00088 String id = hex_encode(filepath.c_str(), filepath.length());
00089 ce->setAttribute(_("id"), id);
00090 if (obj->hasContent)
00091 ce->setAttribute(_("child_count"), String::from(1), mxml_int_type);
00092 else
00093 ce->setAttribute(_("child_count"), String::from(0), mxml_int_type);
00094
00095 Ref<StringConverter> f2i = StringConverter::f2i();
00096 ce->setTextKey(_("title"));
00097 ce->setText(f2i->convert(filename));
00098 containers->appendElementChild(ce);
00099 }
00100 }