public string render_tag_esc(XmlElement e, string t_val, Hashtable t_att, string g_att, Hashtable h) { string r; string format = e.GetAttribute("t-format"); if (t_val == "0") { r = h["0"] as string; } else { r = QU.eval(t_val, h); } if (format.Length != 0) { if (format == "ucfirst") { r = char.ToUpper(r[0]) + r.Substring(1); } else if (format == "upper") { r = r.ToUpper(); } else if (format == "lower") { r = r.ToLower(); } else { r = String.Format(format, r); } } return(HttpUtility.HtmlEncode(r)); }
public string render_tag_if(XmlElement e, string t_val, Hashtable t_att, string g_att, Hashtable h) { if (QU.eval_bool(t_val, h)) { return(render_element(e, g_att, h)); } else { return(""); } }
public string render_tag_invalid(XmlElement e, string t_val, Hashtable t_att, string g_att, Hashtable h) { if (h["form"] == null) { QU.rwe("QWeb: No form was found in the Hashtable"); } QWebForm f = h["form"] as QWebForm; if (f.AnyError()) { return(render_element(e, g_att, h)); } else { return(""); } }
public int control() { HttpContext c = HttpContext.Current; if (Xml != null && Xml.Url != null) { Req = Xml.Url.Request(); } else { Req = new StringDictionary(); foreach (String k in c.Request.QueryString) { Req[k] = c.Request.QueryString[k]; } foreach (String k in c.Request.Form) { Req[k] = c.Request.Form[k]; } } if (debug) { QU.rw("<b>Starting with state : " + _state + "</b><br/>"); } _v = new Hashtable(); _run_done = new Hashtable(); _run_todo = new ArrayList(q_state_split(QState)); while (_run_todo.Count > 0) { string s = (string)_run_todo[0]; string m = s + "control"; _run_todo.RemoveAt(0); _run_done[s] = 1; if (debug) { QU.rw("Executing control state :" + m + "<br/>"); } MethodInfo mi = GetType().GetMethod(m); if (mi != null) { mi.Invoke(this, new Object[] { c, _v }); } } return(0); }
public string view() { foreach (string s in q_state_split(QState)) { string m = s + "view"; if (debug) { QU.rw("Executing view state : " + m + "<br/>"); } if (GetType().GetMethod(m) != null) { Object o = GetType().GetMethod(m).Invoke(this, new Object[] { _v }); if (o is string) { return((string)o); } } } return("qweb: no view returned a string."); }
public static string eval(string expr, Hashtable h) { Regex re_sep = new Regex(@"(==|!=|&&|\|\||[./+*\(\)-]| )"); Regex re_int = new Regex(@"^[0-9]+$"); Regex re_var = new Regex(@"^\$?[a-zA-Z_][0-9a-zA-Z_]*$"); Regex re_float = new Regex(@"^\-?\d+\.?\d*$"); eval_list i = new eval_list(); eval_list s = new eval_list(); try { // Tokenize string[] tokens = re_sep.Split(expr); for (int n = 0; n < tokens.Length; n++) { string token = tokens[n]; if (token == ".") { i.enqueue("DOT", token); } else if (token == "+") { i.enqueue("PLUS", token); } else if (token == "-") { i.enqueue("MINUS", token); } else if (token == "(") { i.enqueue("LP", token); } else if (token == ")") { i.enqueue("RP", token); } else if (token == "==") { i.enqueue("EQUAL", token); } else if (token == "!=") { i.enqueue("NOT_EQUAL", token); } else if (token == "and" || token == "&&") { i.enqueue("AND", token); } else if (token == "or" || token == "||") { i.enqueue("OR", token); } else if (re_int.Match(token).Success) { i.enqueue("STR", token); } else if (re_var.Match(token).Success) { Object o = h[token]; if (o is bool && !(bool)o) { o = ""; } i.enqueue("STR", (o == null) ? "" : o.ToString()); } else if (token.StartsWith("\"") || token.StartsWith("'")) { string term = token.Substring(0, 1); token = token.Substring(1, token.Length - 1); while (!token.EndsWith(term)) { token += tokens[++n]; } i.enqueue("STR", token.Substring(0, token.Length - 1)); } } // print("input: ",tokens); // print("input: ",i.l); // print("*************************************"); // Shift Reduce loop while (i.l.Count > 0 || s.l.Count > 1) { //print("input: ",i.l); //print("stack: ",s.l); //print(); // REDUCE if (s[2][0] == "STR" && s[1][0] == "PLUS" && s[0][0] == "STR") { int r = ToInt(s[2][1]) + ToInt(s[0][1]); s.replace(3, "STR", r.ToString()); } else if (s[2][0] == "STR" && s[1][0] == "MINUS" && s[0][0] == "STR") { int r = ToInt(s[2][1]) - ToInt(s[0][1]); s.replace(3, "STR", r.ToString()); } else if (s[2][0] == "STR" && s[1][0] == "DOT" && s[0][0] == "STR") { s.replace(3, "STR", s[2][1] + s[0][1]); } else if (s[2][0] == "STR" && s[1][0] == "EQUAL" && s[0][0] == "STR") { s.replace(3, "STR", (s[2][1] == s[0][1]) ? "True" : ""); } else if (s[2][0] == "STR" && s[1][0] == "NOT_EQUAL" && s[0][0] == "STR") { s.replace(3, "STR", (s[2][1] != s[0][1]) ? "True" : ""); } else if (s[2][0] == "STR" && s[1][0] == "AND" && s[0][0] == "STR") { s.replace(3, "STR", (s[2][1].Length > 0 && s[0][1].Length > 0) ? "True" : ""); } else if (s[2][0] == "STR" && s[1][0] == "OR" && s[0][0] == "STR") { s.replace(3, "STR", (s[2][1].Length > 0 || s[0][1].Length > 0) ? "True" : ""); } else if (s[2][0] == "LP" && s[1][0] == "STR" && s[0][0] == "RP") { s.replace(3, "STR", s[1][1]); // SHIFT } else { s.push(i.pop()); } } // print("input: ",i.l); // print("stack: ",s.l); // print("eval",expr,s[0][1]); return(s[0][1]); } catch { QU.rwe("Error evaluating : <br/><pre>" + expr); return("ERROR"); } }
public string render_node(XmlNode n, Hashtable h) { string r = ""; if (n.NodeType == XmlNodeType.Text || n.NodeType == XmlNodeType.Whitespace || n.NodeType == XmlNodeType.CDATA) { r = n.Value; } else if (n.NodeType == XmlNodeType.Element) { XmlElement e = n as XmlElement; string g_att = ""; string t_att_first = null; Hashtable t_att = new Hashtable(); foreach (XmlAttribute a in e.Attributes) { if (a.Name.StartsWith("t-")) { if (a.Name.StartsWith("t-att")) { string myval = QU.eval(a.Value, h); g_att += " " + a.Name.Substring(6) + "=\"" + HttpUtility.HtmlEncode(myval) + "\""; } else { t_att[a.Name.Substring(2)] = a.Value; if (t_att_first == null) { t_att_first = a.Name.Substring(2); } } } else { g_att += " " + a.Name + "=\"" + HttpUtility.HtmlEncode(a.Value) + "\""; } } if (t_att.Count > 0) { string val; if ((val = t_att["raw"] as string) != null) { r = render_tag_raw(e, val, t_att, g_att, h); } else if ((val = t_att["esc"] as string) != null) { r = render_tag_esc(e, val, t_att, g_att, h); } else if ((val = t_att["foreach"] as string) != null) { r = render_tag_foreach(e, val, t_att, g_att, h); } else if ((val = t_att["if"] as string) != null) { r = render_tag_if(e, val, t_att, g_att, h); } else if ((val = t_att["call"] as string) != null) { r = render_tag_call(e, val, t_att, g_att, h); } else if ((val = t_att["set"] as string) != null) { r = render_tag_set(e, val, t_att, g_att, h); } else if ((val = t_att["type"] as string) != null) { r = render_tag_type(e, val, t_att, g_att, h); } else if ((val = t_att["select"] as string) != null) { r = render_tag_select(e, val, t_att, g_att, h); } else if ((val = t_att["name"] as string) != null) { r = render_tag_name(e, val, t_att, g_att, h); } else if ((val = t_att["error"] as string) != null) { r = render_tag_error(e, val, t_att, g_att, h); } else if ((val = t_att["invalid"] as string) != null) { r = render_tag_invalid(e, val, t_att, g_att, h); } else { val = t_att[t_att_first] as string; t_att_first = t_att_first.Replace("-", "_"); if (t_att_first.StartsWith("ext_")) { foreach (Object ex in ext) { if (ex.GetType().GetMethod(t_att_first) != null) { Object o = ex.GetType().GetMethod(t_att_first).Invoke(ex, new Object[] { this, e, val, t_att, g_att, h }); if (o is string) { r = (string)o; } } } } } } else { r = render_element(e, g_att, h); } } return(r); }
public string render_tag_href(XmlElement e, string t_val, Hashtable t_att, string g_att, Hashtable h) { return(QU.eval(t_val, h)); }