[hibernate-commits] Hibernate SVN: r18783 - in validator/trunk: hibernate-validator/src/main/java/org/hibernate/validator/constraints and 4 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Thu Feb 11 11:16:22 EST 2010
Author: hardy.ferentschik
Date: 2010-02-11 11:16:21 -0500 (Thu, 11 Feb 2010)
New Revision: 18783
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/Url.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/impl/UrlValidator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/UrlValidatorTest.java
Modified:
validator/trunk/hibernate-validator-archetype/pom.xml
validator/trunk/hibernate-validator-legacy/pom.xml
validator/trunk/pom.xml
Log:
HV-283
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/Url.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/Url.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/Url.java 2010-02-11 16:16:21 UTC (rev 18783)
@@ -0,0 +1,48 @@
+// $Id: Length.java 17427 2009-08-27 09:47:28Z hardy.ferentschik $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.validator.constraints;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+import org.hibernate.validator.constraints.impl.URLValidator;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Validate that the string is a valid URL.
+ *
+ * @author Hardy Ferentschik
+ */
+ at Documented
+ at Constraint(validatedBy = URLValidator.class)
+ at Target({ METHOD, FIELD, TYPE })
+ at Retention(RUNTIME)
+public @interface URL {
+ public abstract String message() default "{org.hibernate.validator.constraints.URL.message}";
+
+ public abstract Class<?>[] groups() default { };
+
+ public abstract Class<? extends Payload>[] payload() default { };
+}
\ No newline at end of file
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/impl/UrlValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/impl/UrlValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/impl/UrlValidator.java 2010-02-11 16:16:21 UTC (rev 18783)
@@ -0,0 +1,47 @@
+// $Id: LengthValidator.java 17521 2009-09-16 12:50:41Z hardy.ferentschik $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.validator.constraints.impl;
+
+import java.net.MalformedURLException;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+import org.hibernate.validator.constraints.URL;
+
+/**
+ * Validate that the string is a valid URL.
+ *
+ * @author Hardy Ferentschik
+ */
+public class URLValidator implements ConstraintValidator<URL, String> {
+ public void initialize(URL url) {
+ }
+
+ public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
+ if ( value == null ) {
+ return true;
+ }
+ try {
+ new java.net.URL( value );
+ return true;
+ }
+ catch ( MalformedURLException e ) {
+ return false;
+ }
+ }
+}
\ No newline at end of file
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/UrlValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/UrlValidatorTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/UrlValidatorTest.java 2010-02-11 16:16:21 UTC (rev 18783)
@@ -0,0 +1,48 @@
+// $Id: LengthValidatorTest.java 17521 2009-09-16 12:50:41Z hardy.ferentschik $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* 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.hibernate.validator.constraints.impl;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.URL;
+import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
+
+/**
+ * Tests the {@code Url} constraint.
+ *
+ * @author Hardy Ferentschik
+ */
+public class URLValidatorTest {
+
+ @Test
+ public void testIsValidUrl() {
+ AnnotationDescriptor<URL> descriptor = new AnnotationDescriptor<URL>( URL.class );
+ descriptor.setValue( "message", "{org.hibernate.validator.constraints.URL.message}" );
+ URL url = AnnotationFactory.create( descriptor );
+ URLValidator validator = new URLValidator();
+ validator.initialize( url );
+ assertTrue( validator.isValid( null, null ) );
+ assertFalse( validator.isValid( "", null ) );
+ assertFalse( validator.isValid( "http", null ) );
+ assertFalse( validator.isValid( "ftp//abc.de", null ) );
+ assertTrue( validator.isValid( "ftp://abc.de", null ) );
+ }
+}
\ No newline at end of file
Modified: validator/trunk/hibernate-validator-archetype/pom.xml
===================================================================
--- validator/trunk/hibernate-validator-archetype/pom.xml 2010-02-11 15:51:25 UTC (rev 18782)
+++ validator/trunk/hibernate-validator-archetype/pom.xml 2010-02-11 16:16:21 UTC (rev 18783)
@@ -54,6 +54,12 @@
<target>1.5</target>
</configuration>
</plugin>
+ <plugin>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
</plugins>
</build>
<repositories>
Modified: validator/trunk/hibernate-validator-legacy/pom.xml
===================================================================
--- validator/trunk/hibernate-validator-legacy/pom.xml 2010-02-11 15:51:25 UTC (rev 18782)
+++ validator/trunk/hibernate-validator-legacy/pom.xml 2010-02-11 16:16:21 UTC (rev 18783)
@@ -106,6 +106,17 @@
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
<profiles>
<profile>
<id>dist</id>
Modified: validator/trunk/pom.xml
===================================================================
--- validator/trunk/pom.xml 2010-02-11 15:51:25 UTC (rev 18782)
+++ validator/trunk/pom.xml 2010-02-11 16:16:21 UTC (rev 18783)
@@ -240,6 +240,11 @@
</configuration>
</plugin>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.5</version>
+ </plugin>
+ <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
More information about the hibernate-commits
mailing list