-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathFormHandler.cpp
More file actions
99 lines (93 loc) · 3.81 KB
/
FormHandler.cpp
File metadata and controls
99 lines (93 loc) · 3.81 KB
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
/*
Copyright 2009-2020, Sumeet Chhetri
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
* FormHandler.cpp
*
* Created on: Jun 17, 2012
* Author: Sumeet
*/
#include "FormHandler.h"
bool FormHandler::handle(HttpRequest* req, HttpResponse* res, Reflector& reflector, Element* ele)
{
//Logger logger = LoggerFactory::getLogger("FormHandler");
//logger << ele->getTagName() << std::endl;
//logger << ele->render() << std::endl;
ClassInfo* clas = ConfigurationData::getClassInfo(ele->getAttribute("bean"), req->getCntxt_name());
ElementList eles = ele->getChildElements();
std::string json = "{";
for (unsigned int apps = 0; apps < eles.size(); apps++)
{
if(eles.at(apps).getTagName()=="field")
{
std::string name = eles.at(apps).getAttribute("name");
Field fld = clas->getField(eles.at(apps).getAttribute("prop"));
if(fld.getType()=="std::string" || fld.getType()=="string")
json += "\""+eles.at(apps).getAttribute("prop")+"\": \"" + req->getParamValue(name) + "\",";
else
{
if(fld.getType()=="short" || fld.getType()=="unsigned short"
|| fld.getType()=="int" || fld.getType()=="unsigned int"
|| fld.getType()=="long" || fld.getType()=="unsigned long"
|| fld.getType()=="char" || fld.getType()=="unsigned char")
{
if(req->getQueryParam(name)=="")
json += "\""+eles.at(apps).getAttribute("prop")+"\": 0,";
else
json += "\""+eles.at(apps).getAttribute("prop")+"\": " + req->getParamValue(name) + ",";
}
else if(fld.getType()=="double" || fld.getType()=="float")
{
if(req->getQueryParam(name)=="")
json += "\""+eles.at(apps).getAttribute("prop")+"\": 0.0,";
else
json += "\""+eles.at(apps).getAttribute("prop")+"\": " + req->getParamValue(name) + ",";
}
else if(fld.getType()=="bool")
{
if(req->getQueryParam(name)=="")
json += "\""+eles.at(apps).getAttribute("prop")+"\": false,";
else
json += "\""+eles.at(apps).getAttribute("prop")+"\": " + req->getParamValue(name) + ",";
}
}
}
}
if(json.find(",")!=std::string::npos)
{
json = json.substr(0,json.length()-1);
}
json += "}";
//logger << json << std::endl;
void *_temp = ConfigurationData::getInstance()->ffeadContext.getBean(ele->getAttribute("controller"), req->getCntxt_name());
args argus;
argus.push_back("void*");
argus.push_back("HttpResponse*");
vals valus;
ClassInfo* srv = ConfigurationData::getClassInfo(ele->getAttribute("controller"), req->getCntxt_name());
Method meth = srv->getMethod("onSubmit", argus);
if(meth.getMethodName()!="")
{
int serOpt = SerializeBase::identifySerOption(ele->getAttribute("bean"));
//logger << ("Fetching Formcontroller for " + ele->getAttribute("bean")) << std::endl;
void *_beaninst = JSONSerialize::unSerializeUnknown(json, serOpt, ele->getAttribute("bean"), std::string(req->getCntxt_name()));
valus.push_back(_beaninst);
valus.push_back(res);
reflector.invokeMethodGVP(_temp,meth,valus,false);
reflector.destroy(_beaninst, ele->getAttribute("bean"));
//logger << "Successfully called Formcontroller" << std::endl;
ConfigurationData::getInstance()->ffeadContext.release(_temp, ele->getAttribute("controller"), req->getCntxt_name());
return true;
}
ConfigurationData::getInstance()->ffeadContext.release(_temp, ele->getAttribute("controller"), req->getCntxt_name());
return false;
}