org.languagetool.databroker
Class DefaultResourceDataBroker

Object
  extended by DefaultResourceDataBroker
All Implemented Interfaces:
ResourceDataBroker

public class DefaultResourceDataBroker
extends 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 /rules and /resource directories are accessible via class-path with following path information:

In this case you have to invoke the methods ResourceDataBroker.setRulesDir(String) and ResourceDataBroker.setResourceDir(String) with following arguments:

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.

Since:
1.0.1
Author:
PAX
See Also:
ResourceDataBroker

Field Summary
 
Fields inherited from interface ResourceDataBroker
RESOURCE_DIR, RULES_DIR
 
Constructor Summary
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.
 
Method Summary
 InputStream getFromResourceDirAsStream(String path)
          See: ResourceDataBroker.getFromResourceDirAsStream(java.lang.String)
 URL getFromResourceDirAsUrl(String path)
          See: ResourceDataBroker.getFromResourceDirAsUrl(java.lang.String)
 InputStream getFromRulesDirAsStream(String path)
          See: ResourceDataBroker.getFromRulesDirAsStream(java.lang.String)
 URL getFromRulesDirAsUrl(String path)
          See: ResourceDataBroker.getFromRulesDirAsUrl(java.lang.String)
 String getResourceDir()
           
 String getRulesDir()
           
 void setResourceDir(String resourceDir)
           
 void setRulesDir(String rulesDir)
           
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultResourceDataBroker

public DefaultResourceDataBroker()
Instantiates this data broker with the default resource directory names as specified in:


DefaultResourceDataBroker

public DefaultResourceDataBroker(String resourceDir,
                                 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 equals ResourceDataBroker.RESOURCE_DIR.
rulesDir - The directory's name of the grammar checker's rules directory. The default value equals ResourceDataBroker.RULES_DIR.
Method Detail

getFromResourceDirAsStream

public InputStream getFromResourceDirAsStream(String path)
See: ResourceDataBroker.getFromResourceDirAsStream(java.lang.String)

Specified by:
getFromResourceDirAsStream in interface ResourceDataBroker
Parameters:
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.
Returns:
An InputStream object to the requested item or null if it wasn't found.

getFromResourceDirAsUrl

public URL getFromResourceDirAsUrl(String path)
See: ResourceDataBroker.getFromResourceDirAsUrl(java.lang.String)

Specified by:
getFromResourceDirAsUrl in interface ResourceDataBroker
Parameters:
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.
Returns:
An URL object to the requested item or null if it wasn't found.

getFromRulesDirAsStream

public InputStream getFromRulesDirAsStream(String path)
See: ResourceDataBroker.getFromRulesDirAsStream(java.lang.String)

Specified by:
getFromRulesDirAsStream in interface ResourceDataBroker
Parameters:
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.
Returns:
An InputStream object to the requested item or null if it wasn't found.

getFromRulesDirAsUrl

public URL getFromRulesDirAsUrl(String path)
See: ResourceDataBroker.getFromRulesDirAsUrl(java.lang.String)

Specified by:
getFromRulesDirAsUrl in interface ResourceDataBroker
Parameters:
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.
Returns:
An URL object to the requested item or null if it wasn't found.

getResourceDir

public String getResourceDir()
Specified by:
getResourceDir in interface ResourceDataBroker
Returns:
The directory's name of the grammar checker's resource directory. The default value equals ResourceDataBroker.RESOURCE_DIR.

setResourceDir

public void setResourceDir(String resourceDir)
Specified by:
setResourceDir in interface ResourceDataBroker
Parameters:
resourceDir - The directory's name of the grammar checker's resource directory. The default value was ResourceDataBroker.RESOURCE_DIR. Please let this string start with '/' and use this character as path separator. Don't set this character to the string's end. Valid example value: /subdir/furtherdir/resourcedir.

getRulesDir

public String getRulesDir()
Specified by:
getRulesDir in interface ResourceDataBroker
Returns:
The directory's name of the grammar checker's rules directory. The default value equals ResourceDataBroker.RULES_DIR.

setRulesDir

public void setRulesDir(String rulesDir)
Specified by:
setRulesDir in interface ResourceDataBroker
Parameters:
rulesDir - The directory's name of the grammar checker's rules directory. The default value was ResourceDataBroker.RULES_DIR. Please let this string start with '/' and use this character as path separator. Don't set this character to the string's end. Valid example value: /subdir/furtherdir/rulesdir.


Copyright © 2005-2011 Daniel Naber