1 19 20 package com.sslexplorer.input.validators; 21 22 import java.io.UnsupportedEncodingException ; 23 import java.net.URLEncoder ; 24 import java.util.Properties ; 25 26 import com.sslexplorer.boot.CodedException; 27 import com.sslexplorer.boot.PropertyDefinition; 28 import com.sslexplorer.boot.PropertyValidator; 29 import com.sslexplorer.core.CoreException; 30 31 34 public class AsciiValidator implements PropertyValidator { 35 private static final String UTF_8 = "UTF-8"; 36 37 public void validate(PropertyDefinition definition, String value, Properties properties) throws CodedException { 38 assertIsAscii(value); 39 } 40 41 private static void assertIsAscii (String value) throws CodedException { 42 try { 43 if (!value.equals(URLEncoder.encode(value, UTF_8))) { 44 throw new CoreException(ErrorConstants.ERR_STRING_NON_ASCII, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, value); 45 } 46 } catch (UnsupportedEncodingException e) { 47 } 49 } 50 } | Popular Tags |