[jboss-dev-forums] [Design of POJO Server] - Re: Facelets scanning for .taglib.xml is broken in trunk

alesj do-not-reply at jboss.com
Wed Feb 6 16:17:37 EST 2008


The current version of Facelets used in our Seam Booking example is 1.1.14:
 - https://facelets.dev.java.net/servlets/ProjectDocumentList?folderID=3635&expandFolder=3635&folderID=0

I think it all starts from FaceletViewHandler.buildView().
Calling DefaultFaceletFactory.getFacelet.
This call another getFacelet method, which calls createFacelet.
Which invokes compiler.compile(url, alias), that does initialize().
Compiler.initialize invokes TagLibraryConfig.loadImplicit, which does the actual search Classpath.search(cl, "META-INF/", ".taglib.xml").
The cl variable is context classloader.

ClassPath class:

  | public final class Classpath {
  | 
  | 	/**
  | 	 * 
  | 	 */
  | 	public Classpath() {
  | 		super();
  | 	}
  | 
  | 	public static URL[] search(String prefix, String suffix) throws IOException {
  |         return search(Thread.currentThread().getContextClassLoader(), prefix,
  |                 suffix);
  | 	}
  | 
  | 	public static URL[] search(ClassLoader cl, String prefix, String suffix) throws IOException {
  | 		Enumeration[] e = new Enumeration[] {
  | 				cl.getResources(prefix),
  | 				cl.getResources(prefix + "MANIFEST.MF")
  | 			};
  | 		Set all = new LinkedHashSet();
  | 		URL url;
  | 		URLConnection conn;
  | 		JarFile jarFile;
  | 		for (int i = 0, s = e.length; i < s; ++i) {
  | 			while (e.hasMoreElements()) {
  | 				url = (URL) e.nextElement();
  | 				conn = url.openConnection();
  | 				conn.setUseCaches(false);
  | 				conn.setDefaultUseCaches(false);
  | 				if (conn instanceof JarURLConnection) {
  | 					jarFile = ((JarURLConnection) conn).getJarFile();
  | 				} else {
  | 					jarFile = getAlternativeJarFile(url);
  | 				}
  | 				if (jarFile != null) {
  | 					searchJar(cl, all, jarFile, prefix, suffix);
  | 				} else {
  |                     searchDir(all,
  |                               new File(URLDecoder.decode(url.getFile(),
  |                                                          "UTF-8")),
  |                               suffix);
  | 				}
  | 			}
  | 		}
  | 		URL[] urlArray = (URL[]) all.toArray(new URL[all.size()]);
  | 		return urlArray;
  | 	}
  | 
  |     private static void searchDir(Set result, File file, String suffix)
  |             throws IOException {
  | 		if (file.exists() && file.isDirectory()) {
  | 			File[] fc = file.listFiles();
  | 			String path;
  | 			URL src;
  | 			for (int i = 0; i < fc.length; i++) {
  | 				path = fc.getAbsolutePath();
  | 				if (fc.isDirectory()) {
  | 					searchDir(result, fc, suffix);
  | 				} else if (path.endsWith(suffix)) {
  | 					// result.add(new URL("file:/" + path));
  | 					result.add(fc.toURL());
  | 				}
  | 			}
  | 		}
  | 	}
  | 
  |     /** For URLs to JARs that do not use JarURLConnection - allowed by
  |      * the servlet spec - attempt to produce a JarFile object all the same.
  |      * Known servlet engines that function like this include Weblogic
  |      * and OC4J.
  |      * This is not a full solution, since an unpacked WAR or EAR will not
  |      * have JAR "files" as such.
  | 	 */
  | 	private static JarFile getAlternativeJarFile(URL url) throws IOException {
  | 		String urlFile = url.getFile();
  | 		// Trim off any suffix - which is prefixed by "!/" on Weblogic
  | 		int separatorIndex = urlFile.indexOf("!/");
  | 
  | 		// OK, didn't find that. Try the less safe "!", used on OC4J
  | 		if (separatorIndex == -1) {
  | 			separatorIndex = urlFile.indexOf('!');
  | 		}
  | 
  | 		if (separatorIndex != -1) {
  | 			String jarFileUrl = urlFile.substring(0, separatorIndex);
  | 			// And trim off any "file:" prefix.
  | 			if (jarFileUrl.startsWith("file:")) {
  | 				jarFileUrl = jarFileUrl.substring("file:".length());
  | 			}
  | 			return new JarFile(jarFileUrl);
  | 		}
  | 		return null;
  | 	}
  | 
  |     private static void searchJar(ClassLoader cl, Set result, JarFile file,
  |             String prefix, String suffix) throws IOException {
  | 		Enumeration e = file.entries();
  | 		JarEntry entry;
  | 		String name;
  | 		while (e.hasMoreElements()) {
  | 			try {
  | 				entry = (JarEntry) e.nextElement();
  | 			} catch (Throwable t) {
  | 				continue;
  | 			}
  | 			name = entry.getName();
  | 			if (name.startsWith(prefix) && name.endsWith(suffix)) {
  | 				Enumeration e2 = cl.getResources(name);
  | 				while (e2.hasMoreElements()) {
  | 					result.add(e2.nextElement());
  | 				}
  | 			}
  | 		}
  | 	}
  | 
  | }
  | 



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4127178#4127178

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4127178



More information about the jboss-dev-forums mailing list