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 grammar checker 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.
ResourceDataBrokerRESOURCE_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 |
getFromResourceDirAsStream(String path)
|
URL |
getFromResourceDirAsUrl(String path)
|
InputStream |
getFromRulesDirAsStream(String path)
|
URL |
getFromRulesDirAsUrl(String path)
|
String |
getResourceDir() |
String |
getRulesDir() |
boolean |
resourceExists(String path)
See:
ResourceDataBroker.resourceExists(java.lang.String)
Checks if a resource in the grammar checker's /resource exists. |
boolean |
ruleFileExists(String path)
See:
ResourceDataBroker.ruleFileExists(java.lang.String)
Checks if a resource in the grammar checker's /rules exists. |
public DefaultResourceDataBroker()
public DefaultResourceDataBroker(String resourceDir, String rulesDir)
resourceDir - The directory's name of the grammar checker's resource
directory. The default value equals ResourceDataBroker.RESOURCE_DIR.rulesDir - The directory's name of the grammar checker's rules directory.
The default value equals ResourceDataBroker.RULES_DIR.public InputStream getFromResourceDirAsStream(String path)
getFromResourceDirAsStream in interface ResourceDataBrokerpath - 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 foundpublic URL getFromResourceDirAsUrl(String path)
getFromResourceDirAsUrl in interface ResourceDataBrokerpath - 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 foundpublic InputStream getFromRulesDirAsStream(String path)
getFromRulesDirAsStream in interface ResourceDataBrokerpath - 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 foundpublic URL getFromRulesDirAsUrl(String path)
getFromRulesDirAsUrl in interface ResourceDataBrokerpath - 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(java.lang.String)
Checks if a resource in the grammar checker's /resource exists.resourceExists in interface ResourceDataBrokerpath - Path to an item from the /resource directory.true if the resource file exists.public boolean ruleFileExists(String path)
ResourceDataBroker.ruleFileExists(java.lang.String)
Checks if a resource in the grammar checker's /rules exists.ruleFileExists in interface ResourceDataBrokerpath - Path to an item from the /rules directory.true if the resource file exists.public String getResourceDir()
getResourceDir in interface ResourceDataBrokerResourceDataBroker.RESOURCE_DIR.public String getRulesDir()
getRulesDir in interface ResourceDataBrokerResourceDataBroker.RULES_DIR.