1
/****************************************************************************
3
| Copyright (c) [2007] Novell, Inc.
6
| This program is free software; you can redistribute it and/or
7
| modify it under the terms of version 2 of the GNU General Public License as
8
| published by the Free Software Foundation.
10
| This program is distributed in the hope that it will be useful,
11
| but WITHOUT ANY WARRANTY; without even the implied warranty of
12
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
| GNU General Public License for more details.
15
| You should have received a copy of the GNU General Public License
16
| along with this program; if not, contact Novell, Inc.
18
| To contact Novell about this file by physical or electronic mail,
19
| you may find current contact information at www.novell.com
21
| Author: Mike Lasky (mlasky@novell.com)
22
|***************************************************************************/
26
namespace Novell.iFolderWeb.Admin
29
using System.Collections;
33
using System.Resources;
35
using System.Web.Services.Protocols;
37
using System.Web.UI.WebControls;
38
using System.Web.UI.HtmlControls;
42
///Summary description for TopNavigation.
44
public class TopNavigation : System.Web.UI.UserControl
49
/// Enumeration of page tabs.
82
private ResourceManager rm;
88
protected HtmlAnchor UserLink;
93
protected HtmlAnchor iFolderLink;
98
protected HtmlAnchor ServerLink;
103
protected HtmlAnchor SystemLink;
108
protected HtmlAnchor ReportsLink;
112
/// Error panel control.
114
protected HtmlGenericControl ErrorPanel;
117
/// Error message control.
119
protected Label ErrorMsg;
122
/// Message panel control.
124
protected HtmlGenericControl MessagePanel;
127
/// Error message control.
129
protected Label InfoMsg;
132
/// Breadcrumb control.
134
protected DataList BreadCrumbs;
137
/// Footer control panel
139
protected Footer footer;
146
/// Gets or sets the bread crumb list.
148
private ArrayList CrumbList
150
get { return ViewState[ "BreadCrumbs" ] as ArrayList; }
151
set { ViewState[ "BreadCrumbs" ] = value; }
156
#region Private Methods
159
/// Creates a data source of breadcrumbs.
161
/// <returns>A DataView item containing breadcrumbs</returns>
162
private DataView CreateDataSource()
164
DataTable dt = new DataTable();
167
dt.Columns.Add( new DataColumn( "CrumbField", typeof( string ) ) );
168
dt.Columns.Add( new DataColumn( "LinkField", typeof( string ) ) );
170
foreach( BreadCrumbInfo bci in CrumbList )
174
dr[ 1 ] = bci.CrumbUri;
178
// Build the data view from the table.
179
return new DataView( dt );
185
/// <param name="sender"></param>
186
/// <param name="e"></param>
187
private void Page_Load(object sender, System.EventArgs e)
190
rm = Application[ "RM" ] as ResourceManager;
192
// Hide the error panel if previously visible.
193
if ( ErrorPanel.Visible )
195
ErrorPanel.Visible = false;
198
if ( MessagePanel.Visible )
200
ErrorPanel.Visible = false;
205
// Initially hide the error panel.
206
ErrorPanel.Visible = false;
207
MessagePanel.Visible = false;
209
Control body = Page.FindControl( "users" );
212
UserLink.HRef = null;
213
iFolderLink.HRef = "iFolders.aspx";
214
ServerLink.HRef = "Servers.aspx";
215
SystemLink.HRef = "SystemInfo.aspx";
216
ReportsLink.HRef = "Reports.aspx";
220
body = Page.FindControl( "ifolders" );
223
UserLink.HRef = "Users.aspx";
224
iFolderLink.HRef = null;
225
ServerLink.HRef = "Servers.aspx";
226
SystemLink.HRef = "SystemInfo.aspx";
227
ReportsLink.HRef = "Reports.aspx";
231
body = Page.FindControl( "system" );
234
UserLink.HRef = "Users.aspx";
235
iFolderLink.HRef = "iFolders.aspx";
236
ServerLink.HRef = "Servers.aspx";
237
SystemLink.HRef = null;
238
ReportsLink.HRef = "Reports.aspx";
242
body = Page.FindControl( "server" );
245
UserLink.HRef = "Users.aspx";
246
iFolderLink.HRef = "iFolders.aspx";
247
ServerLink.HRef = null;
248
SystemLink.HRef = "SystemInfo.aspx";
249
ReportsLink.HRef = "Reports.aspx";
254
body = Page.FindControl( "report" );
257
UserLink.HRef = "Users.aspx";
258
iFolderLink.HRef = "iFolders.aspx";
259
ServerLink.HRef = "Servers.aspx";
260
SystemLink.HRef = "SystemInfo.aspx";
261
ReportsLink.HRef = null;
265
UserLink.HRef = "Users.aspx";
266
iFolderLink.HRef = "iFolders.aspx";
267
ServerLink.HRef = "Servers.aspx";
268
SystemLink.HRef = "SystemInfo.aspx";
269
ReportsLink.HRef = "Reports.aspx";
276
// Initialize the state variables.
277
BreadCrumbs.RepeatColumns = 0;
278
CrumbList = new ArrayList();
284
#region Protected Methods
287
/// Get a Localized String
289
/// <param name="key">Key to the localized string.</param>
290
/// <returns>Localized string.</returns>
291
protected string GetString( string key )
293
return rm.GetString( key );
298
#region Public Methods
301
/// Adds a bread crumb to the bread crumb list.
303
/// <param name="crumb"></param>
304
/// <param name="link"></param>
305
public void AddBreadCrumb( string crumb, string link )
307
if ( crumb.Length > 128 )
309
crumb = crumb.Substring( 0, 128 );
312
CrumbList.Add( new BreadCrumbInfo( crumb, link ) );
313
++BreadCrumbs.RepeatColumns;
314
BreadCrumbs.DataSource = CreateDataSource();
315
BreadCrumbs.DataBind();
319
/// Adds a bread crumb to the bread crumb list.
321
/// <param name="crumbs"></param>
322
/// <param name="links"></param>
323
public void AddBreadCrumb( string[] crumbs, string[] links )
325
for ( int i = 0; i < crumbs.Length; ++i )
327
AddBreadCrumb( crumbs[ i ], links[ i ] );
333
/// Gets the exception message from the Exception object.
335
/// <param name="e"></param>
336
/// <returns></returns>
337
public string ExceptionMessage( Exception e )
339
string type = GetExceptionType( e );
343
case "AuthorizationException":
344
return GetString( "ERRORNOTADMINISTRATOR" );
346
case "AuthenticationException":
347
return GetString( "ERRORAUTHENTICATIONFAILED" );
349
case "iFolderDoesNotExistException":
350
return GetString( "ERRORIFOLDERDOESNOTEXIST" );
352
case "MemberDoesNotExistException":
353
return GetString( "ERRORMEMBERDOESNOTEXIST" );
355
case "UserDoesNotExistException":
356
return GetString( "ERRORUSERDOESNOTEXIST" );
358
case "LockException":
359
return GetString( "ERRORLOCKEXCEPTION" );
361
case "AccessException":
362
return GetString( "ERRORACCESSEXCEPTION" );
364
case "ArgumentException":
373
/// Gets the exception type from the specified exception.
375
/// <param name="e"></param>
376
/// <returns></returns>
377
public static string GetExceptionType( Exception e )
379
string type = e.GetType().Name;
382
if ( e is SoapException )
386
XmlNode node = ( e as SoapException ).Detail.SelectSingleNode( "OriginalException" );
389
// try inside the <detail> tags
390
node = ( e as SoapException ).Detail.SelectSingleNode( "*/OriginalException" );
395
type = node.Attributes.GetNamedItem( "type" ).Value;
396
type = type.Substring( type.LastIndexOf( "." ) + 1 );
401
else if ( e is WebException )
403
type = (e as WebException ).Status.ToString();
405
if ( ( e as WebException ).Status == WebExceptionStatus.ProtocolError )
407
HttpWebResponse response = ( e as WebException ).Response as HttpWebResponse;
408
type = response.StatusDescription;
416
/// Sets the active page tab for utility pages that are used by multiple root pages.
418
/// <param name="page"></param>
419
public void SetActivePageTab( PageTabs page )
425
case PageTabs.iFolders:
426
body = Page.FindControl( "ifolders" );
429
UserLink.HRef = "Users.aspx";
430
iFolderLink.HRef = null;
431
ServerLink.HRef = "Servers.aspx";
432
SystemLink.HRef = "SystemInfo.aspx";
433
ReportsLink.HRef = "Reports.aspx";
437
case PageTabs.Servers:
438
body = Page.FindControl( "servers" );
441
UserLink.HRef = "Users.aspx";
442
iFolderLink.HRef = "iFolders.aspx";
443
ServerLink.HRef = null;
444
SystemLink.HRef = "SystemInfo.aspx";
445
ReportsLink.HRef = "Reports.aspx";
449
case PageTabs.System:
450
body = Page.FindControl( "system" );
453
UserLink.HRef = "Users.aspx";
454
iFolderLink.HRef = "iFolders.aspx";
455
ServerLink.HRef = "Servers.aspx";
456
SystemLink.HRef = null;
457
ReportsLink.HRef = "Reports.aspx";
462
body = Page.FindControl( "users" );
465
UserLink.HRef = null;
466
iFolderLink.HRef = "iFolders.aspx";
467
ServerLink.HRef = "Servers.aspx";
468
SystemLink.HRef = "SystemInfo.aspx";
469
ReportsLink.HRef = "Reports.aspx";
473
case PageTabs.Reports:
474
body = Page.FindControl( "reports" );
477
UserLink.HRef = "Users.aspx";
478
iFolderLink.HRef = "iFolders.aspx";
479
ServerLink.HRef = "Servers.aspx";
480
SystemLink.HRef = "SystemInfo.aspx";
481
ReportsLink.HRef = null;
488
/// Shows up an error below the banner.
490
/// <param name="msg"></param>
491
public void ShowInfo( string msg )
493
InfoMsg.Text = String.Format( msg );
494
MessagePanel.Visible = true;
498
/// Shows up an error below the banner.
500
/// <param name="msg"></param>
501
public void ShowError( string msg )
503
ErrorMsg.Text = String.Format( GetString( "ERRORTEMPLATE" ), msg );
504
ErrorPanel.Visible = true;
508
/// Shows up an error below the banner.
510
/// <param name="ex"></param>
511
public void ShowError( Exception ex )
513
ShowError( ExceptionMessage( ex ) );
517
/// Shows up an error below the banner.
519
/// <param name="msg"></param>
520
/// <param name="ex"></param>
521
public void ShowError( string msg, Exception ex )
523
ShowError( String.Format( "{0} {1}", msg, ExceptionMessage( ex ) ) );
527
/// Determines whether to show exception detail based on the type of exception.
529
/// <param name="e"></param>
530
/// <returns></returns>
531
public bool ShowExceptionDetail( Exception e )
533
switch ( GetExceptionType( e ) )
535
case "AuthorizationException":
536
case "AuthenticationException":
537
case "iFolderDoesNotExistException":
538
case "MemberDoesNotExistException":
539
case "UserDoesNotExistException":
540
case "LockException":
541
case "AccessException":
542
case "ArgumentException":
550
public void AddHelpLink(string PageName)
552
//string code = Session["language"] as string;
553
// Pass this page information to create the help link
554
footer.AddHelpLink(PageName);
559
#region Web Form Designer generated code
564
/// <param name="e"></param>
565
override protected void OnInit(EventArgs e)
568
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
570
InitializeComponent();
575
/// Required method for Designer support - do not modify
576
/// the contents of this method with the code editor.
578
/// this.Load += new System.EventHandler(this.Page_Load);
579
private void InitializeComponent()
581
this.Load += new System.EventHandler(this.Page_Load);
586
#region BreadCrumbInfo
589
/// Contains bread crumb information.
592
private class BreadCrumbInfo
594
#region Class Members
597
/// The bread crumb label.
602
/// The uri associated with the crumb.
604
public string CrumbUri;
613
/// <param name="crumb"></param>
614
/// <param name="crumbUri"></param>
615
public BreadCrumbInfo( string crumb, string crumbUri )