public void TagEndProcess(TemplateManager manager, Tag tag, string innerContent) { Expression exp; string _channelid, _channelishtml, _channellink; exp = tag.AttributeValue("channelid"); if (exp == null) throw new Exception("没有channelid标签"); _channelid = manager.EvalExpression(exp).ToString(); exp = tag.AttributeValue("channelishtml"); if (exp == null) _channelishtml = "0"; _channelishtml = manager.EvalExpression(exp).ToString(); _channellink = (new Normal_ChannelDAL()).GetChannelLink(_channelishtml == "1", _channelid, false); manager.WriteValue(_channellink); }
public void TagEndProcess(TemplateManager manager, Tag tag, string innerContent) { Expression exp; string _channelid, _channelname; exp = tag.AttributeValue("channelid"); if (exp == null) throw new Exception("没有channelid标签"); _channelid = manager.EvalExpression(exp).ToString(); _channelname = (new JumboTCMS.DAL.Normal_ChannelDAL().GetChannelName(_channelid)); manager.WriteValue(_channelname); }
protected void ProcessTagSet(Tag tag) { Expression expName = tag.AttributeValue("name"); if (expName == null) { throw new TemplateRuntimeException("Set is missing required attribute: name", tag.Line, tag.Col); } Expression expValue = tag.AttributeValue("value"); if (expValue == null) { throw new TemplateRuntimeException("Set is missing required attribute: value", tag.Line, tag.Col); } string name = EvalExpression(expName).ToString(); if (!Util.IsValidVariableName(name)) throw new TemplateRuntimeException("'" + name + "' is not valid variable name.", expName.Line, expName.Col); object value = EvalExpression(expValue); this.SetValue(name, value); }
protected void ProcessTag(Tag tag) { string name = tag.Name.ToLowerInvariant(); try { switch (name) { case "template": // skip those, because those are processed first break; case "else": ProcessElements(tag.InnerElements); break; case "apply": object val = EvalExpression(tag.AttributeValue("template")); ProcessTemplate(val.ToString(), tag); break; case "foreach": ProcessForEach(tag); break; case "for": ProcessFor(tag); break; case "set": ProcessTagSet(tag); break; default: ProcessTemplate(tag.Name, tag); break; } } catch (TemplateRuntimeException ex) { DisplayError(ex); } catch (Exception ex) { DisplayError("Error executing tag '" + name + "': " + ex.Message, tag.Line, tag.Col); } }
protected void ProcessForEach(Tag tag) { Expression expCollection = tag.AttributeValue("collection"); if (expCollection == null) { throw new TemplateRuntimeException("Foreach is missing required attribute: collection", tag.Line, tag.Col); } object collection = EvalExpression(expCollection); if (!(collection is IEnumerable)) { throw new TemplateRuntimeException("Collection used in foreach has to be enumerable", tag.Line, tag.Col); } Expression expVar = tag.AttributeValue("var"); if (expCollection == null) { throw new TemplateRuntimeException("Foreach is missing required attribute: var", tag.Line, tag.Col); } object varObject = EvalExpression(expVar); if (varObject == null) varObject = "foreach"; string varname = varObject.ToString(); Expression expIndex = tag.AttributeValue("index"); string indexname = null; if (expIndex != null) { object obj = EvalExpression(expIndex); if (obj != null) indexname = obj.ToString(); } IEnumerator ienum = ((IEnumerable)collection).GetEnumerator(); int index = 0; while (ienum.MoveNext()) { index++; object value = ienum.Current; variables[varname] = value; if (indexname != null) variables[indexname] = index; ProcessElements(tag.InnerElements); } }
protected void ProcessFor(Tag tag) { Expression expFrom = tag.AttributeValue("from"); if (expFrom == null) { throw new TemplateRuntimeException("For is missing required attribute: start", tag.Line, tag.Col); } Expression expTo = tag.AttributeValue("to"); if (expTo == null) { throw new TemplateRuntimeException("For is missing required attribute: to", tag.Line, tag.Col); } Expression expIndex = tag.AttributeValue("index"); if (expIndex == null) { throw new TemplateRuntimeException("For is missing required attribute: index", tag.Line, tag.Col); } object obj = EvalExpression(expIndex); string indexName = obj.ToString(); int start = Convert.ToInt32(EvalExpression(expFrom)); int end = Convert.ToInt32(EvalExpression(expTo)); for (int index = start; index <= end; index++) { SetValue(indexName, index); //variables[indexName] = index; ProcessElements(tag.InnerElements); } }
public void TagEndProcess(TemplateManager manager, Tag tag, string innerContent) { Expression exp; string _sitedir, _channelid, _channeltype, _contentid, _viewnum; exp = tag.AttributeValue("sitedir"); if (exp == null) throw new Exception("没有sitedir标签"); _sitedir = manager.EvalExpression(exp).ToString(); exp = tag.AttributeValue("channelid"); if (exp == null) throw new Exception("没有channelid标签"); _channelid = manager.EvalExpression(exp).ToString(); exp = tag.AttributeValue("channeltype"); if (exp == null) throw new Exception("没有channeltype标签"); _channeltype = manager.EvalExpression(exp).ToString(); exp = tag.AttributeValue("contentid"); if (exp == null) throw new Exception("没有contentid标签"); _contentid = manager.EvalExpression(exp).ToString(); _viewnum = "<script src=\"" + _sitedir + "plus/viewcount.aspx?ccid=" + _channelid + "&cType=" + _channeltype + "&id=" + _contentid + "&addit=0\"></script>"; manager.WriteValue(_viewnum); }
public void TagEndProcess(TemplateManager manager, Tag tag, string innerContent) { Expression exp; string _sitedir, _isimg, _img, _imgurl; exp = tag.AttributeValue("sitedir"); if (exp == null) throw new Exception("没有sitedir标签"); _sitedir = manager.EvalExpression(exp).ToString(); exp = tag.AttributeValue("isimg"); if (exp == null) _isimg = "0"; else _isimg = manager.EvalExpression(exp).ToString(); exp = tag.AttributeValue("img"); if (exp == null) _img = ""; else _img = manager.EvalExpression(exp).ToString(); if (_isimg == "0" || _img.Length == 0) _imgurl = _sitedir + "style/common/nophoto.jpg"; else _imgurl = _img; manager.WriteValue(_imgurl); }
public void TagEndProcess(TemplateManager manager, Tag tag, string innerContent) { Expression exp; string _title, _formattitle; exp = tag.AttributeValue("title"); if (exp == null) throw new Exception("没有title标签"); _title = manager.EvalExpression(exp).ToString(); _formattitle = JumboTCMS.Utils.Strings.HtmlEncode(_title); manager.WriteValue(_formattitle); }
public void TagEndProcess(TemplateManager manager, Tag tag, string innerContent) { Expression exp; string _len, _cutstring; exp = tag.AttributeValue("len"); if (exp == null) throw new Exception("没有len标签"); _len = manager.EvalExpression(exp).ToString(); _cutstring = JumboTCMS.Utils.Strings.CutString(JumboTCMS.Utils.Strings.NoHTML(innerContent), Convert.ToInt32(_len)); manager.WriteValue(_cutstring); }
private Tag CollectForTag(Tag tag, ref int index) { if (tag.IsClosed) // if self-closing tag, do not collect inner elements { return tag; } if (string.Compare(tag.Name, "if", true) == 0) { tag = new TagIf(tag.Line, tag.Col, tag.AttributeValue("test")); } Tag collectTag = tag; for (index++; index < elements.Count; index++) { Element elem = elements[index]; if (elem is Text) collectTag.InnerElements.Add(elem); else if (elem is Expression) collectTag.InnerElements.Add(elem); else if (elem is Tag) { Tag innerTag = (Tag)elem; if (string.Compare(innerTag.Name, "else", true) == 0) { if (collectTag is TagIf) { ((TagIf)collectTag).FalseBranch = innerTag; collectTag = innerTag; } else throw new ParseException("else tag has to be positioned inside of if or elseif tag", innerTag.Line, innerTag.Col); } else if (string.Compare(innerTag.Name, "elseif", true) == 0) { if (collectTag is TagIf) { Tag newTag = new TagIf(innerTag.Line, innerTag.Col, innerTag.AttributeValue("test")); ((TagIf)collectTag).FalseBranch = newTag; collectTag = newTag; } else throw new ParseException("elseif tag is not positioned properly", innerTag.Line, innerTag.Col); } else collectTag.InnerElements.Add(CollectForTag(innerTag, ref index)); } else if (elem is TagClose) { TagClose tagClose = (TagClose)elem; if (string.Compare(tag.Name, tagClose.Name, true) == 0) return tag; throw new ParseException("Close tag for " + tagClose.Name + " doesn't have matching start tag.", elem.Line, elem.Col); } else throw new ParseException("Invalid element: " + elem.GetType().ToString(), elem.Line, elem.Col); } throw new ParseException("Start tag: " + tag.Name + " does not have matching end tag.", tag.Line, tag.Col); }