internal void ProcessUserControlRegistration(UserControlRegisterEntry ucRegisterEntry) { Type type = null; if (_parser.FInDesigner) { // Get the designer to load the appropriate type type = _parser.GetDesignTimeUserControlType(ucRegisterEntry.TagPrefix, ucRegisterEntry.TagName); } else { // Compile it into a Type type = _parser.GetUserControlType(ucRegisterEntry.UserControlSource.VirtualPathString); } if (type == null) { return; } if (_userControlRegisterEntries == null) { _userControlRegisterEntries = new Hashtable(); } _userControlRegisterEntries[ucRegisterEntry.TagPrefix + ":" + ucRegisterEntry.TagName] = ucRegisterEntry; // Register the new tag, including its prefix RegisterTag(ucRegisterEntry.TagPrefix + ":" + ucRegisterEntry.TagName, type); }
private bool TryUserControlRegisterDirectives(string tagName) { if (this._userControlRegisterEntries == null) { return(false); } UserControlRegisterEntry ucRegisterEntry = (UserControlRegisterEntry)this._userControlRegisterEntries[tagName]; if (ucRegisterEntry == null) { return(false); } if (ucRegisterEntry.ComesFromConfig && (ucRegisterEntry.UserControlSource.Parent == this._parser.BaseVirtualDir)) { throw new HttpException(System.Web.SR.GetString("Invalid_use_of_config_uc", new object[] { this._parser.CurrentVirtualPath, ucRegisterEntry.UserControlSource })); } try { this.ProcessUserControlRegistration(ucRegisterEntry); } catch (Exception exception) { throw new HttpParseException(exception.Message, exception, ucRegisterEntry.VirtualPath, null, ucRegisterEntry.Line); } return(true); }
internal override void ProcessDirective(string directiveName, IDictionary directive) { if (StringUtil.EqualsIgnoreCase(directiveName, "register")) { RegisterDirectiveEntry entry; string tagPrefix = System.Web.UI.Util.GetAndRemoveNonEmptyIdentifierAttribute(directive, "tagprefix", true); string tagName = System.Web.UI.Util.GetAndRemoveNonEmptyIdentifierAttribute(directive, "tagname", false); VirtualPath path = System.Web.UI.Util.GetAndRemoveVirtualPathAttribute(directive, "src", false); string namespaceName = System.Web.UI.Util.GetAndRemoveNonEmptyNoSpaceAttribute(directive, "namespace", false); string assemblyName = System.Web.UI.Util.GetAndRemoveNonEmptyAttribute(directive, "assembly", false); if (tagName != null) { if (path == null) { throw new HttpException(System.Web.SR.GetString("Missing_attr", new object[] { "src" })); } if (namespaceName != null) { throw new HttpException(System.Web.SR.GetString("Invalid_attr", new object[] { "namespace", "tagname" })); } if (assemblyName != null) { throw new HttpException(System.Web.SR.GetString("Invalid_attr", new object[] { "assembly", "tagname" })); } UserControlRegisterEntry ucRegisterEntry = new UserControlRegisterEntry(tagPrefix, tagName) { UserControlSource = path }; entry = ucRegisterEntry; base.TypeMapper.ProcessUserControlRegistration(ucRegisterEntry); } else { if (path != null) { throw new HttpException(System.Web.SR.GetString("Missing_attr", new object[] { "tagname" })); } if (namespaceName == null) { throw new HttpException(System.Web.SR.GetString("Missing_attr", new object[] { "namespace" })); } TagNamespaceRegisterEntry nsRegisterEntry = new TagNamespaceRegisterEntry(tagPrefix, namespaceName, assemblyName); entry = nsRegisterEntry; base.TypeMapper.ProcessTagNamespaceRegistration(nsRegisterEntry); } entry.Line = base._lineNumber; entry.VirtualPath = base.CurrentVirtualPathString; System.Web.UI.Util.CheckUnknownDirectiveAttributes(directiveName, directive); } else { base.ProcessDirective(directiveName, directive); } }
private Type GetControlType2(string tagName, IDictionary attribs, bool fAllowHtmlTags) { if (this._mappedTags != null) { Type type = (Type)this._mappedTags[tagName]; if ((type == null) && this.TryUserControlRegisterDirectives(tagName)) { type = (Type)this._mappedTags[tagName]; } if (type != null) { if (((this._parser != null) && (this._parser._pageParserFilter != null)) && (this._parser._pageParserFilter.GetNoCompileUserControlType() == type)) { UserControlRegisterEntry entry = (UserControlRegisterEntry)this._userControlRegisterEntries[tagName]; attribs["virtualpath"] = entry.UserControlSource; } return(type); } } int index = tagName.IndexOf(':'); if (index >= 0) { if (index == (tagName.Length - 1)) { return(null); } string prefix = tagName.Substring(0, index); tagName = tagName.Substring(index + 1); ITagNameToTypeMapper mapper = null; if (this._prefixedMappers != null) { mapper = (ITagNameToTypeMapper)this._prefixedMappers[prefix]; } if (((mapper == null) && this.TryNamespaceRegisterDirectives(prefix)) && (this._prefixedMappers != null)) { mapper = (ITagNameToTypeMapper)this._prefixedMappers[prefix]; } if (mapper == null) { return(null); } return(mapper.GetControlType(tagName, attribs)); } if (fAllowHtmlTags) { return(this._htmlMapper.GetControlType(tagName, attribs)); } return(null); }
/* * Check if the tagName can be handled by a user control register directive. * If so, process the directive and return true. */ private bool TryUserControlRegisterDirectives(string tagName) { if (_userControlRegisterEntries == null) { return(false); } // Is there a registered user control for this tag UserControlRegisterEntry ucRegisterEntry = (UserControlRegisterEntry) _userControlRegisterEntries[tagName]; if (ucRegisterEntry == null) { return(false); } // Don't allow a config registered user control to be used by a // page that lives in the same directory, to avoid circular references. // More specifically, this would break batching because our simple dependency // parser would not be able to detect the *implicit* dependency triggered // by the presence of a tag (VSWhidbey 165042). if (ucRegisterEntry.ComesFromConfig) { VirtualPath ucDirectory = ucRegisterEntry.UserControlSource.Parent; if (ucDirectory == _parser.BaseVirtualDir) { throw new HttpException( SR.GetString(SR.Invalid_use_of_config_uc, _parser.CurrentVirtualPath, ucRegisterEntry.UserControlSource)); } } try { ProcessUserControlRegistration(ucRegisterEntry); } catch (Exception e) { // Make sure we throw the exception with the correct file/line info throw new HttpParseException(e.Message, e, ucRegisterEntry.VirtualPath, null, ucRegisterEntry.Line); } return(true); }
internal void ProcessUserControlRegistration(UserControlRegisterEntry ucRegisterEntry) { Type designTimeUserControlType = null; if (this._parser.FInDesigner) { designTimeUserControlType = this._parser.GetDesignTimeUserControlType(ucRegisterEntry.TagPrefix, ucRegisterEntry.TagName); } else { designTimeUserControlType = this._parser.GetUserControlType(ucRegisterEntry.UserControlSource.VirtualPathString); } if (designTimeUserControlType != null) { if (this._userControlRegisterEntries == null) { this._userControlRegisterEntries = new Hashtable(); } this._userControlRegisterEntries[ucRegisterEntry.TagPrefix + ":" + ucRegisterEntry.TagName] = ucRegisterEntry; this.RegisterTag(ucRegisterEntry.TagPrefix + ":" + ucRegisterEntry.TagName, designTimeUserControlType); } }
internal void FillInRegisterEntries() { TagNamespaceRegisterEntryTable table = new TagNamespaceRegisterEntryTable(); foreach (TagNamespaceRegisterEntry entry in DefaultTagNamespaceRegisterEntries) { table[entry.TagPrefix] = new ArrayList(new object[] { entry }); } Hashtable hashtable = new Hashtable(StringComparer.OrdinalIgnoreCase); foreach (TagPrefixInfo info in this.Controls) { if (!string.IsNullOrEmpty(info.TagName)) { UserControlRegisterEntry entry2 = new UserControlRegisterEntry(info.TagPrefix, info.TagName) { ComesFromConfig = true }; try { entry2.UserControlSource = VirtualPath.CreateNonRelative(info.Source); } catch (Exception exception) { throw new ConfigurationErrorsException(exception.Message, exception, info.ElementInformation.Properties["src"].Source, info.ElementInformation.Properties["src"].LineNumber); } hashtable[entry2.Key] = entry2; } else if (!string.IsNullOrEmpty(info.Namespace)) { TagNamespaceRegisterEntry entry3 = new TagNamespaceRegisterEntry(info.TagPrefix, info.Namespace, info.Assembly); ArrayList list = null; list = (ArrayList) table[info.TagPrefix]; if (list == null) { list = new ArrayList(); table[info.TagPrefix] = list; } list.Add(entry3); } } this._tagNamespaceRegisterEntries = table; this._userControlRegisterEntries = hashtable; }
internal void ProcessUserControlRegistration(UserControlRegisterEntry ucRegisterEntry) { Type type = null; if (_parser.FInDesigner) { // Get the designer to load the appropriate type type = _parser.GetDesignTimeUserControlType(ucRegisterEntry.TagPrefix, ucRegisterEntry.TagName); } else { // Compile it into a Type type = _parser.GetUserControlType(ucRegisterEntry.UserControlSource.VirtualPathString); } if (type == null) return; if (_userControlRegisterEntries == null) { _userControlRegisterEntries = new Hashtable(); } _userControlRegisterEntries[ucRegisterEntry.TagPrefix + ":" + ucRegisterEntry.TagName] = ucRegisterEntry; // Register the new tag, including its prefix RegisterTag(ucRegisterEntry.TagPrefix + ":" + ucRegisterEntry.TagName, type); }
private /*public*/ Type GetControlType2(string tagName, IDictionary attribs, bool fAllowHtmlTags) { Type type; // First, check it the tag name has been mapped if (_mappedTags != null) { type = (Type)_mappedTags[tagName]; if (type == null) { // Maybe there is a register directive that we haven't yet processed if (TryUserControlRegisterDirectives(tagName)) { type = (Type)_mappedTags[tagName]; } } if (type != null) { // If this is the special NoCompile UserControl specified by the PageParserFilter, give it the // virtualPath via the attribute bag if (_parser != null && _parser._pageParserFilter != null && _parser._pageParserFilter.GetNoCompileUserControlType() == type) { UserControlRegisterEntry ucRegisterEntry = (UserControlRegisterEntry)_userControlRegisterEntries[tagName]; attribs["virtualpath"] = ucRegisterEntry.UserControlSource; } return(type); } } // Check if there is a prefix int colonIndex = tagName.IndexOf(':'); if (colonIndex >= 0) { // If ends with : don't try to match (88398) if (colonIndex == tagName.Length - 1) { return(null); } // If so, parse the prefix and tagname string prefix = tagName.Substring(0, colonIndex); tagName = tagName.Substring(colonIndex + 1); // Look for a mapper for the prefix ITagNameToTypeMapper mapper = null; if (_prefixedMappers != null) { mapper = (ITagNameToTypeMapper)_prefixedMappers[prefix]; } if (mapper == null) { // Maybe there is a register directive that we haven't yet processed if (TryNamespaceRegisterDirectives(prefix) && _prefixedMappers != null) { mapper = (ITagNameToTypeMapper)_prefixedMappers[prefix]; } } if (mapper == null) { return(null); } // Try to get the type from the prefix mapper return(mapper.GetControlType(tagName, attribs)); } else { // There is no prefix. // Try the Html mapper if allowed if (fAllowHtmlTags) { return(_htmlMapper.GetControlType(tagName, attribs)); } } return(null); }
internal void FillInRegisterEntries() { // TagNamespaceRegisterEntryTable tagNamespaceRegisterEntries = new TagNamespaceRegisterEntryTable(); foreach (TagNamespaceRegisterEntry entry in DefaultTagNamespaceRegisterEntries) { tagNamespaceRegisterEntries[entry.TagPrefix] = new ArrayList(new object[] { entry }); } Hashtable userControlRegisterEntries = new Hashtable(StringComparer.OrdinalIgnoreCase); // Fill in the collection foreach (TagPrefixInfo tpi in Controls) { if (!String.IsNullOrEmpty(tpi.TagName)) { UserControlRegisterEntry ucRegisterEntry = new UserControlRegisterEntry(tpi.TagPrefix, tpi.TagName); ucRegisterEntry.ComesFromConfig = true; try { ucRegisterEntry.UserControlSource = VirtualPath.CreateNonRelative(tpi.Source); } catch (Exception e) { throw new ConfigurationErrorsException(e.Message, e, tpi.ElementInformation.Properties["src"].Source, tpi.ElementInformation.Properties["src"].LineNumber); } userControlRegisterEntries[ucRegisterEntry.Key] = ucRegisterEntry; } else if (!String.IsNullOrEmpty(tpi.Namespace)) { TagNamespaceRegisterEntry nsRegisterEntry = new TagNamespaceRegisterEntry(tpi.TagPrefix, tpi.Namespace, tpi.Assembly); ArrayList entries = null; entries = (ArrayList)tagNamespaceRegisterEntries[tpi.TagPrefix]; if (entries == null) { entries = new ArrayList(); tagNamespaceRegisterEntries[tpi.TagPrefix] = entries; } entries.Add(nsRegisterEntry); } } _tagNamespaceRegisterEntries = tagNamespaceRegisterEntries; _userControlRegisterEntries = userControlRegisterEntries; }
internal override void ProcessDirective(string directiveName, IDictionary directive) { if (StringUtil.EqualsIgnoreCase(directiveName, "register")) { // Register directive // Get the tagprefix, which is required string tagPrefix = Util.GetAndRemoveNonEmptyIdentifierAttribute(directive, "tagprefix", true /*required*/); string tagName = Util.GetAndRemoveNonEmptyIdentifierAttribute(directive, _tagnameString, false /*required*/); VirtualPath src = Util.GetAndRemoveVirtualPathAttribute(directive, _sourceString, false /*required*/); string ns = Util.GetAndRemoveNonEmptyNoSpaceAttribute(directive, _namespaceString, false /*required*/); // An Assembly can optionally be specified (ASURT 61326/VSWhidbey 87050) string assemblyName = Util.GetAndRemoveNonEmptyAttribute(directive, "assembly", false /*required*/); RegisterDirectiveEntry registerEntry; if (tagName != null) { // It's a user control registration // 'src' is required if (src == null) { throw new HttpException(SR.GetString(SR.Missing_attr, _sourceString)); } // 'namespace' is not allowed if (ns != null) { throw new HttpException( SR.GetString(SR.Invalid_attr, _namespaceString, "tagname")); } // 'assembly' is not allowed if (assemblyName != null) { throw new HttpException( SR.GetString(SR.Invalid_attr, "assembly", "tagname")); } UserControlRegisterEntry ucRegisterEntry = new UserControlRegisterEntry(tagPrefix, tagName); ucRegisterEntry.UserControlSource = src; registerEntry = ucRegisterEntry; TypeMapper.ProcessUserControlRegistration(ucRegisterEntry); } else if (src != null) { // It's missing the tagname attribute. throw new HttpException(SR.GetString(SR.Missing_attr, _tagnameString)); } else { // It's a namespace prefix registration // 'namespace' is required if (ns == null) { throw new HttpException(SR.GetString(SR.Missing_attr, _namespaceString)); } TagNamespaceRegisterEntry nsRegisterEntry = new TagNamespaceRegisterEntry(tagPrefix, ns, assemblyName); registerEntry = nsRegisterEntry; TypeMapper.ProcessTagNamespaceRegistration(nsRegisterEntry); } registerEntry.Line = _lineNumber; registerEntry.VirtualPath = CurrentVirtualPathString; // If there are some attributes left, fail Util.CheckUnknownDirectiveAttributes(directiveName, directive); } else { base.ProcessDirective(directiveName, directive); } }