5 // Igor Zelmanovich <igorz@mainsoft.com>
6 // Marek Habersack <grendel@twistedcode.net>
8 // (C) 2007 Mainsoft, Inc. http://www.mainsoft.com
9 // (C) 2011 Novell, Inc. http://novell.com/
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections.Generic;
33 using System.ComponentModel;
35 using System.Reflection;
36 using System.Resources;
38 using System.Threading;
39 using System.Web.Handlers;
40 using System.Web.UI.WebControls;
42 namespace System.Web.UI
44 [DefaultProperty ("Path")]
45 public class ScriptReference : ScriptReferenceBase
49 bool _ignoreScriptPath;
50 Assembly _resolvedAssembly;
52 public ScriptReference ()
56 public ScriptReference (string path)
61 public ScriptReference (string name, string assembly)
67 public string Assembly {
73 _resolvedAssembly = null;
77 internal Assembly ResolvedAssembly {
79 if (_resolvedAssembly == null) {
80 string assemblyName = this.Assembly;
82 if (String.IsNullOrEmpty (assemblyName))
83 _resolvedAssembly = typeof (ScriptManager).Assembly;
85 _resolvedAssembly = global::System.Reflection.Assembly.Load (assemblyName);
87 return _resolvedAssembly;
91 ScriptMode ScriptModeInternal {
93 if (ScriptMode == ScriptMode.Auto) {
94 if (!String.IsNullOrEmpty (Name))
95 return ScriptMode.Inherit;
97 return ScriptMode.Release;
104 public bool IgnoreScriptPath {
106 return _ignoreScriptPath;
109 _ignoreScriptPath = value;
115 return _name != null ? _name : String.Empty;
122 internal bool IsDebugMode (ScriptManager scriptManager)
124 if (scriptManager == null)
125 return ScriptModeInternal == ScriptMode.Debug;
127 if (scriptManager.IsDeploymentRetail)
130 switch (ScriptModeInternal) {
131 case ScriptMode.Inherit:
132 return scriptManager.IsDebuggingEnabled;
134 case ScriptMode.Debug:
142 [MonoTODO ("Compression not supported yet.")]
143 protected internal override string GetUrl (ScriptManager scriptManager, bool zip)
145 bool isDebugMode = IsDebugMode (scriptManager);
147 string url = String.Empty;
149 WebResourceAttribute wra;
151 // LAMESPEC: Name property takes precedence
152 if (!String.IsNullOrEmpty (name)) {
153 Assembly assembly = ResolvedAssembly;
154 name = GetScriptName (name, isDebugMode, null, assembly, out wra);
155 path = scriptManager.ScriptPath;
156 if (IgnoreScriptPath || String.IsNullOrEmpty (path))
157 url = ScriptResourceHandler.GetResourceUrl (assembly, name, NotifyScriptLoaded);
159 AssemblyName an = assembly.GetName ();
160 url = scriptManager.ResolveClientUrl (String.Concat (VirtualPathUtility.AppendTrailingSlash (path), an.Name, '/', an.Version, '/', name));
162 } else if (!String.IsNullOrEmpty ((path = Path))) {
163 url = GetScriptName (path, isDebugMode, scriptManager.EnableScriptLocalization ? ResourceUICultures : null, null, out wra);
165 throw new InvalidOperationException ("Name and Path cannot both be empty.");
170 protected internal override bool IsAjaxFrameworkScript (ScriptManager scriptManager)
175 [Obsolete ("Use IsAjaxFrameworkScript(ScriptManager)")]
176 protected internal override bool IsFromSystemWebExtensions ()
178 return ResolvedAssembly == ThisAssembly;
181 public override string ToString ()
183 return Name.Length > 0 ? Name : Path;