Interface ResourceDataBroker

All Known Implementing Classes:
DefaultResourceDataBroker

public interface ResourceDataBroker
Is responsible for getting the necessary resources for the LanguageTool library. Following directories are currently needed by a couple of classes:
  • /resource
  • /rules
This interface determines methods to obtain any contents from these directories.

Make sure that you never obtain any LanguageTool resources by calling Object.class.getResource(String) or Object.class.getResourceAsStream(String) directly. If you would like to obtain something from these directories do always use JLanguageTool.getDataBroker() which provides proper methods for reading the directories above.

For example, if you want to get the URL of /rules/de/grammar.xml just invoke getFromRulesDirAsUrl(String) and pass /de/grammar.xml as a string. Note: The /rules directory's name isn't passed, because its name might have changed. The same usage does apply for the /resource directory.

Since:
1.0.1
  • Field Details

  • Method Details

    • getFromResourceDirAsUrl

      URL getFromResourceDirAsUrl(String path)
      Gets any resource from LanguageTool's /resource directory.
      Parameters:
      path - Path to an item from the /resource directory.
      Returns:
      An URL object to the requested item
      Throws:
      RuntimeException - if path cannot be found
    • getFromResourceDirAsUrls

      List<URL> getFromResourceDirAsUrls(String path)
      Gets all resources in a form of URL from LanguageTool's /resource directory with the same path.
      Parameters:
      path - Path to an items from the /resource directory.
      Returns:
      A list of URL objects to the requested item
      Throws:
      RuntimeException - if path cannot be found
    • resourceExists

      boolean resourceExists(String path)
      Checks if a resource in LanguageTool's /resource exists.
      Parameters:
      path - Path to an item from the /resource directory.
      Returns:
      true if the resource file exists.
    • ruleFileExists

      boolean ruleFileExists(String path)
      Checks if a resource in LanguageTool's /rules exists.
      Parameters:
      path - Path to an item from the /rules directory.
      Returns:
      true if the resource file exists.
    • getFromResourceDirAsStream

      InputStream getFromResourceDirAsStream(String path)
      Gets any resource from LanguageTool's /resource directory.
      Parameters:
      path - Path to an item from the /resource directory.
      Returns:
      An InputStream object to the requested item
      Throws:
      RuntimeException - if path cannot be found
    • getFromResourceDirAsLines

      List<String> getFromResourceDirAsLines(String path)
      Gets any resource from the /resource directory.
      Parameters:
      path - The relative path to the item inside of the /resource, e.g. /xx/filename
      Returns:
      An list of strings, one per line
      Throws:
      RuntimeException - if path cannot be found
      Since:
      4.9
    • getAsStream

      InputStream getAsStream(String path)
      Get from resource broker by a path file
      Parameters:
      path - Path to an item
      Returns:
      An InputStream object to the requested item
      Since:
      4.9
    • getAsURL

      URL getAsURL(String path)
      Get from resource broker by a path file
      Parameters:
      path - Path to an item
      Returns:
      An URL object to the requested item
      Since:
      5.0
    • getAsURLs

      List<URL> getAsURLs(String path)
      Get URLs from resource broker by a path file
      Parameters:
      path - Path to an item
      Returns:
      An list of URL objects to the requested item
      Since:
      5.0
    • getFromRulesDirAsUrl

      URL getFromRulesDirAsUrl(String path)
      Gets any resource from LanguageTool's /rules directory.
      Parameters:
      path - Path to an item from the /rules directory.
      Returns:
      An URL object to the requested item
      Throws:
      RuntimeException - if path cannot be found
    • getFromRulesDirAsStream

      InputStream getFromRulesDirAsStream(String path)
      Gets any resource from LanguageTool's /rules directory.
      Parameters:
      path - Path to an item from the /rules directory.
      Returns:
      An InputStream object to the requested item
      Throws:
      RuntimeException - if path cannot be found
    • getResourceDir

      String getResourceDir()
      Returns:
      The currently set resource directory path as a string. Make sure that you comply with the following format when setting this value:
      /subdir/furtherdir/resourcedir
    • getRulesDir

      String getRulesDir()
      Returns:
      The currently set rules directory path as a string. Make sure that you comply with the following format when setting this value:
      /subdir/furtherdir/rulesdir
    • getResourceBundle

      ResourceBundle getResourceBundle(String baseName, Locale locale)
      Gets a resource bundle using the specified base name and locale, and the caller module.
      Parameters:
      baseName - the base name of the resource bundle, a fully qualified class name
      locale - the locale for which a resource bundle is desired
      Returns:
      a resource bundle for the given base name and locale
      Since:
      5.0