Class EjwsUtilities

java.lang.Object
org.bzdev.ejws.EjwsUtilities

public class EjwsUtilities extends Object
Useful methods for writing handlers and subclasses of WebMap.
  • Constructor Details

    • EjwsUtilities

      public EjwsUtilities()
  • Method Details

    • htmlEncode

      public static String htmlEncode(String string)
      HTML encode a string. HTML encoding replaces the special characters "<", ">", and "&" with "&lt;", "&gt;", and * "&amp;" respectively.
      Parameters:
      string - the string to encode
      Returns:
      the encoded string
    • htmlQuoteEncode

      public static String htmlQuoteEncode(String string)
      HTML encode a string, encoding double quotes as well. HTML encoding replaces the special characters "<", ">", ""e;" and "&" with "&lt;", "&gt;", "&quote;" and "&amp;" respectively.
      Parameters:
      string - the string to encode
      Returns:
      the encoded string
    • printHtmlDir

      public static WebMap.Info printHtmlDir(File dir, String uri, String encoding, WebMap.ColorSpec colorSpec) throws IOException
      Print a directory listing in HTML format and encapsulate it in a WebMap.Info instance. The uri argument is used for printing the directory's name, not for locating the directory.
      Parameters:
      dir - a directory
      uri - a URI or path for the directory
      encoding - the character encoding used by the HTML generated
      colorSpec - the instance of WebMap.ColorSpec that called this method
      Returns:
      a WebMap.Info instance for the directory listing
      Throws:
      IOException - an IO exception occurred
    • printHtmlDir

      public static void printHtmlDir(File dir, String uri, String encoding, OutputStream os, WebMap.ColorSpec colorSpec) throws IOException
      Print a directory listing in HTML format to an output stream. The uri argument is used for printing the directory's name, not for locating the directory.
      Parameters:
      dir - a directory
      uri - a URI or path for the directory
      encoding - the character encoding used by the HTML generated
      colorSpec - the instance of WebMap.ColorSpec that called this method
      os - the output stream on which to print the file
      Throws:
      IOException - an IO exception occurred
    • printHtmlDir

      public static WebMap.Info printHtmlDir(File file, String uri, String zprepath, String zpath, String encoding, WebMap.ColorSpec colorSpec) throws IOException
      Print a directory listing in HTML format to an output stream. For each zip entry, the string zpath (the third argument) is stripped from the start of the name if present and the entry is ignored if there is no match. For the remainder of the string, all characters after the first '/' are also stripped off. Additional filtering occurs if the last argument's value is "true" - in that case any name that equals "WEB-INF" or starts with "WEB-INF/" before the zpath string is removed is ignored. The directory name will consist of the URI string concatenated with the zpath string. In a typical case, the URI will end with a '/' and the zpath string will not start with a '/'.
      Parameters:
      file - a zip file,
      uri - a URI or path for the zip file or a directory in the zip file
      zprepath - the initial part of a zip-file entry's name
      zpath - the remainder of the zip-file entry's name
      encoding - the character encoding used by the HTML generated
      colorSpec - the instance of WebMap.ColorSpec that called this method
      Returns:
      a WebMap.Info instance for the directory listing
      Throws:
      IOException - an IO exception occurred
    • printHtmlDir

      public static WebMap.Info printHtmlDir(InputStream is, String uri, String zprepath, String zpath, String encoding, WebMap.ColorSpec colorSpec) throws IOException
      Print a directory listing in HTML format to an output stream. For each zip entry, the string zpath (the third argument) is stripped from the start of the name if present and the entry is ignored if there is no match. For the remainder of the string, all characters after the first '/' are also stripped off. Additional filtering occurs if the last argument's value is "true" - in that case any name that equals "WEB-INF" or starts with "WEB-INF/" before the zpath string is removed is ignored. The directory name will consist of the URI string concatenated with the zpath string. In a typical case, the URI will end with a '/' and the zpath string will not start with a '/'.
      Parameters:
      is - an input stream used to read a file in ZIP format
      uri - a URI or path name for the zip file or a directory in the zip file
      zprepath - the initial part of a zip-file entry's name
      zpath - the initial part of a zip-file entry's name
      encoding - the character encoding used by the HTML generated
      colorSpec - the instance of WebMap.ColorSpec that called this method
      Returns:
      a WebMap.Info instance for the directory listing
      Throws:
      IOException - an IO exception occurred
    • printHtmlDir

      public static void printHtmlDir(File file, String uri, String zpath, String encoding, OutputStream os, WebMap.ColorSpec colorSpec) throws IOException
      Print a directory listing in HTML format to an output stream. For each zip entry, the string zpath (the third argument) is stripped from the start of the name if present and the entry is ignored if there is no match. For the remainder of the string, all characters after the first '/' are also stripped off. Additional filtering occurs if the last argument's value is "true" - in that case any name that equals "WEB-INF" or starts with "WEB-INF/" before the zpath string is removed is ignored. The directory name will consist of the URI string concatenated with the zpath string. In a typical case, the URI will end with a '/' and the zpath string will not start with a '/'.
      Parameters:
      file - a ZIP file,
      uri - a URI for the directory
      zpath - the initial part of a zip-file entry's name
      encoding - the character encoding used by the HTML generated
      os - the output stream on which to print the file
      colorSpec - the instance of WebMap.ColorSpec that called this method
      Throws:
      IOException - an IO exception occurred
    • printHtmlDir

      public static void printHtmlDir(InputStream is, String uri, String zprepath, String zpath, String encoding, OutputStream os, WebMap.ColorSpec colorSpec) throws IOException
      Print a directory listing in HTML format to an output stream given an input stream that will read a ZIP file. For each zip entry, the string zpath (the third argument) is stripped from the start of the name if present and the entry is ignored if there is no match. For the remainder of the string, all characters after the first '/' are also stripped off. Additional filtering occurs if the last argument's value is "true" - in that case any name that equals "WEB-INF" or starts with "WEB-INF/" before the zpath string is removed is ignored. The directory name will consist of the URI string concatenated with the zpath string. In a typical case, the URI will end with a '/' and the zpath string will not start with a '/'.
      Parameters:
      is - an input stream for a file in Zip format
      uri - a URI for the directory
      zprepath - the initial part of a zip-file entry's name
      zpath - the initial part of a zip-file entry's name
      encoding - the character encoding used by the HTML generated
      os - the output stream on which to print the file
      colorSpec - the instance of WebMap.ColorSpec that called this method
      Throws:
      IOException - an IO exception occurred
    • printHtmlDir

      public static WebMap.Info printHtmlDir(ZipFile zipfile, String uri, String zprepath, String zpath, String encoding, WebMap.ColorSpec colorSpec) throws IOException
      Print a directory listing in HTML format and encapsulate it in an instance of WebMap.Info, given a ZIP file as the input. For each zip entry, the string zpath (the third argument) is stripped from the start of the name if present and the entry is ignored if there is no match. For the remainder of the string, all characters after the first '/' are also stripped off. Additional filtering occurs if the last argument's value is "true" - in that case any name that equals "WEB-INF" or starts with "WEB-INF/" before the zpath string is removed is ignored. The directory name will consist of the URI string concatenated with the zpath string. In a typical case, the URI will end with a '/' and the zpath string will not start with a '/'.
      Parameters:
      zipfile - an input stream for a file in Zip format
      uri - a URI for the directory
      zprepath - the initial part of a zip-file entry's name
      zpath - the initial part of a zip-file entry's name
      encoding - the character encoding used by the HTML generated
      colorSpec - the instance of WebMap.ColorSpec that called this method
      Returns:
      a WebMap.Info instance for the directory listing
      Throws:
      IOException - an IO exception occurred
    • printHtmlDir

      public static void printHtmlDir(ZipFile zipfile, String uri, String zprepath, String zpath, String encoding, OutputStream os, WebMap.ColorSpec colorSpec) throws IOException
      Print a directory listing in HTML format to an output stream, given a ZIP file as the input. For each zip entry, the string zpath (the third argument) is stripped from the start of the name if present and the entry is ignored if there is no match. For the remainder of the string, all characters after the first '/' are also stripped off. Additional filtering occurs if the last argument's value is "true" - in that case any name that equals "WEB-INF" or starts with "WEB-INF/" before the zpath string is removed is ignored. The directory name will consist of the URI string concatenated with the zpath string. In a typical case, the URI will end with a '/' and the zpath string will not start with a '/'.
      Parameters:
      zipfile - a zip file
      uri - a URI for the directory
      zprepath - the initial part of a zip-file entry's name
      zpath - the initial part of a zip-file entry's name
      encoding - the character encoding used by the HTML generated
      os - the output stream on which to print the file
      colorSpec - the instance of WebMap.ColorSpec that called this method
      Throws:
      IOException - an IO exception occurred
    • printHtmlDir

      public static WebMap.Info printHtmlDir(Set<String> pathSet, String prefix, String encoding, WebMap.ColorSpec colorSpec) throws IOException
      Print a directory listing in HTML format and encapsulate it in an instance of WebMap.Info, given a set of paths. The members of pathSet that are used are the ones starting with the string prefix. That string is removed, and the portion of the remainder up to the first '/' is kept as the name of the directory entry. An HTML-formatted file is provided to the WebMap.Info return value using the specified character encoding. The directory name will be the prefix string.
      Parameters:
      pathSet - a set of paths
      prefix - the initial path prefix
      encoding - the character encoding used by the HTML generated
      colorSpec - the instance of WebMap.ColorSpec that called this method
      Returns:
      an object encapsulating the directory listing and information useful for displaying the listing.
      Throws:
      IOException - an IO exception occurred
    • printHtmlDir

      public static void printHtmlDir(Set<String> pathSet, String prefix, String encoding, OutputStream os, WebMap.ColorSpec colorSpec) throws IOException
      Print a directory listing in HTML format to an output stream given a set of paths. The members of pathSet that are used are the ones starting with the string prefix. That string is removed, and the portion of the remainder up to the first '/' is kept as the name of the directory entry. An HTML-formatted file is written to the output stream using the specified character encoding. The directory name will be the prefix string.
      Parameters:
      pathSet - a set of paths
      prefix - the initial path prefix
      encoding - the character encoding used by the HTML generated
      os - the output stream
      colorSpec - the instance of WebMap.ColorSpec that called this method
      Throws:
      IOException - an IO exception occurred