/** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.sun.facelets.util; import java.io.IOException; import java.net.URL; import java.util.Enumeration; import java.util.HashSet; import java.util.Set; import org.jboss.virtual.VFS; import org.jboss.virtual.VirtualFile; import org.jboss.virtual.VirtualFileVisitor; import org.jboss.virtual.VisitorAttributes; /** * Direct VFS usage. * * @author Ales Justin (ales.justin@jboss.org) */ final class VFSClasspath { static URL[] search(ClassLoader cl, String prefix, final String suffix) throws IOException { Enumeration[] e = new Enumeration[]{ cl.getResources(prefix), cl.getResources(prefix + "MANIFEST.MF") }; final Set all = new HashSet(); for (int i = 0, s = e.length; i < s; ++i) { while (e[i].hasMoreElements()) { URL url = (URL)e[i].nextElement(); VirtualFile vf = VFS.getRoot(url); vf.visit(new VirtualFileVisitor() { public VisitorAttributes getAttributes() { return VisitorAttributes.RECURSE_LEAVES_ONLY; } public void visit(VirtualFile file) { try { if (file.getName().endsWith(suffix)) all.add(file.toURL()); } catch (Exception e) { throw new RuntimeException(e); } } }); } } return (URL[]) all.toArray(new URL[all.size()]); } }