Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/CUSIP.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/CUSIP.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/CUSIP.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/CUSIP.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,55 @@ +/* + * 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.bval.extras.constraints.checkdigit; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * <p> + * -- + * TODO - This class is NOT part of the bean_validation spec and might disappear + * as soon as a final version of the specification contains a similar functionality. + * -- + * </p> + * Description: annotation to validate as CUSIP<br/> + */ +@Documented +@Constraint(validatedBy = CUSIPValidator.class) +@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) +@Retention(RUNTIME) +public @interface CUSIP { + + Class<?>[] groups() default {}; + + String message() default "{org.apache.bval.extras.constraints.checkdigit.CUSIP.message}"; + + Class<? extends Payload>[] payload() default {}; + +}
Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/CUSIPValidator.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/CUSIPValidator.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/CUSIPValidator.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/CUSIPValidator.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,80 @@ +/* + * 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.bval.extras.constraints.checkdigit; + +import static java.lang.Character.getNumericValue; + +/** + * Modulus 10 <b>CUSIP</b> (North American Securities) + * Check Digit calculation/validation. + * <p> + * CUSIP Numbers are 9 character alphanumeric codes used + * to identify North American Securities. + * <p> + * Check digit calculation uses the <i>Modulus 10 Double Add Double</i> technique + * with every second digit being weighted by 2. Alphabetic characters are + * converted to numbers by their position in the alphabet starting with A being 10. + * Weighted numbers greater than ten are treated as two separate numbers. + * <p> + * + * <p> + * See <a href="http://en.wikipedia.org/wiki/CUSIP">Wikipedia - CUSIP</a> + * for more details. + */ +public final class CUSIPValidator extends ModulusValidator<CUSIP> { + + /** weighting given to digits depending on their right position */ + private static final int[] POSITION_WEIGHT = new int[] { 2, 1 }; + + public CUSIPValidator() { + super(10); + } + + /** + * Calculates the <i>weighted</i> value of a character in the + * code at a specified position. + * <p> + * ABA Routing numbers are weighted in the following manner: + * <pre><code> + * left position: 1 2 3 4 5 6 7 8 9 + * weight: 3 7 1 3 7 1 3 7 1 + * </code></pre> + * + * {@inheritDoc} + */ + @Override + protected int weightedValue(int charValue, int leftPos, int rightPos) throws Exception { + int weight = POSITION_WEIGHT[rightPos % 2]; + int weightedValue = (charValue * weight); + return sumDigits(weightedValue); + } + + /** + * {@inheritDoc} + */ + @Override + protected int toInt(char character, int leftPos, int rightPos) { + int charValue = getNumericValue(character); + if (charValue < 0 || charValue > 35) { + throw new IllegalArgumentException("Invalid Character[" + leftPos + "] = '" + charValue + "'"); + } + return charValue; + } + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,55 @@ +/* + * 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.bval.extras.constraints.checkdigit; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * <p> + * -- + * TODO - This class is NOT part of the bean_validation spec and might disappear + * as soon as a final version of the specification contains a similar functionality. + * -- + * </p> + * Description: annotation to validate as EAN13<br/> + */ +@Documented +@Constraint(validatedBy = EAN13Validator.class) +@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) +@Retention(RUNTIME) +public @interface EAN13 { + + Class<?>[] groups() default {}; + + String message() default "{org.apache.bval.extras.constraints.checkdigit.EAN13.message}"; + + Class<? extends Payload>[] payload() default {}; + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13Validator.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13Validator.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13Validator.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13Validator.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,67 @@ +/* + * 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.bval.extras.constraints.checkdigit; + +/** + * Modulus 10 <b>EAN-13</b> / <b>UPC</b> / <b>ISBN-13</b> Check Digit + * calculation/validation. + * <p> + * Check digit calculation is based on <i>modulus 10</i> with digits in + * an <i>odd</i> position (from right to left) being weighted 1 and <i>even</i> + * position digits being weighted 3. + * <p> + * For further information see: + * <ul> + * <li>EAN-13 - see + * <a href="http://en.wikipedia.org/wiki/European_Article_Number">Wikipedia - + * European Article Number</a>.</li> + * <li>UPC - see + * <a href="http://en.wikipedia.org/wiki/Universal_Product_Code">Wikipedia - + * Universal Product Code</a>.</li> + * <li>ISBN-13 - see + * <a href="http://en.wikipedia.org/wiki/ISBN">Wikipedia - International + * Standard Book Number (ISBN)</a>.</li> + * </ul> + */ +public final class EAN13Validator extends ModulusValidator<EAN13> { + + /** weighting given to digits depending on their right position */ + private static final int[] POSITION_WEIGHT = new int[] { 3, 1 }; + + public EAN13Validator() { + super(10); + } + + /** + * <p>Calculates the <i>weighted</i> value of a character in the + * code at a specified position.</p> + * + * <p>For EAN-13 (from right to left) <b>odd</b> digits are weighted + * with a factor of <b>one</b> and <b>even</b> digits with a factor + * of <b>three</b>.</p> + * + * {@inheritDoc} + */ + @Override + protected int weightedValue(int charValue, int leftPos, int rightPos) throws Exception { + int weight = POSITION_WEIGHT[rightPos % 2]; + return (charValue * weight); + } + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/IBAN.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/IBAN.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/IBAN.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/IBAN.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,55 @@ +/* + * 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.bval.extras.constraints.checkdigit; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * <p> + * -- + * TODO - This class is NOT part of the bean_validation spec and might disappear + * as soon as a final version of the specification contains a similar functionality. + * -- + * </p> + * Description: annotation to validate as IBAN<br/> + */ +@Documented +@Constraint(validatedBy = IBANValidator.class) +@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) +@Retention(RUNTIME) +public @interface IBAN { + + Class<?>[] groups() default {}; + + String message() default "{org.apache.bval.extras.constraints.checkdigit.IBAN.message}"; + + Class<? extends Payload>[] payload() default {}; + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/IBANValidator.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/IBANValidator.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/IBANValidator.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/IBANValidator.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,82 @@ +/* + * 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.bval.extras.constraints.checkdigit; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +import static java.lang.Character.getNumericValue; + +/** + * <b>IBAN</b> (International Bank Account Number) Check Digit calculation/validation. + * <p> + * This routine is based on the ISO 7064 Mod 97,10 check digit caluclation routine. + * <p> + * The two check digit characters in a IBAN number are the third and fourth characters + * in the code. For <i>check digit</i> calculation/validation the first four characters are moved + * to the end of the code. + * So <code>CCDDnnnnnnn</code> becomes <code>nnnnnnnCCDD</code> (where + * <code>CC</code> is the country code and <code>DD</code> is the check digit). For + * check digit calcualtion the check digit value should be set to zero (i.e. + * <code>CC00nnnnnnn</code> in this example. + * <p> + * For further information see + * <a href="http://en.wikipedia.org/wiki/International_Bank_Account_Number">Wikipedia - + * IBAN number</a>. + */ +public final class IBANValidator implements ConstraintValidator<IBAN, CharSequence> { + + private static final long MAX = 999999999; + + private static final long MODULUS = 97; + + /** + * {@inheritDoc} + */ + @Override + public boolean isValid(CharSequence code, ConstraintValidatorContext context) { + if (code.length() < 5) { + return false; + } + + String reformattedCode = code.subSequence(4, code.length()).toString() + code.subSequence(0, 4).toString(); + long total = 0; + for (int i = 0; i < reformattedCode.length(); i++) { + int charValue = getNumericValue(reformattedCode.charAt(i)); + if (charValue < 0 || charValue > 35) { + return false; + } + total = (charValue > 9 ? total * 100 : total * 10) + charValue; + if (total > MAX) { + total = (total % MODULUS); + } + } + + return (total % MODULUS) == 1; + } + + /** + * {@inheritDoc} + */ + @Override + public void initialize(IBAN iban) { + // not needed + } + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/ISBN10.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/ISBN10.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/ISBN10.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/ISBN10.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,55 @@ +/* + * 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.bval.extras.constraints.checkdigit; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * <p> + * -- + * TODO - This class is NOT part of the bean_validation spec and might disappear + * as soon as a final version of the specification contains a similar functionality. + * -- + * </p> + * Description: annotation to validate as ISBN10<br/> + */ +@Documented +@Constraint(validatedBy = ISBN10Validator.class) +@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) +@Retention(RUNTIME) +public @interface ISBN10 { + + Class<?>[] groups() default {}; + + String message() default "{org.apache.bval.extras.constraints.checkdigit.ISBN10.message}"; + + Class<? extends Payload>[] payload() default {}; + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/ISBN10Validator.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/ISBN10Validator.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/ISBN10Validator.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/ISBN10Validator.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,80 @@ +/* + * 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.bval.extras.constraints.checkdigit; + +/** + * Modulus 11 <b>ISBN-10</b> Check Digit calculation/validation. + * <p> + * ISBN-10 Numbers are a numeric code except for the last (check) digit + * which can have a value of "X". + * <p> + * Check digit calculation is based on <i>modulus 11</i> with digits being weighted + * based by their position, from right to left with the first digit being weighted + * 1, the second 2 and so on. If the check digit is calculated as "10" it is converted + * to "X". + * <p> + * <b>N.B.</b> From 1st January 2007 the book industry will start to use a new 13 digit + * ISBN number (rather than this 10 digit ISBN number) which uses the EAN-13 / UPC + * (see {@link EAN13CheckDigit}) standard. + * <p> + * For further information see: + * <ul> + * <li><a href="http://en.wikipedia.org/wiki/ISBN">Wikipedia - International + * Standard Book Number (ISBN)</a>.</li> + * <li><a href="http://www.isbn.org/standards/home/isbn/transition.asp">ISBN-13 + * Transition details</a>.</li> + * </ul> + */ +public final class ISBN10Validator extends ModulusValidator<ISBN10> { + + public ISBN10Validator() { + super(11); + } + + /** + * Calculates the <i>weighted</i> value of a charcter in the + * code at a specified position. + * + * <p>For ISBN-10 (from right to left) digits are weighted + * by their position.</p> + * + * {@inheritDoc} + */ + @Override + protected int weightedValue(int charValue, int leftPos, int rightPos) throws Exception { + return (charValue * rightPos); + } + + /** + * <p>Convert a character at a specified position to an + * integer value.</p> + * + * <p>Character 'X' check digit converted to 10.</p> + * + * {@inheritDoc} + */ + @Override + protected int toInt(char character, int leftPos, int rightPos) { + if (rightPos == 1 && character == 'X') { + return 10; + } + return super.toInt(character, leftPos, rightPos); + } + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Luhn.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Luhn.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Luhn.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Luhn.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,55 @@ +/* + * 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.bval.extras.constraints.checkdigit; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * <p> + * -- + * TODO - This class is NOT part of the bean_validation spec and might disappear + * as soon as a final version of the specification contains a similar functionality. + * -- + * </p> + * Description: annotation to validate as Luhn<br/> + */ +@Documented +@Constraint(validatedBy = LuhnValidator.class) +@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) +@Retention(RUNTIME) +public @interface Luhn { + + Class<?>[] groups() default {}; + + String message() default "{org.apache.bval.extras.constraints.checkdigit.Luhn.message}"; + + Class<? extends Payload>[] payload() default {}; + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/LuhnValidator.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/LuhnValidator.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/LuhnValidator.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/LuhnValidator.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,63 @@ +/* + * 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.bval.extras.constraints.checkdigit; + +/** + * Modulus 10 <b>Luhn</b> Check Digit calculation/validation. + * <p> + * Luhn check digits are used, for example, by: + * <ul> + * <li><a href="http://en.wikipedia.org/wiki/Credit_card">Credit Card Numbers</a></li> + * <li><a href="http://en.wikipedia.org/wiki/IMEI">IMEI Numbers</a> - International + * Mobile Equipment Identity Numbers</li> + * </ul> + * Check digit calculation is based on <i>modulus 10</i> with digits in + * an <i>odd</i> position (from right to left) being weighted 1 and <i>even</i> + * position digits being weighted 2 (weighted values greater than 9 have 9 subtracted). + * <p> + * See <a href="http://en.wikipedia.org/wiki/Luhn_algorithm">Wikipedia</a> + * for more details. + */ +public final class LuhnValidator extends ModulusValidator<Luhn> { + + /** weighting given to digits depending on their right position */ + private static final int[] POSITION_WEIGHT = new int[] { 2, 1 }; + + public LuhnValidator() { + super(10); + } + + /** + * <p>Calculates the <i>weighted</i> value of a charcter in the + * code at a specified position.</p> + * + * <p>For Luhn (from right to left) <b>odd</b> digits are weighted + * with a factor of <b>one</b> and <b>even</b> digits with a factor + * of <b>two</b>. Weighted values > 9, have 9 subtracted</p> + * + * {@inheritDoc} + */ + @Override + protected int weightedValue(int charValue, int leftPos, int rightPos) throws Exception { + int weight = POSITION_WEIGHT[rightPos % 2]; + int weightedValue = (charValue * weight); + return (weightedValue > 9 ? (weightedValue - 9) : weightedValue); + } + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/ModulusValidator.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/ModulusValidator.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/ModulusValidator.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/ModulusValidator.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,135 @@ +/* + * 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.bval.extras.constraints.checkdigit; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import java.lang.annotation.Annotation; + +import static java.lang.Character.getNumericValue; +import static java.lang.Character.isDigit; + +/** + * Abstract <b>Modulus</b> Check digit calculation/validation. + * <p> + * Provides a <i>base</i> class for building <i>modulus</i> Check + * Digit routines. + * <p> + * This implementation only handles <i>numeric</i> codes, such as + * <b>EAN-13</b>. For <i>alphanumeric</i> codes such as <b>EAN-128</b> you + * will need to implement/override the <code>toInt()</code> and + * <code>toChar()</code> methods. + * + * @param <A> + */ +abstract class ModulusValidator<A extends Annotation> implements ConstraintValidator<A, CharSequence> { + + private final int modulus; + + public ModulusValidator(int modulus) { + this.modulus = modulus; + } + + /** + * {@inheritDoc} + */ + @Override + public final void initialize(A annotation) { + // not needed ATM + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isValid(CharSequence code, ConstraintValidatorContext context) { + if (code.length() == 0) { + return false; + } + int total = 0; + for (int i = 0; i < code.length(); i++) { + int lth = code.length(); + int leftPos = i + 1; + int rightPos = lth - i; + try { + int charValue = toInt(code.charAt(i), leftPos, rightPos); + total += weightedValue(charValue, leftPos, rightPos); + } catch (Throwable e) { + return false; + } + } + if (total == 0) { + return false; + } + return (total % modulus) == 0; + } + + /** + * Calculates the <i>weighted</i> value of a character in the + * code at a specified position. + * <p> + * Some modulus routines weight the value of a character + * depending on its position in the code (e.g. ISBN-10), while + * others use different weighting factors for odd/even positions + * (e.g. EAN or Luhn). Implement the appropriate mechanism + * required by overriding this method. + * + * @param charValue The numeric value of the character + * @param leftPos The position of the character in the code, counting from left to right + * @param rightPos The position of the character in the code, counting from right to left + * @return The weighted value of the character + */ + protected abstract int weightedValue(int charValue, int leftPos, int rightPos) throws Exception; + + /** + * Convert a character at a specified position to an integer value. + * <p> + * <b>Note:</b> this implementation only handlers numeric values + * For non-numeric characters, override this method to provide + * character-->integer conversion. + * + * @param character The character to convert + * @param leftPos The position of the character in the code, counting from left to right + * @param rightPos The positionof the character in the code, counting from right to left + * @return The integer value of the character + */ + protected int toInt(char character, int leftPos, int rightPos) { + if (isDigit(character)) { + return getNumericValue(character); + } + throw new IllegalArgumentException("Invalid Character[" + leftPos + "] = '" + character + "'"); + } + + /** + * Add together the individual digits in a number. + * + * @param number The number whose digits are to be added + * @return The sum of the digits + */ + protected static int sumDigits(int number) { + int total = 0; + int todo = number; + while (todo > 0) { + total += todo % 10; + todo = todo / 10; + } + return total; + } + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Sedol.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Sedol.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Sedol.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Sedol.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,55 @@ +/* + * 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.bval.extras.constraints.checkdigit; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * <p> + * -- + * TODO - This class is NOT part of the bean_validation spec and might disappear + * as soon as a final version of the specification contains a similar functionality. + * -- + * </p> + * Description: annotation to validate as Sedol<br/> + */ +@Documented +@Constraint(validatedBy = SedolValidator.class) +@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) +@Retention(RUNTIME) +public @interface Sedol { + + Class<?>[] groups() default {}; + + String message() default "{org.apache.bval.extras.constraints.checkdigit.Sedol.message}"; + + Class<? extends Payload>[] payload() default {}; + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/SedolValidator.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/SedolValidator.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/SedolValidator.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/SedolValidator.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,69 @@ +/* + * 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.bval.extras.constraints.checkdigit; + +import static java.lang.Character.getNumericValue; + +/** + * Modulus 10 <b>SEDOL</b> (UK Securities) Check Digit calculation/validation. + * <p> + * SEDOL Numbers are 7 character alphanumeric codes used + * to identify UK Securities (SEDOL stands for Stock Exchange Daily Official List). + * <p> + * Check digit calculation is based on <i>modulus 10</i> with digits being weighted + * based on their position, from left to right, as follows: + * <p> + * <pre><code> + * position: 1 2 3 4 5 6 7 + * weighting: 1 3 1 7 3 9 1 + * </code></pre> + * <p> + * See <a href="http://en.wikipedia.org/wiki/SEDOL">Wikipedia - SEDOL</a> + * for more details. + */ +public final class SedolValidator extends ModulusValidator<Sedol> { + + /** weighting given to digits depending on their right position */ + private static final int[] POSITION_WEIGHT = new int[] { 1, 3, 1, 7, 3, 9, 1 }; + + public SedolValidator() { + super(10); + } + + /** + * {@inheritDoc} + */ + @Override + protected int weightedValue(int charValue, int leftPos, int rightPos) throws Exception { + return (charValue * POSITION_WEIGHT[leftPos - 1]); + } + + /** + * {@inheritDoc} + */ + @Override + protected int toInt(char character, int leftPos, int rightPos) { + int charValue = getNumericValue(character); + if (charValue < 0 || charValue > 35) { + throw new IllegalArgumentException("Invalid Character[" + leftPos + "] = '" + charValue + "'"); + } + return charValue; + } + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Verhoeff.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Verhoeff.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Verhoeff.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/Verhoeff.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,55 @@ +/* + * 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.bval.extras.constraints.checkdigit; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * <p> + * -- + * TODO - This class is NOT part of the bean_validation spec and might disappear + * as soon as a final version of the specification contains a similar functionality. + * -- + * </p> + * Description: annotation to validate as Verhoeff<br/> + */ +@Documented +@Constraint(validatedBy = VerhoeffValidator.class) +@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) +@Retention(RUNTIME) +public @interface Verhoeff { + + Class<?>[] groups() default {}; + + String message() default "{org.apache.bval.extras.constraints.checkdigit.Verhoeff.message}"; + + Class<? extends Payload>[] payload() default {}; + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/VerhoeffValidator.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/VerhoeffValidator.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/VerhoeffValidator.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/VerhoeffValidator.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,93 @@ +/* + * 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.bval.extras.constraints.checkdigit; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +import static java.lang.Character.getNumericValue; + +/** + * <b>Verhoeff</b> (Dihedral) Check Digit calculation/validation. + * <p> + * Check digit calculation for numeric codes using a + * <a href="http://en.wikipedia.org/wiki/Dihedral_group">Dihedral Group</a> + * of order 10. + * <p> + * See <a href="http://en.wikipedia.org/wiki/Verhoeff_algorithm">Wikipedia + * - Verhoeff algorithm</a> for more details. + */ +public final class VerhoeffValidator implements ConstraintValidator<Verhoeff, CharSequence> { + + //@formatter:off + /** D - multiplication table */ + private static final int[][] D_TABLE = new int[][] { + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + {1, 2, 3, 4, 0, 6, 7, 8, 9, 5}, + {2, 3, 4, 0, 1, 7, 8, 9, 5, 6}, + {3, 4, 0, 1, 2, 8, 9, 5, 6, 7}, + {4, 0, 1, 2, 3, 9, 5, 6, 7, 8}, + {5, 9, 8, 7, 6, 0, 4, 3, 2, 1}, + {6, 5, 9, 8, 7, 1, 0, 4, 3, 2}, + {7, 6, 5, 9, 8, 2, 1, 0, 4, 3}, + {8, 7, 6, 5, 9, 3, 2, 1, 0, 4}, + {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}}; + + /** P - permutation table */ + private static final int[][] P_TABLE = new int[][] { + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, + {1, 5, 7, 6, 2, 8, 3, 0, 9, 4}, + {5, 8, 0, 3, 7, 9, 6, 1, 4, 2}, + {8, 9, 1, 6, 0, 4, 3, 5, 2, 7}, + {9, 4, 5, 3, 1, 2, 6, 8, 7, 0}, + {4, 2, 8, 6, 5, 7, 3, 9, 0, 1}, + {2, 7, 9, 3, 8, 0, 6, 4, 1, 5}, + {7, 0, 4, 6, 9, 1, 3, 2, 5, 8}}; + //@formatter:on + + /** + * {@inheritDoc} + */ + @Override + public boolean isValid(CharSequence code, ConstraintValidatorContext context) { + if (code.length() == 0) { + return false; + } + + int checksum = 0; + for (int i = 0; i < code.length(); i++) { + int idx = code.length() - (i + 1); + int num = getNumericValue(code.charAt(idx)); + if (num < 0 || num > 9) { + return false; + } + checksum = D_TABLE[checksum][P_TABLE[i % 8][num]]; + } + return checksum == 0; + } + + /** + * {@inheritDoc} + */ + @Override + public void initialize(Verhoeff iban) { + // not needed + } + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/package-info.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/package-info.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/package-info.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/package-info.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,23 @@ +/* + * 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. + */ + +/** + * This package contains <i>Check Digit</i> validation routines. + */ +package org.apache.bval.extras.constraints.checkdigit; Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/AmericanExpress.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/AmericanExpress.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/AmericanExpress.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/AmericanExpress.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,60 @@ +/* + * 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.bval.extras.constraints.creditcard; + +import org.apache.bval.extras.constraints.checkdigit.Luhn; + +import javax.validation.Constraint; +import javax.validation.Payload; +import javax.validation.constraints.Pattern; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * <p> + * -- + * TODO - This class is NOT part of the bean_validation spec and might disappear + * as soon as a final version of the specification contains a similar functionality. + * -- + * </p> + * Description: annotation to validate a java.io.File is a directory<br/> + */ +@Documented +@Luhn +@Pattern(regexp = "^(3[47]\\d{13})$") +@Constraint(validatedBy = {}) +@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) +@Retention(RUNTIME) +public @interface AmericanExpress { + + Class<?>[] groups() default {}; + + String message() default "{org.apache.bval.extras.constraints.creditcard.AmericanExpress.message}"; + + Class<? extends Payload>[] payload() default {}; + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/Diners.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/Diners.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/Diners.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/Diners.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,60 @@ +/* + * 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.bval.extras.constraints.creditcard; + +import org.apache.bval.extras.constraints.checkdigit.Luhn; + +import javax.validation.Constraint; +import javax.validation.Payload; +import javax.validation.constraints.Pattern; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * <p> + * -- + * TODO - This class is NOT part of the bean_validation spec and might disappear + * as soon as a final version of the specification contains a similar functionality. + * -- + * </p> + * Description: annotation to validate a java.io.File is a directory<br/> + */ +@Documented +@Luhn +@Pattern(regexp = "^(30[0-5]\\d{11}|3095\\d{10}|36\\d{12}|3[8-9]\\d{12})$") +@Constraint(validatedBy = {}) +@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) +@Retention(RUNTIME) +public @interface Diners { + + Class<?>[] groups() default {}; + + String message() default "{org.apache.bval.extras.constraints.creditcard.Diners.message}"; + + Class<? extends Payload>[] payload() default {}; + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/Discover.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/Discover.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/Discover.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/Discover.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,60 @@ +/* + * 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.bval.extras.constraints.creditcard; + +import org.apache.bval.extras.constraints.checkdigit.Luhn; + +import javax.validation.Constraint; +import javax.validation.Payload; +import javax.validation.constraints.Pattern; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * <p> + * -- + * TODO - This class is NOT part of the bean_validation spec and might disappear + * as soon as a final version of the specification contains a similar functionality. + * -- + * </p> + * Description: annotation to validate a java.io.File is a directory<br/> + */ +@Documented +@Luhn +@Pattern(regexp = "^((6011\\d{12})|(64[4-9]\\d{13})|(65\\d{14}))$") +@Constraint(validatedBy = {}) +@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) +@Retention(RUNTIME) +public @interface Discover { + + Class<?>[] groups() default {}; + + String message() default "{org.apache.bval.extras.constraints.creditcard.Discover.message}"; + + Class<? extends Payload>[] payload() default {}; + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/Mastercard.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/Mastercard.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/Mastercard.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/Mastercard.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,60 @@ +/* + * 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.bval.extras.constraints.creditcard; + +import org.apache.bval.extras.constraints.checkdigit.Luhn; + +import javax.validation.Constraint; +import javax.validation.Payload; +import javax.validation.constraints.Pattern; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * <p> + * -- + * TODO - This class is NOT part of the bean_validation spec and might disappear + * as soon as a final version of the specification contains a similar functionality. + * -- + * </p> + * Description: annotation to validate a java.io.File is a directory<br/> + */ +@Documented +@Luhn +@Pattern(regexp = "^(5[1-5]\\d{14})$") +@Constraint(validatedBy = {}) +@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) +@Retention(RUNTIME) +public @interface Mastercard { + + Class<?>[] groups() default {}; + + String message() default "{org.apache.bval.extras.constraints.creditcard.Mastercard.message}"; + + Class<? extends Payload>[] payload() default {}; + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/Visa.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/Visa.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/Visa.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/Visa.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,58 @@ +/* + * 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.bval.extras.constraints.creditcard; + +import org.apache.bval.extras.constraints.checkdigit.Luhn; + +import javax.validation.Constraint; +import javax.validation.Payload; +import javax.validation.constraints.Pattern; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * <p> + * -- + * TODO - This class is NOT part of the bean_validation spec and might disappear + * as soon as a final version of the specification contains a similar functionality. + * -- + * </p> + * Description: annotation to validate a java.io.File is a directory<br/> + */ +@Documented +@Luhn +@Pattern(regexp = "^(4)(\\d{12}|\\d{15})$") +@Constraint(validatedBy = {}) +@Target({ FIELD, ANNOTATION_TYPE, PARAMETER }) +@Retention(RUNTIME) +public @interface Visa { + + Class<?>[] groups() default {}; + + String message() default "{org.apache.bval.extras.constraints.creditcard.Visa.message}"; + + Class<? extends Payload>[] payload() default {}; + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/package-info.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/package-info.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/package-info.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/creditcard/package-info.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,23 @@ +/* + * 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. + */ + +/** + * This package contains <i>Credit Card</i> validation routines. + */ +package org.apache.bval.extras.constraints.creditcard; Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/Directory.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/Directory.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/Directory.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/Directory.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,53 @@ +/* + * 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.bval.extras.constraints.file; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * <p> + * -- + * TODO - This class is NOT part of the bean_validation spec and might disappear + * as soon as a final version of the specification contains a similar functionality. + * -- + * </p> + * Description: annotation to validate a java.io.File is a directory<br/> + */ +@Documented +@Constraint(validatedBy = DirectoryValidator.class) +@Target({ FIELD, ANNOTATION_TYPE, PARAMETER }) +@Retention(RUNTIME) +public @interface Directory { + + Class<?>[] groups() default {}; + + String message() default "{org.apache.bval.extras.constraints.file.Directory.message}"; + + Class<? extends Payload>[] payload() default {}; + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/DirectoryValidator.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/DirectoryValidator.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/DirectoryValidator.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/DirectoryValidator.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,46 @@ +/* + * 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.bval.extras.constraints.file; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import java.io.File; + +/** + * Description: <br/> + */ +public class DirectoryValidator implements ConstraintValidator<Directory, File> { + + /** + * {@inheritDoc} + */ + @Override + public boolean isValid(File value, ConstraintValidatorContext context) { + return value.isDirectory(); + } + + /** + * {@inheritDoc} + */ + @Override + public void initialize(Directory parameters) { + // do nothing (as long as Directory has no properties) + } + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/NotDirectory.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/NotDirectory.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/NotDirectory.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/NotDirectory.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,53 @@ +/* + * 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.bval.extras.constraints.file; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * <p> + * -- + * TODO - This class is NOT part of the bean_validation spec and might disappear + * as soon as a final version of the specification contains a similar functionality. + * -- + * </p> + * Description: annotation to validate a java.io.File is not a directory<br/> + */ +@Documented +@Constraint(validatedBy = DirectoryValidator.class) +@Target({ FIELD, ANNOTATION_TYPE, PARAMETER }) +@Retention(RUNTIME) +public @interface NotDirectory { + + Class<?>[] groups() default {}; + + String message() default "{org.apache.bval.extras.constraints.file.NotDirectory.message}"; + + Class<? extends Payload>[] payload() default {}; + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/NotDirectoryValidator.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/NotDirectoryValidator.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/NotDirectoryValidator.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/NotDirectoryValidator.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,46 @@ +/* + * 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.bval.extras.constraints.file; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import java.io.File; + +/** + * Description: <br/> + */ +public class NotDirectoryValidator implements ConstraintValidator<NotDirectory, File> { + + /** + * {@inheritDoc} + */ + @Override + public boolean isValid(File value, ConstraintValidatorContext context) { + return value.exists() && !value.isDirectory(); + } + + /** + * {@inheritDoc} + */ + @Override + public void initialize(NotDirectory parameters) { + // do nothing (as long as Directory has no properties) + } + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/Symlink.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/Symlink.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/Symlink.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/Symlink.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,53 @@ +/* + * 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.bval.extras.constraints.file; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * <p> + * -- + * TODO - This class is NOT part of the bean_validation spec and might disappear + * as soon as a final version of the specification contains a similar functionality. + * -- + * </p> + * Description: annotation to validate a java.io.File is a symbolic link<br/> + */ +@Documented +@Constraint(validatedBy = SymlinkValidator.class) +@Target({ FIELD, ANNOTATION_TYPE, PARAMETER }) +@Retention(RUNTIME) +public @interface Symlink { + + Class<?>[] groups() default {}; + + String message() default "{org.apache.bval.extras.constraints.file.Symlink.message}"; + + Class<? extends Payload>[] payload() default {}; + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/SymlinkValidator.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/SymlinkValidator.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/SymlinkValidator.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/SymlinkValidator.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,75 @@ +/* + * 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.bval.extras.constraints.file; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import java.io.File; +import java.io.IOException; + +/** + * Description: <br/> + */ +public class SymlinkValidator implements ConstraintValidator<Symlink, File> { + + /** + * The Windows separator character. + */ + private static final char WINDOWS_SEPARATOR = '\\'; + + /** + * {@inheritDoc} + */ + @Override + public boolean isValid(File value, ConstraintValidatorContext context) { + if (!value.exists()) { + return false; + } + + // routine kindly borrowed from Apache Commons-IO + + if (File.separatorChar == WINDOWS_SEPARATOR) { + return false; + } + + try { + File fileInCanonicalDir; + if (value.getParent() == null) { + fileInCanonicalDir = value; + } else { + File canonicalDir = value.getParentFile().getCanonicalFile(); + fileInCanonicalDir = new File(canonicalDir, value.getName()); + } + + return (!fileInCanonicalDir.getCanonicalFile().equals(fileInCanonicalDir.getAbsoluteFile())); + } catch (IOException e) { + // TODO: is it true? + return false; + } + } + + /** + * {@inheritDoc} + */ + @Override + public void initialize(Symlink parameters) { + // do nothing (as long as Symlink has no properties) + } + +} Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/package-info.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/package-info.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/package-info.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/file/package-info.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,21 @@ +/* + * 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. + */ + +/** + * {@link java.io.File} constraints validators. + */ +package org.apache.bval.extras.constraints.file; Added: tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/net/Domain.java URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/net/Domain.java?rev=1843674&view=auto ============================================================================== --- tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/net/Domain.java (added) +++ tomee/deps/branches/bval-2/bval-extras/src/main/java/org/apache/bval/extras/constraints/net/Domain.java Fri Oct 12 15:00:48 2018 @@ -0,0 +1,55 @@ +/* + * 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.bval.extras.constraints.net; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * <p> + * -- + * TODO - This class is NOT part of the bean_validation spec and might disappear + * as soon as a final version of the specification contains a similar functionality. + * -- + * </p> + * Description: annotation to validate a java.io.File is a directory<br/> + */ +@Documented +@Constraint(validatedBy = DomainValidator.class) +@Target({ FIELD, ANNOTATION_TYPE, PARAMETER }) +@Retention(RUNTIME) +public @interface Domain { + + Class<?>[] groups() default {}; + + String message() default "{org.apache.bval.extras.constraints.net.Domain.message}"; + + Class<? extends Payload>[] payload() default {}; + + boolean allowLocal() default false; + +}