示例#1
0
        private int CommandExtract(string line, int index, TemplateContext tc, string commandname, string param)
        {
            ObjectDictionary args     = ObjectDictionary.FromString(param);
            string           variable = null;

            if (args.ContainsKey("0"))
            {
                variable = args["0"].ToString();
            }
            else if (args.ContainsKey("var"))
            {
                variable = args["var"].ToString();
            }

            if (string.IsNullOrEmpty(variable))
            {
                LOG_ERR(string.Format("Error: Invalid syntax, should be '{0}{1} var-name{2}'", m_commandprefix, commandname, m_commandpostfix));
                return(index);
            }
            object obj = tc.dict.GetObject(variable);

            if (obj == null)
            {
                LOG_ERR(string.Format("Error: Object {0} is not assigned.", variable));
                return(index);
            }
            Dispatch(tc, obj.ToString());
            return(index);
        }
示例#2
0
        private int CommandDef(string line, int index, TemplateContext tc, string commandname, string param)
        {
            string contents;

            index = Capture(line, index, m_commandprefix + commandname, m_commandprefix + "end" + commandname + m_commandpostfix, out contents);
            ObjectDictionary args     = ObjectDictionary.FromString(param);
            string           variable = null;

            if (args.ContainsKey("0"))
            {
                variable = args["0"].ToString();
            }
            else if (args.ContainsKey("var"))
            {
                variable = args["var"].ToString();
            }

            if (string.IsNullOrEmpty(variable))
            {
                LOG_ERR(string.Format("Error: Invalid syntax, should be '{0}{1} var-name{2}'", m_commandprefix, commandname, m_commandpostfix));
                return(index);
            }
            tc.dict[variable] = contents;
            return(index);
        }
示例#3
0
        private int CommandAssign(string line, int index, TemplateContext tc, string commandname, string param)
        {
            ObjectDictionary args     = ObjectDictionary.FromString(param);
            string           variable = null;

            if (args.ContainsKey("0"))
            {
                variable = args["0"].ToString();
            }
            else if (args.ContainsKey("var"))
            {
                variable = args["var"].ToString();
            }

            string value = null;

            if (args.ContainsKey("1"))
            {
                value = args["1"].ToString();
            }
            else if (args.ContainsKey("value"))
            {
                value = args["value"].ToString();
            }

            if ((variable == null) || (value == null))
            {
                LOG_ERR(string.Format("Error: Invalid syntax, should be '{0}{1} var-name expression{2}'", m_commandprefix, commandname, m_commandpostfix));
                return(index);
            }
            tc.dict[variable] = GetExpr(tc.dict, value);
            return(index);
        }
示例#4
0
        private string GetVariableValue(ObjectDictionary dict, string varparam)
        {
            if (varparam == null)
            {
                return(null);
            }
            bool htmlescape  = false;
            bool quoteescape = false;
            bool urlescape   = false;

            char[]   separators = " \t".ToCharArray();
            string[] p          = varparam.Trim(separators).Split(separators, 2);
            // 最初の要素が変数名。
            if (p[0].EndsWith(":h"))
            {
                p[0]       = p[0].Substring(0, p[0].Length - 2);
                htmlescape = true;
            }
            else if (p[0].EndsWith(":q"))
            {
                p[0]        = p[0].Substring(0, p[0].Length - 2);
                quoteescape = true;
            }
            else if (p[0].EndsWith(":u"))
            {
                p[0]      = p[0].Substring(0, p[0].Length - 2);
                urlescape = true;
            }
            object obj = dict.GetObject(p[0]);

            if (obj == null)
            {
                return(null);
            }
            // アサインされたオブジェクトにパラメータをセットする
            if (p.Length > 1)
            {
                SetParameters(p[0], obj, ObjectDictionary.FromString(p[1]));
            }
            // WebControl用の特例: Nameを自動セットする。
            SetParameterIfNull(p[0], obj, "Name", p[0]);
            // オブジェクトの文字列表現を返す。
            if (htmlescape)
            {
                return(HE(obj.ToString()));
            }
            if (quoteescape)
            {
                return(QE(obj.ToString()));
            }
            if (urlescape)
            {
                return(UE(obj.ToString()));
            }
            return(obj.ToString());
        }
示例#5
0
        private int CommandInclude(string line, int index, TemplateContext tc, string commandname, string param)
        {
            ObjectDictionary args  = ObjectDictionary.FromString(param);
            string           fname = null;

            if (args.ContainsKey("0"))
            {
                fname = args["0"].ToString();
            }
            else if (args.ContainsKey("file"))
            {
                fname = args["file"].ToString();
            }
            if (string.IsNullOrEmpty(fname))
            {
                LOG_ERR(string.Format("Error: {0}{1}{2} directive must have filename argument.", m_commandprefix, commandname, m_commandpostfix));
                return(index);
            }
            RenderTemplateAux(tc, Path.Combine(m_dir, fname));
            return(index);
        }
示例#6
0
        private int CommandFor(string line, int index, TemplateContext tc, string commandname, string param)
        {
            string contents;

            index = Capture(line, index, m_commandprefix + commandname, m_commandprefix + "end" + commandname + m_commandpostfix, out contents);
            ObjectDictionary args     = ObjectDictionary.FromString(param);
            string           variable = null;

            if (args.ContainsKey("0"))
            {
                variable = args["0"].ToString();
            }
            else if (args.ContainsKey("var"))
            {
                variable = args["var"].ToString();
            }

            string list = null;

            if (args.ContainsKey("1") && (args["1"].ToString() == "in") && args.ContainsKey("2"))
            {
                list = args["2"].ToString();
            }
            else if (args.ContainsKey("list"))
            {
                list = args["list"].ToString();
            }

            string countvar = null;

            if (args.ContainsKey("count"))
            {
                countvar = args["count"].ToString();
            }
            int countstart = 1;

            if (args.ContainsKey("countstart"))
            {
                object countstartobj = tc.dict.GetObject(args["countstart"].ToString());
                if (countstartobj != null)
                {
                    countstart = StringUtil.ToInt(countstartobj.ToString(), countstart);
                }
            }
            string indexvar = null;

            if (args.ContainsKey("index"))
            {
                indexvar = args["index"].ToString();
            }
            string evenvar = null;

            if (args.ContainsKey("even"))
            {
                evenvar = args["even"].ToString();
            }
            string oddvar = null;

            if (args.ContainsKey("odd"))
            {
                oddvar = args["odd"].ToString();
            }

            if (string.IsNullOrEmpty(variable) || string.IsNullOrEmpty(list))
            {
                LOG_ERR(string.Format("Error: Invalid syntax, should be '{0}{1} var-name in list-variable {2}'", m_commandprefix, commandname, m_commandpostfix));
                return(index);
            }
            object listobj = tc.dict.GetObject(list);

            if (listobj == null)
            {
                LOG_ERR(string.Format("Error: Object {0} is not assigned.", list));
                return(index);
            }
            if (!(listobj is IEnumerable))
            {
                LOG_ERR(string.Format("Error: Object {0} is not an Enumerable.", list));
                return(index);
            }
            TemplateContext innertc = new TemplateContext(tc.sb, tc.dict);
            int             i       = 0;

            foreach (object obj in (listobj as IEnumerable))
            {
                innertc.dict[variable] = obj;
                if (!String.IsNullOrEmpty(countvar))
                {
                    innertc.dict[countvar] = i + countstart;
                }
                if (!String.IsNullOrEmpty(indexvar))
                {
                    innertc.dict[indexvar] = i;
                }
                if (!String.IsNullOrEmpty(evenvar))
                {
                    innertc.dict[evenvar] = ((i % 2) == 0);
                }
                if (!String.IsNullOrEmpty(oddvar))
                {
                    innertc.dict[oddvar] = ((i % 2) == 1);
                }
                Dispatch(innertc, contents);
                i++;
            }
            return(index);
        }