You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2005/11/23 23:03:00 UTC
svn commit: r348580 - in
/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/isbnvalidator: ./
ISBNValidator.java ValidateISBNTag.java
Author: matzew
Date: Wed Nov 23 14:02:54 2005
New Revision: 348580
URL: http://svn.apache.org/viewcvs?rev=348580&view=rev
Log:
reintroduced isbn codes validator
Added:
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/isbnvalidator/
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/isbnvalidator/ISBNValidator.java
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/isbnvalidator/ValidateISBNTag.java
Added: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/isbnvalidator/ISBNValidator.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/isbnvalidator/ISBNValidator.java?rev=348580&view=auto
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/isbnvalidator/ISBNValidator.java (added)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/isbnvalidator/ISBNValidator.java Wed Nov 23 14:02:54 2005
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.custom.isbnvalidator;
+
+import org.apache.myfaces.util.MessageUtils;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+
+/**
+ * @author <a href="mailto:matzew@apache.org">Matthias Weßendorf</a> (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class ISBNValidator implements Validator {
+
+ /**
+ * <p>The standard converter id for this converter.</p>
+ */
+ public static final String VALIDATOR_ID = "org.apache.myfaces.validator.ISBN";
+ /**
+ * <p>The message identifier of the {@link FacesMessage} to be created if
+ * the maximum length check fails.</p>
+ */
+ public static final String ISBN_MESSAGE_ID = "org.apache.myfaces.ISBN.INVALID";
+
+ /**
+ * <p>isbnValidator</p>
+ */
+ private org.apache.commons.validator.ISBNValidator isbnValidator;
+
+ public ISBNValidator(){
+ isbnValidator = new org.apache.commons.validator.ISBNValidator();
+ }
+
+ /**
+ * methode that validates isbn codes.
+ * it uses the commons-validator
+ */
+ public void validate(
+ FacesContext facesContext,
+ UIComponent uiComponent,
+ Object value)
+ throws ValidatorException {
+
+
+ if (facesContext == null) throw new NullPointerException("facesContext");
+ if (uiComponent == null) throw new NullPointerException("uiComponent");
+
+ if (value == null)
+ {
+ return;
+ }
+ if (!isbnValidator.isValid( value.toString())) {
+ Object[] args = {value.toString()};
+ throw new ValidatorException(MessageUtils.getMessage(FacesMessage.SEVERITY_ERROR,ISBN_MESSAGE_ID, args));
+
+ }
+
+ }
+
+}
\ No newline at end of file
Added: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/isbnvalidator/ValidateISBNTag.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/isbnvalidator/ValidateISBNTag.java?rev=348580&view=auto
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/isbnvalidator/ValidateISBNTag.java (added)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/isbnvalidator/ValidateISBNTag.java Wed Nov 23 14:02:54 2005
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.custom.isbnvalidator;
+
+import javax.faces.validator.Validator;
+import javax.faces.webapp.ValidatorTag;
+import javax.servlet.jsp.JspException;
+
+import org.apache.myfaces.custom.isbnvalidator.ISBNValidator;
+
+/**
+ * @author <a href="mailto:matzew@apache.org">Matthias Weßendorf</a> (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class ValidateISBNTag extends ValidatorTag{
+
+ public ValidateISBNTag(){}
+
+ protected Validator createValidator() throws JspException
+ {
+ setValidatorId(ISBNValidator.VALIDATOR_ID);
+ ISBNValidator validator = (ISBNValidator)super.createValidator();
+ return validator;
+ }
+
+ public void release()
+ {
+ super.release();
+ }
+
+
+}
\ No newline at end of file