1 28 29 package com.caucho.jsp; 30 31 import com.caucho.jsp.cfg.TldFunction; 32 import com.caucho.jsp.cfg.TldTag; 33 import com.caucho.jsp.cfg.TldTagFile; 34 import com.caucho.jsp.cfg.TldTaglib; 35 import com.caucho.jsp.cfg.TldValidator; 36 import com.caucho.log.Log; 37 import com.caucho.server.util.CauchoSystem; 38 import com.caucho.util.L10N; 39 import com.caucho.vfs.Path; 40 41 import javax.servlet.jsp.tagext.FunctionInfo ; 42 import javax.servlet.jsp.tagext.TagExtraInfo ; 43 import javax.servlet.jsp.tagext.TagFileInfo ; 44 import javax.servlet.jsp.tagext.TagInfo ; 45 import javax.servlet.jsp.tagext.TagLibraryInfo ; 46 import javax.servlet.jsp.tagext.TagLibraryValidator ; 47 import java.util.ArrayList ; 48 import java.util.logging.Logger ; 49 50 53 public class Taglib extends TagLibraryInfo { 54 private static final Logger log = Log.open(Taglib.class); 55 static final L10N L = new L10N(Taglib.class); 56 57 private TldTaglib _tldTaglib; 58 private TagFileManager _tagFileManager; 59 60 TagLibraryValidator _validator; 61 private ArrayList <TldFunction> _functionList = new ArrayList <TldFunction>(); 62 private ArrayList <Taglib> _libraryList 63 = new ArrayList <Taglib>(); 64 65 Taglib(String prefix, String uri, TldTaglib tldTaglib, 66 TagFileManager tagFileManager) 67 throws JspParseException 68 { 69 super(prefix, uri); 70 71 try { 72 _tldTaglib = tldTaglib; 73 _tagFileManager = tagFileManager; 74 75 fillTagLibraryInfo(tldTaglib, tagFileManager); 76 77 _libraryList.add(this); 78 } catch (JspParseException e) { 79 throw e; 80 } catch (Exception e) { 81 throw new JspParseException(e); 82 } 83 } 84 85 88 public TagLibraryValidator getValidator() 89 throws JspParseException 90 { 91 return _validator; 92 } 93 94 97 public ArrayList <TldFunction> getFunctionList() 98 { 99 return _functionList; 100 } 101 102 105 public Path getPath() 106 { 107 if (_tldTaglib != null) 108 return _tldTaglib.getJarPath(); 109 else 110 return null; 111 } 112 113 122 private void fillTagLibraryInfo(TldTaglib taglib, 123 TagFileManager tagFileManager) 124 throws Exception 125 { 126 this.tlibversion = taglib.getTlibVersion(); 127 128 this.jspversion = taglib.getJspVersion(); 129 130 this.shortname = taglib.getShortName(); 131 132 this.urn = taglib.getURI(); 133 this.info = taglib.getInfo(); 134 135 if (taglib.getDescription() != null) 136 this.info = taglib.getDescription(); 137 138 TldValidator validator = taglib.getValidator(); 139 140 if (validator != null) 141 _validator = validator.getValidator(); 142 143 ArrayList <TldTag> tagList = taglib.getTagList(); 144 145 tags = new TagInfo [tagList.size()]; 146 147 for (int i = 0; i < tagList.size(); i++) { 148 TldTag tag = tagList.get(i); 149 150 TagInfo tagInfo = new TagInfoImpl(tag, this); 151 152 tags[i] = tagInfo; 153 } 154 155 ArrayList <TldTagFile> tagFileList = taglib.getTagFileList(); 156 157 this.tagFiles = new TagFileInfo [tagFileList.size()]; 158 159 for (int i = 0; i < tagFileList.size(); i++) { 160 TldTagFile tagFile = tagFileList.get(i); 161 162 TagFileInfo tagFileInfo = new TagFileInfoExt(tagFileManager, 163 tagFile.getName(), 164 tagFile.getPath()); 165 166 this.tagFiles[i] = tagFileInfo; 167 } 168 169 _functionList = taglib.getFunctionList(); 170 171 this.functions = new FunctionInfo [_functionList.size()]; 172 173 for (int i = 0; i < _functionList.size(); i++) { 174 this.functions[i] = _functionList.get(i).toFunctionInfo(); 175 } 176 } 177 178 185 public Class getClass(String tagName) 186 throws Exception 187 { 188 TagInfo info = getTag(tagName); 189 String className = info == null ? null : info.getTagClassName(); 190 191 if (className != null) 192 return CauchoSystem.loadClass(className); 193 else 194 return null; 195 } 196 197 200 public ArrayList <String > getSingleTagClassNames() 201 { 202 ArrayList <String > singleTags = new ArrayList <String >(); 203 204 TagInfo []tags = getTags(); 205 for (int i = 0; tags != null && i < tags.length; i++) { 206 String name = tags[i].getTagClassName(); 207 208 if (name != null && name.indexOf('.') < 0) 209 singleTags.add(name); 210 } 211 212 return singleTags; 213 } 214 215 218 TagExtraInfo getTagExtraInfo(String tagName) 219 { 220 TagInfo info = getTag(tagName); 221 222 return info != null ? info.getTagExtraInfo() : null; 223 } 224 225 228 public TagInfo getTag(String name) 229 { 230 if (tags == null) 231 return null; 232 233 for (int i = 0; i < tags.length; i++) { 234 if (tags[i].getTagName().equals(name)) 235 return tags[i]; 236 } 237 238 return null; 239 } 240 241 244 public String getTagFilePath(String name) 245 { 246 if (_tldTaglib == null) 247 return null; 248 249 ArrayList <TldTagFile> tagFiles = _tldTaglib.getTagFileList(); 250 251 for (int i = 0; i < tagFiles.size(); i++) { 252 TldTagFile tagFile = tagFiles.get(i); 253 254 if (tagFile.getName().equals(name)) 255 return tagFile.getPath(); 256 } 257 258 return null; 259 } 260 261 public void addTaglib(Taglib taglib) 262 { 263 if (! _libraryList.contains(taglib)) 264 _libraryList.add(taglib); 265 } 266 267 public Taglib copy() 268 throws JspParseException 269 { 270 return new Taglib(getPrefixString(), getURI(), 271 _tldTaglib, _tagFileManager); 272 } 273 274 @Override 275 public TagLibraryInfo []getTagLibraryInfos() 276 { 277 TagLibraryInfo []infoArray = new TagLibraryInfo [_libraryList.size()]; 278 279 _libraryList.toArray(infoArray); 280 281 return infoArray; 282 } 283 284 public String toString() 285 { 286 return "Taglib[prefix=" + prefix + ",uri=" + uri + "]"; 287 } 288 289 class TagFileInfoExt extends TagFileInfo 290 { 291 private TagFileManager _manager; 292 private TagInfo _tagInfo; 293 294 TagFileInfoExt(TagFileManager manager, String name, String path) 295 { 296 super(name, path, null); 297 298 _manager = manager; 299 } 300 301 public TagInfo getTagInfo() 302 { 303 if (_tagInfo == null) { 304 try { 305 _tagInfo = _manager.getTag("", getName(), getPath()); 306 } catch (JspParseException e) { 307 throw new RuntimeException (e); 308 } 309 } 310 311 return _tagInfo; 312 } 313 } 314 315 } 316 | Popular Tags |