java.lang.Object
org.bzdev.ejws.EjwsUtilities
Useful methods for writing handlers and subclasses of WebMap.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
htmlEncode
(String string) HTML encode a string.static String
htmlQuoteEncode
(String string) HTML encode a string, encoding double quotes as well.static void
printHtmlDir
(File dir, String uri, String encoding, OutputStream os, WebMap.ColorSpec colorSpec) Print a directory listing in HTML format to an output stream.static void
printHtmlDir
(File file, String uri, String zpath, String encoding, OutputStream os, WebMap.ColorSpec colorSpec) Print a directory listing in HTML format to an output stream.static WebMap.Info
printHtmlDir
(File file, String uri, String zprepath, String zpath, String encoding, WebMap.ColorSpec colorSpec) Print a directory listing in HTML format to an output stream.static WebMap.Info
printHtmlDir
(File dir, String uri, String encoding, WebMap.ColorSpec colorSpec) Print a directory listing in HTML format and encapsulate it in a WebMap.Info instance.static void
printHtmlDir
(InputStream is, String uri, String zprepath, String zpath, String encoding, OutputStream os, WebMap.ColorSpec colorSpec) Print a directory listing in HTML format to an output stream given an input stream that will read a ZIP file.static WebMap.Info
printHtmlDir
(InputStream is, String uri, String zprepath, String zpath, String encoding, WebMap.ColorSpec colorSpec) Print a directory listing in HTML format to an output stream.static void
printHtmlDir
(Set<String> pathSet, String prefix, String encoding, OutputStream os, WebMap.ColorSpec colorSpec) Print a directory listing in HTML format to an output stream given a set of paths.static WebMap.Info
printHtmlDir
(Set<String> pathSet, String prefix, String encoding, WebMap.ColorSpec colorSpec) Print a directory listing in HTML format and encapsulate it in an instance of WebMap.Info, given a set of paths.static void
printHtmlDir
(ZipFile zipfile, String uri, String zprepath, String zpath, String encoding, OutputStream os, WebMap.ColorSpec colorSpec) Print a directory listing in HTML format to an output stream, given a ZIP file as the input.static WebMap.Info
printHtmlDir
(ZipFile zipfile, String uri, String zprepath, String zpath, String encoding, WebMap.ColorSpec colorSpec) Print a directory listing in HTML format and encapsulate it in an instance of WebMap.Info, given a ZIP file as the input.
-
Constructor Details
-
EjwsUtilities
public EjwsUtilities()
-
-
Method Details
-
htmlEncode
HTML encode a string. HTML encoding replaces the special characters "<", ">", and "&" with "<", ">", and * "&" respectively.- Parameters:
string
- the string to encode- Returns:
- the encoded string
-
htmlQuoteEncode
HTML encode a string, encoding double quotes as well. HTML encoding replaces the special characters "<", ">", ""e;" and "&" with "<", ">", ""e;" and "&" 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 directoryuri
- a URI or path for the directoryencoding
- the character encoding used by the HTML generatedcolorSpec
- 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 directoryuri
- a URI or path for the directoryencoding
- the character encoding used by the HTML generatedcolorSpec
- the instance of WebMap.ColorSpec that called this methodos
- 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 filezprepath
- the initial part of a zip-file entry's namezpath
- the remainder of the zip-file entry's nameencoding
- the character encoding used by the HTML generatedcolorSpec
- 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 formaturi
- a URI or path name for the zip file or a directory in the zip filezprepath
- the initial part of a zip-file entry's namezpath
- the initial part of a zip-file entry's nameencoding
- the character encoding used by the HTML generatedcolorSpec
- 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 directoryzpath
- the initial part of a zip-file entry's nameencoding
- the character encoding used by the HTML generatedos
- the output stream on which to print the filecolorSpec
- 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 formaturi
- a URI for the directoryzprepath
- the initial part of a zip-file entry's namezpath
- the initial part of a zip-file entry's nameencoding
- the character encoding used by the HTML generatedos
- the output stream on which to print the filecolorSpec
- 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 formaturi
- a URI for the directoryzprepath
- the initial part of a zip-file entry's namezpath
- the initial part of a zip-file entry's nameencoding
- the character encoding used by the HTML generatedcolorSpec
- 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 fileuri
- a URI for the directoryzprepath
- the initial part of a zip-file entry's namezpath
- the initial part of a zip-file entry's nameencoding
- the character encoding used by the HTML generatedos
- the output stream on which to print the filecolorSpec
- 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 pathsprefix
- the initial path prefixencoding
- the character encoding used by the HTML generatedcolorSpec
- 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 pathsprefix
- the initial path prefixencoding
- the character encoding used by the HTML generatedos
- the output streamcolorSpec
- the instance of WebMap.ColorSpec that called this method- Throws:
IOException
- an IO exception occurred
-