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/23 15:22:59 UTC

svn commit: r193137 - in /struts/sandbox/trunk/overdrive/PhoneBook: Core/TelephoneProcessor.cs Test/Resources/Command/AppBase.xml Test/Resources/Command/AppConfig.xml Web/Resources/Command/Catalog.xml

Author: husted
Date: Thu Jun 23 06:22:56 2005
New Revision: 193137

URL: http://svn.apache.org/viewcvs?rev=193137&view=rev
Log:
OVR-5
* Add TelephoneProcessor to format telephone numbers in diretory list.

Added:
    struts/sandbox/trunk/overdrive/PhoneBook/Core/TelephoneProcessor.cs
Modified:
    struts/sandbox/trunk/overdrive/PhoneBook/Test/Resources/Command/AppBase.xml
    struts/sandbox/trunk/overdrive/PhoneBook/Test/Resources/Command/AppConfig.xml
    struts/sandbox/trunk/overdrive/PhoneBook/Web/Resources/Command/Catalog.xml

Added: struts/sandbox/trunk/overdrive/PhoneBook/Core/TelephoneProcessor.cs
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/PhoneBook/Core/TelephoneProcessor.cs?rev=193137&view=auto
==============================================================================
--- struts/sandbox/trunk/overdrive/PhoneBook/Core/TelephoneProcessor.cs (added)
+++ struts/sandbox/trunk/overdrive/PhoneBook/Core/TelephoneProcessor.cs Thu Jun 23 06:22:56 2005
@@ -0,0 +1,51 @@
+using System.Text;
+using Nexus.Core.Validators;
+
+namespace PhoneBook.Core
+{
+	/// <summary>
+	/// Remove punctuation on input and insert punctuation on output.
+	/// </summary>
+	public class TelephoneProcessor : Processor
+	{
+		public override bool ConvertInput (IProcessorContext incoming)
+		{
+			string source = incoming.Source as string;
+			if (source == null) return false;
+
+			char[] marks = {'-'};
+			string[] splits = source.Split (marks);
+			StringBuilder sb = new StringBuilder (source.Length);
+			foreach (string s in splits)
+			{
+				sb.Append (s);
+			}
+			incoming.Target = sb.ToString ();
+			return true;
+		}
+
+		public override bool FormatOutput (IProcessorContext outgoing)
+		{
+			string mark = "-";
+			string source = outgoing.Source as string;
+			if (source == null) return false;
+			string buffer = null;
+
+			if (source.Length == 10)
+			{
+				// 012-345-6789
+				string buffer1 = source.Insert (6, mark);
+				buffer = buffer1.Insert (3, mark);
+			}
+			else if (source.Length == 7)
+			{
+				// 012-3456
+				buffer = source.Insert (3, mark);
+			}
+			else buffer = source;
+
+			outgoing.Target = buffer;
+			return true;
+		}
+	}
+}
\ No newline at end of file

Modified: struts/sandbox/trunk/overdrive/PhoneBook/Test/Resources/Command/AppBase.xml
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/PhoneBook/Test/Resources/Command/AppBase.xml?rev=193137&r1=193136&r2=193137&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/PhoneBook/Test/Resources/Command/AppBase.xml (original)
+++ struts/sandbox/trunk/overdrive/PhoneBook/Test/Resources/Command/AppBase.xml Thu Jun 23 06:22:56 2005
@@ -6,6 +6,8 @@
 	<object id="BaseChain" type="Nexus.Core.RequestChain, Nexus.Core"/>
 	
 	<object id="BaseFilterList" type="PhoneBook.Core.Commands.BaseFilterList, PhoneBook.Core"/>
+	
+	<object id="BaseFieldContext" type="Nexus.Core.Tables.FieldContext"/>
 
 	<!-- All child helpers must also specify singleton=false; otherwise, Context is shared. -->
 	<object id="BaseHelper" type="PhoneBook.Web.AppHelper, PhoneBook.Web" singleton="false">

Modified: struts/sandbox/trunk/overdrive/PhoneBook/Test/Resources/Command/AppConfig.xml
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/PhoneBook/Test/Resources/Command/AppConfig.xml?rev=193137&r1=193136&r2=193137&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/PhoneBook/Test/Resources/Command/AppConfig.xml (original)
+++ struts/sandbox/trunk/overdrive/PhoneBook/Test/Resources/Command/AppConfig.xml Thu Jun 23 06:22:56 2005
@@ -9,24 +9,31 @@
 		<property name="AddFieldContexts">
 			<list>
 				<ref object="hired"/> 
+				<ref object="extension"/> 
 				<ref object="_filter"/> 
 			</list>
 		</property>
 		<property name="AddProcessors">
 			<list>
 				<ref object="DateTimeProcessor"/> 
+				<ref object="TelephoneProcessor"/> 
 				<ref object="AppProcessor"/> 
 			</list>
 		</property>
 	</object>
 	
-	<object id="hired" type="Nexus.Core.Tables.FieldContext">
+	<object id="hired" parent="BaseFieldContext">
 		<property name="ID"><value>hired</value></property>	
 		<property name="Alert"><value>{0} must be a valid date</value></property>
 		<property name="ProcessorID"><value>DateTimeProcessor</value></property>
 	</object>
+
+	<object id="extension" parent="BaseFieldContext">
+		<property name="ID"><value>extension</value></property>		
+		<property name="ProcessorID"><value>TelephoneProcessor</value></property>
+	</object>
 	
-	<object id="_filter" type="Nexus.Core.Tables.FieldContext">
+	<object id="_filter" parent="BaseFieldContext">
 		<property name="ID"><value>filter</value></property>
 		<property name="ProcessorID"><value>AppProcessor</value></property>
 	</object>
@@ -37,6 +44,10 @@
 		<property name="DataFormat"><value>d</value></property>
 	</object>
 	
+	<object id="TelephoneProcessor" type="PhoneBook.Core.TelephoneProcessor">
+		<property name="ID"><value>TelephoneProcessor</value></property>
+	</object>
+
 	<object id="AppProcessor" type="PhoneBook.Core.AppProcessor">
 		<property name="ID"><value>AppProcessor</value></property>
 	</object>

Modified: struts/sandbox/trunk/overdrive/PhoneBook/Web/Resources/Command/Catalog.xml
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/overdrive/PhoneBook/Web/Resources/Command/Catalog.xml?rev=193137&r1=193136&r2=193137&view=diff
==============================================================================
--- struts/sandbox/trunk/overdrive/PhoneBook/Web/Resources/Command/Catalog.xml (original)
+++ struts/sandbox/trunk/overdrive/PhoneBook/Web/Resources/Command/Catalog.xml Thu Jun 23 06:22:56 2005
@@ -6,6 +6,11 @@
 	<!-- filter command -->
 
   <object id="filter" type="PhoneBook.Core.Commands.BaseList, PhoneBook.Core">
+		<property name="RelatedIDs">
+			<list>
+				<value>filter</value>
+			</list>
+		</property>
 	<property name="ID"><value>filter</value></property>
   </object>
 	



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org