<%@ page import="java.io.File" errorPage="err.jsp" %> <%@ taglib uri="gnat" prefix="gnat" %> <%-- Use the Servlet 2.2+ temporary working directory to demo some file stuff. Makes it easier because the user doesn't have to configure anything and I don't have to worry about file system and user permissions for the demo. See section 3.7 of Servlet 2.3 spec for description of this attribute. --%> <%! File tempdir = null; %> <% tempdir = (File)application.getAttribute("javax.servlet.context.tempdir"); %> Gnat JSP Taglib

Gnat Taglib

<%-- Until JRun and Jasper escape String literals nested in custom tag attributes properly, it's best to declare them as variables and then use their variable names rather than the literal strings. The multitude of double quotations seems to confuse JRun (3.0, SP1) and Jasper (3.3.dev), though JRun can deal with them if the quotes around the whole attribute are removed. --%> <%-- Name of flat file to create in demo --%> <% final String foo = "/foo-file.txt"; %>
  1. <gnat:deltree dir="dirname"/>

  2. <gnat:ls dir="/absolute/file/path" id="foo">

  3. <gnat:echo message=""/> :

  4. <gnat:touch file="/file/to/touch" millis="modtime in millis" datetime="modtime date format"/>

  5. <gnat:fail message=""/>

    • Exits the current JSP (just throwing a JspTagException), optionally printing additional information via the message attribute.

      Note: This tag is called at the bottom of this page so as not to disrupt the processing of the rest of the tag examples on the page.

  6. <gnat:gzip src="/path/to/file" zipfile="filename.zip"/>

    • GZips a file. The src file is zipped with whatever name and extension is given in the zipfile attribute.
  7. <%-- Name of the file when zipped. --%> <% final String foozip = foo + ".gz"; %>
  8. <gnat:mkdir dir="/directory(ies)/to/create" clobber="true"/>

    • Creates a single directory or a tree of directories if parent directories of the bottom-most directory do not exist. Does nothing if the directory(ies) already exist, unless the optional clobber attribute is set to true, in which case the old directory is forcibly deleted along with any subdirectories and files, and the new directory(ies) created.
  9. <%-- Names of directories to create and place the unzipped file under.. --%> <% final String foodir = "/foodir/bar/baz/pickles"; %>
  10. <gnat:gunzip src="/path/to/file.gz" dest="[ filename | directory ]"/>

    • GUnzips a file. The dest attribute is optional and can be a directory to unzip the file into, or can be a new file name. If dest is omitted, the parent dir of src is taken as the destination (i.e., a copy of the file is unzipped in its current directory). The file is only expanded if the src file is newer than the dest file, or when the dest file does not exist.
  11. <%-- New name of the file when unzipped. --%> <% final String foounzip = foo + ".unzipped.txt"; %>
  12. <gnat:tstamp/>

    • Sets the DSTAMP, TSTAMP and TODAY properties in the current page. The DSTAMP is in the "yyyymmdd" format, the TSTAMP is in the "hhmm" format and TODAY is "month day year". All three are scripting variables. See also tstamp example

<%-- Call the fail tag last --%>