Class DefaultResourceDataBroker
- java.lang.Object
-
- org.languagetool.databroker.DefaultResourceDataBroker
-
- All Implemented Interfaces:
ResourceDataBroker
public class DefaultResourceDataBroker extends java.lang.Object implements ResourceDataBroker
Responsible for getting any items from the grammar checker's resource directories. This default data broker assumes that they are accessible directly via class-path and the directory names are like specified in:If you'd like to determine another resource directory location this default data broker provides proper methods. Assuming your
/rulesand/resourcedirectories 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)orObject.class.getResourceAsStream(String)directly. If you would like to obtain something from these directories do always useJLanguageTool.getDataBroker()which provides proper methods for reading the directories above.For example, if you want to get the
URLof/rules/de/grammar.xmljust invokeResourceDataBroker.getFromRulesDirAsUrl(String)and pass/de/grammar.xmlas a string. Note: The/rulesdirectory's name isn't passed because its name might have changed. The same usage does apply for the/resourcedirectory.- Since:
- 1.0.1
- See Also:
ResourceDataBroker
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringresourceDirThe directory's name of the grammar checker's resource directory.private java.lang.StringrulesDirThe directory's name of the grammar checker's rules directory.-
Fields inherited from interface org.languagetool.databroker.ResourceDataBroker
RESOURCE_DIR, RULES_DIR
-
-
Constructor Summary
Constructors Constructor Description DefaultResourceDataBroker()Instantiates this data broker with the default resource directory names as specified in:ResourceDataBroker.RESOURCE_DIRResourceDataBroker.RULES_DIRDefaultResourceDataBroker(java.lang.String resourceDir, java.lang.String rulesDir)Instantiates this data broker with the passed resource directory names.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.StringappendPath(java.lang.String baseDir, java.lang.String path)private voidassertNotNull(java.lang.Object object, java.lang.String path, java.lang.String completePath)private java.lang.StringgetCompleteResourceUrl(java.lang.String path)Concatenates the passed resource path with the currently setresourcedirectory path.private java.lang.StringgetCompleteRulesUrl(java.lang.String path)Concatenates the passed resource path with the currently setrulesdirectory path.java.io.InputStreamgetFromResourceDirAsStream(java.lang.String path)java.net.URLgetFromResourceDirAsUrl(java.lang.String path)java.io.InputStreamgetFromRulesDirAsStream(java.lang.String path)java.net.URLgetFromRulesDirAsUrl(java.lang.String path)java.lang.StringgetResourceDir()java.lang.StringgetRulesDir()booleanresourceExists(java.lang.String path)See:ResourceDataBroker.resourceExists(String)Checks if a resource in the grammar checker's/resourceexists.booleanruleFileExists(java.lang.String path)See:ResourceDataBroker.ruleFileExists(String)Checks if a resource in the grammar checker's/rulesexists.
-
-
-
Field Detail
-
resourceDir
private final java.lang.String resourceDir
The directory's name of the grammar checker's resource directory. The default value equalsResourceDataBroker.RESOURCE_DIR.
-
rulesDir
private final java.lang.String rulesDir
The directory's name of the grammar checker's rules directory. The default value equalsResourceDataBroker.RULES_DIR.
-
-
Constructor Detail
-
DefaultResourceDataBroker
public DefaultResourceDataBroker()
Instantiates this data broker with the default resource directory names as specified in:
-
DefaultResourceDataBroker
public DefaultResourceDataBroker(java.lang.String resourceDir, java.lang.String rulesDir)Instantiates this data broker with the passed resource directory names.- Parameters:
resourceDir- The directory's name of the grammar checker's resource directory. The default value equalsResourceDataBroker.RESOURCE_DIR.rulesDir- The directory's name of the grammar checker's rules directory. The default value equalsResourceDataBroker.RULES_DIR.
-
-
Method Detail
-
getFromResourceDirAsStream
public java.io.InputStream getFromResourceDirAsStream(java.lang.String path)
- 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:
java.lang.RuntimeException- if path cannot be found
-
getFromResourceDirAsUrl
public java.net.URL getFromResourceDirAsUrl(java.lang.String path)
- 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:
java.lang.RuntimeException- if path cannot be found
-
getCompleteResourceUrl
private java.lang.String getCompleteResourceUrl(java.lang.String path)
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
public java.io.InputStream getFromRulesDirAsStream(java.lang.String path)
- 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:
java.lang.RuntimeException- if path cannot be found
-
getFromRulesDirAsUrl
public java.net.URL getFromRulesDirAsUrl(java.lang.String path)
- 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:
java.lang.RuntimeException- if path cannot be found
-
assertNotNull
private void assertNotNull(java.lang.Object object, java.lang.String path, java.lang.String completePath)
-
getCompleteRulesUrl
private java.lang.String getCompleteRulesUrl(java.lang.String path)
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
private java.lang.String appendPath(java.lang.String baseDir, java.lang.String path)
-
resourceExists
public boolean resourceExists(java.lang.String path)
See:ResourceDataBroker.resourceExists(String)Checks if a resource in the grammar checker's/resourceexists.- Specified by:
resourceExistsin interfaceResourceDataBroker- Parameters:
path- Path to an item from the/resourcedirectory.- Returns:
trueif the resource file exists.
-
ruleFileExists
public boolean ruleFileExists(java.lang.String path)
See:ResourceDataBroker.ruleFileExists(String)Checks if a resource in the grammar checker's/rulesexists.- Specified by:
ruleFileExistsin interfaceResourceDataBroker- Parameters:
path- Path to an item from the/rulesdirectory.- Returns:
trueif the resource file exists.
-
getResourceDir
public java.lang.String getResourceDir()
- Specified by:
getResourceDirin interfaceResourceDataBroker- Returns:
- The directory's name of the grammar checker's resource directory.
The default value equals
ResourceDataBroker.RESOURCE_DIR.
-
getRulesDir
public java.lang.String getRulesDir()
- Specified by:
getRulesDirin interfaceResourceDataBroker- Returns:
- The directory's name of the grammar checker's rules directory.
The default value equals
ResourceDataBroker.RULES_DIR.
-
-