Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

320 lines
8.0 KiB

  1. using System;
  2. using System.Globalization;
  3. using System.IO;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.HtmlControls;
  7. using UDDI;
  8. namespace UDDI.Web
  9. {
  10. public class ContextualHelpControl : UserControl
  11. {
  12. private UddiLabel helptext;
  13. protected UddiLabel HelpText
  14. {
  15. get{ return helptext;}
  16. set{ helptext = (UddiLabel)value; }
  17. }
  18. private HelpControl helplink;
  19. protected HelpControl HelpLink
  20. {
  21. get{ return helplink;}
  22. set{ helplink = (HelpControl)value; }
  23. }
  24. private string cssclass;
  25. public string CssClass
  26. {
  27. get{ return cssclass; }
  28. set{ cssclass=value; }
  29. }
  30. private string borderwidth;
  31. public string BorderWidth
  32. {
  33. get{ return borderwidth; }
  34. set{ borderwidth=value; }
  35. }
  36. private string horizontalalign;
  37. public string HorizontalAlign
  38. {
  39. get{ return horizontalalign; }
  40. set{ horizontalalign=value; }
  41. }
  42. private string verticalalign;
  43. public string VertialAlign
  44. {
  45. get{ return verticalalign; }
  46. set{ verticalalign=value; }
  47. }
  48. private string width="100%";
  49. public string Width
  50. {
  51. get{ return width; }
  52. set{ width=value; }
  53. }
  54. private string height;
  55. public string Height
  56. {
  57. get{ return height; }
  58. set{ height=value; }
  59. }
  60. private string text;
  61. public string Text
  62. {
  63. get{ return text; }
  64. set{ text=value; }
  65. }
  66. private string helpfile;
  67. public string HelpFile
  68. {
  69. get{ return helpfile; }
  70. set{ helpfile=value; }
  71. }
  72. protected override void OnLoad( EventArgs e )
  73. {
  74. if( null==HelpText )
  75. {
  76. HelpText = new UddiLabel();
  77. Controls.Add( HelpText );
  78. }
  79. if( null==HelpLink )
  80. {
  81. HelpLink = new HelpControl();
  82. Controls.Add( HelpLink );
  83. }
  84. HelpText.Text = Text;
  85. HelpLink.HelpFile = HelpFile;
  86. base.OnLoad( e );
  87. }
  88. protected override void Render( HtmlTextWriter output )
  89. {
  90. output.Write(
  91. "<table " +
  92. "id='" + this.ClientID + "' " +
  93. ((Height==null) ? "" : "height='" + Height + "' " ) +
  94. ((Width==null) ? "" : "width='" + Width + "' " ) +
  95. ((BorderWidth==null) ? "border='0' " : "border='" + BorderWidth + "' " ) +
  96. ((CssClass==null) ? "" : "class='" + CssClass + "' " ) +
  97. ">\r\n"
  98. );
  99. output.Write(
  100. "<tr " +
  101. ">\r\n" +
  102. "<td " +
  103. ((VertialAlign==null) ? "valign='top' " : "valign='" + VertialAlign + "' " )+
  104. ">\r\n"
  105. );
  106. HelpText.RenderControl( output );
  107. output.Write(
  108. "</td>\r\n"+
  109. "<td " +
  110. "width='25' "+
  111. ((HorizontalAlign==null) ? "align='right' " : "align='" + HorizontalAlign + "' " )+
  112. ((VertialAlign==null) ? "valign='top' " : "valign='" + VertialAlign + "' " )+
  113. ">\r\n"
  114. );
  115. HelpLink.RenderControl( output );
  116. output.Write(
  117. "</td>\r\n"+
  118. "</tr>\r\n"+
  119. "</table>\r\n"
  120. );
  121. /*
  122. AddAttribute( output,HtmlTextWriterAttribute.Height, Height, null );
  123. AddAttribute( output,HtmlTextWriterAttribute.Border, BorderWidth, "0" );
  124. AddAttribute( output,HtmlTextWriterAttribute.Class, CssClass, null );
  125. AddAttribute( output,HtmlTextWriterAttribute.Id, ClientID, null );
  126. AddAttribute( output,HtmlTextWriterAttribute.Width, Width,null );
  127. output.RenderBeginTag( HtmlTextWriterTag.Table );
  128. output.RenderBeginTag( HtmlTextWriterTag.Tr );
  129. //Text Row
  130. AddAttribute( output,HtmlTextWriterAttribute.Align, HorizontalAlign,null );
  131. AddAttribute( output,HtmlTextWriterAttribute.Valign, VertialAlign,null );
  132. output.RenderBeginTag( HtmlTextWriterTag.Td );
  133. if( null!=HelpText )
  134. HelpText.RenderControl( output );
  135. output.RenderEndTag();//HtmlTextWriterTag.Td
  136. AddAttribute( output,HtmlTextWriterAttribute.Width, "25",null );
  137. AddAttribute( output,HtmlTextWriterAttribute.Align, HorizontalAlign,null );
  138. AddAttribute( output,HtmlTextWriterAttribute.Valign, VertialAlign,null );
  139. output.RenderBeginTag( HtmlTextWriterTag.Td );
  140. if( null!=HelpLink )
  141. HelpLink.RenderControl( output );
  142. output.RenderEndTag();//HtmlTextWriterTag.Td
  143. output.RenderEndTag();//HtmlTextWriterTag.Tr
  144. output.RenderEndTag();//HtmlTextWriterTag.Table
  145. */
  146. }
  147. protected void AddAttribute( HtmlTextWriter output, HtmlTextWriterAttribute name, string val, string defaultvalue )
  148. {
  149. if( null!=val )
  150. {
  151. output.AddAttribute( name, val );
  152. }
  153. else if( null!=defaultvalue )
  154. {
  155. output.AddAttribute( name, val );
  156. }
  157. }
  158. }
  159. public class HelpControl : UserControl
  160. {
  161. protected string helpFile;
  162. protected string root;
  163. public string HelpFile
  164. {
  165. get { return helpFile; }
  166. set { helpFile = value; }
  167. }
  168. protected override void OnInit( EventArgs e )
  169. {
  170. if( "/" == Request.ApplicationPath )
  171. root = "";
  172. else
  173. root = Request.ApplicationPath;
  174. }
  175. protected override void CreateChildControls()
  176. {
  177. CultureInfo culture = UDDI.Localization.GetCulture();
  178. string isoLangCode = culture.LCID.ToString();
  179. string file = "/help/" + isoLangCode + "/" + HelpFile + ".aspx";
  180. string defaultlang = Config.GetString( "Setup.WebServer.ProductLanguage","en" );
  181. int lcid = 1033;
  182. //
  183. // 'cultureIDValue is expected to contain a neutral culture. ie,
  184. // 'en', or 'ko', or 'de'. All but a few neutral cultures have
  185. // a default specific culture. For example, the default specific
  186. // culture of 'en' is 'en-US'.
  187. //
  188. // Traditional & simplified Chinese (zh-CHT and zh-CHS respectively)
  189. // are examples of neutral cultures which have no default specific
  190. // culture!
  191. //
  192. // So what happens below is this: First we try to lookup the default
  193. // specific culture for the neutral culture that we were given. If that
  194. // fails (ie, if CreateSpecificCulture throws), we just get the lcid
  195. // of the neutral culture.
  196. //
  197. try
  198. {
  199. lcid = CultureInfo.CreateSpecificCulture( defaultlang ).LCID;
  200. }
  201. catch
  202. {
  203. CultureInfo ci = new CultureInfo( defaultlang );
  204. lcid = ci.LCID;
  205. }
  206. if( !File.Exists( Server.MapPath( root + file ) ) )
  207. file = "/help/" + lcid.ToString() + "/" + HelpFile + ".aspx";
  208. file = HyperLinkManager.GetNonSecureHyperLink( file );
  209. HtmlAnchor anchor = new HtmlAnchor();
  210. if( ((UddiPage)Page).IsIE4 || ((UddiPage)Page).IsIE5 || ((UddiPage)Page).IsNetscape6 )
  211. {
  212. //
  213. // Standards recommend pointer, but IE4 used hand.
  214. //
  215. if( ((UddiPage)Page).IsIE4 )
  216. anchor.Style.Add( "cursor", "hand" );
  217. else
  218. anchor.Style.Add( "cursor", "pointer" );
  219. anchor.Attributes.Add( "onclick", "ShowHelp( '" + file + "' )" );
  220. anchor.HRef = "";
  221. }
  222. else
  223. {
  224. anchor.HRef = file;
  225. }
  226. anchor.Target = "help";
  227. anchor.InnerHtml = "<img src='" + root + "/images/help.gif' border='0'>";
  228. Controls.Add( anchor );
  229. }
  230. }
  231. public class ContentController : System.Web.UI.WebControls.PlaceHolder
  232. {
  233. private ServiceModeType mode;
  234. public ServiceModeType Mode
  235. {
  236. get{ return mode; }
  237. set{ mode=(ServiceModeType)value; }
  238. }
  239. private RoleType requiredaccesslevel = RoleType.Anonymous;
  240. public RoleType RequiredAccessLevel
  241. {
  242. get{ return requiredaccesslevel; }
  243. set{ requiredaccesslevel=(RoleType)value; }
  244. }
  245. protected internal ServiceModeType currentMode;
  246. protected override void Render( HtmlTextWriter output )
  247. {
  248. if( currentMode==Mode && (int)UDDI.Context.User.Role>=(int)RequiredAccessLevel )
  249. {
  250. base.Render( output );
  251. }
  252. }
  253. protected override void OnLoad( EventArgs e )
  254. {
  255. currentMode = (ServiceModeType)Config.GetInt( "Web.ServiceMode", (int)ServiceModeType.Private );
  256. base.OnLoad( e );
  257. }
  258. }
  259. public enum ServiceModeType
  260. {
  261. Private = 0x00,
  262. Public = 0x01
  263. }
  264. }