1 17 18 package org.apache.jasper.compiler; 19 20 import java.io.InputStream ; 21 import java.util.Collection ; 22 import java.util.Hashtable ; 23 import java.util.Iterator ; 24 import java.util.Set ; 25 import java.util.Vector ; 26 27 import javax.servlet.jsp.tagext.FunctionInfo ; 28 import javax.servlet.jsp.tagext.TagFileInfo ; 29 import javax.servlet.jsp.tagext.TagInfo ; 30 import javax.servlet.jsp.tagext.TagLibraryInfo ; 31 32 import org.apache.jasper.JasperException; 33 import org.apache.jasper.JspCompilationContext; 34 import org.apache.jasper.xmlparser.ParserUtils; 35 import org.apache.jasper.xmlparser.TreeNode; 36 37 44 class ImplicitTagLibraryInfo extends TagLibraryInfo { 45 46 private static final String WEB_INF_TAGS = "/WEB-INF/tags"; 47 private static final String TAG_FILE_SUFFIX = ".tag"; 48 private static final String TAGX_FILE_SUFFIX = ".tagx"; 49 private static final String TAGS_SHORTNAME = "tags"; 50 private static final String TLIB_VERSION = "1.0"; 51 private static final String JSP_VERSION = "2.0"; 52 private static final String IMPLICIT_TLD = "implicit.tld"; 53 54 private Hashtable tagFileMap; 56 57 private ParserController pc; 58 private PageInfo pi; 59 private Vector vec; 60 61 64 public ImplicitTagLibraryInfo(JspCompilationContext ctxt, 65 ParserController pc, 66 PageInfo pi, 67 String prefix, 68 String tagdir, 69 ErrorDispatcher err) throws JasperException { 70 super(prefix, null); 71 this.pc = pc; 72 this.pi = pi; 73 this.tagFileMap = new Hashtable (); 74 this.vec = new Vector (); 75 76 this.functions = new FunctionInfo [0]; 78 79 tlibversion = TLIB_VERSION; 80 jspversion = JSP_VERSION; 81 82 if (!tagdir.startsWith(WEB_INF_TAGS)) { 83 err.jspError("jsp.error.invalid.tagdir", tagdir); 84 } 85 86 if (tagdir.equals(WEB_INF_TAGS) 89 || tagdir.equals( WEB_INF_TAGS + "/")) { 90 shortname = TAGS_SHORTNAME; 91 } else { 92 shortname = tagdir.substring(WEB_INF_TAGS.length()); 93 shortname = shortname.replace('/', '-'); 94 } 95 96 Set dirList = ctxt.getResourcePaths(tagdir); 98 if (dirList != null) { 99 Iterator it = dirList.iterator(); 100 while (it.hasNext()) { 101 String path = (String ) it.next(); 102 if (path.endsWith(TAG_FILE_SUFFIX) 103 || path.endsWith(TAGX_FILE_SUFFIX)) { 104 109 String suffix = path.endsWith(TAG_FILE_SUFFIX) ? 110 TAG_FILE_SUFFIX : TAGX_FILE_SUFFIX; 111 String tagName = path.substring(path.lastIndexOf("/") + 1); 112 tagName = tagName.substring(0, 113 tagName.lastIndexOf(suffix)); 114 tagFileMap.put(tagName, path); 115 } else if (path.endsWith(IMPLICIT_TLD)) { 116 InputStream in = null; 117 try { 118 in = ctxt.getResourceAsStream(path); 119 if (in != null) { 120 121 if (pi != null) { 123 pi.addDependant(path); 124 } 125 126 ParserUtils pu = new ParserUtils(); 127 TreeNode tld = pu.parseXMLDocument(uri, in); 128 129 if (tld.findAttribute("version") != null) { 130 this.jspversion = tld.findAttribute("version"); 131 } 132 133 Iterator list = tld.findChildren(); 135 136 while (list.hasNext()) { 137 TreeNode element = (TreeNode) list.next(); 138 String tname = element.getName(); 139 140 if ("tlibversion".equals(tname) || "tlib-version".equals(tname)) { this.tlibversion = element.getBody(); 143 } else if ("jspversion".equals(tname) 144 || "jsp-version".equals(tname)) { 145 this.jspversion = element.getBody(); 146 } else if ("shortname".equals(tname) || "short-name".equals(tname)) { 147 } else { 149 err.jspError("jsp.error.invalid.implicit", path); 151 } 152 } 153 try { 154 double version = Double.parseDouble(this.jspversion); 155 if (version < 2.0) { 156 err.jspError("jsp.error.invalid.implicit.version", path); 157 } 158 } catch (NumberFormatException e) { 159 err.jspError("jsp.error.invalid.implicit.version", path); 160 } 161 } 162 } finally { 163 if (in != null) { 164 try { 165 in.close(); 166 } catch (Throwable t) { 167 } 168 } 169 } 170 } 171 } 172 } 173 174 } 175 176 183 public TagFileInfo getTagFile(String shortName) { 184 185 TagFileInfo tagFile = super.getTagFile(shortName); 186 if (tagFile == null) { 187 String path = (String ) tagFileMap.get(shortName); 188 if (path == null) { 189 return null; 190 } 191 192 TagInfo tagInfo = null; 193 try { 194 tagInfo = TagFileProcessor.parseTagFileDirectives(pc, 195 shortName, 196 path, 197 this); 198 } catch (JasperException je) { 199 throw new RuntimeException (je.toString(), je); 200 } 201 202 tagFile = new TagFileInfo (shortName, path, tagInfo); 203 vec.addElement(tagFile); 204 205 this.tagFiles = new TagFileInfo [vec.size()]; 206 vec.copyInto(this.tagFiles); 207 } 208 209 return tagFile; 210 } 211 212 public TagLibraryInfo [] getTagLibraryInfos() { 213 Collection coll = pi.getTaglibs(); 214 return (TagLibraryInfo []) coll.toArray(new TagLibraryInfo [0]); 215 } 216 217 } 218 | Popular Tags |