All pastes #89218 Raw Edit

Mine

public java v1 · immutable
#89218 ·published 2006-07-15 23:32 UTC
rendered paste body
/* * BlueFiles.java * * Created on den 15 juli 2006, 21:43 */package blue;import javax.servlet.jsp.tagext.*;import javax.servlet.jsp.*;import java.lang.*;import java.util.*;/** * * @author  blueCommand * @version */public class BlueFiles extends SimpleTagSupport{    private String pattern;    private PageContext page;        public void setPattern(String p)    {        this.pattern = p;    }        public void setJspContext(JspContext j)    {        page = (PageContext)j;            }        /**Called by the container to invoke this tag.     * The implementation of this method is provided by the tag library developer,     * and handles all tag processing, body iteration, etc.     */    public void doTag() throws JspException,java.io.IOException    {                JspWriter out = page.getOut();        JspFragment body = getJspBody();        Collection cfiles = GetFiles(pattern);                Iterator files = cfiles.iterator();        String filename;        while(files.hasNext())        {            filename = (String)files.next();            page.setAttribute("filename",filename);            body.invoke(out);        }            }        /**Fills an array of files matching pattern     */    private Collection GetFiles(String pattern)    {        Collection reses = page.getServletContext().getResourcePaths("/");        List files = new ArrayList();        Iterator file = reses.iterator();                String uri;        while(file.hasNext())        {            uri = (String)file.next();            if(uri.endsWith(pattern))                files.add(uri);        }                return files;    }    }