///////////////////////////////////////////////// // Google-Web-Context-Graph PGgCtxGraph TGgCtxGraph::GetCtxGraph(const TStr& FocusUrlStr){ // create context-graph PGgCtxGraph CtxGraph=TGgCtxGraph::New(); CtxGraph->Ok=false; // get focus-web-page CtxGraph->FocusUrlStr=FocusUrlStr; {bool Ok; TStr MsgStr; TWebFetchBlocking::GetWebPg( CtxGraph->FocusUrlStr, Ok, MsgStr, CtxGraph->FocusWebPg, TNotify::StdNotify); if (!Ok){return CtxGraph;}} // get 'In' set of links PRSet InRSet= TGg::WebSearch(TStr("link:")+CtxGraph->FocusUrlStr, -1, TNotify::StdNotify); for (int HitN=0; HitN<InRSet->GetHits(); HitN++){ TStr UrlStr; TStr TitleStr; TStr SrcNm; TStr CtxStr; InRSet->GetHit(HitN, UrlStr, TitleStr, SrcNm, CtxStr); TitleStr.ChangeChAll('\n', ' '); CtxGraph->InUrlCtxStrPrV.Add(TStrPr(UrlStr, TitleStr)); } // get Out set TStrKdV OutDescUrlStrKdV; CtxGraph->FocusWebPg->GetOutDescUrlStrKdV(OutDescUrlStrKdV); for (int UrlN=0; UrlN<OutDescUrlStrKdV.Len(); UrlN++){ OutDescUrlStrKdV[UrlN].Key.ChangeChAll('\n', ' '); CtxGraph->OutUrlCtxStrPrV.Add( TStrPr(OutDescUrlStrKdV[UrlN].Dat, OutDescUrlStrKdV[UrlN].Key)); } // set context-graph successful CtxGraph->Ok=true; // return context-graph return CtxGraph; }
// if one or more items with FldNm already exist remove them first // add to FldNmValPrV pair (FldNm, FldVal) void TSAppSrvFun::SetFldNmVal(TStrKdV& FldNmValPrV, const TStr& FldNm, const TStr& FldVal) { for (int N = FldNmValPrV.Len() - 1; N >= 0; N--) { if (FldNmValPrV[N].Key == FldNm) FldNmValPrV.Del(N); } FldNmValPrV.Add(TStrKd(FldNm, FldVal)); }
void TSASFunRedirect::Exec(const TStrKdV& FldNmValPrV, const PSAppSrvRqEnv& RqEnv) { PUrl Url = RqEnv->GetHttpRq()->GetUrl(); TStr FunNm = (Url->GetPathSegs() > 1) ? Url->GetPathSeg(1) : ""; EAssert(MapH.IsKey(FunNm)); const TRedirect& Redirect = MapH.GetDat(FunNm); TStrKdV _FldNmValPrV = Redirect.FldNmValPrV; for (int FldN = 0; FldN < FldNmValPrV.Len(); FldN++) { TStr OrgFldNm = FldNmValPrV[FldN].Key; if (Redirect.FldNmMapH.IsKey(OrgFldNm)) { _FldNmValPrV.Add(TStrKd(Redirect.FldNmMapH.GetDat(OrgFldNm), FldNmValPrV[FldN].Dat)); } } RqEnv->ExecFun(Redirect.FunNm, _FldNmValPrV); }
void TSAppSrvFun::LogReqRes(const TStrKdV& FldNmValPrV, const PHttpResp& HttpResp) { if (LogRqFolder == "") return; try { TDir::GenDir(LogRqFolder); TStr TimeNow = TTm::GetCurLocTm().GetWebLogDateTimeStr(true); TimeNow.ChangeChAll(':', '.'); PSOut Output = TFOut::New(LogRqFolder + "/" + TimeNow + ".txt", false); Output->PutStr(FunNm.CStr()); Output->PutCh('\n'); for (int N=0; N < FldNmValPrV.Len(); N++) Output->PutStrFmt(" %s: %s\n", FldNmValPrV[N].Key.CStr(), FldNmValPrV[N].Dat.CStr()); Output->PutCh('\n'); Output->PutStr(HttpResp->GetBodyAsStr(), false); } catch (...) { /*const PNotify& Notify = RqEnv->GetWebSrv()->GetNotify(); Notify->OnStatus("Unable to log request for function '" + GetFunNm() + "'!");*/ } }