Class DefaultResourceDataBroker
- All Implemented Interfaces:
ResourceDataBroker
If you'd like to determine another resource directory location this default
data broker provides proper methods.
Assuming your /rules and /resource directories are accessible
via class-path with following path information:
/res/grammarchecker/rulesdirname/res/grammarchecker/resourcedirname
/res/grammarchecker/rulesdirname/res/grammarchecker/resourcedirname
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
ResourceDataBroker.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
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringThe directory's name of LanguageTool's resource directory.private final StringThe directory's name of LanguageTool's rules directory.Fields inherited from interface org.languagetool.broker.ResourceDataBroker
RESOURCE_DIR, RULES_DIR -
Constructor Summary
ConstructorsConstructorDescriptionInstantiates this data broker with the default resource directory names as specified in:ResourceDataBroker.RESOURCE_DIRResourceDataBroker.RULES_DIRDefaultResourceDataBroker(String resourceDir, String rulesDir) Instantiates this data broker with the passed resource directory names. -
Method Summary
Modifier and TypeMethodDescriptionprivate StringappendPath(String baseDir, String path) private voidassertNotNull(Object object, String path, String completePath) getAsStream(String path) Get from resource broker by a path fileGet from resource broker by a path fileGet URLs from resource broker by a path fileprivate StringgetCompleteResourceUrl(String path) Concatenates the passed resource path with the currently setresourcedirectory path.private StringgetCompleteRulesUrl(String path) Concatenates the passed resource path with the currently setrulesdirectory path.Gets all resources in a form of URL from LanguageTool's/resourcedirectory with the samepath.getFromRulesDirAsUrl(String path) getResourceBundle(String baseName, Locale locale) Gets a resource bundle using the specified base name and locale, and the caller module.booleanresourceExists(String path) See:ResourceDataBroker.resourceExists(String)Checks if a resource in LanguageTool's/resourceexists.booleanruleFileExists(String path) See:ResourceDataBroker.ruleFileExists(String)Checks if a resource in LanguageTool's/rulesexists.
-
Field Details
-
resourceDir
The directory's name of LanguageTool's resource directory. The default value equalsResourceDataBroker.RESOURCE_DIR. -
rulesDir
The directory's name of LanguageTool's rules directory. The default value equalsResourceDataBroker.RULES_DIR.
-
-
Constructor Details
-
DefaultResourceDataBroker
public DefaultResourceDataBroker()Instantiates this data broker with the default resource directory names as specified in: -
DefaultResourceDataBroker
Instantiates this data broker with the passed resource directory names.- Parameters:
resourceDir- The directory's name of LanguageTool's resource directory. The default value equalsResourceDataBroker.RESOURCE_DIR.rulesDir- The directory's name of LanguageTool's rules directory. The default value equalsResourceDataBroker.RULES_DIR.
-
-
Method Details
-
getFromResourceDirAsStream
- Specified by:
getFromResourceDirAsStreamin interfaceResourceDataBroker- Parameters:
path- The relative path to the item inside of the/resourcedirectory. Please start your path information with/because it will be concatenated with the directory's name: /resource/yourpath.- Returns:
- An
InputStreamobject to the requested item - Throws:
RuntimeException- if path cannot be found
-
getFromResourceDirAsLines
- Specified by:
getFromResourceDirAsLinesin interfaceResourceDataBroker- 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- Specified by:
getAsStreamin interfaceResourceDataBroker- Parameters:
path- Path to an item- Returns:
- An
InputStreamobject to the requested item
-
getAsURL
Get from resource broker by a path file- Specified by:
getAsURLin interfaceResourceDataBroker- Parameters:
path- Path to an item- Returns:
- An
URLobject to the requested item
-
getAsURLs
Get URLs from resource broker by a path file- Specified by:
getAsURLsin interfaceResourceDataBroker- Parameters:
path- Path to an item- Returns:
- An list of
URLobjects to the requested item
-
getFromResourceDirAsUrl
- Specified by:
getFromResourceDirAsUrlin interfaceResourceDataBroker- Parameters:
path- The relative path to the item inside of the/resourcedirectory. Please start your path information with/because it will be concatenated with the directory's name: /resource/yourpath.- 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.- Specified by:
getFromResourceDirAsUrlsin interfaceResourceDataBroker- Parameters:
path- Path to an items from the/resourcedirectory.- Returns:
- A list of
URLobjects to the requested item
-
getCompleteResourceUrl
Concatenates the passed resource path with the currently setresourcedirectory path.- Parameters:
path- The relative path to a resource item inside of theresourcedirectory.- Returns:
- The full relative path to the resource including the path to the
resourcedirectory.
-
getFromRulesDirAsStream
- Specified by:
getFromRulesDirAsStreamin interfaceResourceDataBroker- Parameters:
path- The relative path to the item inside of the/rulesdirectory. Please start your path information with/because it will be concatenated with the directory's name: /rules/yourpath.- Returns:
- An
InputStreamobject to the requested item - Throws:
RuntimeException- if path cannot be found
-
getFromRulesDirAsUrl
- Specified by:
getFromRulesDirAsUrlin interfaceResourceDataBroker- Parameters:
path- The relative path to the item inside of the/rulesdirectory. Please start your path information with/because it will be concatenated with the directory's name: /rules/yourpath.- Returns:
- An
URLobject to the requested item - Throws:
RuntimeException- if path cannot be found
-
assertNotNull
-
getCompleteRulesUrl
Concatenates the passed resource path with the currently setrulesdirectory path.- Parameters:
path- The relative path to a resource item inside of therulesdirectory.- Returns:
- The full relative path to the resource including the path to the
rulesdirectory.
-
appendPath
-
resourceExists
See:ResourceDataBroker.resourceExists(String)Checks if a resource in LanguageTool's/resourceexists.- Specified by:
resourceExistsin interfaceResourceDataBroker- Parameters:
path- Path to an item from the/resourcedirectory.- Returns:
trueif the resource file exists.
-
ruleFileExists
See:ResourceDataBroker.ruleFileExists(String)Checks if a resource in LanguageTool's/rulesexists.- Specified by:
ruleFileExistsin interfaceResourceDataBroker- Parameters:
path- Path to an item from the/rulesdirectory.- Returns:
trueif the resource file exists.
-
getResourceDir
- Specified by:
getResourceDirin interfaceResourceDataBroker- Returns:
- The directory's name of LanguageTool's resource directory.
The default value equals
ResourceDataBroker.RESOURCE_DIR.
-
getRulesDir
- Specified by:
getRulesDirin interfaceResourceDataBroker- Returns:
- The directory's name of the grammar checker's rules directory.
The default value equals
ResourceDataBroker.RULES_DIR.
-
getResourceBundle
Gets a resource bundle using the specified base name and locale, and the caller module.- Specified by:
getResourceBundlein interfaceResourceDataBroker- 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
- Throws:
NullPointerException- ifbaseNameorlocaleisnullMissingResourceException- if no resource bundle for the specified base name can be found
-