1 // Copyright 2006-2007, by the California Institute of Technology. 2 // ALL RIGHTS RESERVED. United States Government Sponsorship acknowledged. 3 // Any commercial use must be negotiated with the Office of Technology Transfer 4 // at the California Institute of Technology. 5 // 6 // This software is subject to U. S. export control laws and regulations 7 // (22 C.F.R. 120-130 and 15 C.F.R. 730-774). To the extent that the software 8 // is subject to U.S. export control laws and regulations, the recipient has 9 // the responsibility to obtain export licenses or other export authority as 10 // may be required before exporting such information to foreign countries or 11 // providing access to foreign nationals. 12 // 13 // $Id: LengthChecker.java 3461 2008-08-07 17:43:26Z pramirez $ 14 // 15 16 package gov.nasa.pds.tools.dict.type; 17 18 import gov.nasa.pds.tools.util.Utility; 19 20 /*** 21 * @author pramirez 22 * @version $Revision: 3461 $ 23 * 24 */ 25 public class LengthChecker { 26 27 /* (non-Javadoc) 28 * @see gov.nasa.jpl.pds.tools.label.validate.TypeChecker#checkMinLength(java.lang.String, int) 29 */ 30 public void checkMinLength(String value, int min) throws InvalidLengthException { 31 if (value.length() < min) 32 throw new InvalidLengthException(Utility.trimString(value, 40) + " is less than the acceptable minimum length of " + min); 33 } 34 35 /* (non-Javadoc) 36 * @see gov.nasa.jpl.pds.tools.label.validate.TypeChecker#checkMaxLength(java.lang.String, int) 37 */ 38 public void checkMaxLength(String value, int max) throws InvalidLengthException { 39 if (value.length() > max && Utility.stripWhitespace(value).length() > max) { 40 throw new InvalidLengthException(Utility.trimString(value, 40) + " exceeds the maximum length of " + max); 41 } 42 } 43 }