-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04e8820
commit dd1311a
Showing
6 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
plugin/src/main/groovy/org/clarify4j/common/annotation/IsEmail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.clarify4j.common.annotation; | ||
|
||
import org.clarify4j.config.validator.EmailValidator; | ||
|
||
import javax.validation.Constraint; | ||
import javax.validation.Payload; | ||
import java.lang.annotation.*; | ||
|
||
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.FIELD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Constraint(validatedBy = EmailValidator.class) | ||
@Documented | ||
public @interface IsEmail { | ||
String message() default "Invalid email"; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
|
||
boolean disabled() default false; | ||
} |
29 changes: 29 additions & 0 deletions
29
plugin/src/main/groovy/org/clarify4j/config/validator/EmailValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.clarify4j.config.validator; | ||
|
||
import org.clarify4j.common.annotation.IsEmail; | ||
import org.unify4j.common.Regex4j; | ||
import org.unify4j.common.String4j; | ||
|
||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorContext; | ||
|
||
public class EmailValidator implements ConstraintValidator<IsEmail, String> { | ||
protected boolean disabled; | ||
|
||
@Override | ||
public void initialize(IsEmail url) { | ||
this.disabled = url.disabled(); | ||
} | ||
|
||
@Override | ||
public boolean isValid(String value, ConstraintValidatorContext context) { | ||
if (this.disabled) { | ||
return true; | ||
} | ||
if (String4j.isEmpty(value)) { | ||
return false; | ||
} | ||
return Regex4j.isEmail(value); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters