1 29 30 package com.caucho.jsp; 31 32 import com.caucho.jsp.java.TagTaglib; 33 import com.caucho.loader.SimpleLoader; 34 import com.caucho.util.L10N; 35 import com.caucho.util.Log; 36 import com.caucho.vfs.Path; 37 38 import javax.servlet.jsp.tagext.TagInfo ; 39 import javax.servlet.jsp.tagext.TagLibraryInfo ; 40 import java.util.logging.Level ; 41 import java.util.logging.Logger ; 42 45 public class TagFileManager { 46 static final L10N L = new L10N(TagFileManager.class); 47 private static final Logger log = Log.open(TagFileManager.class); 48 49 private JspCompiler _jspCompiler; 50 51 public TagFileManager(JspCompiler compiler) 52 { 53 _jspCompiler = compiler; 54 } 55 56 public TagInfo getTag(String prefix, String shortName, String location) 57 throws JspParseException 58 { 59 if (location == null) 60 return null; 61 62 try { 63 String originalLocation = location; 64 65 if (location.startsWith("urn:jsptagdir:")) 66 location = location.substring("urn:jsptagdir:".length()); 67 68 TagLibraryInfo taglib = new TagTaglib(prefix, originalLocation); 69 70 String uri = location; 71 72 TagInfo tag = null; 73 74 try { 75 tag = getTag(uri, taglib); 76 if (tag != null) 77 return tag; 78 } catch (Exception e) { 79 log.log(Level.FINEST, e.toString(), e); 80 } 81 82 if (! location.endsWith("/")) 83 location = location + "/"; 84 85 uri = location + shortName + ".tag"; 86 87 tag = getTag(uri, taglib); 88 if (tag != null) 89 return tag; 90 91 uri = location + shortName + ".tagx"; 92 return getTag(uri, taglib); 93 } catch (Exception e) { 94 throw JspParseException.create(e); 95 } 96 } 97 98 public TagInfo getTag(String prefix, String location) 99 throws JspParseException 100 { 101 TagLibraryInfo taglib = new TagTaglib(prefix, location); 102 103 return getTag(location, taglib); 104 } 105 106 public TagInfo getTag(String location, TagLibraryInfo taglib) 107 throws JspParseException 108 { 109 JspResourceManager resourceManager = _jspCompiler.getResourceManager(); 110 if (resourceManager == null) 111 return null; 112 113 Path path = resourceManager.resolvePath(location); 114 115 return getTag(path, location, taglib); 116 } 117 118 public TagInfo getTag(Path path, String prefix, String location) 119 throws JspParseException 120 { 121 TagLibraryInfo taglib = new TagTaglib(prefix, location); 122 123 return getTag(path, location, taglib); 124 } 125 126 public TagInfo getTag(Path path, String location, TagLibraryInfo taglib) 127 throws JspParseException 128 { 129 if (path == null || ! path.canRead()) 130 return null; 131 132 try { 133 if (location.endsWith(".tag")) { 134 JspCompilerInstance tagCompiler; 135 136 tagCompiler = _jspCompiler.getCompilerInstance(path, location); 137 tagCompiler.setXML(false); 138 139 return tagCompiler.compileTag(taglib); 140 } 141 else if (location.endsWith(".tagx")) { 142 JspCompilerInstance tagCompiler; 143 144 tagCompiler = _jspCompiler.getCompilerInstance(path, location); 145 tagCompiler.setXML(true); 146 147 return tagCompiler.compileTag(taglib); 148 } 149 else 150 throw new JspParseException(L.l("tag file '{0}' must end with .tag or .tagx", 151 location)); 152 } catch (Exception e) { 153 throw JspParseException.create(e); 154 } 155 } 156 157 public Class loadClass(String className) 158 throws Exception 159 { 160 Path classDir = _jspCompiler.getClassDir(); 161 162 ClassLoader parentLoader = Thread.currentThread().getContextClassLoader(); 163 ClassLoader jspLoader = SimpleLoader.create(parentLoader, 164 classDir, 165 null); 166 167 return Class.forName(className, false, jspLoader); 168 } 169 } 170 | Popular Tags |