Search in sources :

Example 21 with GateRuntimeException

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);
}
Also used : MalformedURLException(java.net.MalformedURLException) ConfigDataProcessor(gate.config.ConfigDataProcessor) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) GateRuntimeException(gate.util.GateRuntimeException) GateException(gate.util.GateException) IOException(java.io.IOException) URL(java.net.URL) FileInputStream(java.io.FileInputStream)

Example 22 with GateRuntimeException

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) CreoleRegisterImpl(gate.creole.CreoleRegisterImpl) GateRuntimeException(gate.util.GateRuntimeException) GateException(gate.util.GateException) ArrayList(java.util.ArrayList) GateClassLoader(gate.util.GateClassLoader) URL(java.net.URL) HashSet(java.util.HashSet)

Example 23 with GateRuntimeException

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);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) GateRuntimeException(gate.util.GateRuntimeException) URL(java.net.URL)

Example 24 with GateRuntimeException

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);
}
Also used : GateRuntimeException(gate.util.GateRuntimeException) File(java.io.File)

Example 25 with GateRuntimeException

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 + "&nbsp;&nbsp;<font color=#667799><small>F" + (fKeyNumber + 1) + "&nbsp;&nbsp;</small></font>" + "<br>Set last selected annotations " + "&nbsp;&nbsp;<font color=#667799><small>Shift+F" + (fKeyNumber + 1) + "&nbsp;&nbsp;</small></font></html>");
    } else {
        viewButton.setToolTipText("<html>Toggle the view of " + name + "&nbsp;&nbsp;<font color=#667799><small>F" + (fKeyNumber + 1) + "&nbsp;&nbsp;</small></font></html>");
    }
    fKeyNumber++;
}
Also used : ActionEvent(java.awt.event.ActionEvent) GateRuntimeException(gate.util.GateRuntimeException) AbstractAction(javax.swing.AbstractAction)

Aggregations

GateRuntimeException (gate.util.GateRuntimeException)42 ArrayList (java.util.ArrayList)12 URL (java.net.URL)6 FeatureMap (gate.FeatureMap)5 PersistenceException (gate.persist.PersistenceException)5 GateException (gate.util.GateException)5 Point (java.awt.Point)5 LinkedList (java.util.LinkedList)5 DataStore (gate.DataStore)4 ResourceInstantiationException (gate.creole.ResourceInstantiationException)4 InvalidOffsetException (gate.util.InvalidOffsetException)4 GridBagConstraints (java.awt.GridBagConstraints)4 GridBagLayout (java.awt.GridBagLayout)4 MalformedURLException (java.net.MalformedURLException)4 List (java.util.List)4 JButton (javax.swing.JButton)4 JPanel (javax.swing.JPanel)4 Annotation (gate.Annotation)3 AnnotationSet (gate.AnnotationSet)3 Corpus (gate.Corpus)3