Package geekblog.tags

Source Code of geekblog.tags.RandomHeadShot

package geekblog.tags;

import java.io.IOException;
import java.util.Set;
import java.util.prefs.Preferences;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

/**
* Created by IntelliJ IDEA.
* User: Kevin Jones
* Date: Jan 23, 2003
* Time: 10:43:37 PM
* To change this template use Options | File Templates.
*/
public class RandomHeadShot extends TagSupport
{
    public int doStartTag() throws JspException
    {
        String ctx = ((HttpServletRequest)(pageContext.getRequest())).getContextPath();
        Preferences prefs = Preferences.systemRoot().node("net/sourceforge/geekblog" + ctx);

        String headshots = prefs.get("weblog.headshotsdir", "images");
        Set headshotsDir = pageContext.getServletContext().getResourcePaths(headshots);
        JspWriter out = pageContext.getOut();

        System.err.println(headshotsDir);
        String[] fileList = (String[]) headshotsDir.toArray(new String[0]);

        try
        {
            if (fileList.length == 1)
                out.write(fileList[0]);
            else
            {
                int choice = (int) (Math.random() * fileList.length);
                out.write(fileList[choice]);
            }
        }
        catch(IOException e)
        {}
        return EVAL_BODY_INCLUDE;
    }
}
TOP

Related Classes of geekblog.tags.RandomHeadShot

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.