<snip>
On Sat, 29 Jan 2005 09:00:39 -0500, Frank W. Zammetti
<[EMAIL PROTECTED]> wrote:
> Just from a curiosity standpoint Jack... I've already decided it's not
> an approach I'd advocate, but I am interested to know how you serve
> things like graphics and stylesheets from under WEB-INF.  I assume all
> your graphics are actually server by an Action (a trick I've pulled when
> serving images from a database), and I further assume your stylesheets
> aren't just linked in...
</snip>


<img src='resource.do?file=whatever.jpg'>

<link
    href='resource.do?file=whatever.css'
    rel='stylesheet'
    type='text/css'>

You can also put this sort of Struts protocol into Flash ActionScript, etc.

To be complete on this list:

public final class ResourceAction
    extends Action {

  public ActionForward execute(ActionMapping mapping,
                               ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response)
      throws IOException,
             ServletException {
    String file = request.getParameter("file");
    String ext  = file.substring(file.lastIndexOf('.') + 1);
    String type = null;
    String path = null;

    if ("gif".equals(ext)) {
      type = "image/gif";
      path = path("gif");
    } else if ("jpg".equals(ext)) {
      type = "image/jpeg";
      path = path("jpeg");
    } else if ("css".equals(ext)) {
      type = "text/css";
      path = path("css");
    } else if ("flash".equals(ext)) {
      type = "application/x-shockwave-flash";
      path = path("flash");
    } else if ("text".equals(ext)) {
      type = "text/plain";
      path = path("text");
    } else if ("js".equals(ext)) {
      type = "text/javascript";
      path = path("js");
    } else if ("png".equals(ext)) {
      type = "image/png";
      path = path("png");
    } else if ("html".equals(ext)) {
      type = "text/html";
      path = path("html");
    } else if ("applet".equals(ext)) {
      type = "application/x-java-applet";
      path = "classes" + File.separator + "com" + File.separator +
"crackwillow" + File.separator + "applet";
    }

    String name = Classpath.WEB_INF + path + file;

    response.setContentType(type);
    response.setHeader("Cache-Control", "");
    response.setHeader("Pragma", "");
    response.setHeader("Expires", "");
    response.addHeader("Content-Disposition","filename=" + name);

    try {
      FileInputStream     fis   = new FileInputStream(name);
      BufferedInputStream bis   = new BufferedInputStream(fis);
      byte[]              bytes = new byte[bis.available()];
      OutputStream        os    = response.getOutputStream();
      bis.read(bytes);
      os.write(bytes);
      os.flush();
      os.close();
    } catch (IOException ioe) {
      StdOut.log(SiteConstant.ERROR_LOG,"ResourceAction: problem file
is: " + name + "\n" + StackTrace.trace(ioe) + "\n" +
ioe.getMessage());
    }

    return null;
  }

  private String path(String fileType) {
    return "resource" + File.separator + "content_type" +
File.separator + fileType + File.separator;
  }
} ///;-)


-- 
"You can lead a horse to water but you cannot make it float on its back."

~Dakota Jack~

"You can't wake a person who is pretending to be asleep."

~Native Proverb~

"Each man is good in His sight. It is not necessary for eagles to be
crows.  We are poor . . . but we are free."

~Hunkesni (Sitting Bull), Hunkpapa Sioux~

"This message may contain confidential and/or privileged information.
If you are not the addressee or authorized to receive this for the
addressee, you must not use, copy, disclose, or take any action based
on this message or any information herein. If you have received this
message in error, please advise the sender immediately by reply e-mail
and delete this message. Thank you for your cooperation."

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to