Search in sources :

Example 61 with StepInternalException

use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.

the class FrontController method getController.

/**
 * Retrieves a controller, either from the cache, or from Guice.
 *
 * @param controllerName the name of the controller (used as the key for the cache)
 * @param isExternal     indicates whether the request should be found in the external controllers
 * @return the controller object
 */
Object getController(final String controllerName, final boolean isExternal) {
    Object controllerInstance = this.controllers.get(controllerName);
    // if retrieving yields null, get controller from Guice, and put in cache
    if (controllerInstance == null) {
        // make up the full class name
        final String packageName = CONTROLLER_PACKAGE;
        final StringBuilder className = new StringBuilder(packageName.length() + controllerName.length() + CONTROLLER_SUFFIX.length() + 1);
        className.append(packageName);
        className.append(PACKAGE_SEPARATOR);
        if (isExternal) {
            className.append(EXTERNAL_CONTROLLER_SUB_PACKAGE);
            className.append(PACKAGE_SEPARATOR);
        }
        className.append(Character.toUpperCase(controllerName.charAt(0)));
        className.append(controllerName.substring(1));
        className.append(CONTROLLER_SUFFIX);
        try {
            final Class<?> controllerClass = Class.forName(className.toString());
            controllerInstance = this.guiceInjector.getInstance(controllerClass);
            // we use the controller name as it came in to key the map
            this.controllers.put(controllerName, controllerInstance);
        } catch (final ClassNotFoundException e) {
            throw new StepInternalException("Unable to find a controller for " + className, e);
        }
    }
    return controllerInstance;
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException)

Example 62 with StepInternalException

use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.

the class StepRequest method parseArguments.

/**
 * gets the arguments out of the requestURI String.
 *
 * @param parameterStart the location at which the parameters start
 * @param encoding the encoding with which to decode the arguments
 * @return a list of arguments
 */
private String[] parseArguments(final int parameterStart, final String encoding) {
    final List<String> arguments = new ArrayList<String>();
    int argStart = parameterStart;
    int nextArgStop = this.requestURI.indexOf('/', argStart);
    try {
        while (nextArgStop != -1) {
            arguments.add(URLDecoder.decode(this.requestURI.substring(argStart, nextArgStop), encoding));
            argStart = nextArgStop + 1;
            nextArgStop = this.requestURI.indexOf('/', argStart);
        }
    } catch (final UnsupportedEncodingException e) {
        throw new StepInternalException(e.getMessage(), e);
    }
    // add the last argument
    if (argStart < this.requestURI.length()) {
        try {
            arguments.add(URLDecoder.decode(this.requestURI.substring(argStart), encoding));
        } catch (final UnsupportedEncodingException e) {
            throw new StepInternalException("Unable to decode last argument", e);
        }
    }
    return arguments.toArray(new String[arguments.size()]);
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)62 IOException (java.io.IOException)25 Book (org.crosswire.jsword.book.Book)9 Key (org.crosswire.jsword.passage.Key)7 EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)5 OsisWrapper (com.tyndalehouse.step.core.models.OsisWrapper)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 ParseException (org.apache.lucene.queryParser.ParseException)4 BookException (org.crosswire.jsword.book.BookException)4 Versification (org.crosswire.jsword.versification.Versification)4 LocalisedException (com.tyndalehouse.step.core.exceptions.LocalisedException)3 TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)3 KeyWrapper (com.tyndalehouse.step.core.models.KeyWrapper)3 FileInputStream (java.io.FileInputStream)3 TransformingSAXEventProvider (org.crosswire.common.xml.TransformingSAXEventProvider)3 XMLUtil.writeToString (org.crosswire.common.xml.XMLUtil.writeToString)3 NoSuchKeyException (org.crosswire.jsword.passage.NoSuchKeyException)3 BibleBook (org.crosswire.jsword.versification.BibleBook)3 AllResultsCollector (com.tyndalehouse.step.core.data.AllResultsCollector)2