5 // Igor Zelmanovich <igorz@mainsoft.com>
7 // (C) 2007 Mainsoft, Inc. http://www.mainsoft.com
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections.Generic;
32 using System.ComponentModel;
33 using System.Reflection;
35 using System.Threading;
36 using System.Web.Handlers;
37 using System.Web.UI.WebControls;
39 namespace System.Web.UI
41 [DefaultProperty ("Path")]
42 public class ScriptReference : ScriptReferenceBase
46 bool _ignoreScriptPath;
48 public ScriptReference ()
52 public ScriptReference (string path)
57 public ScriptReference (string name, string assembly)
63 public string Assembly {
72 public bool IgnoreScriptPath {
74 return _ignoreScriptPath;
77 _ignoreScriptPath = value;
83 return _name != null ? _name : String.Empty;
90 internal ScriptMode ScriptModeInternal {
92 if (ScriptMode == ScriptMode.Auto) {
93 if (!String.IsNullOrEmpty (Name))
94 return ScriptMode.Inherit;
96 return ScriptMode.Release;
103 [MonoTODO ("Compression not supported yet.")]
104 protected internal override string GetUrl (ScriptManager scriptManager, bool zip)
106 bool isDebugMode = scriptManager.IsDeploymentRetail ? false :
107 (ScriptModeInternal == ScriptMode.Inherit ? scriptManager.IsDebuggingEnabled : (ScriptModeInternal == ScriptMode.Debug));
109 string url = String.Empty;
111 if (!String.IsNullOrEmpty (path)) {
112 url = GetScriptName (path, isDebugMode, scriptManager.EnableScriptLocalization ? ResourceUICultures : null);
113 } else if (!String.IsNullOrEmpty (Name)) {
115 string assemblyName = this.Assembly;
117 if (String.IsNullOrEmpty (assemblyName))
118 assembly = typeof (ScriptManager).Assembly;
120 assembly = global::System.Reflection.Assembly.Load (assemblyName);
121 string name = GetScriptName (Name, isDebugMode, null);
122 string scriptPath = scriptManager.ScriptPath;
123 if (IgnoreScriptPath || String.IsNullOrEmpty (scriptPath))
124 url = ScriptResourceHandler.GetResourceUrl (assembly, name, NotifyScriptLoaded);
126 AssemblyName an = assembly.GetName ();
127 url = scriptManager.ResolveClientUrl (String.Concat (VirtualPathUtility.AppendTrailingSlash (scriptPath), an.Name, '/', an.Version, '/', name));
130 throw new InvalidOperationException ("Name and Path cannot both be empty.");
136 static string GetScriptName (string releaseName, bool isDebugMode, string [] supportedUICultures) {
137 if (!isDebugMode && (supportedUICultures == null || supportedUICultures.Length == 0))
140 if (releaseName.Length < 3 || !releaseName.EndsWith (".js", StringComparison.OrdinalIgnoreCase))
141 throw new InvalidOperationException (String.Format ("'{0}' is not a valid script path. The path must end in '.js'.", releaseName));
143 StringBuilder sb = new StringBuilder (releaseName);
146 sb.Append (".debug");
147 string culture = Thread.CurrentThread.CurrentUICulture.Name;
148 if (supportedUICultures != null && Array.IndexOf<string> (supportedUICultures, culture) >= 0)
149 sb.AppendFormat (".{0}", culture);
152 return sb.ToString ();
155 protected internal override bool IsFromSystemWebExtensions ()
160 public override string ToString ()
162 return Name.Length > 0 ? Name : Path;