Package org.languagetool.broker
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
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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiongetAsStream(String path) Get from resource broker by a path fileGet from resource broker by a path fileGet URLs from resource broker by a path fileGets any resource from the/resourcedirectory.Gets any resource from LanguageTool's/resourcedirectory.Gets any resource from LanguageTool's/resourcedirectory.Gets all resources in a form of URL from LanguageTool's/resourcedirectory with the samepath.Gets any resource from LanguageTool's/rulesdirectory.getFromRulesDirAsUrl(String path) Gets any resource from LanguageTool's/rulesdirectory.getResourceBundle(String baseName, Locale locale) Gets a resource bundle using the specified base name and locale, and the caller module.booleanresourceExists(String path) Checks if a resource in LanguageTool's/resourceexists.booleanruleFileExists(String path) Checks if a resource in LanguageTool's/rulesexists.
-
Field Details
-
RESOURCE_DIR
The directory name of the/resourcedirectory.- See Also:
-
RULES_DIR
The directory name of the/rulesdirectory.- See Also:
-
-
Method Details
-
getFromResourceDirAsUrl
Gets any resource from LanguageTool's/resourcedirectory.- Parameters:
path- Path to an item from the/resourcedirectory.- Returns:
- An
URLobject to the requested item - Throws:
RuntimeException- if path cannot be found
-
getFromResourceDirAsUrls
Gets all resources in a form of URL from LanguageTool's/resourcedirectory with the samepath.- Parameters:
path- Path to an items from the/resourcedirectory.- Returns:
- A list of
URLobjects to the requested item - Throws:
RuntimeException- if path cannot be found
-
resourceExists
Checks if a resource in LanguageTool's/resourceexists.- Parameters:
path- Path to an item from the/resourcedirectory.- Returns:
trueif the resource file exists.
-
ruleFileExists
Checks if a resource in LanguageTool's/rulesexists.- Parameters:
path- Path to an item from the/rulesdirectory.- Returns:
trueif the resource file exists.
-
getFromResourceDirAsStream
Gets any resource from LanguageTool's/resourcedirectory.- Parameters:
path- Path to an item from the/resourcedirectory.- Returns:
- An
InputStreamobject to the requested item - Throws:
RuntimeException- if path cannot be found
-
getFromResourceDirAsLines
Gets any resource from the/resourcedirectory.- 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
Get from resource broker by a path file- Parameters:
path- Path to an item- Returns:
- An
InputStreamobject to the requested item - Since:
- 4.9
-
getAsURL
Get from resource broker by a path file- Parameters:
path- Path to an item- Returns:
- An
URLobject to the requested item - Since:
- 5.0
-
getAsURLs
Get URLs from resource broker by a path file- Parameters:
path- Path to an item- Returns:
- An list of
URLobjects to the requested item - Since:
- 5.0
-
getFromRulesDirAsUrl
Gets any resource from LanguageTool's/rulesdirectory.- Parameters:
path- Path to an item from the/rulesdirectory.- Returns:
- An
URLobject to the requested item - Throws:
RuntimeException- if path cannot be found
-
getFromRulesDirAsStream
Gets any resource from LanguageTool's/rulesdirectory.- Parameters:
path- Path to an item from the/rulesdirectory.- Returns:
- An
InputStreamobject 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
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 namelocale- the locale for which a resource bundle is desired- Returns:
- a resource bundle for the given base name and locale
- Since:
- 5.0
-