Class DownloadUtil.DownloadParser

java.lang.Object
opennlp.tools.util.DownloadUtil.DownloadParser
Enclosing class:
DownloadUtil

@Internal static class DownloadUtil.DownloadParser extends Object
  • Field Details

  • Constructor Details

    • DownloadParser

      DownloadParser(URL indexUrl, Path localIndex)
      Initializes a parser that keeps a copy of the index page.
      Parameters:
      indexUrl - The index page.
      localIndex - The file that keeps a copy of the index page, or null to keep no copy.
      Throws:
      IllegalArgumentException - Thrown if indexUrl is null.
  • Method Details

    • getAvailableModels

      Lists the models of the index page. If the page lists models, it is stored as the local copy. Otherwise, for example if the page cannot be read, the local copy is used.
      Returns:
      The model URLs per language and ModelType. Empty if neither the page nor the local copy lists models.
      Throws:
      MalformedURLException - Thrown if a model URL is malformed.
      URISyntaxException - Thrown if a model URL is not a valid URI.
    • readLocalIndex

      private String readLocalIndex()
      Reads the local copy of the index page.
      Returns:
      The page content, or null if there is no readable copy.
    • storeLocalIndex

      private void storeLocalIndex(String page)
      Stores the index page as the local copy. The page is written to a temporary file that then replaces the copy, so a reader never sees a partly written copy. A failure is only logged.
      Parameters:
      page - The page content.
    • extractLinks

      List<String> extractLinks(String page)
      Collects the href values of the anchor elements in an index page. The tag name and attribute are matched ignoring case, the value is quoted with double or single quotes, a value ends at its closing quote followed by >, a link ends at the first </a>, and both may span lines. An anchor whose value is not quoted, or whose value or tag is not closed, is skipped.
      Parameters:
      page - The page content.
      Returns:
      The href values in order.
    • closingQuote

      private int closingQuote(String page, char quote, int from)
      Finds the quote that closes an attribute value and is followed by the end of the tag.
      Parameters:
      page - The page content.
      quote - The quote character that opened the value.
      from - The first offset of the value.
      Returns:
      The offset of the closing quote, or -1.
    • indexOfIgnoreCase

      private int indexOfIgnoreCase(String text, String literal, int from)
      Finds a literal in the text, ignoring case.
      Parameters:
      text - The text.
      literal - The literal.
      from - The start offset.
      Returns:
      The first match offset, or -1.
    • toMap

      Throws:
      MalformedURLException
      URISyntaxException
    • addModel

      private void addModel(String locale, String link, Map<String,Map<ModelType,URL>> result) throws URISyntaxException, MalformedURLException
      Throws:
      URISyntaxException
      MalformedURLException
    • fetchPageIndex

      private String fetchPageIndex()
      Reads the index page from its URL, joining its lines.
      Returns:
      The page content, or null if the page could not be read completely.