void TagParsed (ILocation location, TagType tagtype, string tagid, TagAttributes attributes) { bool tagIgnored; this.location = new Location (location); if (tparser != null) tparser.Location = location; if (text.Length != 0) { bool ignoreEmptyString = lastTag == TagType.CodeRender; #if NET_4_0 ignoreEmptyString |= lastTag == TagType.CodeRenderEncode; #endif FlushText (ignoreEmptyString); } if (0 == String.Compare (tagid, "script", true, Helpers.InvariantCulture)) { bool in_script = (inScript || ignore_text); if (in_script) { if (ProcessScript (tagtype, attributes)) return; } else if (ProcessScript (tagtype, attributes)) return; } lastTag = tagtype; switch (tagtype) { case TagType.Directive: if (tagid.Length == 0) tagid = tparser.DefaultDirectiveName; tparser.AddDirective (tagid, attributes.GetDictionary (null)); break; case TagType.Tag: if (ProcessTag (location, tagid, attributes, tagtype, out tagIgnored)) { if (!tagIgnored) useOtherTags = true; break; } if (useOtherTags) { stack.Builder.EnsureOtherTags (); stack.Builder.OtherTags.Add (tagid); } { string plainText = location.PlainText; if (!ProcessTagsInAttributes (location, tagid, attributes, TagType.Tag)) TextParsed (location, ChopOffTagStart (location, plainText, tagid)); } break; case TagType.Close: bool notServer = (useOtherTags && TryRemoveTag (tagid, stack.Builder.OtherTags)); if (!notServer && CloseControl (tagid)) break; TextParsed (location, location.PlainText); break; case TagType.SelfClosing: int count = stack.Count; if (!ProcessTag (location, tagid, attributes, tagtype, out tagIgnored) && !tagIgnored) { string plainText = location.PlainText; if (!ProcessTagsInAttributes (location, tagid, attributes, TagType.SelfClosing)) TextParsed (location, ChopOffTagStart (location, plainText, tagid)); } else if (stack.Count != count) { CloseControl (tagid); } break; case TagType.DataBinding: case TagType.CodeRenderExpression: case TagType.CodeRender: #if NET_4_0 case TagType.CodeRenderEncode: #endif if (isApplication) throw new ParseException (location, "Invalid content for application file."); ProcessCode (tagtype, tagid, location); break; case TagType.Include: if (isApplication) throw new ParseException (location, "Invalid content for application file."); string file = attributes ["virtual"] as string; bool isvirtual = (file != null); if (!isvirtual) file = attributes ["file"] as string; if (isvirtual) { bool parsed = false; VirtualPathProvider vpp = HostingEnvironment.VirtualPathProvider; if (vpp.FileExists (file)) { VirtualFile vf = vpp.GetFile (file); if (vf != null) { Parse (vf.Open (), file, true); parsed = true; } } if (!parsed) Parse (tparser.MapPath (file), true); } else { string includeFilePath = GetIncludeFilePath (tparser.ParserDir, file); CheckIfIncludeFileIsSecure (includeFilePath); tparser.PushIncludeDir (Path.GetDirectoryName (includeFilePath)); try { Parse (includeFilePath, true); } finally { tparser.PopIncludeDir (); } } break; default: break; } //PrintLocation (location); }
bool ProcessTag (ILocation location, string tagid, TagAttributes atts, TagType tagtype, out bool ignored) { ignored = false; if (isApplication) { if (String.Compare (tagid, "object", true, Helpers.InvariantCulture) != 0) throw new ParseException (location, "Invalid tag for application file."); } ControlBuilder parent = stack.Builder; ControlBuilder builder = null; if (parent != null && parent.ControlType == typeof (HtmlTable) && (String.Compare (tagid, "thead", true, Helpers.InvariantCulture) == 0 || String.Compare (tagid, "tbody", true, Helpers.InvariantCulture) == 0)) { ignored = true; return true; } IDictionary htable = (atts != null) ? atts.GetDictionary (null) : emptyHash; if (stack.Count > 1) { try { builder = parent.CreateSubBuilder (tagid, htable, null, tparser, location); } catch (TypeLoadException e) { throw new ParseException (Location, "Type not found.", e); } catch (Exception e) { throw new ParseException (Location, e.Message, e); } } bool runatServer = atts != null && atts.IsRunAtServer (); if (builder == null && runatServer) { string id = htable ["id"] as string; if (id != null && !CodeGenerator.IsValidLanguageIndependentIdentifier (id)) throw new ParseException (Location, "'" + id + "' is not a valid identifier"); try { builder = RootBuilder.CreateSubBuilder (tagid, htable, null, tparser, location); } catch (TypeLoadException e) { throw new ParseException (Location, "Type not found.", e); } catch (HttpException e) { CompilationException inner = e.InnerException as CompilationException; if (inner != null) throw inner; throw new ParseException (Location, e.Message, e); } catch (Exception e) { throw new ParseException (Location, e.Message, e); } } if (builder == null) return false; // This is as good as we can do for now - if the parsed location contains // both expressions and code render blocks then we're out of luck... string plainText = location.PlainText; if (!runatServer && plainText.IndexOf ("<%$") == -1&& plainText.IndexOf ("<%") > -1) return false; PageParserFilter pfilter = PageParserFilter; if (pfilter != null && !pfilter.AllowControl (builder.ControlType, builder)) throw new ParseException (Location, "Control type '" + builder.ControlType + "' not allowed."); if (!OtherControlsAllowed (builder)) throw new ParseException (Location, "Only Content controls are allowed directly in a content page that contains Content controls."); builder.Location = location; builder.ID = htable ["id"] as string; if (typeof (HtmlForm).IsAssignableFrom (builder.ControlType)) { if (inForm) throw new ParseException (location, "Only one <form> allowed."); inForm = true; } if (builder.HasBody () && !(builder is ObjectTagBuilder)) { if (builder is TemplateBuilder) { // push the id list } stack.Push (builder, location); } else { if (!isApplication && builder is ObjectTagBuilder) { ObjectTagBuilder ot = (ObjectTagBuilder) builder; if (ot.Scope != null && ot.Scope.Length > 0) throw new ParseException (location, "Scope not allowed here"); if (tagtype == TagType.Tag) { stack.Push (builder, location); return true; } } parent.AppendSubBuilder (builder); builder.CloseControl (); } return true; }
internal virtual void AddAssemblyDirective (ILocation location, TagAttributes attrs) { Hashtable tbl = attrs.GetDictionary (null); string name = GetAndRemove (tbl, "Name"); string src = GetAndRemove (tbl, "Src"); if (name == null && src == null) throw new ParseException (location, "You gotta specify Src or Name"); if (name != null && src != null) throw new ParseException (location, "Src and Name cannot be used together"); if (name != null) { AddAssemblyByName (name, location); } else { GetAssemblyFromSource (src, location); } if (tbl.Count > 0) throw new ParseException (location, "Unrecognized attribute in Assembly directive"); }
internal virtual void AddDefaultDirective (ILocation location, TagAttributes attrs) { #if NET_2_0 CompilationSection compConfig; #else CompilationConfiguration compConfig; #endif compConfig = CompilationConfig; if (gotDefault) throw new ParseException (location, "duplicate " + DefaultDirectiveName + " directive"); gotDefault = true; Hashtable attributes = attrs.GetDictionary (null); className = GetAndRemove (attributes, "class"); if (className == null) throw new ParseException (null, "No Class attribute found."); string d = GetAndRemove (attributes, "debug"); if (d != null) { debug = (String.Compare (d, "true", true, Helpers.InvariantCulture) == 0); if (debug == false && String.Compare (d, "false", true, Helpers.InvariantCulture) != 0) throw new ParseException (null, "Invalid value for Debug attribute"); } else debug = compConfig.Debug; language = GetAndRemove (attributes, "language"); if (language == null) language = compConfig.DefaultLanguage; GetAndRemove (attributes, "codebehind"); if (attributes.Count > 0) throw new ParseException (location, "Unrecognized attribute in " + DefaultDirectiveName + " directive"); }
bool ProcessTag (string tagid, TagAttributes atts, TagType tagtype) { if ((atts == null || !atts.IsRunAtServer ()) && String.Compare (tagid, "tbody", true) == 0) { // MS completely ignores tbody or, if runat="server", fails when compiling if (stack.Count > 0) return stack.Builder.ChildrenAsProperties; return false; } if (isApplication) { if (String.Compare (tagid, "object", true) != 0) throw new ParseException (location, "Invalid tag for application file."); } ControlBuilder parent = stack.Builder; ControlBuilder builder = null; Hashtable htable = (atts != null) ? atts.GetDictionary (null) : emptyHash; if (stack.Count > 1) { try { builder = parent.CreateSubBuilder (tagid, htable, null, tparser, location); } catch (TypeLoadException e) { throw new ParseException (Location, "Type not found.", e); } catch (Exception e) { throw new ParseException (Location, e.Message, e); } } if (builder == null && atts != null && atts.IsRunAtServer ()) { string id = htable ["id"] as string; if (id != null && !CodeGenerator.IsValidLanguageIndependentIdentifier (id)) throw new ParseException (Location, "'" + id + "' is not a valid identifier"); try { builder = rootBuilder.CreateSubBuilder (tagid, htable, null, tparser, location); } catch (TypeLoadException e) { throw new ParseException (Location, "Type not found.", e); } catch (Exception e) { throw new ParseException (Location, e.Message, e); } } if (builder == null) return false; builder.location = location; builder.ID = htable ["id"] as string; if (typeof (HtmlForm).IsAssignableFrom (builder.ControlType)) { if (inForm) throw new ParseException (location, "Only one <form> allowed."); inForm = true; } if (builder.HasBody () && !(builder is ObjectTagBuilder)) { if (builder is TemplateBuilder) { // push the id list } stack.Push (builder, location); } else { if (!isApplication && builder is ObjectTagBuilder) { ObjectTagBuilder ot = (ObjectTagBuilder) builder; if (ot.Scope != null && ot.Scope != "") throw new ParseException (location, "Scope not allowed here"); if (tagtype == TagType.Tag) { stack.Push (builder, location); return true; } } parent.AppendSubBuilder (builder); builder.CloseControl (); } return true; }
void TagParsed (ILocation location, TagType tagtype, string tagid, TagAttributes attributes) { this.location = new Location (location); if (tparser != null) tparser.Location = location; if (text.Length != 0) FlushText (); if (0 == String.Compare (tagid, "script", true)) { if (ProcessScript (tagtype, attributes)) return; } switch (tagtype) { case TagType.Directive: if (tagid == "") tagid = tparser.DefaultDirectiveName; tparser.AddDirective (tagid, attributes.GetDictionary (null)); break; case TagType.Tag: if (ProcessTag (tagid, attributes, tagtype)) { useOtherTags = true; break; } if (useOtherTags) { stack.Builder.EnsureOtherTags (); stack.Builder.OtherTags.Add (tagid); } TextParsed (location, location.PlainText); break; case TagType.Close: bool notServer = (useOtherTags && TryRemoveTag (tagid, stack.Builder.OtherTags)); if (!notServer && CloseControl (tagid)) break; TextParsed (location, location.PlainText); break; case TagType.SelfClosing: int count = stack.Count; if (!ProcessTag (tagid, attributes, tagtype)) { TextParsed (location, location.PlainText); } else if (stack.Count != count) { CloseControl (tagid); } break; case TagType.DataBinding: goto case TagType.CodeRender; case TagType.CodeRenderExpression: goto case TagType.CodeRender; case TagType.CodeRender: if (isApplication) throw new ParseException (location, "Invalid content for application file."); ProcessCode (tagtype, tagid, location); break; case TagType.Include: if (isApplication) throw new ParseException (location, "Invalid content for application file."); string file = attributes ["virtual"] as string; bool isvirtual = (file != null); if (!isvirtual) file = attributes ["file"] as string; if (isvirtual) { file = tparser.MapPath (file); } else { file = GetIncludeFilePath (tparser.BaseDir, file); } InitParser (file); DoParse (); break; default: break; } //PrintLocation (location); }