You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shale.apache.org by cr...@apache.org on 2006/11/28 18:39:08 UTC
svn commit: r480137 [1/2] - in
/shale/framework/trunk/shale-validator/src/main:
java/org/apache/shale/validator/converter/
java/org/apache/shale/validator/tag/
java/org/apache/shale/validator/validator/ resources/META-INF/
resources/org/apache/shale/va...
Author: craigmcc
Date: Tue Nov 28 09:39:03 2006
New Revision: 480137
URL: http://svn.apache.org/viewvc?view=rev&rev=480137
Log:
Add JSP tags for the integer converter and validator. Two new tag libraries
are defined, with clever :-) default prefixes, so that you can code reasonably
elegant things like:
<h:inputText id="milliseconds" ...>
<convert:integer pattern="###,###"/>
<validate:integer minimum="0" maximum="999999"/>
</h:inputText>
and be able to use locale-sensitive grouping characters, plus enforce the
minimum-maximum range limits.
SHALE-342
Added:
shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/DoubleConverter.java (with props)
shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/FloatConverter.java (with props)
shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/LongConverter.java (with props)
shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/ShortConverter.java (with props)
shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/tag/IntegerConverterTag.java (with props)
shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/tag/IntegerValidatorTag.java (with props)
shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/DoubleValidator.java (with props)
shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/FloatValidator.java (with props)
shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/LongValidator.java (with props)
shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/ShortValidator.java (with props)
shale/framework/trunk/shale-validator/src/main/resources/META-INF/converters.tld (with props)
shale/framework/trunk/shale-validator/src/main/resources/META-INF/validators.tld (with props)
Modified:
shale/framework/trunk/shale-validator/src/main/resources/META-INF/taglib.tld
shale/framework/trunk/shale-validator/src/main/resources/org/apache/shale/validator/resources/Bundle.properties
Added: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/DoubleConverter.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/DoubleConverter.java?view=auto&rev=480137
==============================================================================
--- shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/DoubleConverter.java (added)
+++ shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/DoubleConverter.java Tue Nov 28 09:39:03 2006
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.validator.converter;
+
+import java.util.Locale;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.ConverterException;
+import org.apache.commons.validator.routines.DoubleValidator;
+
+/**
+ * <p>JavaServer Faces <code>Converter</code> for Double (and int)
+ * instances. Parsing and formatting is controlled by the properties
+ * that are set on a Converter instance.</p>
+ */
+public final class DoubleConverter extends AbstractConverter {
+
+
+ // -------------------------------------------------------- Static Variables
+
+
+ /**
+ * <p>The Apache Commons Validator instance we will use to perform
+ * our formatting and parsing.</p>
+ */
+ private static final DoubleValidator INSTANCE =
+ DoubleValidator.getInstance();
+
+
+
+ // -------------------------------------------------------------- Properties
+
+
+ /**
+ * <p>The <code>Locale</code> to apply to this conversion, if any.</p>
+ */
+ private Locale locale = null;
+
+
+ /**
+ * <p>Return the <code>Locale</code> to apply to this conversion, or
+ * <code>null</code> to use the <code>Locale</code> for the current view.</p>
+ */
+ public Locale getLocale() {
+ return this.locale;
+ }
+
+
+ /**
+ * <p>Set the <code>Locale</code> to apply to this conversion, or
+ * <code>null</code> to use the <code>Locale</code> for the current view.</p>
+ *
+ * @param locale The new Locale
+ */
+ public void setLocale(Locale locale) {
+ this.locale = locale;
+ }
+
+
+ /**
+ * <p>The formatting pattern to apply to this conversion, if any.</p>
+ */
+ private String pattern = null;
+
+
+ /**
+ * <p>Return the <code>java.text.NumberFormat</code> pattern to apply
+ * to this conversion, or <code>null</code> for using no pattern.</p>
+ */
+ public String getPattern() {
+ return this.pattern;
+ }
+
+
+ /**
+ * <p>Set the <code>java.text.NumberFormat</code> pattern to apply to
+ * this conversion, or <code>null</code> for using no pattern.</p>
+ *
+ * @param pattern The new formatting pattern
+ */
+ public void setPattern(String pattern) {
+ this.pattern = null;
+ }
+
+
+ // ------------------------------------------------------- Converter Methods
+
+
+ /** {@inheritDoc} */
+ public Object getAsObject(FacesContext context, UIComponent component,
+ String value) {
+
+ if ((context == null) || (component == null)) {
+ throw new NullPointerException(message(context, "common.null"));
+ }
+
+ try {
+ if (locale == null) {
+ return INSTANCE.validate(value, pattern, context.getViewRoot().getLocale());
+ } else {
+ return INSTANCE.validate(value, pattern, locale);
+ }
+ } catch (Exception e) {
+ throw new ConverterException(e);
+ }
+
+ }
+
+
+ /** {@inheritDoc} */
+ public String getAsString(FacesContext context, UIComponent component,
+ Object value) {
+
+ if ((context == null) || (component == null)) {
+ throw new NullPointerException(message(context, "common.null"));
+ }
+
+ try {
+ if (locale == null) {
+ return INSTANCE.format(value, pattern, context.getViewRoot().getLocale());
+ } else {
+ return INSTANCE.format(value, pattern, locale);
+ }
+ } catch (Exception e) {
+ throw new ConverterException(e);
+ }
+
+ }
+
+
+
+ // ----------------------------------------------------- StateHolder Methods
+
+
+ /** {@inheritDoc} */
+ public void restoreState(FacesContext context, Object state) {
+ Object[] values = (Object[]) state;
+ super.restoreState(context, values[0]);
+ this.locale = (Locale) values[1];
+ this.pattern = (String) values[2];
+ }
+
+
+ /** {@inheritDoc} */
+ public Object saveState(FacesContext context) {
+ Object[] values = new Object[3];
+ values[0] = super.saveState(context);
+ values[1] = this.locale;
+ values[2] = this.pattern;
+ return values;
+ }
+
+
+}
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/DoubleConverter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/DoubleConverter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/FloatConverter.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/FloatConverter.java?view=auto&rev=480137
==============================================================================
--- shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/FloatConverter.java (added)
+++ shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/FloatConverter.java Tue Nov 28 09:39:03 2006
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.validator.converter;
+
+import java.util.Locale;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.ConverterException;
+import org.apache.commons.validator.routines.FloatValidator;
+
+/**
+ * <p>JavaServer Faces <code>Converter</code> for Float (and int)
+ * instances. Parsing and formatting is controlled by the properties
+ * that are set on a Converter instance.</p>
+ */
+public final class FloatConverter extends AbstractConverter {
+
+
+ // -------------------------------------------------------- Static Variables
+
+
+ /**
+ * <p>The Apache Commons Validator instance we will use to perform
+ * our formatting and parsing.</p>
+ */
+ private static final FloatValidator INSTANCE =
+ FloatValidator.getInstance();
+
+
+
+ // -------------------------------------------------------------- Properties
+
+
+ /**
+ * <p>The <code>Locale</code> to apply to this conversion, if any.</p>
+ */
+ private Locale locale = null;
+
+
+ /**
+ * <p>Return the <code>Locale</code> to apply to this conversion, or
+ * <code>null</code> to use the <code>Locale</code> for the current view.</p>
+ */
+ public Locale getLocale() {
+ return this.locale;
+ }
+
+
+ /**
+ * <p>Set the <code>Locale</code> to apply to this conversion, or
+ * <code>null</code> to use the <code>Locale</code> for the current view.</p>
+ *
+ * @param locale The new Locale
+ */
+ public void setLocale(Locale locale) {
+ this.locale = locale;
+ }
+
+
+ /**
+ * <p>The formatting pattern to apply to this conversion, if any.</p>
+ */
+ private String pattern = null;
+
+
+ /**
+ * <p>Return the <code>java.text.NumberFormat</code> pattern to apply
+ * to this conversion, or <code>null</code> for using no pattern.</p>
+ */
+ public String getPattern() {
+ return this.pattern;
+ }
+
+
+ /**
+ * <p>Set the <code>java.text.NumberFormat</code> pattern to apply to
+ * this conversion, or <code>null</code> for using no pattern.</p>
+ *
+ * @param pattern The new formatting pattern
+ */
+ public void setPattern(String pattern) {
+ this.pattern = null;
+ }
+
+
+ // ------------------------------------------------------- Converter Methods
+
+
+ /** {@inheritDoc} */
+ public Object getAsObject(FacesContext context, UIComponent component,
+ String value) {
+
+ if ((context == null) || (component == null)) {
+ throw new NullPointerException(message(context, "common.null"));
+ }
+
+ try {
+ if (locale == null) {
+ return INSTANCE.validate(value, pattern, context.getViewRoot().getLocale());
+ } else {
+ return INSTANCE.validate(value, pattern, locale);
+ }
+ } catch (Exception e) {
+ throw new ConverterException(e);
+ }
+
+ }
+
+
+ /** {@inheritDoc} */
+ public String getAsString(FacesContext context, UIComponent component,
+ Object value) {
+
+ if ((context == null) || (component == null)) {
+ throw new NullPointerException(message(context, "common.null"));
+ }
+
+ try {
+ if (locale == null) {
+ return INSTANCE.format(value, pattern, context.getViewRoot().getLocale());
+ } else {
+ return INSTANCE.format(value, pattern, locale);
+ }
+ } catch (Exception e) {
+ throw new ConverterException(e);
+ }
+
+ }
+
+
+
+ // ----------------------------------------------------- StateHolder Methods
+
+
+ /** {@inheritDoc} */
+ public void restoreState(FacesContext context, Object state) {
+ Object[] values = (Object[]) state;
+ super.restoreState(context, values[0]);
+ this.locale = (Locale) values[1];
+ this.pattern = (String) values[2];
+ }
+
+
+ /** {@inheritDoc} */
+ public Object saveState(FacesContext context) {
+ Object[] values = new Object[3];
+ values[0] = super.saveState(context);
+ values[1] = this.locale;
+ values[2] = this.pattern;
+ return values;
+ }
+
+
+}
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/FloatConverter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/FloatConverter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/LongConverter.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/LongConverter.java?view=auto&rev=480137
==============================================================================
--- shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/LongConverter.java (added)
+++ shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/LongConverter.java Tue Nov 28 09:39:03 2006
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.validator.converter;
+
+import java.util.Locale;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.ConverterException;
+import org.apache.commons.validator.routines.LongValidator;
+
+/**
+ * <p>JavaServer Faces <code>Converter</code> for Long (and int)
+ * instances. Parsing and formatting is controlled by the properties
+ * that are set on a Converter instance.</p>
+ */
+public final class LongConverter extends AbstractConverter {
+
+
+ // -------------------------------------------------------- Static Variables
+
+
+ /**
+ * <p>The Apache Commons Validator instance we will use to perform
+ * our formatting and parsing.</p>
+ */
+ private static final LongValidator INSTANCE =
+ LongValidator.getInstance();
+
+
+
+ // -------------------------------------------------------------- Properties
+
+
+ /**
+ * <p>The <code>Locale</code> to apply to this conversion, if any.</p>
+ */
+ private Locale locale = null;
+
+
+ /**
+ * <p>Return the <code>Locale</code> to apply to this conversion, or
+ * <code>null</code> to use the <code>Locale</code> for the current view.</p>
+ */
+ public Locale getLocale() {
+ return this.locale;
+ }
+
+
+ /**
+ * <p>Set the <code>Locale</code> to apply to this conversion, or
+ * <code>null</code> to use the <code>Locale</code> for the current view.</p>
+ *
+ * @param locale The new Locale
+ */
+ public void setLocale(Locale locale) {
+ this.locale = locale;
+ }
+
+
+ /**
+ * <p>The formatting pattern to apply to this conversion, if any.</p>
+ */
+ private String pattern = null;
+
+
+ /**
+ * <p>Return the <code>java.text.NumberFormat</code> pattern to apply
+ * to this conversion, or <code>null</code> for using no pattern.</p>
+ */
+ public String getPattern() {
+ return this.pattern;
+ }
+
+
+ /**
+ * <p>Set the <code>java.text.NumberFormat</code> pattern to apply to
+ * this conversion, or <code>null</code> for using no pattern.</p>
+ *
+ * @param pattern The new formatting pattern
+ */
+ public void setPattern(String pattern) {
+ this.pattern = null;
+ }
+
+
+ // ------------------------------------------------------- Converter Methods
+
+
+ /** {@inheritDoc} */
+ public Object getAsObject(FacesContext context, UIComponent component,
+ String value) {
+
+ if ((context == null) || (component == null)) {
+ throw new NullPointerException(message(context, "common.null"));
+ }
+
+ try {
+ if (locale == null) {
+ return INSTANCE.validate(value, pattern, context.getViewRoot().getLocale());
+ } else {
+ return INSTANCE.validate(value, pattern, locale);
+ }
+ } catch (Exception e) {
+ throw new ConverterException(e);
+ }
+
+ }
+
+
+ /** {@inheritDoc} */
+ public String getAsString(FacesContext context, UIComponent component,
+ Object value) {
+
+ if ((context == null) || (component == null)) {
+ throw new NullPointerException(message(context, "common.null"));
+ }
+
+ try {
+ if (locale == null) {
+ return INSTANCE.format(value, pattern, context.getViewRoot().getLocale());
+ } else {
+ return INSTANCE.format(value, pattern, locale);
+ }
+ } catch (Exception e) {
+ throw new ConverterException(e);
+ }
+
+ }
+
+
+
+ // ----------------------------------------------------- StateHolder Methods
+
+
+ /** {@inheritDoc} */
+ public void restoreState(FacesContext context, Object state) {
+ Object[] values = (Object[]) state;
+ super.restoreState(context, values[0]);
+ this.locale = (Locale) values[1];
+ this.pattern = (String) values[2];
+ }
+
+
+ /** {@inheritDoc} */
+ public Object saveState(FacesContext context) {
+ Object[] values = new Object[3];
+ values[0] = super.saveState(context);
+ values[1] = this.locale;
+ values[2] = this.pattern;
+ return values;
+ }
+
+
+}
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/LongConverter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/LongConverter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/ShortConverter.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/ShortConverter.java?view=auto&rev=480137
==============================================================================
--- shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/ShortConverter.java (added)
+++ shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/ShortConverter.java Tue Nov 28 09:39:03 2006
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.validator.converter;
+
+import java.util.Locale;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.ConverterException;
+import org.apache.commons.validator.routines.ShortValidator;
+
+/**
+ * <p>JavaServer Faces <code>Converter</code> for Short (and int)
+ * instances. Parsing and formatting is controlled by the properties
+ * that are set on a Converter instance.</p>
+ */
+public final class ShortConverter extends AbstractConverter {
+
+
+ // -------------------------------------------------------- Static Variables
+
+
+ /**
+ * <p>The Apache Commons Validator instance we will use to perform
+ * our formatting and parsing.</p>
+ */
+ private static final ShortValidator INSTANCE =
+ ShortValidator.getInstance();
+
+
+
+ // -------------------------------------------------------------- Properties
+
+
+ /**
+ * <p>The <code>Locale</code> to apply to this conversion, if any.</p>
+ */
+ private Locale locale = null;
+
+
+ /**
+ * <p>Return the <code>Locale</code> to apply to this conversion, or
+ * <code>null</code> to use the <code>Locale</code> for the current view.</p>
+ */
+ public Locale getLocale() {
+ return this.locale;
+ }
+
+
+ /**
+ * <p>Set the <code>Locale</code> to apply to this conversion, or
+ * <code>null</code> to use the <code>Locale</code> for the current view.</p>
+ *
+ * @param locale The new Locale
+ */
+ public void setLocale(Locale locale) {
+ this.locale = locale;
+ }
+
+
+ /**
+ * <p>The formatting pattern to apply to this conversion, if any.</p>
+ */
+ private String pattern = null;
+
+
+ /**
+ * <p>Return the <code>java.text.NumberFormat</code> pattern to apply
+ * to this conversion, or <code>null</code> for using no pattern.</p>
+ */
+ public String getPattern() {
+ return this.pattern;
+ }
+
+
+ /**
+ * <p>Set the <code>java.text.NumberFormat</code> pattern to apply to
+ * this conversion, or <code>null</code> for using no pattern.</p>
+ *
+ * @param pattern The new formatting pattern
+ */
+ public void setPattern(String pattern) {
+ this.pattern = null;
+ }
+
+
+ // ------------------------------------------------------- Converter Methods
+
+
+ /** {@inheritDoc} */
+ public Object getAsObject(FacesContext context, UIComponent component,
+ String value) {
+
+ if ((context == null) || (component == null)) {
+ throw new NullPointerException(message(context, "common.null"));
+ }
+
+ try {
+ if (locale == null) {
+ return INSTANCE.validate(value, pattern, context.getViewRoot().getLocale());
+ } else {
+ return INSTANCE.validate(value, pattern, locale);
+ }
+ } catch (Exception e) {
+ throw new ConverterException(e);
+ }
+
+ }
+
+
+ /** {@inheritDoc} */
+ public String getAsString(FacesContext context, UIComponent component,
+ Object value) {
+
+ if ((context == null) || (component == null)) {
+ throw new NullPointerException(message(context, "common.null"));
+ }
+
+ try {
+ if (locale == null) {
+ return INSTANCE.format(value, pattern, context.getViewRoot().getLocale());
+ } else {
+ return INSTANCE.format(value, pattern, locale);
+ }
+ } catch (Exception e) {
+ throw new ConverterException(e);
+ }
+
+ }
+
+
+
+ // ----------------------------------------------------- StateHolder Methods
+
+
+ /** {@inheritDoc} */
+ public void restoreState(FacesContext context, Object state) {
+ Object[] values = (Object[]) state;
+ super.restoreState(context, values[0]);
+ this.locale = (Locale) values[1];
+ this.pattern = (String) values[2];
+ }
+
+
+ /** {@inheritDoc} */
+ public Object saveState(FacesContext context) {
+ Object[] values = new Object[3];
+ values[0] = super.saveState(context);
+ values[1] = this.locale;
+ values[2] = this.pattern;
+ return values;
+ }
+
+
+}
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/ShortConverter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/converter/ShortConverter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/tag/IntegerConverterTag.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/tag/IntegerConverterTag.java?view=auto&rev=480137
==============================================================================
--- shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/tag/IntegerConverterTag.java (added)
+++ shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/tag/IntegerConverterTag.java Tue Nov 28 09:39:03 2006
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.validator.tag;
+
+import java.util.Locale;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.el.ValueBinding;
+import javax.faces.webapp.ConverterTag;
+import javax.faces.webapp.UIComponentTag;
+import org.apache.shale.util.ConverterHelper;
+import org.apache.shale.validator.converter.IntegerConverter;
+
+/**
+ * <p>JSP custom action for <code>IntegerConverter</code>.</p>
+ */
+public final class IntegerConverterTag extends ConverterTag {
+
+
+ // -------------------------------------------------------- Static Variables
+
+
+ /**
+ * <p>Helper object for performing conversions.</p>
+ */
+ private static final ConverterHelper HELPER =
+ new ConverterHelper();
+
+
+ // -------------------------------------------------------------- Properties
+
+
+ private String locale = null;
+ public void setLocale(String locale) {
+ this.locale = locale;
+ }
+
+
+ private String message = null;
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+
+ private String pattern = null;
+ public void setPattern(String pattern) {
+ this.pattern = pattern;
+ }
+
+
+ // ------------------------------------------------------------- Tag Methods
+
+
+ /**
+ * <p>Release resources allocated for this instance.</p>
+ */
+ public void release() {
+
+ locale = null;
+ message = null;
+ pattern = null;
+
+ super.release();
+
+ }
+
+
+ // ---------------------------------------------------- ConverterTag Methods
+
+
+ /**
+ * <p>Create and return a new <code>Converter</code> instance to be
+ * registered on our corresponding <code>UIComponent</code>.</p>
+ */
+ protected Converter createConverter() {
+
+ FacesContext context = FacesContext.getCurrentInstance();
+ IntegerConverter converter = new IntegerConverter();
+
+ if (locale != null) {
+ Locale value = null;
+ if (UIComponentTag.isValueReference(locale)) {
+ ValueBinding vb = context.getApplication().createValueBinding(locale);
+ value = (Locale) vb.getValue(context);
+ } else {
+ value = (Locale) HELPER.asObject(context, Locale.class, locale);
+ }
+ converter.setLocale(value);
+ }
+
+ if (pattern != null) {
+ String value = null;
+ if (UIComponentTag.isValueReference(message)) {
+ ValueBinding vb = context.getApplication().createValueBinding(pattern);
+ value = (String) vb.getValue(context);
+ } else {
+ value = pattern;
+ }
+ converter.setPattern(value);
+ }
+
+ return converter;
+
+ }
+
+
+}
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/tag/IntegerConverterTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/tag/IntegerConverterTag.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/tag/IntegerValidatorTag.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/tag/IntegerValidatorTag.java?view=auto&rev=480137
==============================================================================
--- shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/tag/IntegerValidatorTag.java (added)
+++ shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/tag/IntegerValidatorTag.java Tue Nov 28 09:39:03 2006
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.validator.tag;
+
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+import javax.faces.validator.Validator;
+import javax.faces.webapp.UIComponentTag;
+import javax.faces.webapp.ValidatorTag;
+import org.apache.shale.util.ConverterHelper;
+import org.apache.shale.validator.validator.IntegerValidator;
+
+/**
+ * <p>JSP custom action for <code>IntegerValidator</code>.</p>
+ */
+public final class IntegerValidatorTag extends ValidatorTag {
+
+
+ // -------------------------------------------------------- Static Variables
+
+
+ /**
+ * <p>Helper object for performing conversions.</p>
+ */
+ private static final ConverterHelper HELPER =
+ new ConverterHelper();
+
+
+ // -------------------------------------------------------------- Properties
+
+
+ private String client = null;
+ public void setClient(String client) {
+ this.client = client;
+ }
+
+
+ private String maximum = null;
+ public void setMaximum(String maximum) {
+ this.maximum = maximum;
+ }
+
+
+ private String message = null;
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+
+ private String minimum = null;
+ public void setMinimum(String minimum) {
+ this.minimum = minimum;
+ }
+
+
+ // ------------------------------------------------------------- Tag Methods
+
+
+ /**
+ * <p>Release resources allocated for this instance.</p>
+ */
+ public void release() {
+
+ client = null;
+ maximum = null;
+ message = null;
+ minimum = null;
+
+ super.release();
+
+ }
+
+
+ // ---------------------------------------------------- ValidatorTag Methods
+
+
+ /**
+ * <p>Create and return a new <code>Validator</code> instance to be
+ * registered on our corresponding <code>UIComponent</code>.</p>
+ */
+ protected Validator createValidator() {
+
+ FacesContext context = FacesContext.getCurrentInstance();
+ IntegerValidator validator = new IntegerValidator();
+
+ if (client != null) {
+ Boolean value = null;
+ if (UIComponentTag.isValueReference(client)) {
+ ValueBinding vb = context.getApplication().createValueBinding(client);
+ value = (Boolean) vb.getValue(context);
+ } else {
+ value = (Boolean) HELPER.asObject(context, Boolean.class, client);
+ }
+ validator.setClient(value.booleanValue());
+ }
+
+ if (maximum != null) {
+ Integer value = null;
+ if (UIComponentTag.isValueReference(maximum)) {
+ ValueBinding vb = context.getApplication().createValueBinding(maximum);
+ value = (Integer) vb.getValue(context);
+ } else {
+ value = (Integer) HELPER.asObject(context, Integer.class, maximum);
+ }
+ validator.setMaximum(value.intValue());
+ }
+
+ if (message != null) {
+ String value = null;
+ if (UIComponentTag.isValueReference(message)) {
+ ValueBinding vb = context.getApplication().createValueBinding(message);
+ value = (String) vb.getValue(context);
+ } else {
+ value = message;
+ }
+ validator.setMessage(value);
+ }
+
+ if (minimum != null) {
+ Integer value = null;
+ if (UIComponentTag.isValueReference(minimum)) {
+ ValueBinding vb = context.getApplication().createValueBinding(minimum);
+ value = (Integer) vb.getValue(context);
+ } else {
+ value = (Integer) HELPER.asObject(context, Integer.class, minimum);
+ }
+ validator.setMinimum(value.intValue());
+ }
+
+ return validator;
+
+ }
+
+
+}
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/tag/IntegerValidatorTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/tag/IntegerValidatorTag.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/DoubleValidator.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/DoubleValidator.java?view=auto&rev=480137
==============================================================================
--- shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/DoubleValidator.java (added)
+++ shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/DoubleValidator.java Tue Nov 28 09:39:03 2006
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.validator.validator;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.ValidatorException;
+
+/**
+ * <p><code>Validator</code> implementation that will perform both format
+ * and (optional) range checks on a Double value.</p>
+ */
+public final class DoubleValidator extends AbstractValidator
+ implements StateHolder {
+
+
+ // -------------------------------------------------------- Static Variables
+
+
+ /**
+ * <p>The Apache Commons Validator instance we will be using.</p>
+ */
+ private static final
+ org.apache.commons.validator.routines.DoubleValidator INSTANCE =
+ org.apache.commons.validator.routines.DoubleValidator.getInstance();
+
+
+ // -------------------------------------------------------------- Properties
+
+
+ private double maximum = Double.MAX_VALUE;
+ private boolean maximumSet = false;
+
+
+ /**
+ * <p>Return the configured maximum value for this validator.</p>
+ */
+ public double getMaximum() {
+ return this.maximum;
+ }
+
+
+ /**
+ * <p>Set the configured maximum value for this validator.</p>
+ *
+ * @param maximum The new maximum value
+ */
+ public void setMaximum(double maximum) {
+ this.maximum = maximum;
+ this.maximumSet = true;
+ }
+
+
+ private double minimum = Double.MIN_VALUE;
+ private boolean minimumSet = false;
+
+
+ /**
+ * <p>Return the configured minimum value for this validator.</p>
+ */
+ public double getMinimum() {
+ return this.minimum;
+ }
+
+
+ /**
+ * <p>Set the configured minimum value for this validator.</p>
+ *
+ * @param minimum The new minimum value
+ */
+ public void setMinimum(double minimum) {
+ this.minimum = minimum;
+ this.minimumSet = true;
+ }
+
+
+ // ------------------------------------------------------- Validator Methods
+
+
+ /** {@inheritDoc} */
+ public void validate(FacesContext context,
+ UIComponent component,
+ Object value) throws ValidatorException {
+
+ // Validate our parameters
+ if ((context == null) || (component == null)) {
+ throw new NullPointerException(message(context, "common.null"));
+ }
+ if (value == null) {
+ return;
+ }
+
+ // Conversion is expected to have occurred already, via an
+ // explicit or implicit Converter having been applied.
+ // Throw a validation error if this is not the case
+ if (!(value instanceof Double)) {
+ throw new ValidatorException
+ (new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ message(context, "Double.unconverted"),
+ null));
+ }
+
+ // Perform the requested range checks (if any)
+ Double dvalue = (Double) value;
+ if (minimumSet) {
+ if (maximumSet) {
+ if (!INSTANCE.isInRange(dvalue, minimum, maximum)) {
+ throw new ValidatorException
+ (new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ message(context, "Common.range",
+ new Object[] { dvalue,
+ new Double(minimum),
+ new Double(maximum) }),
+ null));
+ }
+ } else {
+ if (!INSTANCE.minValue(dvalue, minimum)) {
+ throw new ValidatorException
+ (new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ message(context, "Common.minimum",
+ new Object[] { dvalue,
+ new Double(minimum) }),
+ null));
+ }
+ }
+ } else if (maximumSet) {
+ if (!INSTANCE.maxValue(dvalue, maximum)) {
+ throw new ValidatorException
+ (new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ message(context, "Common.maximum",
+ new Object[] { dvalue,
+ new Double(maximum) }),
+ null));
+ }
+ }
+
+ }
+
+
+ // ----------------------------------------------------- StateHolder Methods
+
+
+ /** {@inheritDoc} */
+ public void restoreState(FacesContext context, Object state) {
+
+ Object[] values = (Object[]) state;
+ super.restoreState(context, values[0]);
+ maximum = ((Double) values[1]).doubleValue();
+ maximumSet = ((Boolean) values[2]).booleanValue();
+ minimum = ((Double) values[3]).doubleValue();
+ minimumSet = ((Boolean) values[4]).booleanValue();
+
+ }
+
+
+ /** {@inheritDoc} */
+ public Object saveState(FacesContext context) {
+
+ Object[] values = new Object[5];
+ values[0] = super.saveState(context);
+ values[1] = new Double(maximum);
+ values[2] = this.maximumSet ? Boolean.TRUE : Boolean.FALSE;
+ values[3] = new Double(minimum);
+ values[4] = this.minimumSet ? Boolean.TRUE : Boolean.FALSE;
+ return values;
+
+ }
+
+
+ // ---------------------------------------------------------- Object Methods
+
+
+}
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/DoubleValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/DoubleValidator.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/FloatValidator.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/FloatValidator.java?view=auto&rev=480137
==============================================================================
--- shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/FloatValidator.java (added)
+++ shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/FloatValidator.java Tue Nov 28 09:39:03 2006
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.validator.validator;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.ValidatorException;
+
+/**
+ * <p><code>Validator</code> implementation that will perform both format
+ * and (optional) range checks on a Float value.</p>
+ */
+public final class FloatValidator extends AbstractValidator
+ implements StateHolder {
+
+
+ // -------------------------------------------------------- Static Variables
+
+
+ /**
+ * <p>The Apache Commons Validator instance we will be using.</p>
+ */
+ private static final
+ org.apache.commons.validator.routines.FloatValidator INSTANCE =
+ org.apache.commons.validator.routines.FloatValidator.getInstance();
+
+
+ // -------------------------------------------------------------- Properties
+
+
+ private float maximum = Float.MAX_VALUE;
+ private boolean maximumSet = false;
+
+
+ /**
+ * <p>Return the configured maximum value for this validator.</p>
+ */
+ public float getMaximum() {
+ return this.maximum;
+ }
+
+
+ /**
+ * <p>Set the configured maximum value for this validator.</p>
+ *
+ * @param maximum The new maximum value
+ */
+ public void setMaximum(float maximum) {
+ this.maximum = maximum;
+ this.maximumSet = true;
+ }
+
+
+ private float minimum = Float.MIN_VALUE;
+ private boolean minimumSet = false;
+
+
+ /**
+ * <p>Return the configured minimum value for this validator.</p>
+ */
+ public float getMinimum() {
+ return this.minimum;
+ }
+
+
+ /**
+ * <p>Set the configured minimum value for this validator.</p>
+ *
+ * @param minimum The new minimum value
+ */
+ public void setMinimum(float minimum) {
+ this.minimum = minimum;
+ this.minimumSet = true;
+ }
+
+
+ // ------------------------------------------------------- Validator Methods
+
+
+ /** {@inheritDoc} */
+ public void validate(FacesContext context,
+ UIComponent component,
+ Object value) throws ValidatorException {
+
+ // Validate our parameters
+ if ((context == null) || (component == null)) {
+ throw new NullPointerException(message(context, "common.null"));
+ }
+ if (value == null) {
+ return;
+ }
+
+ // Conversion is expected to have occurred already, via an
+ // explicit or implicit Converter having been applied.
+ // Throw a validation error if this is not the case
+ if (!(value instanceof Float)) {
+ throw new ValidatorException
+ (new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ message(context, "Float.unconverted"),
+ null));
+ }
+
+ // Perform the requested range checks (if any)
+ Float fvalue = (Float) value;
+ if (minimumSet) {
+ if (maximumSet) {
+ if (!INSTANCE.isInRange(fvalue, minimum, maximum)) {
+ throw new ValidatorException
+ (new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ message(context, "Common.range",
+ new Object[] { fvalue,
+ new Float(minimum),
+ new Float(maximum) }),
+ null));
+ }
+ } else {
+ if (!INSTANCE.minValue(fvalue, minimum)) {
+ throw new ValidatorException
+ (new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ message(context, "Common.minimum",
+ new Object[] { fvalue,
+ new Float(minimum) }),
+ null));
+ }
+ }
+ } else if (maximumSet) {
+ if (!INSTANCE.maxValue(fvalue, maximum)) {
+ throw new ValidatorException
+ (new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ message(context, "Common.maximum",
+ new Object[] { fvalue,
+ new Float(maximum) }),
+ null));
+ }
+ }
+
+ }
+
+
+ // ----------------------------------------------------- StateHolder Methods
+
+
+ /** {@inheritDoc} */
+ public void restoreState(FacesContext context, Object state) {
+
+ Object[] values = (Object[]) state;
+ super.restoreState(context, values[0]);
+ maximum = ((Float) values[1]).floatValue();
+ maximumSet = ((Boolean) values[2]).booleanValue();
+ minimum = ((Float) values[3]).floatValue();
+ minimumSet = ((Boolean) values[4]).booleanValue();
+
+ }
+
+
+ /** {@inheritDoc} */
+ public Object saveState(FacesContext context) {
+
+ Object[] values = new Object[5];
+ values[0] = super.saveState(context);
+ values[1] = new Float(maximum);
+ values[2] = this.maximumSet ? Boolean.TRUE : Boolean.FALSE;
+ values[3] = new Float(minimum);
+ values[4] = this.minimumSet ? Boolean.TRUE : Boolean.FALSE;
+ return values;
+
+ }
+
+
+ // ---------------------------------------------------------- Object Methods
+
+
+}
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/FloatValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/FloatValidator.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/LongValidator.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/LongValidator.java?view=auto&rev=480137
==============================================================================
--- shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/LongValidator.java (added)
+++ shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/LongValidator.java Tue Nov 28 09:39:03 2006
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.validator.validator;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.ValidatorException;
+
+/**
+ * <p><code>Validator</code> implementation that will perform both format
+ * and (optional) range checks on a Long value.</p>
+ */
+public final class LongValidator extends AbstractValidator
+ implements StateHolder {
+
+
+ // -------------------------------------------------------- Static Variables
+
+
+ /**
+ * <p>The Apache Commons Validator instance we will be using.</p>
+ */
+ private static final
+ org.apache.commons.validator.routines.LongValidator INSTANCE =
+ org.apache.commons.validator.routines.LongValidator.getInstance();
+
+
+ // -------------------------------------------------------------- Properties
+
+
+ private long maximum = Long.MAX_VALUE;
+ private boolean maximumSet = false;
+
+
+ /**
+ * <p>Return the configured maximum value for this validator.</p>
+ */
+ public long getMaximum() {
+ return this.maximum;
+ }
+
+
+ /**
+ * <p>Set the configured maximum value for this validator.</p>
+ *
+ * @param maximum The new maximum value
+ */
+ public void setMaximum(long maximum) {
+ this.maximum = maximum;
+ this.maximumSet = true;
+ }
+
+
+ private long minimum = Long.MIN_VALUE;
+ private boolean minimumSet = false;
+
+
+ /**
+ * <p>Return the configured minimum value for this validator.</p>
+ */
+ public long getMinimum() {
+ return this.minimum;
+ }
+
+
+ /**
+ * <p>Set the configured minimum value for this validator.</p>
+ *
+ * @param minimum The new minimum value
+ */
+ public void setMinimum(long minimum) {
+ this.minimum = minimum;
+ this.minimumSet = true;
+ }
+
+
+ // ------------------------------------------------------- Validator Methods
+
+
+ /** {@inheritDoc} */
+ public void validate(FacesContext context,
+ UIComponent component,
+ Object value) throws ValidatorException {
+
+ // Validate our parameters
+ if ((context == null) || (component == null)) {
+ throw new NullPointerException(message(context, "common.null"));
+ }
+ if (value == null) {
+ return;
+ }
+
+ // Conversion is expected to have occurred already, via an
+ // explicit or implicit Converter having been applied.
+ // Throw a validation error if this is not the case
+ if (!(value instanceof Long)) {
+ throw new ValidatorException
+ (new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ message(context, "Long.unconverted"),
+ null));
+ }
+
+ // Perform the requested range checks (if any)
+ Long lvalue = (Long) value;
+ if (minimumSet) {
+ if (maximumSet) {
+ if (!INSTANCE.isInRange(lvalue, minimum, maximum)) {
+ throw new ValidatorException
+ (new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ message(context, "Common.range",
+ new Object[] { lvalue,
+ new Long(minimum),
+ new Long(maximum) }),
+ null));
+ }
+ } else {
+ if (!INSTANCE.minValue(lvalue, minimum)) {
+ throw new ValidatorException
+ (new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ message(context, "Common.minimum",
+ new Object[] { lvalue,
+ new Long(minimum) }),
+ null));
+ }
+ }
+ } else if (maximumSet) {
+ if (!INSTANCE.maxValue(lvalue, maximum)) {
+ throw new ValidatorException
+ (new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ message(context, "Common.maximum",
+ new Object[] { lvalue,
+ new Long(maximum) }),
+ null));
+ }
+ }
+
+ }
+
+
+ // ----------------------------------------------------- StateHolder Methods
+
+
+ /** {@inheritDoc} */
+ public void restoreState(FacesContext context, Object state) {
+
+ Object[] values = (Object[]) state;
+ super.restoreState(context, values[0]);
+ maximum = ((Long) values[1]).longValue();
+ maximumSet = ((Boolean) values[2]).booleanValue();
+ minimum = ((Long) values[3]).longValue();
+ minimumSet = ((Boolean) values[4]).booleanValue();
+
+ }
+
+
+ /** {@inheritDoc} */
+ public Object saveState(FacesContext context) {
+
+ Object[] values = new Object[5];
+ values[0] = super.saveState(context);
+ values[1] = new Long(maximum);
+ values[2] = this.maximumSet ? Boolean.TRUE : Boolean.FALSE;
+ values[3] = new Long(minimum);
+ values[4] = this.minimumSet ? Boolean.TRUE : Boolean.FALSE;
+ return values;
+
+ }
+
+
+ // ---------------------------------------------------------- Object Methods
+
+
+}
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/LongValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/LongValidator.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/ShortValidator.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/ShortValidator.java?view=auto&rev=480137
==============================================================================
--- shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/ShortValidator.java (added)
+++ shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/ShortValidator.java Tue Nov 28 09:39:03 2006
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.validator.validator;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.ValidatorException;
+
+/**
+ * <p><code>Validator</code> implementation that will perform both format
+ * and (optional) range checks on a Short value.</p>
+ */
+public final class ShortValidator extends AbstractValidator
+ implements StateHolder {
+
+
+ // -------------------------------------------------------- Static Variables
+
+
+ /**
+ * <p>The Apache Commons Validator instance we will be using.</p>
+ */
+ private static final
+ org.apache.commons.validator.routines.ShortValidator INSTANCE =
+ org.apache.commons.validator.routines.ShortValidator.getInstance();
+
+
+ // -------------------------------------------------------------- Properties
+
+
+ private short maximum = Short.MAX_VALUE;
+ private boolean maximumSet = false;
+
+
+ /**
+ * <p>Return the configured maximum value for this validator.</p>
+ */
+ public short getMaximum() {
+ return this.maximum;
+ }
+
+
+ /**
+ * <p>Set the configured maximum value for this validator.</p>
+ *
+ * @param maximum The new maximum value
+ */
+ public void setMaximum(short maximum) {
+ this.maximum = maximum;
+ this.maximumSet = true;
+ }
+
+
+ private short minimum = Short.MIN_VALUE;
+ private boolean minimumSet = false;
+
+
+ /**
+ * <p>Return the configured minimum value for this validator.</p>
+ */
+ public short getMinimum() {
+ return this.minimum;
+ }
+
+
+ /**
+ * <p>Set the configured minimum value for this validator.</p>
+ *
+ * @param minimum The new minimum value
+ */
+ public void setMinimum(short minimum) {
+ this.minimum = minimum;
+ this.minimumSet = true;
+ }
+
+
+ // ------------------------------------------------------- Validator Methods
+
+
+ /** {@inheritDoc} */
+ public void validate(FacesContext context,
+ UIComponent component,
+ Object value) throws ValidatorException {
+
+ // Validate our parameters
+ if ((context == null) || (component == null)) {
+ throw new NullPointerException(message(context, "common.null"));
+ }
+ if (value == null) {
+ return;
+ }
+
+ // Conversion is expected to have occurred already, via an
+ // explicit or implicit Converter having been applied.
+ // Throw a validation error if this is not the case
+ if (!(value instanceof Short)) {
+ throw new ValidatorException
+ (new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ message(context, "Short.unconverted"),
+ null));
+ }
+
+ // Perform the requested range checks (if any)
+ Short svalue = (Short) value;
+ if (minimumSet) {
+ if (maximumSet) {
+ if (!INSTANCE.isInRange(svalue, minimum, maximum)) {
+ throw new ValidatorException
+ (new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ message(context, "Common.range",
+ new Object[] { svalue,
+ new Short(minimum),
+ new Short(maximum) }),
+ null));
+ }
+ } else {
+ if (!INSTANCE.minValue(svalue, minimum)) {
+ throw new ValidatorException
+ (new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ message(context, "Common.minimum",
+ new Object[] { svalue,
+ new Short(minimum) }),
+ null));
+ }
+ }
+ } else if (maximumSet) {
+ if (!INSTANCE.maxValue(svalue, maximum)) {
+ throw new ValidatorException
+ (new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ message(context, "Common.maximum",
+ new Object[] { svalue,
+ new Short(maximum) }),
+ null));
+ }
+ }
+
+ }
+
+
+ // ----------------------------------------------------- StateHolder Methods
+
+
+ /** {@inheritDoc} */
+ public void restoreState(FacesContext context, Object state) {
+
+ Object[] values = (Object[]) state;
+ super.restoreState(context, values[0]);
+ maximum = ((Short) values[1]).shortValue();
+ maximumSet = ((Boolean) values[2]).booleanValue();
+ minimum = ((Short) values[3]).shortValue();
+ minimumSet = ((Boolean) values[4]).booleanValue();
+
+ }
+
+
+ /** {@inheritDoc} */
+ public Object saveState(FacesContext context) {
+
+ Object[] values = new Object[5];
+ values[0] = super.saveState(context);
+ values[1] = new Short(maximum);
+ values[2] = this.maximumSet ? Boolean.TRUE : Boolean.FALSE;
+ values[3] = new Short(minimum);
+ values[4] = this.minimumSet ? Boolean.TRUE : Boolean.FALSE;
+ return values;
+
+ }
+
+
+ // ---------------------------------------------------------- Object Methods
+
+
+}
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/ShortValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/validator/ShortValidator.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: shale/framework/trunk/shale-validator/src/main/resources/META-INF/converters.tld
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-validator/src/main/resources/META-INF/converters.tld?view=auto&rev=480137
==============================================================================
--- shale/framework/trunk/shale-validator/src/main/resources/META-INF/converters.tld (added)
+++ shale/framework/trunk/shale-validator/src/main/resources/META-INF/converters.tld Tue Nov 28 09:39:03 2006
@@ -0,0 +1,276 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to you under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!DOCTYPE taglib PUBLIC
+ "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
+ "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
+
+<taglib>
+
+
+ <tlib-version>1.0</tlib-version>
+ <jsp-version>1.2</jsp-version>
+ <short-name>convert</short-name>
+ <uri>http://shale.apache.org/converters</uri>
+ <display-name>Shale Converter JSF Tags</display-name>
+ <description>
+ This tag library contains tags for the JSF Converters supported by
+ the Shale Framework for integration with Commons Validator.
+ </description>
+
+
+ <!-- ================= JSF Converter Tags ============================== -->
+
+
+ <tag>
+
+ <name>double</name>
+ <tag-class>org.apache.shale.validator.tag.DoubleConverterTag</tag-class>
+ <body-content>empty</body-content>
+ <display-name>Double Converter</display-name>
+ <description>
+ Convert between strings and doubles based on the specified
+ converter properties.
+ </description>
+
+ <attribute>
+ <name>locale</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ Locale to use for locale-sensitive conversions. If not
+ specified, the Locale for the current view is used.
+ </description>
+ </attribute>
+
+ <attribute>
+ <name>message</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ Error message template for reporting conversion errors. If not
+ specified, the default value from either the application
+ message resource bundle, or the default resource bundle,
+ will be used.
+ </description>
+ </attribute>
+
+ <attribute>
+ <name>pattern</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ Number format pattern string (see javadocs for
+ java.text.DecimalFormat for details) to use for
+ conversion. If not specified, no pattern is used.
+ </description>
+ </attribute>
+
+ </tag>
+
+
+ <tag>
+
+ <name>float</name>
+ <tag-class>org.apache.shale.validator.tag.FloatConverterTag</tag-class>
+ <body-content>empty</body-content>
+ <display-name>Float Converter</display-name>
+ <description>
+ Convert between strings and floats based on the specified
+ converter properties.
+ </description>
+
+ <attribute>
+ <name>locale</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ Locale to use for locale-sensitive conversions. If not
+ specified, the Locale for the current view is used.
+ </description>
+ </attribute>
+
+ <attribute>
+ <name>message</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ Error message template for reporting conversion errors. If not
+ specified, the default value from either the application
+ message resource bundle, or the default resource bundle,
+ will be used.
+ </description>
+ </attribute>
+
+ <attribute>
+ <name>pattern</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ Number format pattern string (see javadocs for
+ java.text.DecimalFormat for details) to use for
+ conversion. If not specified, no pattern is used.
+ </description>
+ </attribute>
+
+ </tag>
+
+
+ <tag>
+
+ <name>integer</name>
+ <tag-class>org.apache.shale.validator.tag.IntegerConverterTag</tag-class>
+ <body-content>empty</body-content>
+ <display-name>Integer Converter</display-name>
+ <description>
+ Convert between strings and integers based on the specified
+ converter properties.
+ </description>
+
+ <attribute>
+ <name>locale</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ Locale to use for locale-sensitive conversions. If not
+ specified, the Locale for the current view is used.
+ </description>
+ </attribute>
+
+ <attribute>
+ <name>message</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ Error message template for reporting conversion errors. If not
+ specified, the default value from either the application
+ message resource bundle, or the default resource bundle,
+ will be used.
+ </description>
+ </attribute>
+
+ <attribute>
+ <name>pattern</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ Number format pattern string (see javadocs for
+ java.text.DecimalFormat for details) to use for
+ conversion. If not specified, no pattern is used.
+ </description>
+ </attribute>
+
+ </tag>
+
+
+ <tag>
+
+ <name>long</name>
+ <tag-class>org.apache.shale.validator.tag.LongConverterTag</tag-class>
+ <body-content>empty</body-content>
+ <display-name>Long Converter</display-name>
+ <description>
+ Convert between strings and longs based on the specified
+ converter properties.
+ </description>
+
+ <attribute>
+ <name>locale</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ Locale to use for locale-sensitive conversions. If not
+ specified, the Locale for the current view is used.
+ </description>
+ </attribute>
+
+ <attribute>
+ <name>message</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ Error message template for reporting conversion errors. If not
+ specified, the default value from either the application
+ message resource bundle, or the default resource bundle,
+ will be used.
+ </description>
+ </attribute>
+
+ <attribute>
+ <name>pattern</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ Number format pattern string (see javadocs for
+ java.text.DecimalFormat for details) to use for
+ conversion. If not specified, no pattern is used.
+ </description>
+ </attribute>
+
+ </tag>
+
+
+ <tag>
+
+ <name>short</name>
+ <tag-class>org.apache.shale.validator.tag.ShortConverterTag</tag-class>
+ <body-content>empty</body-content>
+ <display-name>Short Converter</display-name>
+ <description>
+ Convert between strings and shorts based on the specified
+ converter properties.
+ </description>
+
+ <attribute>
+ <name>locale</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ Locale to use for locale-sensitive conversions. If not
+ specified, the Locale for the current view is used.
+ </description>
+ </attribute>
+
+ <attribute>
+ <name>message</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ Error message template for reporting conversion errors. If not
+ specified, the default value from either the application
+ message resource bundle, or the default resource bundle,
+ will be used.
+ </description>
+ </attribute>
+
+ <attribute>
+ <name>pattern</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ Number format pattern string (see javadocs for
+ java.text.DecimalFormat for details) to use for
+ conversion. If not specified, no pattern is used.
+ </description>
+ </attribute>
+
+ </tag>
+
+
+</taglib>
Propchange: shale/framework/trunk/shale-validator/src/main/resources/META-INF/converters.tld
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: shale/framework/trunk/shale-validator/src/main/resources/META-INF/converters.tld
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: shale/framework/trunk/shale-validator/src/main/resources/META-INF/taglib.tld
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-validator/src/main/resources/META-INF/taglib.tld?view=diff&rev=480137&r1=480136&r2=480137
==============================================================================
--- shale/framework/trunk/shale-validator/src/main/resources/META-INF/taglib.tld (original)
+++ shale/framework/trunk/shale-validator/src/main/resources/META-INF/taglib.tld Tue Nov 28 09:39:03 2006
@@ -35,14 +35,6 @@
</description>
- <!-- ===================== Servlet Listeners ============================= -->
-
-
- <listener>
- <listener-class>org.apache.shale.validator.faces.ValidatorLifecycleListener</listener-class>
- </listener>
-
-
<!-- ================= JSF Component Tags ================================ -->