Package org.bzdev.net

Class URLPathParser

java.lang.Object
org.bzdev.net.URLPathParser

public class URLPathParser extends Object
URL Path Parser for string of URLs separated by a '|' delimiter. A component in a path should be either a URL or a file name. A sequence of n "|" characters will be replaced by floor(n/2) "|" characters and if n is odd, the final "|" is treated as the separator. As a result, except when it is the first component, a file name cannot start with "|". If it is really necessary to have a "|" at the start of a file name, use a "file" URL (in which case the "|" should be encoded as "%7C".) If a path component's initial characters, up to and including the first ":" are syntactically valid as part of a URL, the component is interpreted as a URL, not a file name.

In addition, a leading "~", followed by either the standard file-separator character or "/", is replaced with the user's home directory. The sequence "~~" at the start of a component will be replaced by a single "~". All subsequent "~" characters in that component are left as is. The method getURLs(File,String,String) and getURLs(File,String,String, Appendable) will treat a leading "..." followed by the file separator or "/" as a shorthand for a specified directory. The programs scrunner and lsnof set that directory to the one containing the BZDev library's JAR file.

  • Constructor Details

    • URLPathParser

      public URLPathParser()
  • Method Details

    • getURLs

      public static URL[] getURLs(String urlPath) throws MalformedURLException
      Parse a list of URLs or file names, separated by "|". Relative files are resolved using the current working directory. In addition, for each URL, a leading~~ will be replaced with ~, and ~ followed by the filename separator will be replaced with the user's home directory followed by the filename separator (in this case, a security exception will be thrown if the caller does not have permission to acesss the system property user.home).
      Parameters:
      urlPath - the string representation of multiple URLs or files, separated by "|"
      Returns:
      an array of URLs
      Throws:
      MalformedURLException - if there was a syntax error
    • getURLs

      public static URL[] getURLs(File dir, String urlPath) throws MalformedURLException
      Parse a list of URLs or file names, separated by "|", given a directory. Relative files are resolved using the current working directory. If the argument urlPath is an empty string, the array returned will have a length of 0. In addition, for each URL, a leading~~ will be replaced with ~, and ~ followed by the filename separator will be replaced with the user's home directory followed by the filename separator (in this case, a security exception will be thrown if the caller does not have permission to acesss the system property user.home).
      Parameters:
      dir - the directory against which to resolve relative files; null indicates the current working directory
      urlPath - the string representation of multiple URLs or files, separated by "|"
      Returns:
      an array of URLs
      Throws:
      MalformedURLException - a URL was malformed
    • getURLs

      public static URL[] getURLs(File dir, String urlPath, String threeDotDir) throws MalformedURLException, SecurityException
      Parse a list of URLs or file names, separated by "|", given a directory.

      When the third argument threeDotDir is not null, some substitutions may be performed The string "...", if it starts a file name as opposed to a URL and is followed by the name separator ("/" on Unix), will be replaced with the directory given by the third argument when that argument is not null. In addition, ~~ will be replaced with ~, and ~ followed by the filename separator will be replaced with the user's home directory followed by the filename separator (in this case, a security exception will be thrown if the caller does not have permission to acesss the system property user.home).

      A file component is not tested to see if the file (or directory) exists and is readable by the application. If the argument urlPath is an empty string, the array returned will have a length of 0. Relative files are resolved using the current working directory.

      Parameters:
      dir - the directory against which to resolve relative files; null indicates the current working directory
      urlPath - the string representation of multiple URLs or files, separated by "|"
      threeDotDir - the directory that will replace a leading file-name component equal to "..."; null for no replacement
      Returns:
      an array of URLs
      Throws:
      MalformedURLException - a URL was malformed
      SecurityException - a security exception occurred (most likely because the system property user.home could not be accessed)
    • getURLs

      public static URL[] getURLs(File dir, String urlPath, String threeDotDir, Appendable output) throws MalformedURLException, SecurityException
      Parse list of URLs or file names, separated by "|", given a directory with an optional file-name test.

      When the third argument threeDotDir is not null, some substitutions may be performed The string "...", if it starts a file name as opposed to a URL and is followed by the name separator ("/" on Unix), will be replaced with the directory given by the third argument when that argument is not null. In addition, for each URL, a leading~~ will be replaced with ~, and ~ followed by the filename separator will be replaced with the user's home directory followed by the filename separator (in this case, a security exception will be thrown if the caller does not have permission to acesss the system property user.home). If the argument is an empty string, the array returned will have a length of 0. Relative files are resolved using the current working directory.

      Parameters:
      dir - the directory against which to resolve relative files; null indicates the current working directory
      urlPath - the string representation of multiple URLs or files, separated by "|"
      threeDotDir - the directory that will replace a leading file-name component equal to "..."; null for no replacement
      output - an Appendable to log output for a file-name test; null a file-name test is not wanted
      Returns:
      an array of URLs
      Throws:
      MalformedURLException - a URL was malformed
      SecurityException - a security exception occurred (most likely because the system property user.home could not be accessed)
    • split

      public static String[] split(String urlPath)
      Parse a path of URLs or file names that are separated by "|". When an odd number of "|" characters is found, all but the last are kept as part of a the current path component. Each string in the array of strings that is returned can be passed to on the getURLs method, which will then return an array whose length is 1. If the argument is an empty string, the array returned will have a length of 0.

      This method does not treat "~" as a special character.

      Parameters:
      urlPath - a string containing the URLs or file names.
      Returns:
      an array of strings providing the paths or URLs.