1 25 package org.archive.util.anvl; 26 27 32 abstract class SubElement { 33 private final String e; 34 35 protected SubElement() { 36 this(null); 37 } 38 39 public SubElement(final String s) { 40 this.e = baseCheck(s); 41 } 42 43 protected String baseCheck(final String s) { 44 if (s == null || s.length() <= 0) { 46 throw new IllegalArgumentException ("Can't be null or empty"); 47 } 48 for (int i = 0; i < s.length(); i++) { 50 checkCharacter(s.charAt(i), s, i); 51 } 52 return s; 53 } 54 55 protected void checkCharacter(final char c, final String srcStr, 56 final int index) { 57 checkControlCharacter(c, srcStr, index); 58 checkCRLF(c, srcStr, index); 59 } 60 61 protected void checkControlCharacter(final char c, final String srcStr, 62 final int index) { 63 if (Character.isISOControl(c) && !Character.isWhitespace(c) || 64 !Character.isValidCodePoint(c)) { 65 throw new IllegalArgumentException (srcStr + 66 " contains a control character(s) or invalid code point: 0x" + 67 Integer.toHexString(c)); 68 } 69 } 70 71 protected void checkCRLF(final char c, final String srcStr, 72 final int index) { 73 if (ANVLRecord.isCROrLF(c)) { 74 throw new IllegalArgumentException (srcStr + 75 " contains disallowed CRLF control character(s): 0x" + 76 Integer.toHexString(c)); 77 } 78 } 79 80 @Override 81 public String toString() { 82 return e; 83 } 84 } | Popular Tags |