You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hu...@apache.org on 2005/06/21 13:37:27 UTC
svn commit: r191650 - in /struts/sandbox/trunk/overdrive/Nexus:
Core/Core.csproj Core/Helpers/ViewHelper.cs Core/IKeyValue.cs
Core/IRequestCatalog.cs Core/KeyValue.cs Extras/Spring/Catalog.cs
Web/Web.csproj Web/WebHelper.cs Web/WebViewHelper.cs
Author: husted
Date: Tue Jun 21 04:37:24 2005
New Revision: 191650
URL: http://svn.apache.org/viewcvs?rev=191650&view=rev
Log:
OVR-14
OVR-8
OVR-16
* WebViewHelper: Implement Read/Bind methods of IVHelperInterface
* IRequestCatalog: Add GetHelper method.
* IKeyValue: Add interface and default implementation.
Added:
struts/sandbox/trunk/overdrive/Nexus/Core/IKeyValue.cs
struts/sandbox/trunk/overdrive/Nexus/Core/KeyValue.cs
Removed:
struts/sandbox/trunk/overdrive/Nexus/Web/WebHelper.cs
Modified:
struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj
struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs
struts/sandbox/trunk/overdrive/Nexus/Core/IRequestCatalog.cs
struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/Catalog.cs
struts/sandbox/trunk/overdrive/Nexus/Web/Web.csproj
struts/sandbox/trunk/overdrive/Nexus/Web/WebViewHelper.cs
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj?rev=191650&r1=191649&r2=191650&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Core.csproj Tue Jun 21 04:37:24 2005
@@ -94,6 +94,11 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "IKeyValue.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "IRequestCatalog.cs"
SubType = "Code"
BuildAction = "Compile"
@@ -110,6 +115,11 @@
/>
<File
RelPath = "IRequestContext.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "KeyValue.cs"
SubType = "Code"
BuildAction = "Compile"
/>
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs?rev=191650&r1=191649&r2=191650&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/Helpers/ViewHelper.cs Tue Jun 21 04:37:24 2005
@@ -25,7 +25,7 @@
///
public abstract class ViewHelper : IViewHelper
{
- #region private
+ #region Context
private IRequestContext _Context;
public IRequestContext Context
Added: struts/sandbox/trunk/overdrive/Nexus/Core/IKeyValue.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/IKeyValue.cs?rev=191650&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/IKeyValue.cs (added)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/IKeyValue.cs Tue Jun 21 04:37:24 2005
@@ -0,0 +1,51 @@
+ /*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Nexus.Core
+{
+ /// <summary>
+ /// Generic object to represent a key/value pair,
+ /// as stored in an IDictionary or displayed
+ /// by a list in a user interface.
+ /// </summary>
+ /// <remarks>
+ /// The Text method returns the string form of Value,
+ /// which is useful for text-based controls.
+ /// </remarks>
+ ///
+ public interface IKeyValue
+ {
+ /// <summary>
+ /// The Key property under which the Value is stored.
+ /// </summary>
+ ///
+ string Key { get; set; }
+
+ /// <summary>
+ /// The Value stored for the Key.
+ /// </summary>
+ ///
+ object Value { get; set; }
+
+
+ /// <summary>
+ /// The Value in its standard string format.
+ /// </summary>
+ ///
+ string Text { get; set; }
+
+ }
+}
\ No newline at end of file
Modified: struts/sandbox/trunk/overdrive/Nexus/Core/IRequestCatalog.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/IRequestCatalog.cs?rev=191650&r1=191649&r2=191650&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/IRequestCatalog.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/IRequestCatalog.cs Tue Jun 21 04:37:24 2005
@@ -1,5 +1,3 @@
-using System.Collections;
-using Agility.Core;
/*
* Copyright 2005 The Apache Software Foundation.
*
@@ -15,6 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+using System.Collections;
+using Agility.Core;
+using Nexus.Core.Helpers;
namespace Nexus.Core
{
@@ -26,24 +27,31 @@
public interface IRequestCatalog : ICatalog
{
/// <summary>
+ /// Obtains a IViewHelper for helper ID.
+ /// </summary>
+ /// <param name="name">Our helper ID</param>
+ /// <returns>IViewHelper or null</returns>
+ IViewHelper GetHelper (string name);
+
+ /// <summary>
/// Obtain a IRequestContext for command ID,
/// including embedded resources.
/// </summary>
- /// <param name="command">Our command ID</param>
+ /// <param name="name">Our command ID</param>
/// <returns>IRequestContext with embedded resources.</returns>
///
- IRequestContext GetRequest (string command);
+ IRequestContext GetRequest (string name);
/// <summary>
/// Obtain a IRequestContext for command ID,
/// including embedded resources,
/// and process string-based input.
/// </summary>
- /// <param name="command">Our command ID</param>
+ /// <param name="name">Our command ID</param>
/// <param name="input">Our input values</param>
/// <returns>IRequestContext with embedded resources.</returns>
///
- IRequestContext GetRequest (string command, IDictionary input);
+ IRequestContext GetRequest (string name, IDictionary input);
/// <summary>
/// Obtain a IRequestContext for the command,
@@ -57,10 +65,10 @@
/// <summary>
/// Obtain and execute a IRequestContext.
/// </summary>
- /// <param name="command">Our command ID</param>
+ /// <param name="name">Our command ID</param>
/// <returns>Context after execution</returns>
///
- IRequestContext ExecuteRequest (string command);
+ IRequestContext ExecuteRequest (string name);
/// <summary>
/// Execute a IRequestContext.
Added: struts/sandbox/trunk/overdrive/Nexus/Core/KeyValue.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Core/KeyValue.cs?rev=191650&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Core/KeyValue.cs (added)
+++ struts/sandbox/trunk/overdrive/Nexus/Core/KeyValue.cs Tue Jun 21 04:37:24 2005
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+
+namespace Nexus.Core
+{
+ /// <summary>
+ /// Implement IKeyValue.
+ /// </summary>
+ [Serializable]
+ public class KeyValue : IKeyValue
+ {
+ public KeyValue ()
+ {
+ ;
+ }
+
+ public KeyValue (string aKey, object aValue)
+ {
+ _Key = aKey;
+ _Value = aValue;
+ }
+
+ protected string _Key;
+
+ public virtual string Key
+ {
+ get { return _Key; }
+ set { _Key = value; }
+ }
+
+ protected object _Value;
+
+ public virtual object Value
+ {
+ get { return _Value; }
+ set { _Value = value; }
+ }
+
+ public virtual string Text
+ {
+ get { return _Value as string; }
+ set { _Value = Text; }
+ }
+
+ public override string ToString ()
+ {
+ return Text;
+ }
+
+ }
+}
\ No newline at end of file
Modified: struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/Catalog.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/Catalog.cs?rev=191650&r1=191649&r2=191650&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/Catalog.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Extras/Spring/Catalog.cs Tue Jun 21 04:37:24 2005
@@ -17,6 +17,7 @@
using System.Collections;
using Agility.Core;
using Nexus.Core;
+using Nexus.Core.Helpers;
using Nexus.Core.Tables;
using Spring.Context;
@@ -33,9 +34,9 @@
private const string msg_ADD_COMMAND = "This catalog instance is created through dependency injection.";
private const string msg_MISSING = "Object is not found in Factory.";
- private const string msg_NAME = "name";
- private const string msg_NULL = "Command name cannot be null.";
+ private const string msg_NULL = "Object ID cannot be null.";
private const string msg_TYPE = "Command is not a IRequestCommand or IRequestChain.";
+ private const string msg_TYPE_HELPER = "Object is not a IViewHelper.";
private const string msg_CATALOG_CONTEXT_NULL = "Catalog: Context cannot be null!";
private const string msg_CATALOG_COMMAND_NULL = "Catalog: Command within Context cannot be null! -- Was Context retrieved from Catalog?";
@@ -57,13 +58,22 @@
/// <param name="name">ID for object</param>
/// <returns>Object instance</returns>
/// <exception cref="Exception">
- /// Throws Exception if name is null.
+ /// Throws Exception if name is null or object is not in catalog.
/// </exception>
private object GetObject (string name)
{
if (null == name)
- throw new ArgumentNullException (msg_NAME, "Nexus.Extras.Spring.Catalog.GetObject");
- return Factory ().GetObject (name);
+ {
+ Exception e = new Exception (msg_NULL);
+ throw(e);
+ }
+ object o = Factory ().GetObject (name);
+ if (o == null)
+ {
+ Exception e = new Exception (msg_MISSING);
+ throw(e);
+ }
+ return o;
}
#endregion
@@ -92,17 +102,7 @@
/// </exception>
public ICommand GetCommand (string name)
{
- if (null == name)
- {
- Exception e = new Exception (msg_NULL);
- throw(e);
- }
object o = GetObject (name);
- if (o == null)
- {
- Exception e = new Exception (msg_MISSING);
- throw(e);
- }
IRequestCommand command = o as IRequestCommand;
if (command == null)
{
@@ -167,9 +167,21 @@
return _FieldTable;
}
- public IRequestContext GetRequest (string command)
+ public IViewHelper GetHelper (string name)
+ {
+ object o = GetObject (name);
+ IViewHelper helper = o as IViewHelper;
+ if (helper == null)
+ {
+ Exception e = new Exception (msg_TYPE_HELPER);
+ throw(e);
+ }
+ return helper;
+ }
+
+ public IRequestContext GetRequest (string name)
{
- ICommand _command = GetCommand (command);
+ ICommand _command = GetCommand (name);
IRequestCommand _rc = _command as IRequestCommand;
return GetRequest (_rc);
}
@@ -195,9 +207,9 @@
}
- public IRequestContext GetRequest (string command, IDictionary input)
+ public IRequestContext GetRequest (string name, IDictionary input)
{
- IRequestContext context = GetRequest (command);
+ IRequestContext context = GetRequest (name);
context.Criteria = input;
return context;
}
@@ -223,9 +235,9 @@
return command;
}
- public IRequestContext ExecuteRequest (string command)
+ public IRequestContext ExecuteRequest (string name)
{
- IRequestContext context = GetRequest (command);
+ IRequestContext context = GetRequest (name);
ExecuteRequest (context);
return context;
}
Modified: struts/sandbox/trunk/overdrive/Nexus/Web/Web.csproj
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/Web.csproj?rev=191650&r1=191649&r2=191650&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/Web.csproj (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/Web.csproj Tue Jun 21 04:37:24 2005
@@ -129,11 +129,6 @@
BuildAction = "Content"
/>
<File
- RelPath = "WebHelper.cs"
- SubType = "Code"
- BuildAction = "Compile"
- />
- <File
RelPath = "WebViewHelper.cs"
SubType = "Code"
BuildAction = "Compile"
Modified: struts/sandbox/trunk/overdrive/Nexus/Web/WebViewHelper.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/Nexus/Web/WebViewHelper.cs?rev=191650&r1=191649&r2=191650&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/Nexus/Web/WebViewHelper.cs (original)
+++ struts/sandbox/trunk/overdrive/Nexus/Web/WebViewHelper.cs Tue Jun 21 04:37:24 2005
@@ -1,12 +1,29 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
using System;
using System.Collections;
using System.Text;
+using System.Web.UI;
+using System.Web.UI.WebControls;
using Nexus.Core.Helpers;
namespace Nexus.Web.Helpers
{
/// <summary>
- /// Default implementation of IWebViewHelper [OVR-14].
+ /// Implement IWebViewHelper [OVR-14].
/// </summary>
///
public class WebViewHelper : ViewHelper
@@ -74,22 +91,267 @@
public override void ExecuteBind (ICollection controls)
{
- throw new NotImplementedException ();
+ Execute ();
+ Bind (controls);
}
public override void ReadExecute (ICollection controls)
{
- throw new NotImplementedException ();
+ Read (controls);
+ Execute ();
}
public override void Bind (ICollection controls)
{
- throw new NotImplementedException ();
+ ControlCollection cc = controls as ControlCollection;
+ BindControls (cc, Context.Criteria, Prefix, ListSuffix);
}
public override void Read (ICollection controls)
{
- throw new NotImplementedException ();
+ ControlCollection cc = controls as ControlCollection;
+ ReadControls (cc, Context.Criteria, Prefix, ListSuffix, NullIfEmpty);
+ }
+
+ #endregion
+
+ #region Bind methods
+
+ private void BindControls (ControlCollection controls, IDictionary dictionary, string prefix, string list_suffix)
+ {
+ foreach (Control t in controls)
+ {
+ if (IsCheckBox (t))
+ {
+ CheckBox x = (CheckBox) t;
+ string v = dictionary [ToColumn (x.ID, prefix)] as string;
+ x.Checked = (v != null);
+ }
+ if (IsLabel (t))
+ {
+ Label x = (Label) t;
+ object v = dictionary [ToColumn (x.ID, prefix)];
+ if (v != null) x.Text = v.ToString ();
+ }
+ if (IsListControl (t))
+ {
+ ListControl x = (ListControl) t;
+ string root = RootId (x.ID, prefix, list_suffix);
+ IList s = dictionary [root + list_suffix] as IList; // this_key_list
+ string r = dictionary [root] as string; // this_key
+ if ((null == r) || (0 == r.Length))
+ BindListControl (x, s);
+ else
+ BindListControl (x, s, r);
+ }
+ if (IsRadioButton (t))
+ {
+ RadioButton x = (RadioButton) t;
+ string v = dictionary [ToColumn (x.ID, prefix)] as string;
+ x.Checked = (v != null);
+ }
+ if (IsTextBox (t))
+ {
+ TextBox x = (TextBox) t;
+ object v = dictionary [ToColumn (x.ID, prefix)];
+ if (v != null) x.Text = v.ToString ();
+ }
+ }
+ }
+
+ private void BindListControl (ListControl control, IList list)
+ {
+ bool insertKey = ((list != null) && (!list.Contains (String.Empty)) && (!list.Contains (SelectItemPrompt)));
+ if (insertKey) list.Insert (0, SelectItemPrompt);
+ BindListControl (control, list, null);
+ }
+
+ /// <summary>
+ /// Bind a list of KeyValue objects to a ListControl,
+ /// select any item matching value.
+ /// </summary>
+ /// <param name="control">ListControl to process</param>
+ /// <param name="list">List of TextKey objects.</param>
+ /// <param name="value">Value to select, or null if nothing is selected.</param>
+ ///
+ private void BindListControl (ListControl control, IList list, string value)
+ {
+ control.DataTextField = "Value";
+ control.DataValueField = "Key";
+ control.DataSource = list;
+ control.DataBind ();
+ SelectListItem (control, value);
+ }
+
+ #endregion
+
+ #region Read method
+
+ private void ReadControls (ControlCollection controls, IDictionary dictionary, string prefix, string list_suffix, bool nullIfEmpty)
+ {
+ foreach (Control t in controls)
+ {
+ if (IsCheckBox (t))
+ {
+ CheckBox x = (CheckBox) t;
+ string key = ToColumn (x.ID, prefix);
+ string value = (x.Checked) ? key : null;
+ dictionary.Add (key, value);
+ }
+ if (IsLabel (t))
+ {
+ Label x = (Label) t;
+ string value = (nullIfEmpty) ? DoNullIfEmpty (x.Text) : x.Text;
+ dictionary.Add (ToColumn (x.ID, prefix), value);
+ }
+ if (IsListControl (t))
+ {
+ ListControl x = (ListControl) t;
+ string root = RootId (x.ID, prefix, list_suffix);
+ string value = (nullIfEmpty) ? DoNullIfEmpty (x.SelectedValue) : x.SelectedValue;
+ dictionary.Add (root, value);
+ }
+ if (IsRadioButton (t))
+ {
+ RadioButton x = (RadioButton) t;
+ string key = ToColumn (x.ID, prefix);
+ string value = (x.Checked) ? key : null;
+ dictionary.Add (key, value);
+ }
+ if (IsTextBox (t))
+ {
+ TextBox x = (TextBox) t;
+ string value = (nullIfEmpty) ? DoNullIfEmpty (x.Text) : x.Text;
+ dictionary.Add (ToColumn (x.ID, prefix), value);
+ }
+ }
+ }
+
+ #endregion
+
+ #region Control utilities
+
+ private bool IsCheckBox (Control control)
+ {
+ return (typeof (CheckBox).Equals (control.GetType ()));
+ }
+
+ private bool IsLabel (Control control)
+ {
+ return (typeof (Label).Equals (control.GetType ()));
+ }
+
+ private bool IsListControl (Control control)
+ {
+ bool isList = false;
+ Type type = control.GetType ();
+ isList = (isList) || typeof (ListControl).Equals (type);
+ isList = (isList) || typeof (CheckBoxList).Equals (type);
+ isList = (isList) || typeof (DropDownList).Equals (type);
+ isList = (isList) || typeof (ListBox).Equals (type);
+ isList = (isList) || typeof (RadioButtonList).Equals (type);
+ return isList;
+ }
+
+ private bool IsRadioButton (Control control)
+ {
+ return (typeof (RadioButton).Equals (control.GetType ()));
+ }
+
+ private bool IsTextBox (Control control)
+ {
+ return (typeof (TextBox).Equals (control.GetType ()));
+ }
+
+ #endregion
+
+ #region String utilities
+
+ /// <summary>
+ /// If the input is an empty string, return null instead.
+ /// </summary>
+ /// <param name="input">Value</param>
+ /// <returns>Null if value is empty, or the original value</returns>
+ private string DoNullIfEmpty (string input)
+ {
+ return (string.Empty.Equals (input)) ? null : input;
+ }
+
+ /// <summary>
+ /// Extract the root name from the id, allowing for a prefix and suffix.
+ /// </summary>
+ /// <param name="id">The full id, including prefix and suffix.</param>
+ /// <param name="prefix">The prefix to omit.</param>
+ /// <param name="suffix">The suffix to omit.</param>
+ /// <returns></returns>
+ private string RootId (string id, string prefix, string suffix)
+ {
+ int v = id.LastIndexOf (suffix);
+ string fore = id.Substring (0, v);
+ string root = ToColumn (fore, prefix);
+ return root;
+ }
+
+ /// <summary>
+ /// Render a control id as a column name
+ /// by trimming a prefix from the id, if any.
+ /// </summary>
+ /// <param name="id">String to process.</param>
+ /// <param name="prefix">Prefix to remove.</param>
+ /// <returns>id without prefix.</returns>
+ ///
+ private string ToColumn (string id, string prefix)
+ {
+ string trimmed;
+ if (null == prefix) trimmed = id;
+ else trimmed = id.Substring (prefix.Length);
+ return trimmed;
+ }
+
+ #endregion
+
+ #region ListControl utilities
+
+ /// <summary>
+ /// Select only those items in control
+ /// whose Value property matches the given value.
+ /// If the value is null, no action is taken.
+ /// </summary>
+ /// <param name="control"></param>
+ /// <param name="value"></param>
+ ///
+ private void SelectItem (ListControl control, string value)
+ {
+ if (value != null)
+ {
+ foreach (ListItem i in control.Items)
+ i.Selected = false;
+
+ foreach (ListItem i in control.Items)
+ {
+ if (value.Equals (i.Value))
+ i.Selected = true;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Deactivate the selected item, and select any item matching value.
+ /// </summary>
+ /// <param name="control">Control to set</param>
+ /// <param name="value">Default value</param>
+ ///
+ private void SelectListItem (ListControl control, string value)
+ {
+ try
+ {
+ control.SelectedIndex = -1;
+ SelectItem (control, value);
+ }
+ catch (NullReferenceException e1)
+ {
+ if (e1 == null) value = string.Empty; // placate the IDE
+ }
}
#endregion
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org