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;
}
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()]);
}
Aggregations