1 18 package net.sf.uitags.tagutil.validation; 19 20 import javax.servlet.jsp.PageContext ; 21 22 import net.sf.uitags.tagutil.ScopedIdGenerator; 23 import net.sf.uitags.util.UiString; 24 25 31 public final class RuntimeValidator { 32 35 private RuntimeValidator() { 36 } 38 39 47 public static void assertSingleUse( 48 String tagId, String tagName, PageContext pageContext) { 49 long instanceId = ScopedIdGenerator.nextId( 50 PageContext.REQUEST_SCOPE, tagId, pageContext); 51 if (instanceId > 1) { 52 throw new RuntimeValidationException(UiString.simpleConstruct( 53 "'{0}' tag can only be used at most once in a request.", 54 new String [] { tagName })); 55 } 56 } 57 58 67 public static void assertAttributeExclusive( 68 String name1, String value1, String name2, String value2) { 69 if ((value1 != null && value2 != null) && 70 (!value1.equals("") && !value2.equals(""))) { 71 throw new DeferredValidationException("The attribute '" + name1 + 72 "' and '" + name2 + "' are exclusive."); 73 } 74 } 75 76 85 public static void assertEitherSpecified( 86 String name1, String value1, String name2, String value2) { 87 if ((isStringEmpty(value1) && isStringEmpty(value2))) { 88 throw new DeferredValidationException("One of the attributes '" + name1 + 89 "' and '" + name2 + "' must be specified."); 90 } 91 } 92 93 100 private static boolean isStringEmpty(String value) { 101 return value == null || value.equals(""); 102 } 103 } 104 | Popular Tags |