Return-Path: X-Original-To: apmail-incubator-bval-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-bval-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 09B739CD9 for ; Sat, 7 Jan 2012 10:17:18 +0000 (UTC) Received: (qmail 83120 invoked by uid 500); 7 Jan 2012 10:17:17 -0000 Delivered-To: apmail-incubator-bval-commits-archive@incubator.apache.org Received: (qmail 83082 invoked by uid 500); 7 Jan 2012 10:17:12 -0000 Mailing-List: contact bval-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: bval-dev@incubator.apache.org Delivered-To: mailing list bval-commits@incubator.apache.org Received: (qmail 83063 invoked by uid 99); 7 Jan 2012 10:17:08 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Jan 2012 10:17:08 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Jan 2012 10:17:04 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 825AD2388860; Sat, 7 Jan 2012 10:16:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1228588 - in /incubator/bval/trunk/bval-extras/src: main/java/org/apache/bval/extras/constraints/checkdigit/ test/java/org/apache/bval/extras/constraints/checkdigit/ Date: Sat, 07 Jan 2012 10:16:42 -0000 To: bval-commits@incubator.apache.org From: simonetripodi@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120107101642.825AD2388860@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: simonetripodi Date: Sat Jan 7 10:16:41 2012 New Revision: 1228588 URL: http://svn.apache.org/viewvc?rev=1228588&view=rev Log: added EAN13 validation, imported and readapted from commons-validations Added: incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13.java (with props) incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13Validator.java (with props) incubator/bval/trunk/bval-extras/src/test/java/org/apache/bval/extras/constraints/checkdigit/EAN13CheckDigitTest.java (with props) Added: incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13.java URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13.java?rev=1228588&view=auto ============================================================================== --- incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13.java (added) +++ incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13.java Sat Jan 7 10:16:41 2012 @@ -0,0 +1,54 @@ +/* + * 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.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; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import javax.validation.Constraint; +import javax.validation.Payload; + +/** + *

+ * -- + * 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. + * -- + *

+ * Description: annotation to validate a java.io.File is a directory
+ */ +@Documented +@Constraint( validatedBy = EAN13Validator.class ) +@Target( { FIELD, ANNOTATION_TYPE, PARAMETER } ) +@Retention( RUNTIME ) +public @interface EAN13 { + + Class[] groups() default {}; + + String message() default "{org.apache.bval.extras.constraints.checkdigit.EAN13.message}"; + + Class[] payload() default {}; + +} Propchange: incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13Validator.java URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13Validator.java?rev=1228588&view=auto ============================================================================== --- incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13Validator.java (added) +++ incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13Validator.java Sat Jan 7 10:16:41 2012 @@ -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; + +/** + * Modulus 10 EAN-13 / UPC / ISBN-13 Check Digit + * calculation/validation. + *

+ * Check digit calculation is based on modulus 10 with digits in + * an odd position (from right to left) being weighted 1 and even + * position digits being weighted 3. + *

+ * For further information see: + *

+ */ +public final class EAN13Validator + extends ModulusValidator { + + /** weighting given to digits depending on their right position */ + private static final int[] POSITION_WEIGHT = new int[] {3, 1}; + + public EAN13Validator() { + super(10); + } + + /** + *

Calculates the weighted value of a character in the + * code at a specified position.

+ * + *

For EAN-13 (from right to left) odd digits are weighted + * with a factor of one and even digits with a factor + * of three.

+ * + * {@inheritDoc} + */ + @Override + protected int weightedValue( int charValue, int leftPos, int rightPos ) + throws Exception { + int weight = POSITION_WEIGHT[rightPos % 2]; + return (charValue * weight); + } + +} Propchange: incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13Validator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13Validator.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: incubator/bval/trunk/bval-extras/src/main/java/org/apache/bval/extras/constraints/checkdigit/EAN13Validator.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: incubator/bval/trunk/bval-extras/src/test/java/org/apache/bval/extras/constraints/checkdigit/EAN13CheckDigitTest.java URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-extras/src/test/java/org/apache/bval/extras/constraints/checkdigit/EAN13CheckDigitTest.java?rev=1228588&view=auto ============================================================================== --- incubator/bval/trunk/bval-extras/src/test/java/org/apache/bval/extras/constraints/checkdigit/EAN13CheckDigitTest.java (added) +++ incubator/bval/trunk/bval-extras/src/test/java/org/apache/bval/extras/constraints/checkdigit/EAN13CheckDigitTest.java Sat Jan 7 10:16:41 2012 @@ -0,0 +1,43 @@ +/* + * 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 java.lang.annotation.Annotation; + +import javax.validation.ConstraintValidator; + +/** + * EAN-13 Check Digit Test. + */ +public class EAN13CheckDigitTest extends AbstractCheckDigitTest { + + @Override + protected ConstraintValidator getConstraint() { + return new EAN13Validator(); + } + + @Override + protected String[] getValid() { + return new String[] { + "9780072129519", + "9780764558313", + "4025515373438", + "0095673400332" + }; + } + +} Propchange: incubator/bval/trunk/bval-extras/src/test/java/org/apache/bval/extras/constraints/checkdigit/EAN13CheckDigitTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/bval/trunk/bval-extras/src/test/java/org/apache/bval/extras/constraints/checkdigit/EAN13CheckDigitTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: incubator/bval/trunk/bval-extras/src/test/java/org/apache/bval/extras/constraints/checkdigit/EAN13CheckDigitTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain