23 #include "ExtHandler.h"
25 ExtHandler::ExtHandler() {
30 ExtHandler::~ExtHandler() {
34 string ExtHandler::getContentStr(
string url,
string locale,
string ext)
43 if(locale.find(
"english")==string::npos && (ext==
".html" || ext==
".htm"))
46 StringUtil::replaceFirst(fnj,
".",(
"_" + locale+
"."));
47 myfile.open(fnj.c_str(),ios::in | ios::binary);
51 while(getline(myfile,line)){all.append(line+
"\n");}
57 myfile1.open(fname.c_str(),ios::in | ios::binary);
58 if (myfile1.is_open())
61 while(getline(myfile1,line)){all.append(line+
"\n");}
68 map<string, string> tmplMap, map<string, string> vwMap,
string ext, map<string, string> props, map<string, string> ajaxIntfMap)
70 Logger logger = Logger::getLogger(
"ExtHandler");
73 string acurl = req->getActUrl();
74 StringUtil::replaceFirst(acurl,
"//",
"/");
76 acurl = acurl.substr(1);
77 if(acurl.find(req->getCntxt_name())!=0)
78 acurl = req->getCntxt_name() +
"/" + acurl;
80 if(ajaxIntfMap[acurl]!=
"" && req->getMethod()==
"POST" && req->getRequestParam(
"method")!=
"")
83 AfcUtil::execute(*req, &res, ajaxIntfMap[acurl]);
87 string libName = Constants::INTER_LIB_FILE;
91 int s = req->getUrl().find_last_of(
"/")+1;
92 int en = req->getUrl().find_last_of(
".");
94 file = req->getUrl().substr(s,en-s);
95 meth =
"_" + file +
"emittHTML";
97 void *mkr = dlsym(ddlib, meth.c_str());
101 DCPPtr f = (DCPPtr)mkr;
109 if(ext!=
"" && content.length()==0)
111 res.setHTTPResponseStatus(HTTPResponseStatus::NotFound);
116 res.setHTTPResponseStatus(HTTPResponseStatus::Ok);
117 res.setContent_type(props[ext]);
118 res.setContent_str(content);
123 else if(ext==
".view" && vwMap[req->getCntxt_name()+req->getFile()]!=
"")
126 string libName = Constants::INTER_LIB_FILE;
129 cerr << dlerror() << endl;
132 claz =
"getReflectionCIFor" + vwMap[req->getCntxt_name()+req->getFile()];
133 void *mkr = dlsym(dlib, claz.c_str());
136 FunPtr f = (FunPtr)mkr;
141 void *_temp = ref.newInstanceGVP(ctor);
145 string t = view.generateDocument(doc);
149 if(ext!=
"" && (content.length()==0))
151 res.setHTTPResponseStatus(HTTPResponseStatus::NotFound);
156 res.setHTTPResponseStatus(HTTPResponseStatus::Ok);
157 res.setContent_type(props[ext]);
158 res.setContent_str(content);
162 else if(ext==
".tpe" && tmplMap[req->getCntxt_name()+req->getFile()]!=
"")
170 cerr << dlerror() << endl;
174 claz =
"getReflectionCIFor" + tmplMap[req->getCntxt_name()+req->getFile()];
175 void *mkr = dlsym(dlib, claz.c_str());
178 FunPtr f = (FunPtr)mkr;
183 void *_temp = ref.newInstanceGVP(ctor);
185 Context cnt = thrd->getContext();
187 logger <<
"Done with Template Context fetch" << endl;
188 map<string, void*> args;
189 Context::iterator it;
190 for (it=cnt.begin();it!=cnt.end();it++) {
191 string key = it->first;
193 logger << (
"Template key=" + key +
" Value = ") << o.getVoidPointer()<< endl;
194 args[key] = o.getVoidPointer();
197 int s = req->getUrl().find_last_of(
"/")+1;
198 int en = req->getUrl().find_last_of(
".");
200 file = req->getUrl().substr(s,en-s);
201 meth =
"_" + file +
"emittTemplateHTML";
203 mkr = dlsym(ddlib, meth.c_str());
207 TemplatePtr f = (TemplatePtr)mkr;
215 if(ext!=
"" && (content.length()==0))
217 res.setHTTPResponseStatus(HTTPResponseStatus::NotFound);
222 res.setHTTPResponseStatus(HTTPResponseStatus::Ok);
223 res.setContent_type(props[ext]);
224 res.setContent_str(content);
229 else if(ext==
".wsdl")
232 content = getContentStr(resourcePath+req->getFile(),
"english",ext);
233 if((content.length()==0))
235 res.setHTTPResponseStatus(HTTPResponseStatus::NotFound);
240 res.setHTTPResponseStatus(HTTPResponseStatus::Ok);
241 res.setContent_type(props[ext]);
242 res.setContent_str(content);