1 12 package org.displaytag.tags; 13 14 import java.util.ArrayList ; 15 import java.util.Arrays ; 16 import java.util.List ; 17 18 import javax.servlet.jsp.tagext.TagAttributeInfo ; 19 import javax.servlet.jsp.tagext.TagData ; 20 import javax.servlet.jsp.tagext.TagExtraInfo ; 21 import javax.servlet.jsp.tagext.VariableInfo ; 22 23 24 33 public class TableTagExtraInfo extends TagExtraInfo 34 { 35 36 39 public static final String ROWNUM_SUFFIX = "_rowNum"; 41 44 private static final String [] KEYWORDS = {"abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "default", "do", "double", "else", "enum", "extends", "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while"}; 98 105 public VariableInfo [] getVariableInfo(TagData data) 106 { 107 List variables = new ArrayList (2); 108 109 Object idObj = data.getAttribute(TagAttributeInfo.ID); 110 111 if (idObj == null) 113 { 114 idObj = data.getAttribute("uid"); } 116 117 if (idObj != TagData.REQUEST_TIME_VALUE && idObj != null) 119 { 120 String tagId = idObj.toString(); 121 122 if (isJavaId(tagId)) 124 { 125 variables.add(new VariableInfo (tagId, Object .class.getName(), true, VariableInfo.NESTED)); 127 variables.add(new VariableInfo ( 129 tagId + ROWNUM_SUFFIX, 130 Integer .class.getName(), 131 true, 132 VariableInfo.NESTED)); 133 } 134 } 135 136 return (VariableInfo []) variables.toArray(new VariableInfo []{}); 137 } 138 139 144 public static boolean isJavaId(String id) 145 { 146 if (id == null 147 || id.length() == 0 148 || Arrays.binarySearch(KEYWORDS, id) >= 0 149 || !Character.isJavaIdentifierStart(id.charAt(0))) 150 { 151 return false; 152 } 153 154 for (int j = 1; j < id.length(); j++) 155 { 156 if (!Character.isJavaIdentifierPart(id.charAt(j))) 157 { 158 return false; 159 } 160 } 161 return true; 162 } 163 164 } | Popular Tags |