You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by Daniel Rall <dl...@finemaltcoding.com> on 2001/11/18 20:41:02 UTC
Re: Intake commit
John, I'd appreciate it if you would look over this commit.
dlr@apache.org writes:
> dlr 01/11/18 11:18:59
>
> Modified: src/services/java/org/apache/fulcrum/intake/model
> BigDecimalField.java BooleanField.java
> ComboKeyField.java DateStringField.java Field.java
> FileItemField.java IntegerField.java
> NumberKeyField.java StringField.java
> StringKeyField.java
> Log:
> Cleaned up and added some localization.
>
> Revision Changes Path
> 1.3 +36 -10 jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/BigDecimalField.java
>
> Index: BigDecimalField.java
> ===================================================================
> RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/BigDecimalField.java,v
> retrieving revision 1.2
> retrieving revision 1.3
> diff -u -u -r1.2 -r1.3
> --- BigDecimalField.java 2001/08/30 05:23:57 1.2
> +++ BigDecimalField.java 2001/11/18 19:18:59 1.3
> @@ -55,12 +55,14 @@
> */
>
> import java.math.BigDecimal;
> -import java.util.Vector;
> -import org.apache.fulcrum.intake.xmlmodel.Rule;
> +import java.text.DecimalFormatSymbols;
> import org.apache.fulcrum.intake.xmlmodel.XmlField;
> import org.apache.fulcrum.util.parser.ValueParser;
>
> -/** */
> +/**
> + * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
> + * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
> + */
> public class BigDecimalField extends Field
> {
> public BigDecimalField(XmlField field, Group group)
> @@ -82,21 +84,45 @@
> /**
> * converts the parameter to the correct Object.
> */
> - protected void doSetValue(ValueParser pp)
> + protected void doSetValue()
> {
> if ( isMultiValued )
> {
> - String[] ss = pp.getStrings(getKey());
> - BigDecimal[] ival = new BigDecimal[ss.length];
> - for (int i=0; i<ss.length; i++)
> + String[] inputs = pp.getStrings(getKey());
> + BigDecimal[] values = new BigDecimal[inputs.length];
> + for (int i = 0; i < inputs.length; i++)
> {
> - ival[i] = new BigDecimal(ss[i]);
> + values[i] = canonicalizeDecimalInput(inputs[i]);
> }
> - setTestValue(ival);
> + setTestValue(values);
> }
> else
> {
> - setTestValue( new BigDecimal(pp.getString(getKey())) );
> + setTestValue( canonicalizeDecimalInput(pp.getString(getKey())) );
> }
> + }
> +
> + /**
> + * Canonicalizes an user-inputted <code>BigDecimal</code> string
> + * to the system's internal format.
> + *
> + * @param bigDecimal Text conforming to a <code>BigDecimal</code>
> + * description for a set of <code>DecimalFormatSymbols</code>.
> + * @return The canonicalized representation.
> + */
> + protected final BigDecimal canonicalizeDecimalInput(String bigDecimal)
> + {
> + if (getLocale() != null)
> + {
> + DecimalFormatSymbols internal = new DecimalFormatSymbols();
> + DecimalFormatSymbols user = new DecimalFormatSymbols(getLocale());
> +
> + if (!internal.equals(user))
> + {
> + bigDecimal = bigDecimal.replace(user.getDecimalSeparator(),
> + internal.getDecimalSeparator());
> + }
> + }
> + return new BigDecimal(bigDecimal);
> }
> }
>
>
>
> 1.4 +4 -4 jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/BooleanField.java
>
> Index: BooleanField.java
> ===================================================================
> RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/BooleanField.java,v
> retrieving revision 1.3
> retrieving revision 1.4
> diff -u -u -r1.3 -r1.4
> --- BooleanField.java 2001/08/31 08:04:58 1.3
> +++ BooleanField.java 2001/11/18 19:18:59 1.4
> @@ -59,10 +59,10 @@
> import org.apache.log4j.Category;
>
> /**
> - * Base class for Intake generated input processing classes.
> + * Processor for boolean fields.
> *
> - * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
> - * @version $Id: BooleanField.java,v 1.3 2001/08/31 08:04:58 jvanzyl Exp $
> + * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
> + * @version $Id: BooleanField.java,v 1.4 2001/11/18 19:18:59 dlr Exp $
> */
> public class BooleanField extends Field
> {
> @@ -90,7 +90,7 @@
> /**
> * converts the parameter to the correct Object.
> */
> - protected void doSetValue(ValueParser pp)
> + protected void doSetValue()
> {
> setTestValue( pp.getBool(getKey()) );
> }
>
>
>
> 1.4 +4 -2 jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/ComboKeyField.java
>
> Index: ComboKeyField.java
> ===================================================================
> RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/ComboKeyField.java,v
> retrieving revision 1.3
> retrieving revision 1.4
> diff -u -u -r1.3 -r1.4
> --- ComboKeyField.java 2001/08/31 08:04:58 1.3
> +++ ComboKeyField.java 2001/11/18 19:18:59 1.4
> @@ -63,7 +63,9 @@
> //import org.apache.fulcrum.ServiceException;
> import org.apache.log4j.Category;
>
> -/** */
> +/**
> + * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
> + */
> public class ComboKeyField extends Field
> {
> /**
> @@ -80,7 +82,7 @@
> /**
> * converts the parameter to the correct Object.
> */
> - protected void doSetValue(ValueParser pp)
> + protected void doSetValue()
> {
> try
> {
>
>
>
> 1.2 +4 -1 jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/DateStringField.java
>
> Index: DateStringField.java
> ===================================================================
> RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/DateStringField.java,v
> retrieving revision 1.1
> retrieving revision 1.2
> diff -u -u -r1.1 -r1.2
> --- DateStringField.java 2001/09/21 18:59:46 1.1
> +++ DateStringField.java 2001/11/18 19:18:59 1.2
> @@ -66,6 +66,8 @@
> * Field for date inputs as free form text. The parsing of date strings
> * is dependent on any rules that are defined, so this field will expect that
> * any validator will be (or extend) DateStringValidator.
> + *
> + * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
> */
> public class DateStringField extends Field
> {
> @@ -96,7 +98,7 @@
> /**
> * converts the parameter to the correct Object.
> */
> - protected void doSetValue(ValueParser pp)
> + protected void doSetValue()
> {
> if ( isMultiValued )
> {
> @@ -119,6 +121,7 @@
> Date date = null;
> try
> {
> + // FIXME: Canonicalize user-entered date strings.
> if ( df == null ) // guarantees validator != null
> {
> date = ((DateStringValidator)validator).parse(dateString);
>
>
>
> 1.5 +66 -11 jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/Field.java
>
> Index: Field.java
> ===================================================================
> RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/Field.java,v
> retrieving revision 1.4
> retrieving revision 1.5
> diff -u -u -r1.4 -r1.5
> --- Field.java 2001/10/28 19:52:05 1.4
> +++ Field.java 2001/11/18 19:18:59 1.5
> @@ -54,10 +54,15 @@
> * <http://www.apache.org/>.
> */
>
> +import java.util.Locale;
> import java.util.Map;
> import java.lang.reflect.Method;
> +
> import org.apache.regexp.RE;
> -import org.apache.fulcrum.util.parser.ValueParser;
> +import org.apache.fulcrum.ServiceException;
> +import org.apache.fulcrum.TurbineServices;
> +import org.apache.fulcrum.localization.Localization;
> +import org.apache.fulcrum.localization.LocalizationService;
> import org.apache.fulcrum.intake.Retrievable;
> import org.apache.fulcrum.intake.TurbineIntake;
> import org.apache.fulcrum.intake.xmlmodel.Rule;
> @@ -66,14 +71,16 @@
> import org.apache.fulcrum.intake.validator.Validator;
> import org.apache.fulcrum.intake.validator.InitableByConstraintMap;
> import org.apache.fulcrum.intake.validator.ValidationException;
> -import org.apache.fulcrum.ServiceException;
> +import org.apache.fulcrum.util.parser.ParameterParser;
> +import org.apache.fulcrum.util.parser.ValueParser;
> import org.apache.log4j.Category;
>
> /**
> * Base class for Intake generated input processing classes.
> *
> * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
> - * @version $Id: Field.java,v 1.4 2001/10/28 19:52:05 jmcnally Exp $
> + * @author <a href="mailto:dlr@finemaltcoding.com>Daniel Rall</a>
> + * @version $Id: Field.java,v 1.5 2001/11/18 19:18:59 dlr Exp $
> */
> public abstract class Field
> {
> @@ -102,13 +109,17 @@
> protected String message;
> protected Retrievable retrievable;
>
> + private Locale locale;
> private String stringValue;
> private String[] stringValues;
> private Object validValue;
> private Object testValue;
> private Object[] valArray; // for reflection
>
> - /** The object containing the request data */
> + /**
> + * The object containing the field data.
> + * TODO: Rename to parser.
> + */
> protected ValueParser pp;
>
> /**
> @@ -122,6 +133,7 @@
> *
> * @param field a <code>XmlField</code> value
> * @param group a <code>Group</code> value
> + * @param locale The locale
> * @exception Exception if an error occurs
> */
> public Field(XmlField field, Group group)
> @@ -195,6 +207,22 @@
> this.pp = pp;
> valid_flag = true;
>
> + // If the parser is for a HTTP request, use the request it's
> + // associated with to grok the locale.
> + if (TurbineServices.getInstance()
> + .isRegistered(LocalizationService.SERVICE_NAME))
> + {
> + if (pp instanceof ParameterParser)
> + {
> + this.locale = Localization.getLocale
> + ( ((ParameterParser)pp).getRequest() );
> + }
> + else
> + {
> + this.locale = Localization.getLocale((String)null);
> + }
> + }
> +
> if ( pp.containsKey(getKey()) && pp.getString(getKey()) != null )
> {
> set_flag = true;
> @@ -234,7 +262,20 @@
> return this;
> }
>
> + /**
> + * Returns the <code>Locale</code> used when localizing data for
> + * this field, or <code>null</code> if unknown.
> + *
> + * @return Where to localize for.
> + */
> + protected Locale getLocale()
> + {
> + return locale;
> + }
>
> + /**
> + * Produces the fully qualified class name of the default validator.
> + */
> protected String getDefaultValidator()
> {
> return "org.apache.fulcrum.intake.validator.DefaultValidator";
> @@ -258,7 +299,7 @@
> * Set whether this field is required to have a value.
> * @param v Value to assign to required.
> */
> - public void setRequired(boolean v)
> + public void setRequired(boolean v)
> {
> setRequired(v, ifRequiredMessage);
> }
> @@ -269,7 +310,7 @@
> * @param v a <code>boolean</code> value
> * @param message, override the value from intake.xml
> */
> - public void setRequired(boolean v, String message)
> + public void setRequired(boolean v, String message)
> {
> this.required = v;
> if (v && !set_flag)
> @@ -304,6 +345,7 @@
> message = null;
> retrievable = null;
>
> + locale = null;
> stringValue = null;
> stringValues = null;
> validValue = null;
> @@ -407,9 +449,17 @@
> }
>
> /**
> - * Compares request data with constraints and sets the valid flag.
> + * @deprecated Call validate() instead (with no parameters).
> */
> protected boolean validate(ValueParser pp)
> + {
> + return validate();
> + }
> +
> + /**
> + * Compares request data with constraints and sets the valid flag.
> + */
> + protected boolean validate()
> // throws ServiceException
> {
> if ( isMultiValued )
> @@ -442,7 +492,6 @@
> {
> doSetValue(pp);
> }
> -
> }
> else
> {
> @@ -478,12 +527,18 @@
> }
>
> /**
> + * @deprecated Use doSetValue() instead (with no parameters).
> + */
> + protected void doSetValue(ValueParser pp)
> + {
> + doSetValue();
> + }
> +
> + /**
> * Compares request data with constraints and sets the valid flag.
> * To be implemented in subclasses
> */
> - protected abstract void doSetValue(ValueParser pp);
> -
> -
> + protected abstract void doSetValue();
>
> /**
> * Set the value used as a default, in the event the field
>
>
>
> 1.3 +8 -7 jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/FileItemField.java
>
> Index: FileItemField.java
> ===================================================================
> RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/FileItemField.java,v
> retrieving revision 1.2
> retrieving revision 1.3
> diff -u -u -r1.2 -r1.3
> --- FileItemField.java 2001/08/30 05:23:57 1.2
> +++ FileItemField.java 2001/11/18 19:18:59 1.3
> @@ -67,10 +67,11 @@
> import org.apache.fulcrum.upload.FileItem;
> import org.apache.fulcrum.ServiceException;
>
> -/** */
> +/**
> + * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
> + */
> public class FileItemField extends Field
> {
> -
> public FileItemField(XmlField field, Group group)
> throws Exception
> {
> @@ -102,7 +103,7 @@
> {
> try
> {
> - this.pp = (ParameterParser)vp;
> + super.pp = (ParameterParser) vp;
> }
> catch (ClassCastException e)
> {
> @@ -125,10 +126,10 @@
> /**
> * Compares request data with constraints and sets the valid flag.
> */
> - protected boolean validate(ValueParser vp)
> + protected boolean validate()
> // throws ServiceException
> {
> - ParameterParser pp = (ParameterParser)vp;
> + ParameterParser pp = (ParameterParser) super.pp;
> if ( isMultiValued )
> {
> FileItem[] ss = pp.getFileItems(getKey());
> @@ -196,9 +197,9 @@
> /**
> * converts the parameter to the correct Object.
> */
> - protected void doSetValue(ValueParser vp)
> + protected void doSetValue()
> {
> - ParameterParser pp = (ParameterParser)vp;
> + ParameterParser pp = (ParameterParser) super.pp;
> if ( isMultiValued )
> {
> setTestValue(pp.getFileItems(getKey()));
>
>
>
> 1.4 +4 -3 jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/IntegerField.java
>
> Index: IntegerField.java
> ===================================================================
> RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/IntegerField.java,v
> retrieving revision 1.3
> retrieving revision 1.4
> diff -u -u -r1.3 -r1.4
> --- IntegerField.java 2001/09/21 18:57:42 1.3
> +++ IntegerField.java 2001/11/18 19:18:59 1.4
> @@ -59,10 +59,11 @@
> import org.apache.fulcrum.intake.xmlmodel.XmlField;
> import org.apache.fulcrum.util.parser.ValueParser;
>
> -/** */
> +/**
> + * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
> + */
> public class IntegerField extends Field
> {
> -
> public IntegerField(XmlField field, Group group)
> throws Exception
> {
> @@ -82,7 +83,7 @@
> /**
> * converts the parameter to the correct Object.
> */
> - protected void doSetValue(ValueParser pp)
> + protected void doSetValue()
> {
> if ( isMultiValued )
> {
>
>
>
> 1.3 +15 -33 jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/NumberKeyField.java
>
> Index: NumberKeyField.java
> ===================================================================
> RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/NumberKeyField.java,v
> retrieving revision 1.2
> retrieving revision 1.3
> diff -u -u -r1.2 -r1.3
> --- NumberKeyField.java 2001/08/30 05:23:57 1.2
> +++ NumberKeyField.java 2001/11/18 19:18:59 1.3
> @@ -54,15 +54,18 @@
> * <http://www.apache.org/>.
> */
>
> -import java.util.Vector;
> +import java.math.BigDecimal;
> import org.apache.torque.om.NumberKey;
> import org.apache.torque.om.ObjectKey;
> import org.apache.fulcrum.intake.xmlmodel.Rule;
> import org.apache.fulcrum.intake.xmlmodel.XmlField;
> import org.apache.fulcrum.util.parser.ValueParser;
>
> -/** */
> -public class NumberKeyField extends Field
> +/**
> + * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
> + * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
> + */
> +public class NumberKeyField extends BigDecimalField
> {
> public NumberKeyField(XmlField field, Group group)
> throws Exception
> @@ -71,7 +74,6 @@
>
> }
>
> -
> /**
> * A suitable validator.
> *
> @@ -79,48 +81,28 @@
> */
> protected String getDefaultValidator()
> {
> - return
> - "org.apache.fulcrum.intake.validator.NumberKeyValidator";
> + return "org.apache.fulcrum.intake.validator.NumberKeyValidator";
> }
>
> /**
> * converts the parameter to the correct Object.
> */
> - protected void doSetValue(ValueParser pp)
> + protected void doSetValue()
> {
> if ( isMultiValued )
> {
> - String[] ss = pp.getStrings(getKey());
> - NumberKey[] ival = new NumberKey[ss.length];
> - for (int i=0; i<ss.length; i++)
> + String[] inputs = pp.getStrings(getKey());
> + NumberKey[] values = new NumberKey[inputs.length];
> + for (int i = 0; i < inputs.length; i++)
> {
> - ival[i] = new NumberKey(ss[i]);
> + values[i] = new NumberKey(canonicalizeDecimalInput(inputs[i]));
> }
> - setTestValue(ival);
> + setTestValue(values);
> }
> else
> {
> - setTestValue( new NumberKey(pp.getString(getKey())) );
> + BigDecimal bd = canonicalizeDecimalInput( pp.getString(getKey()) );
> + setTestValue( new NumberKey(bd) );
> }
> }
> -
> }
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
>
>
>
> 1.3 +6 -14 jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/StringField.java
>
> Index: StringField.java
> ===================================================================
> RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/StringField.java,v
> retrieving revision 1.2
> retrieving revision 1.3
> diff -u -u -r1.2 -r1.3
> --- StringField.java 2001/08/30 05:23:57 1.2
> +++ StringField.java 2001/11/18 19:18:59 1.3
> @@ -58,10 +58,10 @@
> import org.apache.fulcrum.intake.xmlmodel.XmlField;
>
> /**
> - * Base class for Intake generated input processing classes.
> + * Text field.
> *
> - * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
> - * @version $Id: StringField.java,v 1.2 2001/08/30 05:23:57 jmcnally Exp $
> + * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
> + * @version $Id: StringField.java,v 1.3 2001/11/18 19:18:59 dlr Exp $
> */
> public class StringField extends Field
> {
> @@ -74,7 +74,7 @@
> /**
> * converts the parameter to the correct Object.
> */
> - protected void doSetValue(ValueParser pp)
> + protected void doSetValue()
> {
> if ( isMultiValued )
> {
> @@ -91,21 +91,13 @@
> * Set the value of required.
> * @param v Value to assign to required.
> */
> - public void setRequired(boolean v, String message)
> + public void setRequired(boolean v, String message)
> {
> this.required = v;
> if (v && (!set_flag || ((String)getTestValue()).length() == 0) )
> {
> - valid_flag=false;
> + valid_flag = false;
> this.message = message;
> }
> }
> }
> -
> -
> -
> -
> -
> -
> -
> -
>
>
>
> 1.2 +5 -7 jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/StringKeyField.java
>
> Index: StringKeyField.java
> ===================================================================
> RCS file: /home/cvs/jakarta-turbine-fulcrum/src/services/java/org/apache/fulcrum/intake/model/StringKeyField.java,v
> retrieving revision 1.1
> retrieving revision 1.2
> diff -u -u -r1.1 -r1.2
> --- StringKeyField.java 2001/10/04 20:26:39 1.1
> +++ StringKeyField.java 2001/11/18 19:18:59 1.2
> @@ -58,17 +58,17 @@
> import org.apache.fulcrum.intake.xmlmodel.XmlField;
> import org.apache.fulcrum.util.parser.ValueParser;
>
> -/** */
> +/**
> + * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
> + */
> public class StringKeyField extends Field
> {
> public StringKeyField(XmlField field, Group group)
> throws Exception
> {
> super(field, group);
> -
> }
>
> -
> /**
> * A suitable validator.
> *
> @@ -76,14 +76,13 @@
> */
> protected String getDefaultValidator()
> {
> - return
> - "org.apache.fulcrum.intake.validator.DefaultValidator";
> + return "org.apache.fulcrum.intake.validator.DefaultValidator";
> }
>
> /**
> * converts the parameter to the correct Object.
> */
> - protected void doSetValue(ValueParser pp)
> + protected void doSetValue()
> {
> if ( isMultiValued )
> {
> @@ -100,5 +99,4 @@
> setTestValue( new StringKey(pp.getString(getKey())) );
> }
> }
> -
> }
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>