23 #include "ApplicationUtil.h"
25 ApplicationUtil::ApplicationUtil()
29 ApplicationUtil::~ApplicationUtil() {
33 string ApplicationUtil::buildAllApplications(vector<string> files,vector<string> apps,map<string,string> &appMap)
35 string headers =
"#include \"fstream\"\n#include \"string\"\n#include \"HttpSession.h\"\n#include \"CastUtil.h\"\nusing namespace std;\n";
37 string meth,methdef,vars;
38 for (
unsigned int var = 0; var < files.size(); ++var)
40 string path = files.at(var).substr(0,files.at(var).find_last_of(
"/")+1);
41 string appName = apps.at(var).substr(0,apps.at(var).find_last_of(
"/"));
44 Element root = parser.getDocument(files.at(var)).getRootElement();
45 ElementList eles = root.getChildElements();
47 appMap[appName] =
"false";
50 meth +=
"string "+appName+
"checkRules(string to,HttpSession session)\n{\nstring curr=session.getAttribute(\"CURR\");\n";
51 for (
unsigned int var = 0; var < eles.size(); var++)
53 if(eles.at(var).getTagName()==
"include")
55 string inc = eles.at(var).getText();
57 StringUtil::split(incs, inc, (
" "));
58 for (
unsigned int i = 0; i < incs.size(); i++)
60 headers += (
"#include \"" + incs.at(i) +
"\"\n");
63 else if(eles.at(var).getTagName()==
"page" || eles.at(var).getTagName()==
"welcome")
65 meth += (
"string " + eles.at(var).getAttribute(
"id") +
" = \""+path+eles.at(var).getAttribute(
"path")+
"\";\n");
66 if(eles.at(var).getAttribute(
"who")!=
"" && eles.at(var).getAttribute(
"where")!=
"")
68 if(eles.at(var).getAttribute(
"where").find(
"FILE:")!=string::npos)
70 string fileName = eles.at(var).getAttribute(
"where");
71 StringUtil::replaceFirst(fileName,
"FILE:",
"");
72 fileName = (path + fileName);
73 meth +=
"string path;\nif(to=="+eles.at(var).getAttribute(
"id")+
")\n{";
74 meth +=
"string user = session.getAttribute(\"USER\");\n";
75 meth +=
"string pass = session.getAttribute(\"PASS\");\n";
76 meth +=
"ifstream f(\""+fileName+
"\");\n";
77 meth +=
"if(f.is_open())\n{\nstring temp;\nwhile(getline(f,temp,'\\n'))\n{";
78 meth +=
"if(temp==(user+\" \"+pass)){f.close();path = "+eles.at(var).getAttribute(
"id")+
";break;}\n}}\nif(path==\"\")\npath=\"FAILED\";\n}";
81 else if(eles.at(var).getAttribute(
"onsuccess")!=
"" && eles.at(var).getAttribute(
"onfail")!=
"")
86 else if(eles.at(var).getTagName()==
"rule")
88 meth +=
"\nif(to=="+eles.at(var).getAttribute(
"topage")+
" && curr=="+eles.at(var).getAttribute(
"currpage")+
")\n{";
89 ElementList elesc = eles.at(var).getChildElements();
90 for (
unsigned int var1 = 0; var1 < elesc.size(); var1++)
92 if(elesc.at(var1).getTagName()==
"execute")
94 string call = elesc.at(var1).getAttribute(
"call");
95 string clas = call.substr(0,call.find(
"."));
96 string method = call.substr(call.find(
".")+1);
97 headers += (
"#include \""+clas+
".h\"\n");
98 meth += clas +
" _object;\n";
100 ElementList elesce = elesc.at(var1).getChildElements();
101 for (
unsigned int var2 = 0; var2 < elesce.size(); var2++)
103 meth += (elesce.at(var2).getTagName() +
" _" + CastUtil::lexical_cast<
string>(var2+1) +
" = CastUtil::lexical_cast<"+elesce.at(var2).getTagName()+
">(\""+elesce.at(var2).getText()+
"\");\n");
104 args += (
"_"+CastUtil::lexical_cast<
string>(var2+1));
105 if(var2!=elesce.size()-1)
108 if(elesc.at(var1).getAttribute(
"rettype")!=
"" || elesc.at(var1).getAttribute(
"rettype")!=
"void")
110 meth += (elesc.at(var1).getAttribute(
"rettype") +
" " + elesc.at(var1).getAttribute(
"retname") +
" = ");
111 meth +=
"_object."+method+
"("+args+
");\n";
115 meth +=
"path=to;\n}\n";
118 meth +=
"return path;}\n";
122 code += (headers +
"extern \"C\"\n{\n"+vars+meth+
"}\n");