use of gate.util.GateRuntimeException in project gate-core by GateNLP.
the class Gate method initConfigData.
// initDataStoreRegister()
/**
* Reads config data (<TT>gate.xml</TT> files). There are three sorts of
* these files:
* <UL>
* <LI> The builtin file from GATE's resources - this is read first.
* <LI> A site-wide init file given as a command-line argument or as a
* <TT>gate.config</TT> property - this is read second.
* <LI> The user's file from their home directory - this is read last.
* </UL>
* Settings from files read after some settings have already been made will
* simply overwrite the previous settings.
*/
public static void initConfigData() throws GateException {
ConfigDataProcessor configProcessor = new ConfigDataProcessor();
URL configURL;
// parse the site configuration file
if (siteConfigFile != null && siteConfigFile.exists()) {
try {
configURL = siteConfigFile.toURI().toURL();
} catch (MalformedURLException mue) {
// this should never happen
throw new GateRuntimeException(mue);
}
try {
InputStream configStream = new FileInputStream(siteConfigFile);
configProcessor.parseConfigFile(configStream, configURL);
} catch (IOException e) {
throw new GateException("Couldn't open site configuration file: " + configURL + " " + e);
}
}
// parse the user configuration data if present
if (userConfigFile != null && userConfigFile.exists()) {
try {
configURL = userConfigFile.toURI().toURL();
} catch (MalformedURLException mue) {
// this should never happen
throw new GateRuntimeException(mue);
}
try {
InputStream configStream = new FileInputStream(userConfigFile);
configProcessor.parseConfigFile(configStream, configURL);
} catch (IOException e) {
throw new GateException("Couldn't open user configuration file: " + configURL + " " + e);
}
}
// remember the init-time config options
originalUserConfig.putAll(userConfig);
}
use of gate.util.GateRuntimeException in project gate-core by GateNLP.
the class Gate method init.
/**
* Initialisation - must be called by all clients before using any other parts
* of the library. Also initialises the CREOLE register and reads config data (<TT>gate.xml</TT>
* files).
*
* @see #initCreoleRegister
*/
public static void init() throws GateException {
// init local paths
if (!sandboxed)
initLocalPaths();
// check if benchmarking should be enabled or disabled
if (System.getProperty(ENABLE_BENCHMARKING_FEATURE_NAME) != null && System.getProperty(ENABLE_BENCHMARKING_FEATURE_NAME).equalsIgnoreCase("true")) {
Benchmark.setBenchmarkingEnabled(true);
}
// builtin creole dir
if (builtinCreoleDir == null) {
String builtinCreoleDirPropertyValue = System.getProperty(BUILTIN_CREOLE_DIR_PROPERTY_NAME);
if (builtinCreoleDirPropertyValue == null) {
// default to /gate/resources/creole in gate.jar
builtinCreoleDir = Files.getGateResource("/creole/");
} else {
String builtinCreoleDirPath = builtinCreoleDirPropertyValue;
// a creole directory URL should always end with a forward slash
if (!builtinCreoleDirPath.endsWith("/")) {
builtinCreoleDirPath += "/";
}
try {
builtinCreoleDir = new URL(builtinCreoleDirPath);
} catch (MalformedURLException mue) {
// couldn't parse as a File either, so throw an exception
throw new GateRuntimeException(BUILTIN_CREOLE_DIR_PROPERTY_NAME + " value \"" + builtinCreoleDirPropertyValue + "\" could" + " not be parsed as either a URL or a file path.");
}
log.info("Using " + builtinCreoleDir + " as built-in CREOLE" + " directory URL");
}
}
// initialise the symbols generator
lastSym = 0;
// create class loader and creole register if they're null
if (classLoader == null)
classLoader = new GateClassLoader("Top-Level GATE ClassLoader", Gate.class.getClassLoader());
if (creoleRegister == null)
creoleRegister = new CreoleRegisterImpl();
if (knownPlugins == null)
knownPlugins = new HashSet<Plugin>();
if (autoloadPlugins == null)
autoloadPlugins = new ArrayList<Plugin>();
// if(pluginData == null) pluginData = new HashSet<Plugin>();
// init the creole register
initCreoleRegister();
// init the data store register
initDataStoreRegister();
// initialisation in order for the CREOLE-DIR elements to have and effect
if (!sandboxed)
initConfigData();
if (!sandboxed)
initCreoleRepositories();
// the creoleRegister acts as a proxy for datastore related events
dataStoreRegister.addCreoleListener(creoleRegister);
// some of the events are actually fired by the {@link gate.Factory}
Factory.addCreoleListener(creoleRegister);
// check we have a useable JDK
if (System.getProperty("java.version").compareTo(MIN_JDK_VERSION) < 0) {
throw new GateException("GATE requires JDK " + MIN_JDK_VERSION + " or newer");
}
initFinished = true;
}
use of gate.util.GateRuntimeException in project gate-core by GateNLP.
the class Gate method normaliseCreoleUrl.
/**
* Makes sure the provided URL ends with "/" (CREOLE URLs always point to
* directories so thry should always end with a slash.
*
* @param url
* the URL to be normalised
* @return the (maybe) corrected URL.
*/
public static URL normaliseCreoleUrl(URL url) {
// CREOLE URLs are directory URLs so they should end with "/"
String urlName = url.toExternalForm();
String separator = "/";
if (urlName.endsWith(separator)) {
return url;
} else {
urlName += separator;
try {
return new URL(urlName);
} catch (MalformedURLException mue) {
throw new GateRuntimeException(mue);
}
}
}
use of gate.util.GateRuntimeException in project gate-core by GateNLP.
the class Utils method loadPlugin.
/**
* Load a plugin from the default GATE plugins directory.
*
* This will load the plugin with the specified directory name from the
* default GATE plugins path, if GATE knows its own location.
*
* @param dirName The directory name of the plugin within the standard GATE plugins directory.
*/
@Deprecated
public static void loadPlugin(String dirName) {
File gatehome = Gate.getGateHome();
if (gatehome == null) {
throw new GateRuntimeException("Cannot load Plugin, Gate home location not known");
}
File pluginDir = new File(new File(gatehome, "plugins"), dirName);
loadPlugin(pluginDir);
}
use of gate.util.GateRuntimeException in project gate-core by GateNLP.
the class DocumentEditor method addView.
/**
* Registers a new view by adding it to the right list and creating the
* activation button for it.
*
* @param view
* view to add to the GUI as a button
* @param name
* name of the view used in the GUI as a button name
*/
protected void addView(DocumentView view, String name) {
topBar.add(Box.createHorizontalStrut(5));
final ViewButton viewButton = new ViewButton(view, name);
switch(view.getType()) {
case DocumentView.CENTRAL:
centralViews.add(view);
// leftBar.add(new ViewButton(view, name));
topBar.add(viewButton);
break;
case DocumentView.VERTICAL:
verticalViews.add(view);
// rightBar.add(new ViewButton(view, name));
topBar.add(viewButton);
break;
case DocumentView.HORIZONTAL:
horizontalViews.add(view);
topBar.add(viewButton);
// bottomBar.add(new ViewButton(view, name));
break;
default:
throw new GateRuntimeException(getClass().getName() + ": Invalid view type");
}
// avoid the F-Key F1,2,6,8,10 because already used
if ((fKeyNumber == 5) || (fKeyNumber == 7) || (fKeyNumber == 9)) {
fKeyNumber++;
}
getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("F" + (fKeyNumber + 1)), "Shows view " + fKeyNumber + 1);
getActionMap().put("Shows view " + fKeyNumber + 1, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent evt) {
viewButton.doClick();
}
});
// add a tooltip with the key shortcut
if (view instanceof AnnotationSetsView) {
getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("shift F" + (fKeyNumber + 1)), "Shows view " + fKeyNumber + 1);
viewButton.setToolTipText("<html>Toggle the view of " + name + " <font color=#667799><small>F" + (fKeyNumber + 1) + " </small></font>" + "<br>Set last selected annotations " + " <font color=#667799><small>Shift+F" + (fKeyNumber + 1) + " </small></font></html>");
} else {
viewButton.setToolTipText("<html>Toggle the view of " + name + " <font color=#667799><small>F" + (fKeyNumber + 1) + " </small></font></html>");
}
fKeyNumber++;
}
Aggregations