001/* 002 * jPOS Project [http://jpos.org] 003 * Copyright (C) 2000-2026 jPOS Software SRL 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018 019package org.jpos.iso; 020 021import org.jpos.iso.validator.ISOVException; 022 023/** 024 * Validator for ASCII alphanum no-zero no-blank filled fields. 025 * 026 * <p>Title: jPOS</p> 027 * <p>Description: Java Framework for Financial Systems</p> 028 * <p>Copyright: Copyright (c) 2000 jPOS.org. All rights reserved.</p> 029 * <p>Company: www.jPOS.org</p> 030 * @author Jose Eduardo Leon 031 * @version 1.0 032 */ 033public class IVA_ALPHANUMNOZERO_NOBLANK extends IVA_ALPHANUMNOZERO { 034 035 /** Default constructor. */ 036 public IVA_ALPHANUMNOZERO_NOBLANK() { 037 super(); 038 } 039 040 /** 041 * Constructs a validator using only a description. 042 * 043 * @param Description human-readable field description 044 */ 045 public IVA_ALPHANUMNOZERO_NOBLANK( String Description ) { 046 super( Description ); 047 } 048 049 /** 050 * Constructs a validator with explicit length bounds. 051 * 052 * @param minLen minimum acceptable length 053 * @param maxLen maximum acceptable length 054 * @param Description human-readable field description 055 */ 056 public IVA_ALPHANUMNOZERO_NOBLANK( int minLen, int maxLen, String Description ) { 057 super( minLen, maxLen, Description ); 058 } 059 060 /** 061 * Constructs a validator with a maximum length. 062 * 063 * @param maxLen maximum acceptable length 064 * @param Description human-readable field description 065 */ 066 public IVA_ALPHANUMNOZERO_NOBLANK( int maxLen, String Description ) { 067 super( maxLen, Description ); 068 } 069 070 /** 071 * Constructs a validator with a custom break-on-error flag. 072 * 073 * @param breakOnError if {@code true}, validation throws on the first error 074 * @param Description human-readable field description 075 */ 076 public IVA_ALPHANUMNOZERO_NOBLANK( boolean breakOnError, String Description ) { 077 this( Description ); 078 this.breakOnError = breakOnError; 079 } 080 081 /** 082 * Constructs a validator with a custom break-on-error flag and a maximum length. 083 * 084 * @param breakOnError if {@code true}, validation throws on the first error 085 * @param maxLen maximum acceptable length 086 * @param Description human-readable field description 087 */ 088 public IVA_ALPHANUMNOZERO_NOBLANK( boolean breakOnError, int maxLen, String Description ) { 089 this( maxLen, Description ); 090 this.breakOnError = breakOnError; 091 } 092 093 /** 094 * Constructs a validator with a custom break-on-error flag and explicit length bounds. 095 * 096 * @param breakOnError if {@code true}, validation throws on the first error 097 * @param minLen minimum acceptable length 098 * @param maxLen maximum acceptable length 099 * @param Description human-readable field description 100 */ 101 public IVA_ALPHANUMNOZERO_NOBLANK( boolean breakOnError, int minLen, int maxLen, String Description ) { 102 this( minLen, maxLen, Description ); 103 this.breakOnError = breakOnError; 104 } 105 106 /** 107 * Validate that the component is not blank-filled. 108 * 109 * @param f component to validate 110 * @return the validated (possibly wrapped) component 111 * @throws ISOException if {@link #breakOnError} is set and the field is blank or fails the inherited zero-fill check 112 */ 113 public ISOComponent validate ( ISOComponent f ) throws ISOException { 114 ISOField c = (ISOField)f; 115 try { 116 /** no zero... **/ 117 c = (ISOField)super.validate( c ); 118 /** no blank **/ 119 if ( ISOUtil.isBlank( (String)c.getValue() ) ){ 120 ISOVError e = new ISOVError( "Invalid Value Error. It can not be blank-filled. (Current value: "+ 121 c.getValue() +") ", getRejCode( ISOVError.ERR_INVALID_VALUE ) ); 122 if ( c instanceof ISOVField ) 123 ((ISOVField)c).addISOVError( e ); 124 else 125 c = new ISOVField( c, e ); 126 if ( breakOnError ) 127 throw new ISOVException ( "Error on field " + c.getKey(), c ); 128 } 129 return c; 130 } 131 catch (Exception ex) { 132 if ( ex instanceof ISOVException ) throw (ISOVException)ex; 133 return c; 134 } 135 } 136}