public class DefaultResourceDataBroker extends Object implements 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.
ResourceDataBroker
RESOURCE_DIR, RULES_DIR
Constructor and Description |
---|
DefaultResourceDataBroker()
Instantiates this data broker with the default resource directory names
as specified in:
ResourceDataBroker.RESOURCE_DIR
ResourceDataBroker.RULES_DIR
|
DefaultResourceDataBroker(String resourceDir,
String rulesDir)
Instantiates this data broker with the passed resource directory names.
|
Modifier and Type | Method and Description |
---|---|
InputStream |
getAsStream(String path)
Get from resource broker by a path file
|
URL |
getAsURL(String path)
Get from resource broker by a path file
|
List<URL> |
getAsURLs(String path)
Get URLs from resource broker by a path file
|
List<String> |
getFromResourceDirAsLines(String path)
|
InputStream |
getFromResourceDirAsStream(String path)
|
URL |
getFromResourceDirAsUrl(String path)
|
List<URL> |
getFromResourceDirAsUrls(String path)
Gets all resources in a form of URL from LanguageTool's
/resource
directory with the same path . |
InputStream |
getFromRulesDirAsStream(String path)
|
URL |
getFromRulesDirAsUrl(String path)
|
ResourceBundle |
getResourceBundle(String baseName,
Locale locale)
Gets a resource bundle using the specified base name and locale, and the caller module.
|
String |
getResourceDir() |
String |
getRulesDir() |
boolean |
resourceExists(String path)
See:
ResourceDataBroker.resourceExists(String)
Checks if a resource in LanguageTool's /resource exists. |
boolean |
ruleFileExists(String path)
See:
ResourceDataBroker.ruleFileExists(String)
Checks if a resource in LanguageTool's /rules exists. |
public DefaultResourceDataBroker()
public DefaultResourceDataBroker(String resourceDir, String rulesDir)
resourceDir
- The directory's name of LanguageTool's resource
directory. The default value equals ResourceDataBroker.RESOURCE_DIR
.rulesDir
- The directory's name of LanguageTool's rules directory.
The default value equals ResourceDataBroker.RULES_DIR
.@NotNull public InputStream getFromResourceDirAsStream(String path)
getFromResourceDirAsStream
in interface ResourceDataBroker
path
- The relative path to the item inside of the /resource
directory. Please start your path information with /
because it will be concatenated with the directory's name:
/resource/yourpath.InputStream
object to the requested itemRuntimeException
- if path cannot be found@NotNull public List<String> getFromResourceDirAsLines(String path)
getFromResourceDirAsLines
in interface ResourceDataBroker
path
- The relative path to the item inside of the /resource
, e.g. /xx/filename
RuntimeException
- if path cannot be found@Nullable public InputStream getAsStream(String path)
getAsStream
in interface ResourceDataBroker
path
- Path to an itemInputStream
object to the requested item@Nullable public URL getAsURL(String path)
getAsURL
in interface ResourceDataBroker
path
- Path to an itemURL
object to the requested item@Nullable public List<URL> getAsURLs(String path)
getAsURLs
in interface ResourceDataBroker
path
- Path to an itemURL
objects to the requested item@NotNull public URL getFromResourceDirAsUrl(String path)
getFromResourceDirAsUrl
in interface ResourceDataBroker
path
- The relative path to the item inside of the /resource
directory. Please start your path information with /
because it will be concatenated with the directory's name:
/resource/yourpath.URL
object to the requested itemRuntimeException
- if path cannot be found@NotNull public List<URL> getFromResourceDirAsUrls(String path)
/resource
directory with the same path
.getFromResourceDirAsUrls
in interface ResourceDataBroker
path
- Path to an items from the /resource
directory.URL
objects to the requested item@NotNull public InputStream getFromRulesDirAsStream(String path)
getFromRulesDirAsStream
in interface ResourceDataBroker
path
- The relative path to the item inside of the /rules
directory. Please start your path information with /
because it
will be concatenated with the directory's name: /rules/yourpath.InputStream
object to the requested itemRuntimeException
- if path cannot be found@NotNull public URL getFromRulesDirAsUrl(String path)
getFromRulesDirAsUrl
in interface ResourceDataBroker
path
- The relative path to the item inside of the /rules
directory. Please start your path information with /
because it
will be concatenated with the directory's name: /rules/yourpath.URL
object to the requested itemRuntimeException
- if path cannot be foundpublic boolean resourceExists(String path)
ResourceDataBroker.resourceExists(String)
Checks if a resource in LanguageTool's /resource
exists.resourceExists
in interface ResourceDataBroker
path
- Path to an item from the /resource
directory.true
if the resource file exists.public boolean ruleFileExists(String path)
ResourceDataBroker.ruleFileExists(String)
Checks if a resource in LanguageTool's /rules
exists.ruleFileExists
in interface ResourceDataBroker
path
- Path to an item from the /rules
directory.true
if the resource file exists.public String getResourceDir()
getResourceDir
in interface ResourceDataBroker
ResourceDataBroker.RESOURCE_DIR
.public String getRulesDir()
getRulesDir
in interface ResourceDataBroker
ResourceDataBroker.RULES_DIR
.public ResourceBundle getResourceBundle(String baseName, Locale locale)
getResourceBundle
in interface ResourceDataBroker
baseName
- the base name of the resource bundle, a fully qualified class namelocale
- the locale for which a resource bundle is desiredNullPointerException
- if baseName
or locale
is null
MissingResourceException
- if no resource bundle for the specified base name can be found