You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by ra...@apache.org on 2005/08/10 23:11:40 UTC
svn commit: r231329 [2/13] - in /jakarta/taglibs/proper/rdc/trunk/src:
META-INF/tags/rdc/ org/apache/taglibs/rdc/ org/apache/taglibs/rdc/core/
org/apache/taglibs/rdc/dm/ org/apache/taglibs/rdc/resources/
org/apache/taglibs/rdc/sampleapps/mortgage/ org/...
Modified: jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Date.java
URL: http://svn.apache.org/viewcvs/jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Date.java?rev=231329&r1=231328&r2=231329&view=diff
==============================================================================
--- jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Date.java (original)
+++ jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Date.java Wed Aug 10 14:10:59 2005
@@ -36,270 +36,270 @@
*/
public class Date extends BaseModel {
- // The date RDC will be associated with the date input, the maximum and
- // minimum dates within which the date input must lie, and a date format to
- // which the date input must conform.
-
- // Date returned must conform to this format
- private String format;
- // Date returned cannot be beyond this date
- private java.util.Date maxDate;
- // Date returned cannot be before this date
- private java.util.Date minDate;
-
- // formatter for the date strings and objects
- private SimpleDateFormat formatter;
-
- // Error codes, corresponding prompts defined in configuration file
- /**A constant for Error Code stating Invalid date*/
- public static final int ERR_INVALID_DATE = 1;
-
- /**A constant for Error Code stating the date entered is earlier
- * than allowed */
- public static final int ERR_NEED_LATER_DATE = 2;
-
- /**A constant for Error Code stating the date entered is later
- * than allowed */
- public static final int ERR_NEED_EARLIER_DATE = 3;
-
- /**
- * Sets default values for all data members
- */
- public Date() {
- super();
- this.minDate = null;
- this.maxDate = null;
-
- // MM - month, dd - day of month, yyyy - year
- // not using mm (lowercase), because it represents minutes in DateFormat
- this.format = "MMddyyyy";
- this.formatter = new SimpleDateFormat(format);
- this.formatter.setLenient(false);
- } // end Date constructor
-
- /**
- * Sets the date string format to use for vaidation
- *
- * @param strDateFormat The date format string
- */
- public void setFormat(String strDateFormat) {
- if (strDateFormat != null) {
- try {
- formatter.applyPattern(strDateFormat);
- this.format = strDateFormat;
- } catch (IllegalArgumentException e) {
- throw new IllegalArgumentException("format attribute of \"" +
- getId() + "\" date tag is invalid.");
- }
- }
- } // end setFormat()
-
- /**
- * Sets the Maximum Date value
- *
- * @param strMaxDate The Maximum Date value (conforms to format)
- */
- public void setMaxDate(String strMaxDate) {
- if (strMaxDate != null) {
- this.maxDate = (java.util.Date)canonicalize(strMaxDate, true);
- }
- } // end setMaxDate()
-
- /**
- * Gets the Maximum Date value
- *
- * @return The Maximum Date value
- */
- public String getMaxDate() {
- return calculateCanonicalizedValue(maxDate);
- } // end getMaxDate()
-
- /**
- * Sets the Minimum Date value
- *
- * @param strMinDate The Minimum Date value (conforms to format)
- */
- public void setMinDate(String strMinDate) {
- if (strMinDate != null) {
- this.minDate = (java.util.Date)canonicalize(strMinDate, true);
- }
- } // end setMinDate()
-
- /**
- * Gets the Minimum Date value
- *
- * @return The Minimum Date value
- */
- public String getMinDate() {
- return calculateCanonicalizedValue(minDate);
- } // end getMinDate()
-
- /**
- * Get the date currently associated with this date component as a string
- * in the specified format.
- *
- * @return value the value as a string
- */
- public Object getValue() {
- if (this.value == null) {
- return null;
- }
- return formatter.format((java.util.Date) this.value);
- }
-
- /**
- * Sets up the date string, converting phrases of today and tomorrow
- * into valid dates followed by the format filter
- *
- * @param strInput The date input string
- * @return The value of date (conforming to format)
- */
- protected Object canonicalize(Object input, boolean isAttribute) {
- if (input == null) {
- return null;
- }
- Calendar thisDay = new GregorianCalendar();
- String strInput = (String) input;
- if ("today".equalsIgnoreCase(strInput)) {
- return thisDay.getTime();
- } else if ("tomorrow".equalsIgnoreCase(strInput)) {
- thisDay.add(Calendar.DATE, 1);
- return thisDay.getTime();
- } else if ("yesterday".equalsIgnoreCase(strInput)) {
- thisDay.add(Calendar.DATE, -1);
- return thisDay.getTime();
- } else {
- if (isAttribute) {
- if (strInput.toLowerCase().indexOf('x') >= 0) {
- return doOffsetDate(strInput);
- }
- return formatter.parse(strInput, new ParsePosition(0));
- } else {
- java.util.Date inputDate = doParseDate(strInput);
- if (inputDate == null) {
- // will be here if the grammar allows invalid dates
- // example: 02292007
- setErrorCode(ERR_INVALID_DATE);
- }
- return inputDate;
- }
- }
- } // end canonicalize()
-
- /**
- * Validates the received input against the validation constraints
- *
- * @return True if valid, False if invalid
- */
- protected Boolean validate(Object newValue, boolean setErrorCode) {
-
- java.util.Date newDate = (java.util.Date) newValue;
- if (minDate != null && newDate.before(minDate)) {
- if (setErrorCode) setErrorCode(ERR_NEED_LATER_DATE);
- return Boolean.FALSE;
- }
- if (maxDate != null && newDate.after(maxDate)) {
- if (setErrorCode) setErrorCode(ERR_NEED_EARLIER_DATE);
- return Boolean.FALSE;
- }
- return Boolean.TRUE;
- } // end customValidate()
-
- /**
- * Builds a date string to be used for normalized output
- * For e.g., 07082004 gets converted to July 8, 2004
- *
- * @return The date string for date
- */
- protected String calculateCanonicalizedValue(Object newValue) {
- String format = "";
- if (newValue == null) {
- return format;
- }
- int nMMPos = format.indexOf("MM");
- int nDDPos = format.indexOf("dd");
- int nYYPos = format.indexOf("yy");
- if (nMMPos >= 0) {
- format = "MMMM";
- }
- if (nDDPos >= 0) {
- format = format + (format.length() > 0 ? " d" : "d");
- }
- if (nYYPos >= 0) {
- format = format + (format.length() > 0 ? ", " : "") + "yyyy";
- }
- SimpleDateFormat df = new SimpleDateFormat(format);
- return df.format((java.util.Date) newValue);
- }
-
- /**
- * Sets dates that are partially specified like 06xxxxxx (6 months from today).
- *
- * @param date The partial date
- * @return A date string from a partially specified date string (conforming
- * to format)
- */
- private java.util.Date doOffsetDate(String strDate) {
- int nMMPos = format.indexOf("MM");
- int nDDPos = format.indexOf("dd");
- int nYYPos = format.indexOf("yy");
- int nYYYYPos = format.indexOf("yyyy");
-
- String mm = "xx";
- String dd = "xx";
- String yyyy = "xxxx";
-
- if (nMMPos >= 0) {
- mm = strDate.substring(nMMPos, nMMPos + 2);
- }
- if (nDDPos >= 0) {
- dd = strDate.substring(nDDPos, nDDPos + 2);
- }
- if (nYYYYPos >= 0) {
- yyyy = strDate.substring(nYYYYPos, nYYYYPos + 4);
- } else if (nYYPos >= 0) {
- yyyy = strDate.substring(nYYPos, nYYPos + 2);
- }
-
- Calendar thisDay = new GregorianCalendar();
- if (!mm.equals("xx")) {
- thisDay.add(Calendar.MONTH, Integer.parseInt(mm));
- }
- if (!dd.equals("xx")) {
- thisDay.add(Calendar.DATE, Integer.parseInt(dd));
- }
- if (!(yyyy.equals("xxxx") || yyyy.equals("xx"))) {
- thisDay.add(Calendar.YEAR, Integer.parseInt(yyyy));
- }
- return thisDay.getTime();
- } // end doOffsetDate()
-
- /**
- * Parses a date like 0806????, 06042004, etc. to produce a date object
- *
- * @param date The date string (MMddyyyy)
- * @return Date The Date object
- */
- private java.util.Date doParseDate(String strDate) {
-
- String mm = strDate.substring(0, 2);
- String dd = strDate.substring(2, 4);
- String yyyy = strDate.substring(4, 8);
-
- Calendar today = new GregorianCalendar();
- if ("????".equals(yyyy)) {
- yyyy = String.valueOf(today.get(Calendar.YEAR));
- }
- if ("??".equals(mm)) {
- mm = String.valueOf(today.get(Calendar.MONTH));
- }
- if ("??".equals(dd)) {
- dd = String.valueOf(today.get(Calendar.DATE));
- }
- SimpleDateFormat df = new SimpleDateFormat("MMddyyyy");
- df.setLenient(false);
- return df.parse(mm + dd + yyyy, new ParsePosition(0));
- } // end doParseDate()
+ // The date RDC will be associated with the date input, the maximum and
+ // minimum dates within which the date input must lie, and a date format to
+ // which the date input must conform.
+
+ // Date returned must conform to this format
+ private String format;
+ // Date returned cannot be beyond this date
+ private java.util.Date maxDate;
+ // Date returned cannot be before this date
+ private java.util.Date minDate;
+
+ // formatter for the date strings and objects
+ private SimpleDateFormat formatter;
+
+ // Error codes, corresponding prompts defined in configuration file
+ /**A constant for Error Code stating Invalid date*/
+ public static final int ERR_INVALID_DATE = 1;
+
+ /**A constant for Error Code stating the date entered is earlier
+ * than allowed */
+ public static final int ERR_NEED_LATER_DATE = 2;
+
+ /**A constant for Error Code stating the date entered is later
+ * than allowed */
+ public static final int ERR_NEED_EARLIER_DATE = 3;
+
+ /**
+ * Sets default values for all data members
+ */
+ public Date() {
+ super();
+ this.minDate = null;
+ this.maxDate = null;
+
+ // MM - month, dd - day of month, yyyy - year
+ // not using mm (lowercase), because it represents minutes in DateFormat
+ this.format = "MMddyyyy";
+ this.formatter = new SimpleDateFormat(format);
+ this.formatter.setLenient(false);
+ } // end Date constructor
+
+ /**
+ * Sets the date string format to use for vaidation
+ *
+ * @param strDateFormat The date format string
+ */
+ public void setFormat(String strDateFormat) {
+ if (strDateFormat != null) {
+ try {
+ formatter.applyPattern(strDateFormat);
+ this.format = strDateFormat;
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException("format attribute of \"" +
+ getId() + "\" date tag is invalid.");
+ }
+ }
+ } // end setFormat()
+
+ /**
+ * Sets the Maximum Date value
+ *
+ * @param strMaxDate The Maximum Date value (conforms to format)
+ */
+ public void setMaxDate(String strMaxDate) {
+ if (strMaxDate != null) {
+ this.maxDate = (java.util.Date)canonicalize(strMaxDate, true);
+ }
+ } // end setMaxDate()
+
+ /**
+ * Gets the Maximum Date value
+ *
+ * @return The Maximum Date value
+ */
+ public String getMaxDate() {
+ return calculateCanonicalizedValue(maxDate);
+ } // end getMaxDate()
+
+ /**
+ * Sets the Minimum Date value
+ *
+ * @param strMinDate The Minimum Date value (conforms to format)
+ */
+ public void setMinDate(String strMinDate) {
+ if (strMinDate != null) {
+ this.minDate = (java.util.Date)canonicalize(strMinDate, true);
+ }
+ } // end setMinDate()
+
+ /**
+ * Gets the Minimum Date value
+ *
+ * @return The Minimum Date value
+ */
+ public String getMinDate() {
+ return calculateCanonicalizedValue(minDate);
+ } // end getMinDate()
+
+ /**
+ * Get the date currently associated with this date component as a string
+ * in the specified format.
+ *
+ * @return value the value as a string
+ */
+ public Object getValue() {
+ if (this.value == null) {
+ return null;
+ }
+ return formatter.format((java.util.Date) this.value);
+ }
+
+ /**
+ * Sets up the date string, converting phrases of today and tomorrow
+ * into valid dates followed by the format filter
+ *
+ * @param strInput The date input string
+ * @return The value of date (conforming to format)
+ */
+ protected Object canonicalize(Object input, boolean isAttribute) {
+ if (input == null) {
+ return null;
+ }
+ Calendar thisDay = new GregorianCalendar();
+ String strInput = (String) input;
+ if ("today".equalsIgnoreCase(strInput)) {
+ return thisDay.getTime();
+ } else if ("tomorrow".equalsIgnoreCase(strInput)) {
+ thisDay.add(Calendar.DATE, 1);
+ return thisDay.getTime();
+ } else if ("yesterday".equalsIgnoreCase(strInput)) {
+ thisDay.add(Calendar.DATE, -1);
+ return thisDay.getTime();
+ } else {
+ if (isAttribute) {
+ if (strInput.toLowerCase().indexOf('x') >= 0) {
+ return doOffsetDate(strInput);
+ }
+ return formatter.parse(strInput, new ParsePosition(0));
+ } else {
+ java.util.Date inputDate = doParseDate(strInput);
+ if (inputDate == null) {
+ // will be here if the grammar allows invalid dates
+ // example: 02292007
+ setErrorCode(ERR_INVALID_DATE);
+ }
+ return inputDate;
+ }
+ }
+ } // end canonicalize()
+
+ /**
+ * Validates the received input against the validation constraints
+ *
+ * @return True if valid, False if invalid
+ */
+ protected Boolean validate(Object newValue, boolean setErrorCode) {
+
+ java.util.Date newDate = (java.util.Date) newValue;
+ if (minDate != null && newDate.before(minDate)) {
+ if (setErrorCode) setErrorCode(ERR_NEED_LATER_DATE);
+ return Boolean.FALSE;
+ }
+ if (maxDate != null && newDate.after(maxDate)) {
+ if (setErrorCode) setErrorCode(ERR_NEED_EARLIER_DATE);
+ return Boolean.FALSE;
+ }
+ return Boolean.TRUE;
+ } // end customValidate()
+
+ /**
+ * Builds a date string to be used for normalized output
+ * For e.g., 07082004 gets converted to July 8, 2004
+ *
+ * @return The date string for date
+ */
+ protected String calculateCanonicalizedValue(Object newValue) {
+ String format = "";
+ if (newValue == null) {
+ return format;
+ }
+ int nMMPos = format.indexOf("MM");
+ int nDDPos = format.indexOf("dd");
+ int nYYPos = format.indexOf("yy");
+ if (nMMPos >= 0) {
+ format = "MMMM";
+ }
+ if (nDDPos >= 0) {
+ format = format + (format.length() > 0 ? " d" : "d");
+ }
+ if (nYYPos >= 0) {
+ format = format + (format.length() > 0 ? ", " : "") + "yyyy";
+ }
+ SimpleDateFormat df = new SimpleDateFormat(format);
+ return df.format((java.util.Date) newValue);
+ }
+
+ /**
+ * Sets dates that are partially specified like 06xxxxxx (6 months from today).
+ *
+ * @param date The partial date
+ * @return A date string from a partially specified date string (conforming
+ * to format)
+ */
+ private java.util.Date doOffsetDate(String strDate) {
+ int nMMPos = format.indexOf("MM");
+ int nDDPos = format.indexOf("dd");
+ int nYYPos = format.indexOf("yy");
+ int nYYYYPos = format.indexOf("yyyy");
+
+ String mm = "xx";
+ String dd = "xx";
+ String yyyy = "xxxx";
+
+ if (nMMPos >= 0) {
+ mm = strDate.substring(nMMPos, nMMPos + 2);
+ }
+ if (nDDPos >= 0) {
+ dd = strDate.substring(nDDPos, nDDPos + 2);
+ }
+ if (nYYYYPos >= 0) {
+ yyyy = strDate.substring(nYYYYPos, nYYYYPos + 4);
+ } else if (nYYPos >= 0) {
+ yyyy = strDate.substring(nYYPos, nYYPos + 2);
+ }
+
+ Calendar thisDay = new GregorianCalendar();
+ if (!mm.equals("xx")) {
+ thisDay.add(Calendar.MONTH, Integer.parseInt(mm));
+ }
+ if (!dd.equals("xx")) {
+ thisDay.add(Calendar.DATE, Integer.parseInt(dd));
+ }
+ if (!(yyyy.equals("xxxx") || yyyy.equals("xx"))) {
+ thisDay.add(Calendar.YEAR, Integer.parseInt(yyyy));
+ }
+ return thisDay.getTime();
+ } // end doOffsetDate()
+
+ /**
+ * Parses a date like 0806????, 06042004, etc. to produce a date object
+ *
+ * @param date The date string (MMddyyyy)
+ * @return Date The Date object
+ */
+ private java.util.Date doParseDate(String strDate) {
+
+ String mm = strDate.substring(0, 2);
+ String dd = strDate.substring(2, 4);
+ String yyyy = strDate.substring(4, 8);
+
+ Calendar today = new GregorianCalendar();
+ if ("????".equals(yyyy)) {
+ yyyy = String.valueOf(today.get(Calendar.YEAR));
+ }
+ if ("??".equals(mm)) {
+ mm = String.valueOf(today.get(Calendar.MONTH));
+ }
+ if ("??".equals(dd)) {
+ dd = String.valueOf(today.get(Calendar.DATE));
+ }
+ SimpleDateFormat df = new SimpleDateFormat("MMddyyyy");
+ df.setLenient(false);
+ return df.parse(mm + dd + yyyy, new ParsePosition(0));
+ } // end doParseDate()
} // end class Date{}
Modified: jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/DateRange.java
URL: http://svn.apache.org/viewcvs/jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/DateRange.java?rev=231329&r1=231328&r2=231329&view=diff
==============================================================================
--- jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/DateRange.java (original)
+++ jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/DateRange.java Wed Aug 10 14:10:59 2005
@@ -28,18 +28,18 @@
*/
public class DateRange extends ComponentModel
{
- public DateRange()
- {
- super();
- }
-
- /**
- * Stores the id and file attributes from the config xml to the configMap
- *
- * @see ComponentModel#configHandler()
- */
- public void configHandler()
- {
- this.configMap = RDCUtils.configHandler(this.config, (PageContext) this.context);
- }
+ public DateRange()
+ {
+ super();
+ }
+
+ /**
+ * Stores the id and file attributes from the config xml to the configMap
+ *
+ * @see ComponentModel#configHandler()
+ */
+ public void configHandler()
+ {
+ this.configMap = RDCUtils.configHandler(this.config, (PageContext) this.context);
+ }
}
Modified: jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/DateRangeData.java
URL: http://svn.apache.org/viewcvs/jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/DateRangeData.java?rev=231329&r1=231328&r2=231329&view=diff
==============================================================================
--- jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/DateRangeData.java (original)
+++ jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/DateRangeData.java Wed Aug 10 14:10:59 2005
@@ -26,64 +26,64 @@
*/
public class DateRangeData implements Serializable
{
- // Start and end dates
- private String startDate;
- private String endDate;
+ // Start and end dates
+ private String startDate;
+ private String endDate;
- public DateRangeData()
- {
- this.startDate = null;
- this.endDate = null;
- }
-
- /**
- * Gets the start date
- *
- * @return Returns the start date.
- */
- public String getStartDate()
- {
- return startDate;
- }
-
- /**
- * Gets the end date
- *
- * @return Returns the end date.
- */
- public String getEndDate()
- {
- return endDate;
- }
+ public DateRangeData()
+ {
+ this.startDate = null;
+ this.endDate = null;
+ }
+
+ /**
+ * Gets the start date
+ *
+ * @return Returns the start date.
+ */
+ public String getStartDate()
+ {
+ return startDate;
+ }
+
+ /**
+ * Gets the end date
+ *
+ * @return Returns the end date.
+ */
+ public String getEndDate()
+ {
+ return endDate;
+ }
- /**
- * Sets the start date
- *
- * @param startDate The start date to set.
- */
- public void setStartDate(String startDate)
- {
- this.startDate = startDate;
- }
+ /**
+ * Sets the start date
+ *
+ * @param startDate The start date to set.
+ */
+ public void setStartDate(String startDate)
+ {
+ this.startDate = startDate;
+ }
- /**
- * Sets the ending date
- *
- * @param endDate The ending to set.
- */
- public void setEndDate(String endDate)
- {
- this.endDate = endDate;
- }
-
- /**
- * A serialized version of the DateRangeData object
- */
- public String toString()
- {
- StringBuffer buf = new StringBuffer();
- buf.append("startDate=").append(startDate).
- append(";endDate=").append(endDate);
- return buf.toString();
- }
+ /**
+ * Sets the ending date
+ *
+ * @param endDate The ending to set.
+ */
+ public void setEndDate(String endDate)
+ {
+ this.endDate = endDate;
+ }
+
+ /**
+ * A serialized version of the DateRangeData object
+ */
+ public String toString()
+ {
+ StringBuffer buf = new StringBuffer();
+ buf.append("startDate=").append(startDate).
+ append(";endDate=").append(endDate);
+ return buf.toString();
+ }
}
Modified: jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Digits.java
URL: http://svn.apache.org/viewcvs/jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Digits.java?rev=231329&r1=231328&r2=231329&view=diff
==============================================================================
--- jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Digits.java (original)
+++ jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Digits.java Wed Aug 10 14:10:59 2005
@@ -34,144 +34,144 @@
*/
public class Digits extends BaseModel {
- // The digits RDC will be associated with the digits,
- // the maximum and minimum length within
- // which the input's length must lie, and a pattern to which
- // the input must conform.
-
- // Maximum allowed length of the input; -1 indicates
- // no constraint on maximum length
- private int minLength;
- // Minimum allowed length of the input; -1 indicates
- // no constraint on minimum length
- private int maxLength;
- // The digits input must conform to this pattern
- private String pattern;
-
- // Error codes, defined in configuration file
- /**A constant for Error Code stating Invalid digit */
- public static final int ERR_INVALID_DIGIT = 1;
-
- /**A constant for Error Code stating the digit entered is
- * larger than allowed */
- public static final int ERR_NEED_SHORTER_DIGIT = 2;
-
- /**A constant for Error Code stating the digit entered is
- * smaller than allowed */
- public static final int ERR_NEED_LONGER_DIGIT = 3;
-
- /**
- * Sets default values for all data members
- */
- public Digits() {
- super();
- this.minLength = -1;
- this.maxLength = -1;
- // Default pattern allows any combination of digits
- this.pattern = "[0-9]*";
- }
-
- /**
- * Gets the maximum allowed length of input
- *
- * @return the maximum allowed length of input
- */
- public String getMaxLength() {
- return String.valueOf(maxLength);
- }
-
- /**
- * Sets the maximum allowed length of digit
- *
- * @param maxLength the maximum allowed length of digit
- */
- public void setMaxLength(String maxLength) {
- if (maxLength != null) {
- try {
- this.maxLength = Integer.parseInt(maxLength);
- } catch (NumberFormatException e) {
- throw new IllegalArgumentException("maxLength attribute " +
- "of \"" + getId() + "\" digit tag is not a number.");
- }
- }
- }
-
- /**
- * Gets the minimum allowed length of input
- *
- * @return the minimum allowed length of input
- */
- public String getMinLength() {
- return String.valueOf(minLength);
- }
-
- /**
- * Sets the minimum allowed length of input
- *
- * @param minLength the minimum allowed length of input
- */
- public void setMinLength(String minLength) {
- if (minLength != null) {
- try {
- this.minLength = Integer.parseInt(minLength);
- } catch (NumberFormatException e) {
- throw new IllegalArgumentException("minLength attribute " +
- "of \"" + getId() + "\" digit tag is not a number.");
- }
- }
- }
-
- /**
- * Gets the pattern string
- *
- * @return the pattern string
- */
- public String getPattern() {
- return this.pattern;
- }
-
- /**
- * Sets the pattern string to which the input must conform
- *
- * @param pattern the pattern string to which the input must conform
- */
- public void setPattern(String pattern) {
- if (pattern != null) {
- try {
- Pattern.compile(pattern);
- this.pattern = pattern;
- } catch (PatternSyntaxException e) {
- throw new IllegalArgumentException( "pattern attribute " +
- "of \"" + getId() + "\" digit tag not in proper format.");
- }
- }
- }
-
- /**
- * Validates the input against the given constraints
- *
- * @return TRUE if valid, FALSE otherwise
- */
- protected Boolean validate(Object newValue, boolean setErrorCode) {
-
- if (pattern != null) {
- if (!(Pattern.matches(pattern, (String) newValue))) {
- if (setErrorCode) setErrorCode(ERR_INVALID_DIGIT);
- return Boolean.FALSE;
- }
- }
- if (maxLength > 0) {
- if (((String) newValue).length() > maxLength) {
- if (setErrorCode) setErrorCode(ERR_NEED_SHORTER_DIGIT);
- return Boolean.FALSE;
- }
- }
- if (minLength > 0) {
- if (((String) newValue).length() < minLength) {
- if (setErrorCode) setErrorCode(ERR_NEED_LONGER_DIGIT);
- return Boolean.FALSE;
- }
- }
- return Boolean.TRUE;
- }
+ // The digits RDC will be associated with the digits,
+ // the maximum and minimum length within
+ // which the input's length must lie, and a pattern to which
+ // the input must conform.
+
+ // Maximum allowed length of the input; -1 indicates
+ // no constraint on maximum length
+ private int minLength;
+ // Minimum allowed length of the input; -1 indicates
+ // no constraint on minimum length
+ private int maxLength;
+ // The digits input must conform to this pattern
+ private String pattern;
+
+ // Error codes, defined in configuration file
+ /**A constant for Error Code stating Invalid digit */
+ public static final int ERR_INVALID_DIGIT = 1;
+
+ /**A constant for Error Code stating the digit entered is
+ * larger than allowed */
+ public static final int ERR_NEED_SHORTER_DIGIT = 2;
+
+ /**A constant for Error Code stating the digit entered is
+ * smaller than allowed */
+ public static final int ERR_NEED_LONGER_DIGIT = 3;
+
+ /**
+ * Sets default values for all data members
+ */
+ public Digits() {
+ super();
+ this.minLength = -1;
+ this.maxLength = -1;
+ // Default pattern allows any combination of digits
+ this.pattern = "[0-9]*";
+ }
+
+ /**
+ * Gets the maximum allowed length of input
+ *
+ * @return the maximum allowed length of input
+ */
+ public String getMaxLength() {
+ return String.valueOf(maxLength);
+ }
+
+ /**
+ * Sets the maximum allowed length of digit
+ *
+ * @param maxLength the maximum allowed length of digit
+ */
+ public void setMaxLength(String maxLength) {
+ if (maxLength != null) {
+ try {
+ this.maxLength = Integer.parseInt(maxLength);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("maxLength attribute " +
+ "of \"" + getId() + "\" digit tag is not a number.");
+ }
+ }
+ }
+
+ /**
+ * Gets the minimum allowed length of input
+ *
+ * @return the minimum allowed length of input
+ */
+ public String getMinLength() {
+ return String.valueOf(minLength);
+ }
+
+ /**
+ * Sets the minimum allowed length of input
+ *
+ * @param minLength the minimum allowed length of input
+ */
+ public void setMinLength(String minLength) {
+ if (minLength != null) {
+ try {
+ this.minLength = Integer.parseInt(minLength);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("minLength attribute " +
+ "of \"" + getId() + "\" digit tag is not a number.");
+ }
+ }
+ }
+
+ /**
+ * Gets the pattern string
+ *
+ * @return the pattern string
+ */
+ public String getPattern() {
+ return this.pattern;
+ }
+
+ /**
+ * Sets the pattern string to which the input must conform
+ *
+ * @param pattern the pattern string to which the input must conform
+ */
+ public void setPattern(String pattern) {
+ if (pattern != null) {
+ try {
+ Pattern.compile(pattern);
+ this.pattern = pattern;
+ } catch (PatternSyntaxException e) {
+ throw new IllegalArgumentException( "pattern attribute " +
+ "of \"" + getId() + "\" digit tag not in proper format.");
+ }
+ }
+ }
+
+ /**
+ * Validates the input against the given constraints
+ *
+ * @return TRUE if valid, FALSE otherwise
+ */
+ protected Boolean validate(Object newValue, boolean setErrorCode) {
+
+ if (pattern != null) {
+ if (!(Pattern.matches(pattern, (String) newValue))) {
+ if (setErrorCode) setErrorCode(ERR_INVALID_DIGIT);
+ return Boolean.FALSE;
+ }
+ }
+ if (maxLength > 0) {
+ if (((String) newValue).length() > maxLength) {
+ if (setErrorCode) setErrorCode(ERR_NEED_SHORTER_DIGIT);
+ return Boolean.FALSE;
+ }
+ }
+ if (minLength > 0) {
+ if (((String) newValue).length() < minLength) {
+ if (setErrorCode) setErrorCode(ERR_NEED_LONGER_DIGIT);
+ return Boolean.FALSE;
+ }
+ }
+ return Boolean.TRUE;
+ }
}
Modified: jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Duration.java
URL: http://svn.apache.org/viewcvs/jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Duration.java?rev=231329&r1=231328&r2=231329&view=diff
==============================================================================
--- jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Duration.java (original)
+++ jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Duration.java Wed Aug 10 14:10:59 2005
@@ -33,203 +33,203 @@
*/
public class Duration extends BaseModel {
- //The duration RDC will be associated
- //with the duration input, the maximum and minimum
- //duration within which the input's duration must lie, and a pattern to
- //which the input must conform.
-
- // value returned cannot be more than this value
- private String maxDuration;
- // value returned cannot be less than this value
- private String minDuration;
- // The duration input must conform to this pattern
- private String pattern;
-
- //Error codes defined in the configuration file
- /**A constant for Error Code stating Invalid duration */
- public static final int ERR_INVALID_DURATION = 1;
-
- /**A constant for Error Code stating the duration entered is
- * larger than allowed */
- public static final int ERR_NEED_LOWER_VALUE = 2;
-
- /**A constant for Error Code stating the duration entered is
- * smaller than allowed */
- public static final int ERR_NEED_HIGHER_VALUE = 3;
-
- //this constant that checks whether one value is less than the other
- private static final int LESS = -1;
- //this constant constant checks whether two values are equal
- private static final int EQUAL = 0;
- //this constant checks whether one value is more than the other
- private static final int MORE = 1;
-
- /**
- * Sets default values for all data members
- */
- public Duration() {
- super();
- maxDuration = null;
- minDuration = null;
- this.pattern = "P([0-9]{2}Y)?([0-9]{2}M)?([0-9]{2}D)?";
- }
-
- /**
- * Gets the maximum Duration that a user has specified in the attirbute
- * @return the user specified maximum duration
- */
- public String getMaxDuration() {
- return maxDuration;
- }
-
- /**
- * Sets the maximum Duration value.
- * @param maxDuration The maximum duration value.
- */
- public void setMaxDuration(String maxDuration) {
- if (maxDuration != null) {
- this.maxDuration = (String)canonicalize(maxDuration, true);
- }
- }
-
- /**
- * Gets what minimum duration that a user has specified in the attirbute
- * @return the user specified minimum duration
- */
- public String getMinDuration() {
- return minDuration;
- }
-
- /**
- * Sets the minimum duration value.
- * @param minDuration The minimum duration value.
- */
- public void setMinDuration(String minDuration) {
- if (minDuration != null) {
- this.minDuration = (String)canonicalize(minDuration, true);
- }
- }
-
- /**
- * Validates the received input against the validation constraints
- * @return true if valid, false if invalid
- */
- protected Boolean validate(Object newValue, boolean setErrorCode) {
-
- if (pattern != null && !(Pattern.matches(pattern, (String)newValue))) {
- if (setErrorCode) setErrorCode(ERR_INVALID_DURATION);
- return Boolean.FALSE;
- }
- if (cmpDuration((String) newValue, minDuration) == LESS) {
- if (setErrorCode) setErrorCode(ERR_NEED_HIGHER_VALUE);
- return Boolean.FALSE;
- } else if (cmpDuration((String) newValue, maxDuration) == MORE) {
- if (setErrorCode) setErrorCode(ERR_NEED_LOWER_VALUE);
- return Boolean.FALSE;
- }
- return Boolean.TRUE;
- }
-
- /**
- * This method returns the full duration format if either partial
- * duration is spoken or retuns full duration if input is
- * full duration
- *
- * @param input The duration value(either partial or full)
- * @return The full duration format
- */
- protected Object canonicalize(Object input, boolean isAttribute) {
- if (input == null) {
- return null;
- }
- String inputStr = (String) input;
- int INDEX_YEAR_END = inputStr.indexOf('Y');
- int INDEX_MONTH_END = inputStr.indexOf('M');
- int INDEX_DAY_END = inputStr.indexOf('D');
-
- if (!(Pattern.matches(pattern, inputStr))) {
- if (isAttribute) {
- throw new IllegalArgumentException("The required value \"" +
- inputStr + "\" does not match the expected pattern for " +
- "duration RDC with ID " + getId());
- } else {
- setErrorCode(ERR_INVALID_DURATION);
- return null;
- }
- } else {
- if (INDEX_YEAR_END == -1) {
- inputStr = "P00Y" + (inputStr.length() > 1 ?
- inputStr.substring(1) : "");
- }
- if (INDEX_DAY_END == -1) {
- inputStr += "00D";
- }
- if (INDEX_MONTH_END == -1) {
- inputStr = inputStr.substring(0,inputStr.indexOf('Y')) + "Y00M"
- + inputStr.substring(inputStr.indexOf('Y')+1);
- }
- }
- return inputStr;
- }
-
- /**
- * This method compares the minimum and maximu durations
- * against the input and returns LESS,MORE or EQUAL accordingly
- *
- * @param s1 the duration value
- * @param s2 could be minimum and maximum durations
- *
- * @return could be LESS,MORE or EQUAL
- */
- private int cmpDuration(String s1, String s2) {
- int INDEX_YEAR_END = s1.indexOf('Y');
- int INDEX_MONTH_END = s1.indexOf('M');
- int INDEX_DAY_END = s1.indexOf('D');
- int INDEX_YEAR_BEGIN = s1.indexOf('P') + 1;
- int INDEX_MONTH_BEGIN = INDEX_MONTH_END - 2;
- int INDEX_DAY_BEGIN = INDEX_DAY_END - 2;
-
- switch (cmp(Integer.parseInt(s1.substring(INDEX_YEAR_BEGIN,
- INDEX_YEAR_END)), Integer.parseInt(s2.substring(INDEX_YEAR_BEGIN,
- INDEX_YEAR_END)))) {
- case LESS :
- return LESS;
- case MORE :
- return MORE;
- case EQUAL :
- switch (cmp(Integer.parseInt(s1.substring(INDEX_MONTH_BEGIN,
- INDEX_MONTH_END)), Integer.parseInt(s2.
- substring(INDEX_MONTH_BEGIN, INDEX_MONTH_END)))) {
- case LESS :
- return LESS;
- case MORE :
- return MORE;
- case EQUAL :
- switch (cmp(Integer.parseInt(s1.
- substring(INDEX_DAY_BEGIN, INDEX_DAY_END)),
- Integer.parseInt(s2.substring(INDEX_DAY_BEGIN,
- INDEX_DAY_END)))) {
- case LESS :
- return LESS;
- case MORE :
- return MORE;
- }
- }
- }
- return EQUAL;
- }
-
- /**
- * Compares the minimum and maximum durations
- * against the duration input and returns LESS,MORE or
- * EQUAL accordingly
- *
- * @param a the duration value
- * @param b could be minimum and maximum durations
- * @return could be LESS,MORE or EQUAL
- */
- private int cmp(int a, int b) {
- return a < b ? LESS : a > b ? MORE : EQUAL;
- }
+ //The duration RDC will be associated
+ //with the duration input, the maximum and minimum
+ //duration within which the input's duration must lie, and a pattern to
+ //which the input must conform.
+
+ // value returned cannot be more than this value
+ private String maxDuration;
+ // value returned cannot be less than this value
+ private String minDuration;
+ // The duration input must conform to this pattern
+ private String pattern;
+
+ //Error codes defined in the configuration file
+ /**A constant for Error Code stating Invalid duration */
+ public static final int ERR_INVALID_DURATION = 1;
+
+ /**A constant for Error Code stating the duration entered is
+ * larger than allowed */
+ public static final int ERR_NEED_LOWER_VALUE = 2;
+
+ /**A constant for Error Code stating the duration entered is
+ * smaller than allowed */
+ public static final int ERR_NEED_HIGHER_VALUE = 3;
+
+ //this constant that checks whether one value is less than the other
+ private static final int LESS = -1;
+ //this constant constant checks whether two values are equal
+ private static final int EQUAL = 0;
+ //this constant checks whether one value is more than the other
+ private static final int MORE = 1;
+
+ /**
+ * Sets default values for all data members
+ */
+ public Duration() {
+ super();
+ maxDuration = null;
+ minDuration = null;
+ this.pattern = "P([0-9]{2}Y)?([0-9]{2}M)?([0-9]{2}D)?";
+ }
+
+ /**
+ * Gets the maximum Duration that a user has specified in the attirbute
+ * @return the user specified maximum duration
+ */
+ public String getMaxDuration() {
+ return maxDuration;
+ }
+
+ /**
+ * Sets the maximum Duration value.
+ * @param maxDuration The maximum duration value.
+ */
+ public void setMaxDuration(String maxDuration) {
+ if (maxDuration != null) {
+ this.maxDuration = (String)canonicalize(maxDuration, true);
+ }
+ }
+
+ /**
+ * Gets what minimum duration that a user has specified in the attirbute
+ * @return the user specified minimum duration
+ */
+ public String getMinDuration() {
+ return minDuration;
+ }
+
+ /**
+ * Sets the minimum duration value.
+ * @param minDuration The minimum duration value.
+ */
+ public void setMinDuration(String minDuration) {
+ if (minDuration != null) {
+ this.minDuration = (String)canonicalize(minDuration, true);
+ }
+ }
+
+ /**
+ * Validates the received input against the validation constraints
+ * @return true if valid, false if invalid
+ */
+ protected Boolean validate(Object newValue, boolean setErrorCode) {
+
+ if (pattern != null && !(Pattern.matches(pattern, (String)newValue))) {
+ if (setErrorCode) setErrorCode(ERR_INVALID_DURATION);
+ return Boolean.FALSE;
+ }
+ if (cmpDuration((String) newValue, minDuration) == LESS) {
+ if (setErrorCode) setErrorCode(ERR_NEED_HIGHER_VALUE);
+ return Boolean.FALSE;
+ } else if (cmpDuration((String) newValue, maxDuration) == MORE) {
+ if (setErrorCode) setErrorCode(ERR_NEED_LOWER_VALUE);
+ return Boolean.FALSE;
+ }
+ return Boolean.TRUE;
+ }
+
+ /**
+ * This method returns the full duration format if either partial
+ * duration is spoken or retuns full duration if input is
+ * full duration
+ *
+ * @param input The duration value(either partial or full)
+ * @return The full duration format
+ */
+ protected Object canonicalize(Object input, boolean isAttribute) {
+ if (input == null) {
+ return null;
+ }
+ String inputStr = (String) input;
+ int INDEX_YEAR_END = inputStr.indexOf('Y');
+ int INDEX_MONTH_END = inputStr.indexOf('M');
+ int INDEX_DAY_END = inputStr.indexOf('D');
+
+ if (!(Pattern.matches(pattern, inputStr))) {
+ if (isAttribute) {
+ throw new IllegalArgumentException("The required value \"" +
+ inputStr + "\" does not match the expected pattern for " +
+ "duration RDC with ID " + getId());
+ } else {
+ setErrorCode(ERR_INVALID_DURATION);
+ return null;
+ }
+ } else {
+ if (INDEX_YEAR_END == -1) {
+ inputStr = "P00Y" + (inputStr.length() > 1 ?
+ inputStr.substring(1) : "");
+ }
+ if (INDEX_DAY_END == -1) {
+ inputStr += "00D";
+ }
+ if (INDEX_MONTH_END == -1) {
+ inputStr = inputStr.substring(0,inputStr.indexOf('Y')) + "Y00M"
+ + inputStr.substring(inputStr.indexOf('Y')+1);
+ }
+ }
+ return inputStr;
+ }
+
+ /**
+ * This method compares the minimum and maximu durations
+ * against the input and returns LESS,MORE or EQUAL accordingly
+ *
+ * @param s1 the duration value
+ * @param s2 could be minimum and maximum durations
+ *
+ * @return could be LESS,MORE or EQUAL
+ */
+ private int cmpDuration(String s1, String s2) {
+ int INDEX_YEAR_END = s1.indexOf('Y');
+ int INDEX_MONTH_END = s1.indexOf('M');
+ int INDEX_DAY_END = s1.indexOf('D');
+ int INDEX_YEAR_BEGIN = s1.indexOf('P') + 1;
+ int INDEX_MONTH_BEGIN = INDEX_MONTH_END - 2;
+ int INDEX_DAY_BEGIN = INDEX_DAY_END - 2;
+
+ switch (cmp(Integer.parseInt(s1.substring(INDEX_YEAR_BEGIN,
+ INDEX_YEAR_END)), Integer.parseInt(s2.substring(INDEX_YEAR_BEGIN,
+ INDEX_YEAR_END)))) {
+ case LESS :
+ return LESS;
+ case MORE :
+ return MORE;
+ case EQUAL :
+ switch (cmp(Integer.parseInt(s1.substring(INDEX_MONTH_BEGIN,
+ INDEX_MONTH_END)), Integer.parseInt(s2.
+ substring(INDEX_MONTH_BEGIN, INDEX_MONTH_END)))) {
+ case LESS :
+ return LESS;
+ case MORE :
+ return MORE;
+ case EQUAL :
+ switch (cmp(Integer.parseInt(s1.
+ substring(INDEX_DAY_BEGIN, INDEX_DAY_END)),
+ Integer.parseInt(s2.substring(INDEX_DAY_BEGIN,
+ INDEX_DAY_END)))) {
+ case LESS :
+ return LESS;
+ case MORE :
+ return MORE;
+ }
+ }
+ }
+ return EQUAL;
+ }
+
+ /**
+ * Compares the minimum and maximum durations
+ * against the duration input and returns LESS,MORE or
+ * EQUAL accordingly
+ *
+ * @param a the duration value
+ * @param b could be minimum and maximum durations
+ * @return could be LESS,MORE or EQUAL
+ */
+ private int cmp(int a, int b) {
+ return a < b ? LESS : a > b ? MORE : EQUAL;
+ }
}
Modified: jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/GetConfigElemTag.java
URL: http://svn.apache.org/viewcvs/jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/GetConfigElemTag.java?rev=231329&r1=231328&r2=231329&view=diff
==============================================================================
--- jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/GetConfigElemTag.java (original)
+++ jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/GetConfigElemTag.java Wed Aug 10 14:10:59 2005
@@ -42,72 +42,72 @@
public class GetConfigElemTag
extends SimpleTagSupport {
- // Error messages (to be i18n'zed)
- private static final String ERR_PROCESS_XPATH = "Failed to obtain" +
- " element from configuration file with XPath \"{0}\"";
-
- // Logging
- private static Log log = LogFactory.getLog(GetConfigElemTag.class);
-
- /**
- * Describe xml: Config file as a parsed document
- */
- private Document xml;
-
- /**
- * Describe locator: The XPath expression
- */
- private String locator;
-
- /**
- * Set the xml value.
- *
- * @param xml The parsed config document
- */
- public final void setXml(final Document xml) {
- this.xml = xml;
- }
-
- /**
- * Set the locator value.
- *
- * @param locator The XPath expression
- */
- public final void setLocator(final String locator) {
- this.locator = locator;
- }
+ // Error messages (to be i18n'zed)
+ private static final String ERR_PROCESS_XPATH = "Failed to obtain" +
+ " element from configuration file with XPath \"{0}\"";
+
+ // Logging
+ private static Log log = LogFactory.getLog(GetConfigElemTag.class);
+
+ /**
+ * Describe xml: Config file as a parsed document
+ */
+ private Document xml;
+
+ /**
+ * Describe locator: The XPath expression
+ */
+ private String locator;
+
+ /**
+ * Set the xml value.
+ *
+ * @param xml The parsed config document
+ */
+ public final void setXml(final Document xml) {
+ this.xml = xml;
+ }
+
+ /**
+ * Set the locator value.
+ *
+ * @param locator The XPath expression
+ */
+ public final void setLocator(final String locator) {
+ this.locator = locator;
+ }
- /**
- * Get the element specified by the locator and render to JspWriter
- *
- */
+ /**
+ * Get the element specified by the locator and render to JspWriter
+ *
+ */
public void doTag()
throws IOException, JspException {
- getJspContext().getOut().write(render(xml, locator));
+ getJspContext().getOut().write(render(xml, locator));
}
-
- private static OutputFormat format;
- static {
- format = new OutputFormat();
- format.setOmitXMLDeclaration(true);
- }
+
+ private static OutputFormat format;
+ static {
+ format = new OutputFormat();
+ format.setOmitXMLDeclaration(true);
+ }
- private static String render(Document configuration, String elementXPath) {
- StringWriter out = new StringWriter();
- try {
- NodeList nodesOfInterest = XPathAPI.selectNodeList(configuration.
- getDocumentElement(), elementXPath);
- XMLSerializer output = new XMLSerializer(out, format);
- for (int i = 0; i < nodesOfInterest.getLength(); i++) {
- output.serialize((Element) nodesOfInterest.item(i));
- }
- } catch (Exception e) {
- MessageFormat msgFormat = new MessageFormat(ERR_PROCESS_XPATH);
- log.warn(msgFormat.format(new Object[] {elementXPath}));
- }
- return out.toString();
- }
+ private static String render(Document configuration, String elementXPath) {
+ StringWriter out = new StringWriter();
+ try {
+ NodeList nodesOfInterest = XPathAPI.selectNodeList(configuration.
+ getDocumentElement(), elementXPath);
+ XMLSerializer output = new XMLSerializer(out, format);
+ for (int i = 0; i < nodesOfInterest.getLength(); i++) {
+ output.serialize((Element) nodesOfInterest.item(i));
+ }
+ } catch (Exception e) {
+ MessageFormat msgFormat = new MessageFormat(ERR_PROCESS_XPATH);
+ log.warn(msgFormat.format(new Object[] {elementXPath}));
+ }
+ return out.toString();
+ }
}
Modified: jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/GetDefaultConfigTag.java
URL: http://svn.apache.org/viewcvs/jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/GetDefaultConfigTag.java?rev=231329&r1=231328&r2=231329&view=diff
==============================================================================
--- jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/GetDefaultConfigTag.java (original)
+++ jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/GetDefaultConfigTag.java Wed Aug 10 14:10:59 2005
@@ -45,10 +45,10 @@
*/
private String name;
- /**
- * Describe model: BaseModel of component that needs its default config
- */
- private BaseModel model;
+ /**
+ * Describe model: BaseModel of component that needs its default config
+ */
+ private BaseModel model;
/**
* Get the <code>Name</code> value.
@@ -59,53 +59,53 @@
return name;
}
- /**
- * Set the <code>Name</code> value.
- *
- * @param newName The new Name value.
- */
- public final void setName(final String newName) {
- this.name = newName;
- }
-
- /**
- * Get the <code>BaseModel</code> value.
- *
- * @return a <code>BaseModel</code> value
- */
- public final BaseModel getModel() {
- return model;
- }
+ /**
+ * Set the <code>Name</code> value.
+ *
+ * @param newName The new Name value.
+ */
+ public final void setName(final String newName) {
+ this.name = newName;
+ }
- /**
- * Set the <code>BaseModel</code> value.
- *
- * @param model The new model value.
- */
- public final void setModel(final BaseModel model) {
- this.model = model;
- }
+ /**
+ * Get the <code>BaseModel</code> value.
+ *
+ * @return a <code>BaseModel</code> value
+ */
+ public final BaseModel getModel() {
+ return model;
+ }
+
+ /**
+ * Set the <code>BaseModel</code> value.
+ *
+ * @param model The new model value.
+ */
+ public final void setModel(final BaseModel model) {
+ this.model = model;
+ }
public void doTag()
throws IOException, JspException {
- final String jar = ((PageContext) getJspContext()).
- getServletContext().getRealPath(Constants.RDC_JAR);
- InputSource inputSrc = RDCUtils.extract(jar, name);
+ final String jar = ((PageContext) getJspContext()).
+ getServletContext().getRealPath(Constants.RDC_JAR);
+ InputSource inputSrc = RDCUtils.extract(jar, name);
DOMParser dp = new DOMParser();
try {
dp.parse(inputSrc);
} catch (SAXException sx) {
- throw new IOException("Cannot parse the default config: " + name);
+ throw new IOException("Cannot parse the default config: " + name);
} // end of try-catch
- Document d = dp.getDocument();
+ Document d = dp.getDocument();
if (d == null) {
throw new IOException("Could not get document from located Jar entry.");
} // end of if (d == null)
if (model == null) {
- throw new JspException("Null BaseModel");
+ throw new JspException("Null BaseModel");
} // end of if (model == null)
model.setConfiguration(d);
Modified: jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/GetResourceTag.java
URL: http://svn.apache.org/viewcvs/jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/GetResourceTag.java?rev=231329&r1=231328&r2=231329&view=diff
==============================================================================
--- jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/GetResourceTag.java (original)
+++ jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/GetResourceTag.java Wed Aug 10 14:10:59 2005
@@ -34,74 +34,74 @@
*/
public class GetResourceTag extends SimpleTagSupport {
- /**
- * The ResourceBundle
- */
- private ResourceBundle bundle;
-
- /**
- * The key in which the String resource is stored
- */
- private String key;
-
- /**
- * The variable which will hold the value of the resource
- */
- private String var;
-
- /**
- * Whether the resource is a grammar URI
- */
- private Boolean isGrammarURI;
-
- /**
- * @param bundle The bundle to set.
- */
- public void setBundle(ResourceBundle bundle) {
- this.bundle = bundle;
- }
-
- /**
- * @param key The key to set.
- */
- public void setKey(String key) {
- this.key = key;
- }
-
- /**
- * @param var The var to set.
- */
- public void setVar(String var) {
- this.var = var;
- }
-
- /**
- * @param isGrammarURI The isGrammarURI to set.
- */
- public void setIsGrammarURI(Boolean isGrammarURI) {
- this.isGrammarURI = isGrammarURI;
- }
-
- /**
- * Get the resource and assign it to the variable in the JSP context
- */
+ /**
+ * The ResourceBundle
+ */
+ private ResourceBundle bundle;
+
+ /**
+ * The key in which the String resource is stored
+ */
+ private String key;
+
+ /**
+ * The variable which will hold the value of the resource
+ */
+ private String var;
+
+ /**
+ * Whether the resource is a grammar URI
+ */
+ private Boolean isGrammarURI;
+
+ /**
+ * @param bundle The bundle to set.
+ */
+ public void setBundle(ResourceBundle bundle) {
+ this.bundle = bundle;
+ }
+
+ /**
+ * @param key The key to set.
+ */
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ /**
+ * @param var The var to set.
+ */
+ public void setVar(String var) {
+ this.var = var;
+ }
+
+ /**
+ * @param isGrammarURI The isGrammarURI to set.
+ */
+ public void setIsGrammarURI(Boolean isGrammarURI) {
+ this.isGrammarURI = isGrammarURI;
+ }
+
+ /**
+ * Get the resource and assign it to the variable in the JSP context
+ */
public void doTag()
throws IOException, JspException {
- Object retVal = bundle.getObject(key);
-
- if (isGrammarURI != null && isGrammarURI.booleanValue() &&
- retVal != null && ((String)retVal).startsWith(".grammar/")) {
- // .grammar is a reserved directory for grammar URIs
- // @see GrammarServlet
- StringBuffer buf = new StringBuffer(((HttpServletRequest)
- ((PageContext)getJspContext()).getRequest()).getContextPath());
- buf.append('/').append(retVal);
- retVal = buf.toString();
- }
-
- getJspContext().setAttribute(var, retVal);
+ Object retVal = bundle.getObject(key);
+
+ if (isGrammarURI != null && isGrammarURI.booleanValue() &&
+ retVal != null && ((String)retVal).startsWith(".grammar/")) {
+ // .grammar is a reserved directory for grammar URIs
+ // @see GrammarServlet
+ StringBuffer buf = new StringBuffer(((HttpServletRequest)
+ ((PageContext)getJspContext()).getRequest()).getContextPath());
+ buf.append('/').append(retVal);
+ retVal = buf.toString();
+ }
+
+ getJspContext().setAttribute(var, retVal);
}
-
+
}
Modified: jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/GrammarServlet.java
URL: http://svn.apache.org/viewcvs/jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/GrammarServlet.java?rev=231329&r1=231328&r2=231329&view=diff
==============================================================================
--- jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/GrammarServlet.java (original)
+++ jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/GrammarServlet.java Wed Aug 10 14:10:59 2005
@@ -43,31 +43,31 @@
public class GrammarServlet
extends HttpServlet {
- //// Constants
- // Init params and default values
- private static final String INIT_PARAM_GRAM_DIR = "grammarDirectory";
- private static final String DEFAULT_GRAM_DIR = ".grammar";
-
- private static final String INIT_PARAM_JAR = "jar";
- private static final String DEFAULT_JAR = "/WEB-INF/lib/taglibs-rdc.jar";
-
- // Mimes and extensions
- private static final String MIME_JAVASCRIPT = "application/x-javascript";
- private static final String EXT_JAVASCRIPT = "js";
- private static final String MIME_SRGS_GRAM = "application/srgs+xml";
-
- // Error messages (to be i18n'zed)
- private static final String ERR_NO_SUCH_ENTRY = "Could not locate jar " +
- "entry: \"{0}\" in jar: \"{1}\"";
- private static final String ERR_NO_INPUT_STREAM = "Could not obtain " +
- "input stream from located Jar entry: \"{0}\" in jar: \"{1}\"";
- private static final String ERR_NO_PERMISSION = "Do not have " +
- "permission to access: \"{0}\"";
-
- // Logging
- private static Log log = LogFactory.getLog(GrammarServlet.class);
-
- /* Records name of the jar from which we extract the grammar */
+ //// Constants
+ // Init params and default values
+ private static final String INIT_PARAM_GRAM_DIR = "grammarDirectory";
+ private static final String DEFAULT_GRAM_DIR = ".grammar";
+
+ private static final String INIT_PARAM_JAR = "jar";
+ private static final String DEFAULT_JAR = "/WEB-INF/lib/taglibs-rdc.jar";
+
+ // Mimes and extensions
+ private static final String MIME_JAVASCRIPT = "application/x-javascript";
+ private static final String EXT_JAVASCRIPT = "js";
+ private static final String MIME_SRGS_GRAM = "application/srgs+xml";
+
+ // Error messages (to be i18n'zed)
+ private static final String ERR_NO_SUCH_ENTRY = "Could not locate jar " +
+ "entry: \"{0}\" in jar: \"{1}\"";
+ private static final String ERR_NO_INPUT_STREAM = "Could not obtain " +
+ "input stream from located Jar entry: \"{0}\" in jar: \"{1}\"";
+ private static final String ERR_NO_PERMISSION = "Do not have " +
+ "permission to access: \"{0}\"";
+
+ // Logging
+ private static Log log = LogFactory.getLog(GrammarServlet.class);
+
+ /* Records name of the jar from which we extract the grammar */
private String jar;
/* Name of directory within the jar that holds grammar files */
@@ -106,9 +106,9 @@
public void doGet(HttpServletRequest request,
HttpServletResponse response)
- throws ServletException, IOException {
- MessageFormat msgFormat;
- String errMsg;
+ throws ServletException, IOException {
+ MessageFormat msgFormat;
+ String errMsg;
try {
JarFile j = new JarFile (jar);
// locate desired entry name from PATHINFO
@@ -117,20 +117,20 @@
String p = grammarDirectory + request.getPathInfo();
JarEntry e = j.getJarEntry(p);
if (e == null) {
- msgFormat = new MessageFormat(ERR_NO_SUCH_ENTRY);
- errMsg = msgFormat.format(new Object[] {p, jar});
- // Log error and send bad response
- log.error(errMsg);
- PrintWriter out = response.getWriter();
+ msgFormat = new MessageFormat(ERR_NO_SUCH_ENTRY);
+ errMsg = msgFormat.format(new Object[] {p, jar});
+ // Log error and send bad response
+ log.error(errMsg);
+ PrintWriter out = response.getWriter();
out.println(errMsg);
return;
} // end of if (e != null)
InputStream i = j.getInputStream(e);
if (i == null) {
- msgFormat = new MessageFormat(ERR_NO_INPUT_STREAM);
- errMsg = msgFormat.format(new Object[] {p, jar});
- log.error(errMsg);
- PrintWriter out = response.getWriter();
+ msgFormat = new MessageFormat(ERR_NO_INPUT_STREAM);
+ errMsg = msgFormat.format(new Object[] {p, jar});
+ log.error(errMsg);
+ PrintWriter out = response.getWriter();
out.println(errMsg);
return;
} // end of if (i == nul)
@@ -140,35 +140,35 @@
// out of the .grammar directory.
// Thanks Stu for the mime types!
if (p.endsWith( EXT_JAVASCRIPT )) {
- response.setContentType( MIME_JAVASCRIPT );
+ response.setContentType( MIME_JAVASCRIPT );
} else {
- response.setContentType( MIME_SRGS_GRAM );
+ response.setContentType( MIME_SRGS_GRAM );
}
copy (i, response);
} catch (SecurityException e) {
- msgFormat = new MessageFormat(ERR_NO_PERMISSION);
- errMsg = msgFormat.format(new Object[] {jar});
- log.error(errMsg);
- PrintWriter out = response.getWriter();
- out.println(errMsg);
+ msgFormat = new MessageFormat(ERR_NO_PERMISSION);
+ errMsg = msgFormat.format(new Object[] {jar});
+ log.error(errMsg);
+ PrintWriter out = response.getWriter();
+ out.println(errMsg);
} // end of try-catch
}
- /**
- * This method is called once by the container just before the servlet
- * is taken out of service.
- *
- */
- public void destroy() {
- jar = null;
- grammarDirectory = null;
- }
+ /**
+ * This method is called once by the container just before the servlet
+ * is taken out of service.
+ *
+ */
+ public void destroy() {
+ jar = null;
+ grammarDirectory = null;
+ }
- /**
- * This way please
- */
+ /**
+ * This way please
+ */
private void copy (InputStream i, HttpServletResponse response)
- throws IOException {
+ throws IOException {
ServletOutputStream out = response.getOutputStream();
byte[] b = new byte[ 1024 ];
while( true ) {
@@ -179,7 +179,7 @@
out.write( b, 0, bytes );
}
i.close();
- out.flush();
+ out.flush();
}
}
Modified: jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/ISBN.java
URL: http://svn.apache.org/viewcvs/jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/ISBN.java?rev=231329&r1=231328&r2=231329&view=diff
==============================================================================
--- jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/ISBN.java (original)
+++ jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/ISBN.java Wed Aug 10 14:10:59 2005
@@ -34,111 +34,111 @@
*/
public class ISBN extends BaseModel {
- // The isbn RDC is associated with the International Standards Book Number
- // input and a pattern to which the input must confirm. The
- // ISBN is a 10 digit
- // number and should conform to this length.
-
- // The ISBN input must conform to this pattern
- private String pattern;
-
- // Error codes, defined in configuration file
- /**A constant for Error Code stating Invalid ISBN Code */
- public static final int ERR_INVALID_ISBN_CODE = 1;
-
- /**A constant for Error Code stating the incorrect length of ISBN Code */
- public static final int ERR_NEED_CORRECT_LENGTH_ISBN_CODE = 2;
-
- // the length of ISBN is 10
- public static final int ISBN_LENGTH = 10;
-
- /**
- * Sets default values for all data members
- */
- public ISBN() {
- super();
- // Default pattern allows any combination of digits or X
- this.pattern = "[0-9X]+";
- }
-
-
- /**
- * Sets the pattern string to which the ISBN must conform
- *
- * @param pattern the pattern string to which the ISBN must conform
- */
- public void setPattern(String pattern) {
- if (pattern != null) {
- try {
- Pattern.compile(pattern);
- this.pattern = pattern;
- } catch (PatternSyntaxException e) {
- throw new IllegalArgumentException("pattern attribute of \"" +
- getId() + "\" ssn tag not in proper format.");
- }
- }
- }
-
- /**
- * Gets the pattern string
- *
- * @return the pattern string
- */
- public String getPattern() {
- return this.pattern;
- }
-
- /**
- * Validates the input against the given constraints
- *
- * @return TRUE if valid, FALSE otherwise
- */
- protected Boolean validate(Object newValue, boolean setErrorCode) {
-
- if (((String) newValue).length() != ISBN_LENGTH) {
- if (setErrorCode) setErrorCode(ERR_NEED_CORRECT_LENGTH_ISBN_CODE);
- return Boolean.FALSE;
- }
- if (pattern != null && !(Pattern.matches(pattern, (String)newValue))) {
- if (setErrorCode) setErrorCode(ERR_INVALID_ISBN_CODE);
- return Boolean.FALSE;
- }
- if (!checksum(((String) newValue).toUpperCase())) {
- if (setErrorCode) setErrorCode(ERR_INVALID_ISBN_CODE);
- return Boolean.FALSE;
- }
- return Boolean.TRUE;
- }
-
- /**
- * Verifies the checksum of the given ISBN value
- *
- * @return true if checksum is valid, false otherwise
- */
-
- private boolean checksum(String isbn) {
- int sum = 0;
- int val;
- String numberValues = "0123456789X";
-
- for (int i = 0; i < isbn.length(); i++) {
- val = numberValues.indexOf(isbn.charAt(i));
- if (val >= 0) {
- if (val == 10 && (i != isbn.length() - 1)) {
- // X in wrong position, should be only in the last place
- return false;
- }
- sum += (10 - i) * val;
- } else {
- // invalid character
- return false;
- }
- }
-
- if ((sum % 11) == 0) {
- return true;
- } else {
- return false;
- }
- }
+ // The isbn RDC is associated with the International Standards Book Number
+ // input and a pattern to which the input must confirm. The
+ // ISBN is a 10 digit
+ // number and should conform to this length.
+
+ // The ISBN input must conform to this pattern
+ private String pattern;
+
+ // Error codes, defined in configuration file
+ /**A constant for Error Code stating Invalid ISBN Code */
+ public static final int ERR_INVALID_ISBN_CODE = 1;
+
+ /**A constant for Error Code stating the incorrect length of ISBN Code */
+ public static final int ERR_NEED_CORRECT_LENGTH_ISBN_CODE = 2;
+
+ // the length of ISBN is 10
+ public static final int ISBN_LENGTH = 10;
+
+ /**
+ * Sets default values for all data members
+ */
+ public ISBN() {
+ super();
+ // Default pattern allows any combination of digits or X
+ this.pattern = "[0-9X]+";
+ }
+
+
+ /**
+ * Sets the pattern string to which the ISBN must conform
+ *
+ * @param pattern the pattern string to which the ISBN must conform
+ */
+ public void setPattern(String pattern) {
+ if (pattern != null) {
+ try {
+ Pattern.compile(pattern);
+ this.pattern = pattern;
+ } catch (PatternSyntaxException e) {
+ throw new IllegalArgumentException("pattern attribute of \"" +
+ getId() + "\" ssn tag not in proper format.");
+ }
+ }
+ }
+
+ /**
+ * Gets the pattern string
+ *
+ * @return the pattern string
+ */
+ public String getPattern() {
+ return this.pattern;
+ }
+
+ /**
+ * Validates the input against the given constraints
+ *
+ * @return TRUE if valid, FALSE otherwise
+ */
+ protected Boolean validate(Object newValue, boolean setErrorCode) {
+
+ if (((String) newValue).length() != ISBN_LENGTH) {
+ if (setErrorCode) setErrorCode(ERR_NEED_CORRECT_LENGTH_ISBN_CODE);
+ return Boolean.FALSE;
+ }
+ if (pattern != null && !(Pattern.matches(pattern, (String)newValue))) {
+ if (setErrorCode) setErrorCode(ERR_INVALID_ISBN_CODE);
+ return Boolean.FALSE;
+ }
+ if (!checksum(((String) newValue).toUpperCase())) {
+ if (setErrorCode) setErrorCode(ERR_INVALID_ISBN_CODE);
+ return Boolean.FALSE;
+ }
+ return Boolean.TRUE;
+ }
+
+ /**
+ * Verifies the checksum of the given ISBN value
+ *
+ * @return true if checksum is valid, false otherwise
+ */
+
+ private boolean checksum(String isbn) {
+ int sum = 0;
+ int val;
+ String numberValues = "0123456789X";
+
+ for (int i = 0; i < isbn.length(); i++) {
+ val = numberValues.indexOf(isbn.charAt(i));
+ if (val >= 0) {
+ if (val == 10 && (i != isbn.length() - 1)) {
+ // X in wrong position, should be only in the last place
+ return false;
+ }
+ sum += (10 - i) * val;
+ } else {
+ // invalid character
+ return false;
+ }
+ }
+
+ if ((sum % 11) == 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}
Modified: jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Mortgage.java
URL: http://svn.apache.org/viewcvs/jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Mortgage.java?rev=231329&r1=231328&r2=231329&view=diff
==============================================================================
--- jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Mortgage.java (original)
+++ jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Mortgage.java Wed Aug 10 14:10:59 2005
@@ -29,19 +29,19 @@
*/
public class Mortgage extends ComponentModel {
- public Mortgage(){
- super();
- }
+ public Mortgage(){
+ super();
+ }
- /**
- * Stores the id and file attributes from the config xml to the
- * configMap
- *
- * @see ComponentModel#configHandler()
- */
- public void configHandler() {
- this.configMap = RDCUtils.configHandler(this.config,
- (PageContext) this.context);
- }
+ /**
+ * Stores the id and file attributes from the config xml to the
+ * configMap
+ *
+ * @see ComponentModel#configHandler()
+ */
+ public void configHandler() {
+ this.configMap = RDCUtils.configHandler(this.config,
+ (PageContext) this.context);
+ }
}
Modified: jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/MortgageData.java
URL: http://svn.apache.org/viewcvs/jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/MortgageData.java?rev=231329&r1=231328&r2=231329&view=diff
==============================================================================
--- jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/MortgageData.java (original)
+++ jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/MortgageData.java Wed Aug 10 14:10:59 2005
@@ -28,61 +28,61 @@
public class MortgageData implements Serializable
{
- private String percent;
- private String mortgageType;
+ private String percent;
+ private String mortgageType;
- public MortgageData() {
- this.percent = null;
- this.mortgageType = null;
-
- }
- /**
- * Get the mortgage percentage value
- *
- * @return the mortgage type value
- */
- public String getPercent() {
- return percent;
- }
+ public MortgageData() {
+ this.percent = null;
+ this.mortgageType = null;
+
+ }
+ /**
+ * Get the mortgage percentage value
+ *
+ * @return the mortgage type value
+ */
+ public String getPercent() {
+ return percent;
+ }
- /**
- * Set the mortgage percentage value
- *
- * @param input The input value.
- */
- public void setPercent(String input) {
- this.percent = input;
+ /**
+ * Set the mortgage percentage value
+ *
+ * @param input The input value.
+ */
+ public void setPercent(String input) {
+ this.percent = input;
- }
-
-
- /**
- * Get the mortgage type value
- *
- * @return the mortgage type value
- */
- public String getMortgageType() {
- return mortgageType;
- }
-
+ }
+
+
+ /**
+ * Get the mortgage type value
+ *
+ * @return the mortgage type value
+ */
+ public String getMortgageType() {
+ return mortgageType;
+ }
+
+ /**
+ * Set the mortgage type value
+ *
+ * @param input The input value.
+ */
+ public void setMortgageType(String input) {
+ this.mortgageType = input;
+ }
+
/**
- * Set the mortgage type value
- *
- * @param input The input value.
- */
- public void setMortgageType(String input) {
- this.mortgageType = input;
- }
-
- /**
- * A serialized version of MortgageData object
- */
- public String toString() {
- StringBuffer buf = new StringBuffer();
- buf.append("mortgagetype=").append(this.mortgageType).
- append(";percentdown=").append(this.percent);
- return buf.toString();
- }
+ * A serialized version of MortgageData object
+ */
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append("mortgagetype=").append(this.mortgageType).
+ append(";percentdown=").append(this.percent);
+ return buf.toString();
+ }
-
+
}
Modified: jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/MortgageType.java
URL: http://svn.apache.org/viewcvs/jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/MortgageType.java?rev=231329&r1=231328&r2=231329&view=diff
==============================================================================
--- jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/MortgageType.java (original)
+++ jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/MortgageType.java Wed Aug 10 14:10:59 2005
@@ -31,141 +31,141 @@
public class MortgageType extends BaseModel {
-
- // value returned cannot be less than this value
- private String minTerm;
- // value returned cannot be more than this value
- private String maxTerm;
- // The mortgage term input must conform to this pattern
- private String pattern;
-
- // Error Codes defined in config file
- // Invalid pattern specified
- public static final int ERR_INVALID_MORTGAGE_TERM = 1;
- // If the current value is higher than the maximum value allowed
- public static final int ERR_NEED_LOWER_VALUE = 2;
- // If the current value is lower than the minimum value allowed
- public static final int ERR_NEED_HIGHER_VALUE = 3;
-
- private static final int LESS = -1;
- private static final int EQUAL = 0;
- private static final int MORE = 1;
-
- public MortgageType() {
- super();
- this.maxTerm = null;
- this.minTerm = null;
- this.pattern = "[0-9]{1,2}Y(fixed|adjustable)";
- }
-
- /**
- * Get the max mortgage term that a user has specified in the attirbute
- * @return the user specified maxTerm
- */
- public String getMaxTerm() {
- return maxTerm;
- }
-
- /**
- * Set the MaxTerm value.
- * @param maxTerm The max mortgage term value.
- */
- public void setMaxTerm(String maxTerm) {
- if (maxTerm != null) {
- this.maxTerm = (String)canonicalize(maxTerm, true);
- }
- }
-
- /**
- * Get what min Mortgage term that a user has specified in the attirbute
- * @return the user specified minTerm
- */
- public String getMinTerm() {
- return minTerm;
- }
-
- /**
- * Set the MinTerm value.
- * @param minTerm The min Mortgage term value.
- */
- public void setMinTerm(String minTerm) {
- if (minTerm != null) {
- this.minTerm = (String)canonicalize(minTerm, true);
- }
- }
-
- /**
- * This method returns the mortgage term format
- *
- *@param input The mortgage term input string
- *@return The value of mortgage term
- */
- protected Object canonicalize(Object input, boolean isAttribute) {
-
- boolean patternValue = Pattern.matches(pattern, (String) input);
- if (!patternValue) {
- if (isAttribute) {
- throw new IllegalArgumentException("The required value of \"" +
- getId()+ "\"and the mortgage term of minimum or maximum " +
- "value do not match.");
- } else {
- return null;
- }
- }
- return input;
- }
-
- /**
- * Validate the received input against the validation constraints
- * @return boolean - true if valid, false if invalid
- */
- protected Boolean validate(Object newValue, boolean setErrorCode) {
-
- String val = newValue.toString();
- if (pattern != null) {
- boolean patternValue = Pattern.matches(pattern, val);
- if (!patternValue) {
- if (setErrorCode) setErrorCode(ERR_INVALID_MORTGAGE_TERM);
- return Boolean.FALSE;
- }
- }
- if (minTerm != null && cmpTerm(val, minTerm) == LESS) {
- if (setErrorCode) setErrorCode(ERR_NEED_HIGHER_VALUE);
- return Boolean.FALSE;
- } else if (maxTerm != null && cmpTerm(val, maxTerm) == MORE) {
- if (setErrorCode) setErrorCode(ERR_NEED_LOWER_VALUE);
- return Boolean.FALSE;
- }
- return Boolean.TRUE;
- }
-
- /**
- * This method compares the minimum and maximu Mortgage terms
- * against the input and returns LESS,MORE or EQUAL accordingly
- *
- * @param String s1-> the mortgage term value
- * @param String s2 -> could be minimum and maximum terms
- *
- * @return could be LESS,MORE or EQUAL
- */
- private int cmpTerm(String s1, String s2) {
- return cmp(
- Integer.parseInt(s1.substring(0, s1.indexOf('Y'))),
- Integer.parseInt(s2.substring(0, s2.indexOf('Y'))));
- }
-
- /**
- * Compares the minimum and maximum mortgage terms
- * against the mortgage input and returns LESS,MORE or
- * EQUAL accordingly
- *
- * @param a-> the mortgage term value
- * @param int b -> could be minimum and maximum terms
- *
- * @return could be LESS,MORE or EQUAL
- */
- private int cmp(int a, int b) {
- return a < b ? LESS : a > b ? MORE : EQUAL;
- }
+
+ // value returned cannot be less than this value
+ private String minTerm;
+ // value returned cannot be more than this value
+ private String maxTerm;
+ // The mortgage term input must conform to this pattern
+ private String pattern;
+
+ // Error Codes defined in config file
+ // Invalid pattern specified
+ public static final int ERR_INVALID_MORTGAGE_TERM = 1;
+ // If the current value is higher than the maximum value allowed
+ public static final int ERR_NEED_LOWER_VALUE = 2;
+ // If the current value is lower than the minimum value allowed
+ public static final int ERR_NEED_HIGHER_VALUE = 3;
+
+ private static final int LESS = -1;
+ private static final int EQUAL = 0;
+ private static final int MORE = 1;
+
+ public MortgageType() {
+ super();
+ this.maxTerm = null;
+ this.minTerm = null;
+ this.pattern = "[0-9]{1,2}Y(fixed|adjustable)";
+ }
+
+ /**
+ * Get the max mortgage term that a user has specified in the attirbute
+ * @return the user specified maxTerm
+ */
+ public String getMaxTerm() {
+ return maxTerm;
+ }
+
+ /**
+ * Set the MaxTerm value.
+ * @param maxTerm The max mortgage term value.
+ */
+ public void setMaxTerm(String maxTerm) {
+ if (maxTerm != null) {
+ this.maxTerm = (String)canonicalize(maxTerm, true);
+ }
+ }
+
+ /**
+ * Get what min Mortgage term that a user has specified in the attirbute
+ * @return the user specified minTerm
+ */
+ public String getMinTerm() {
+ return minTerm;
+ }
+
+ /**
+ * Set the MinTerm value.
+ * @param minTerm The min Mortgage term value.
+ */
+ public void setMinTerm(String minTerm) {
+ if (minTerm != null) {
+ this.minTerm = (String)canonicalize(minTerm, true);
+ }
+ }
+
+ /**
+ * This method returns the mortgage term format
+ *
+ *@param input The mortgage term input string
+ *@return The value of mortgage term
+ */
+ protected Object canonicalize(Object input, boolean isAttribute) {
+
+ boolean patternValue = Pattern.matches(pattern, (String) input);
+ if (!patternValue) {
+ if (isAttribute) {
+ throw new IllegalArgumentException("The required value of \"" +
+ getId()+ "\"and the mortgage term of minimum or maximum " +
+ "value do not match.");
+ } else {
+ return null;
+ }
+ }
+ return input;
+ }
+
+ /**
+ * Validate the received input against the validation constraints
+ * @return boolean - true if valid, false if invalid
+ */
+ protected Boolean validate(Object newValue, boolean setErrorCode) {
+
+ String val = newValue.toString();
+ if (pattern != null) {
+ boolean patternValue = Pattern.matches(pattern, val);
+ if (!patternValue) {
+ if (setErrorCode) setErrorCode(ERR_INVALID_MORTGAGE_TERM);
+ return Boolean.FALSE;
+ }
+ }
+ if (minTerm != null && cmpTerm(val, minTerm) == LESS) {
+ if (setErrorCode) setErrorCode(ERR_NEED_HIGHER_VALUE);
+ return Boolean.FALSE;
+ } else if (maxTerm != null && cmpTerm(val, maxTerm) == MORE) {
+ if (setErrorCode) setErrorCode(ERR_NEED_LOWER_VALUE);
+ return Boolean.FALSE;
+ }
+ return Boolean.TRUE;
+ }
+
+ /**
+ * This method compares the minimum and maximu Mortgage terms
+ * against the input and returns LESS,MORE or EQUAL accordingly
+ *
+ * @param String s1-> the mortgage term value
+ * @param String s2 -> could be minimum and maximum terms
+ *
+ * @return could be LESS,MORE or EQUAL
+ */
+ private int cmpTerm(String s1, String s2) {
+ return cmp(
+ Integer.parseInt(s1.substring(0, s1.indexOf('Y'))),
+ Integer.parseInt(s2.substring(0, s2.indexOf('Y'))));
+ }
+
+ /**
+ * Compares the minimum and maximum mortgage terms
+ * against the mortgage input and returns LESS,MORE or
+ * EQUAL accordingly
+ *
+ * @param a-> the mortgage term value
+ * @param int b -> could be minimum and maximum terms
+ *
+ * @return could be LESS,MORE or EQUAL
+ */
+ private int cmp(int a, int b) {
+ return a < b ? LESS : a > b ? MORE : EQUAL;
+ }
}
Modified: jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Number.java
URL: http://svn.apache.org/viewcvs/jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Number.java?rev=231329&r1=231328&r2=231329&view=diff
==============================================================================
--- jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Number.java (original)
+++ jakarta/taglibs/proper/rdc/trunk/src/org/apache/taglibs/rdc/Number.java Wed Aug 10 14:10:59 2005
@@ -31,111 +31,111 @@
public class Number extends BaseModel {
- // The default/initial value of number
- // initial is of type String and not Double because
- // Double.toString returns scientific notation for
- // numbers less that 10 pow -3 and greater than 10 pow 7.
- // The value returned by the grammar is fixed-number representation
- // and initial must conform to that.
-
- // Maximum allowed value of the input; null value indicates
- // no constraint on maximum value
- private Double minValue;
-
- // Minimum allowed value of the input; null value indicates
- // no constraint on minimum value
- private Double maxValue;
-
- // Error codes, defined in configuration file
- /**A constant for Error Code stating the number entered is
- * longer than allowed */
- public static final int ERR_NEED_SHORTER_NUMBER = 1;
-
- /**A constant for Error Code stating the number entered is
- * shorter than allowed */
- public static final int ERR_NEED_LONGER_NUMBER = 2;
-
- /**
- * Sets default values for all data members
- */
- public Number() {
- super();
- this.minValue = null;
- this.maxValue = null;
- }
-
- /**
- * Gets the maximum allowed value of number
- *
- * @return The maximum allowed value of number
- */
- public String getMaxValue() {
- return maxValue.toString();
- }
-
- /**
- * Sets the maximum allowed value of input
- *
- * @param maxValue the maximum allowed value of input
- */
- public void setMaxValue(String maxValue) {
- if (maxValue != null) {
- this.maxValue = (Double)canonicalize(maxValue, true);
- }
- }
-
- /**
- * Gets the minimum allowed value of number
- * @return The minimum allowed value of number
- */
-
- public String getMinValue() {
- return minValue.toString();
- }
-
- /**
- * Sets the minimum allowed value
- *
- * @param minValue the minimum allowed value of input
- */
- public void setMinValue(String minValue) {
- if (minValue != null) {
- this.minValue = (Double)canonicalize(minValue, true);
- }
- }
-
- /**
- * Custom canonicalization
- */
- protected Object canonicalize(Object newValue, boolean isAttribute) {
- Double dabal = null;
- try {
- dabal = new Double((String) newValue);
- } catch (NumberFormatException e) {
- if (isAttribute) {
- throw new IllegalArgumentException("Cannot canonicalize " +
- "value " + newValue + " for number tag with ID " + getId());
- }
- }
- return dabal;
- }
-
- /**
- * Validates the input against the given constraints
- *
- * @return TRUE if valid, FALSE otherwise
- */
- protected Boolean validate(Object newValue, boolean setErrorCode) {
-
- if (maxValue != null && maxValue.compareTo(newValue) < 0) {
- if (setErrorCode) setErrorCode(ERR_NEED_SHORTER_NUMBER);
- return Boolean.FALSE;
- }
- if (minValue != null && minValue.compareTo(newValue) > 0) {
- if (setErrorCode) setErrorCode(ERR_NEED_LONGER_NUMBER);
- return Boolean.FALSE;
- }
- return Boolean.TRUE;
- }
+ // The default/initial value of number
+ // initial is of type String and not Double because
+ // Double.toString returns scientific notation for
+ // numbers less that 10 pow -3 and greater than 10 pow 7.
+ // The value returned by the grammar is fixed-number representation
+ // and initial must conform to that.
+
+ // Maximum allowed value of the input; null value indicates
+ // no constraint on maximum value
+ private Double minValue;
+
+ // Minimum allowed value of the input; null value indicates
+ // no constraint on minimum value
+ private Double maxValue;
+
+ // Error codes, defined in configuration file
+ /**A constant for Error Code stating the number entered is
+ * longer than allowed */
+ public static final int ERR_NEED_SHORTER_NUMBER = 1;
+
+ /**A constant for Error Code stating the number entered is
+ * shorter than allowed */
+ public static final int ERR_NEED_LONGER_NUMBER = 2;
+
+ /**
+ * Sets default values for all data members
+ */
+ public Number() {
+ super();
+ this.minValue = null;
+ this.maxValue = null;
+ }
+
+ /**
+ * Gets the maximum allowed value of number
+ *
+ * @return The maximum allowed value of number
+ */
+ public String getMaxValue() {
+ return maxValue.toString();
+ }
+
+ /**
+ * Sets the maximum allowed value of input
+ *
+ * @param maxValue the maximum allowed value of input
+ */
+ public void setMaxValue(String maxValue) {
+ if (maxValue != null) {
+ this.maxValue = (Double)canonicalize(maxValue, true);
+ }
+ }
+
+ /**
+ * Gets the minimum allowed value of number
+ * @return The minimum allowed value of number
+ */
+
+ public String getMinValue() {
+ return minValue.toString();
+ }
+
+ /**
+ * Sets the minimum allowed value
+ *
+ * @param minValue the minimum allowed value of input
+ */
+ public void setMinValue(String minValue) {
+ if (minValue != null) {
+ this.minValue = (Double)canonicalize(minValue, true);
+ }
+ }
+
+ /**
+ * Custom canonicalization
+ */
+ protected Object canonicalize(Object newValue, boolean isAttribute) {
+ Double dabal = null;
+ try {
+ dabal = new Double((String) newValue);
+ } catch (NumberFormatException e) {
+ if (isAttribute) {
+ throw new IllegalArgumentException("Cannot canonicalize " +
+ "value " + newValue + " for number tag with ID " + getId());
+ }
+ }
+ return dabal;
+ }
+
+ /**
+ * Validates the input against the given constraints
+ *
+ * @return TRUE if valid, FALSE otherwise
+ */
+ protected Boolean validate(Object newValue, boolean setErrorCode) {
+
+ if (maxValue != null && maxValue.compareTo(newValue) < 0) {
+ if (setErrorCode) setErrorCode(ERR_NEED_SHORTER_NUMBER);
+ return Boolean.FALSE;
+ }
+ if (minValue != null && minValue.compareTo(newValue) > 0) {
+ if (setErrorCode) setErrorCode(ERR_NEED_LONGER_NUMBER);
+ return Boolean.FALSE;
+ }
+ return Boolean.TRUE;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org