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 "server.h"
00037 #include <stdio.h>
00038 #include "common.h"
00039 #include "content_manager.h"
00040 #include "cds_objects.h"
00041 #include "pages.h"
00042 #include "tools.h"
00043 #include "metadata_handler.h"
00044
00045 using namespace zmm;
00046 using namespace mxml;
00047
00048 web::addObject::addObject() : WebRequestHandler()
00049 {}
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 void web::addObject::addContainer(int parentID)
00064 {
00065 ContentManager::getInstance()->addContainer(parentID, param(_("title")), param(_("class")));
00066 }
00067
00068 Ref<CdsObject> web::addObject::addItem(int parentID, Ref<CdsItem> item)
00069 {
00070 String tmp;
00071
00072 item->setParentID(parentID);
00073
00074 item->setTitle(param(_("title")));
00075 item->setLocation(param(_("location")));
00076 item->setClass(param(_("class")));
00077
00078 tmp = param(_("description"));
00079 if (string_ok(tmp))
00080 item->setMetadata(MetadataHandler::getMetaFieldName(M_DESCRIPTION), tmp);
00081
00083 tmp = param(_("mime-type"));
00084 if (!string_ok(tmp))
00085 tmp = _(MIMETYPE_DEFAULT);
00086 item->setMimeType(tmp);
00087
00088 item->setFlag(OBJECT_FLAG_USE_RESOURCE_REF);
00089
00090
00091 return RefCast(item, CdsObject);
00092 }
00093
00094 Ref<CdsObject> web::addObject::addActiveItem(int parentID)
00095 {
00096 String tmp;
00097 Ref<CdsActiveItem> item (new CdsActiveItem());
00098
00099 item->setAction(param(_("action")));
00100
00102 tmp = param(_("state"));
00103 if (string_ok(tmp))
00104 item->setState(tmp);
00105
00106 item->setParentID(parentID);
00107 item->setLocation(param(_("location")));
00108
00109 tmp = param(_("mime-type"));
00110 if (!string_ok(tmp))
00111 tmp = _(MIMETYPE_DEFAULT);
00112 item->setMimeType(tmp);
00113
00114 MetadataHandler::setMetadata(RefCast(item, CdsItem));
00115
00116 item->setTitle(param(_("title")));
00117 item->setClass(param(_("class")));
00118
00119 tmp = param(_("description"));
00120 if (string_ok(tmp))
00121 item->setMetadata(MetadataHandler::getMetaFieldName(M_DESCRIPTION), tmp);
00122
00124
00125
00126
00127
00128
00129
00130
00131
00132 return RefCast(item, CdsObject);
00133 }
00134
00135 Ref<CdsObject> web::addObject::addUrl(int parentID, Ref<CdsItemExternalURL> item, bool addProtocol)
00136 {
00137 String tmp;
00138 String protocolInfo;
00139
00140 item->setParentID(parentID);
00141
00142 item->setTitle(param(_("title")));
00143 item->setURL(param(_("location")));
00144 item->setClass(param(_("class")));
00145
00146 tmp = param(_("description"));
00147 if (string_ok(tmp))
00148 item->setMetadata(MetadataHandler::getMetaFieldName(M_DESCRIPTION), tmp);
00149
00151 tmp = param(_("mime-type"));
00152 if (!string_ok(tmp))
00153 tmp = _(MIMETYPE_DEFAULT);
00154 item->setMimeType(tmp);
00155
00156 if (addProtocol)
00157 {
00158 String protocol = param(_("protocol"));
00159 if (string_ok(protocol))
00160 protocolInfo = renderProtocolInfo(tmp, protocol);
00161 else protocolInfo = renderProtocolInfo(tmp);
00162 }
00163 else
00164 protocolInfo = renderProtocolInfo(tmp);
00165
00166 Ref<CdsResource> resource(new CdsResource(CH_DEFAULT));
00167 resource->addAttribute(MetadataHandler::getResAttrName(R_PROTOCOLINFO),
00168 protocolInfo);
00169 item->addResource(resource);
00170
00171 return RefCast(item, CdsObject);
00172 }
00173
00174 void web::addObject::process()
00175 {
00176 check_request();
00177
00178 String obj_type = param(_("obj_type"));
00179 String location = param(_("location"));
00180
00181 if (!string_ok(param(_("title"))))
00182 throw _Exception(_("empty title"));
00183
00184 if (!string_ok(param(_("class"))))
00185 throw _Exception(_("empty class"));
00186
00187 int parentID = intParam(_("parent_id"), 0);
00188
00189 Ref<CdsObject> obj = nil;
00190
00191 Ref<Element> updateContainerEl;
00192
00193 bool allow_fifo = false;
00194
00195 if (obj_type == STRING_OBJECT_TYPE_CONTAINER)
00196 {
00197 this->addContainer(parentID);
00198
00199
00200
00201
00202 }
00203 else if (obj_type == STRING_OBJECT_TYPE_ITEM)
00204 {
00205 if (!string_ok(location)) throw _Exception(_("no location given"));
00206 if (!check_path(location, false)) throw _Exception(_("file not found"));
00207 obj = this->addItem(parentID, Ref<CdsItem> (new CdsItem()));
00208 allow_fifo = true;
00209 }
00210 else if (obj_type == STRING_OBJECT_TYPE_ACTIVE_ITEM)
00211 {
00212 if (!string_ok(param(_("action")))) throw _Exception(_("no action given"));
00213 if (!string_ok(location)) throw _Exception(_("no location given"));
00214 if (!check_path(location, false))
00215 throw _Exception(_("path not found"));
00216 obj = this->addActiveItem(parentID);
00217 allow_fifo = true;
00218 }
00219 else if (obj_type == STRING_OBJECT_TYPE_EXTERNAL_URL)
00220 {
00221 if (!string_ok(location)) throw _Exception(_("No URL given"));
00222 obj = this->addUrl(parentID, Ref<CdsItemExternalURL> (new CdsItemExternalURL()), true);
00223 }
00224 else if (obj_type == STRING_OBJECT_TYPE_INTERNAL_URL)
00225 {
00226 if (!string_ok(location)) throw _Exception(_("No URL given"));
00227 obj = this->addUrl(parentID, Ref<CdsItemExternalURL> (new CdsItemInternalURL()), false);
00228 }
00229 else
00230 {
00231 throw _Exception(_("unknown object type: ") + obj_type.c_str());
00232 }
00233
00234 if (obj != nil)
00235 {
00236 obj->setVirtual(true);
00237 if (obj_type == STRING_OBJECT_TYPE_ITEM)
00238 {
00239 ContentManager::getInstance()->addVirtualItem(obj, allow_fifo);
00240 }
00241 else
00242 {
00243 ContentManager::getInstance()->addObject(obj);
00244 }
00245 }
00246 }