bool ProcessScript (TagType tagtype, TagAttributes attributes) { if (tagtype != TagType.Close) { if (attributes != null && attributes.IsRunAtServer ()) { string language = (string) attributes ["language"]; if (language != null && language.Length > 0 && tparser.ImplicitLanguage) tparser.SetLanguage (language); CheckLanguage (language); string src = (string) attributes ["src"]; if (src != null) { if (src.Length == 0) throw new ParseException (Parser, "src cannot be an empty string"); string content = ReadFile (src); inScript = true; TextParsed (Parser, content); FlushText (); inScript = false; if (tagtype != TagType.SelfClosing) { ignore_text = true; Parser.VerbatimID = "script"; } } else if (tagtype == TagType.Tag) { Parser.VerbatimID = "script"; inScript = true; } return true; } else { if (tagtype != TagType.SelfClosing) { Parser.VerbatimID = "script"; javascript = true; } string content = location.PlainText; /* HACK, HACK, HACK */ if (content.StartsWith ("<script")) { TextParsed (location, "<script"); content = content.Substring (7); } TextParsed (location, content); return true; } } bool result; if (inScript) { result = inScript; inScript = false; } else if (!ignore_text) { result = javascript; javascript = false; TextParsed (location, location.PlainText); } else { ignore_text = false; result = true; } return result; }
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; }
TagAttributes GetAttributes() { int token; TagAttributes attributes; string id; bool wellFormedForServer = true; attributes = new TagAttributes(); while ((token = tokenizer.get_token()) != Token.EOF) { if (token == '<' && Eat('%')) { tokenizer.Verbatim = true; attributes.Add(String.Empty, "<%" + GetVerbatim(tokenizer.get_token(), "%>") + "%>"); tokenizer.Verbatim = false; tokenizer.InTag = true; continue; } if (token != Token.IDENTIFIER) { break; } id = tokenizer.Value; if (Eat('=')) { if (Eat(Token.ATTVALUE)) { attributes.Add(id, tokenizer.Value); wellFormedForServer &= tokenizer.AlternatingQuotes; } else if (Eat('<') && Eat('%')) { tokenizer.Verbatim = true; attributes.Add(id, "<%" + GetVerbatim(tokenizer.get_token(), "%>") + "%>"); tokenizer.Verbatim = false; tokenizer.InTag = true; } else { OnError("expected ATTVALUE"); return(null); } } else { attributes.Add(id, null); } } tokenizer.put_back(); if (attributes.IsRunAtServer() && !wellFormedForServer) { OnError("The server tag is not well formed."); return(null); } return(attributes); }
TagAttributes GetAttributes () { int token; TagAttributes attributes; string id; bool wellFormedForServer = true; attributes = new TagAttributes (); while ((token = tokenizer.get_token ()) != Token.EOF){ if (token == '<' && Eat ('%')) { tokenizer.Verbatim = true; attributes.Add (String.Empty, "<%" + GetVerbatim (tokenizer.get_token (), "%>") + "%>"); tokenizer.Verbatim = false; tokenizer.InTag = true; continue; } if (token != Token.IDENTIFIER) break; id = tokenizer.Value; if (Eat ('=')){ if (Eat (Token.ATTVALUE)){ attributes.Add (id, tokenizer.Value); wellFormedForServer &= tokenizer.AlternatingQuotes; } else if (Eat ('<') && Eat ('%')) { tokenizer.Verbatim = true; attributes.Add (id, "<%" + GetVerbatim (tokenizer.get_token (), "%>") + "%>"); tokenizer.Verbatim = false; tokenizer.InTag = true; } else { OnError ("expected ATTVALUE"); return null; } } else { attributes.Add (id, null); } } tokenizer.put_back (); if (attributes.IsRunAtServer () && !wellFormedForServer) { OnError ("The server tag is not well formed."); return null; } return attributes; }
bool ProcessScript (TagType tagtype, TagAttributes attributes) { if (tagtype != TagType.Close) { if (attributes != null && attributes.IsRunAtServer ()) { CheckLanguage ((string) attributes ["language"]); if (tagtype == TagType.Tag) { Parser.VerbatimID = "script"; inScript = true; } //else if (tagtype == TagType.SelfClosing) // load script file here return true; } else { if (tagtype != TagType.SelfClosing) { Parser.VerbatimID = "script"; javascript = true; } TextParsed (location, location.PlainText); return true; } } bool result; if (inScript) { result = inScript; inScript = false; } else { result = javascript; javascript = false; TextParsed (location, location.PlainText); } return result; }
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; }