Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.Web / UI / BaseParser.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="BaseParser.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 //------------------------------------------------------------------------------
6
7 /*
8  * Implements the ASP.NET template parser
9  *
10  * Copyright (c) 1998 Microsoft Corporation
11  */
12
13 /*********************************
14
15 Class hierarchy
16
17 BaseParser
18     DependencyParser
19         TemplateControlDependencyParser
20             PageDependencyParser
21             UserControlDependencyParser
22             MasterPageDependencyParser
23     TemplateParser
24         BaseTemplateParser
25             TemplateControlParser
26                 PageParser
27                 UserControlParser
28                     MasterPageParser
29             PageThemeParser
30         ApplicationFileParser
31
32 **********************************/
33
34 namespace System.Web.UI {
35 using System;
36 using System.Collections;
37 using System.Reflection;
38 using System.Web.Compilation;
39 using System.Web.Hosting;
40 using System.Web.Util;
41 using System.Text.RegularExpressions;
42 using System.Web.RegularExpressions;
43 using System.Security.Permissions;
44
45 // Internal interface for Parser that have exteranl assembly dependency.
46 internal interface IAssemblyDependencyParser {
47     ICollection AssemblyDependencies { get; }
48 }
49
50
51 /// <devdoc>
52 ///    <para>[To be supplied.]</para>
53 /// </devdoc>
54 public class BaseParser {
55
56     // The directory used for relative path calculations
57     private VirtualPath _baseVirtualDir;
58     internal VirtualPath BaseVirtualDir {
59         get { return _baseVirtualDir; }
60
61     }
62
63     // The virtual path to the file currently being processed
64     private VirtualPath _currentVirtualPath;
65     internal VirtualPath CurrentVirtualPath {
66         get { return _currentVirtualPath; }
67         set {
68             _currentVirtualPath = value;
69
70             // Can happen in the designer
71             if (value == null) return;
72
73             _baseVirtualDir = value.Parent;
74         }
75     }
76
77     internal string CurrentVirtualPathString {
78         get { return System.Web.VirtualPath.GetVirtualPathString(CurrentVirtualPath); }
79     }
80
81     private Regex _tagRegex;
82     // The 3.5 regex is used only when targeting 2.0/3.5 for backward compatibility (Dev10 bug 830783).
83     private readonly static Regex tagRegex35 = new TagRegex35();
84     // The 4.0 regex is used for web sites targeting 4.0 and above. 
85     private readonly static Regex tagRegex40 = new TagRegex();
86
87     internal readonly static Regex directiveRegex = new DirectiveRegex();
88     internal readonly static Regex endtagRegex = new EndTagRegex();
89     internal readonly static Regex aspCodeRegex = new AspCodeRegex();
90     internal readonly static Regex aspExprRegex = new AspExprRegex();
91     internal readonly static Regex aspEncodedExprRegex = new AspEncodedExprRegex();
92     internal readonly static Regex databindExprRegex = new DatabindExprRegex();
93     internal readonly static Regex commentRegex = new CommentRegex();
94     internal readonly static Regex includeRegex = new IncludeRegex();
95     internal readonly static Regex textRegex = new TextRegex();
96
97     // Regexes used in DetectSpecialServerTagError
98     internal readonly static Regex gtRegex = new GTRegex();
99     internal readonly static Regex ltRegex = new LTRegex();
100     internal readonly static Regex serverTagsRegex = new ServerTagsRegex();
101     internal readonly static Regex runatServerRegex = new RunatServerRegex();
102
103     /*
104      * Turns relative virtual path into absolute ones
105      */
106     internal VirtualPath ResolveVirtualPath(VirtualPath virtualPath) {
107         return VirtualPathProvider.CombineVirtualPathsInternal(CurrentVirtualPath, virtualPath);
108     }
109
110     private bool IsVersion40OrAbove() {
111         if (HostingEnvironment.IsHosted) {
112             // If we are running in a hosted environment, then we can simply check the target version.
113             return MultiTargetingUtil.IsTargetFramework40OrAbove;
114         }
115         else {
116             // Otherwise, we are in the designer, and thus should check using the type description provider.
117             // The new type TagRegex35 only exists when targeting 4.0 and above.
118             return TargetFrameworkUtil.IsSupportedType(typeof(TagRegex35));
119         }
120     }
121
122     internal Regex TagRegex {
123         get {
124             if (_tagRegex == null) {
125                 _tagRegex = IsVersion40OrAbove() ? tagRegex40 : tagRegex35;
126             }
127             return _tagRegex;
128         }
129     }
130 }
131
132
133 }