use of org.apache.struts.config.ModuleConfig in project sonar-java by SonarSource.
the class AbstractSelectInput method execute.
// ---------------------------------------------------------- Public Methods
/**
* <p>Select and cache a <code>ForwardConfig</code> for the input page for
* the current request.</p>
*
* @param actionCtx The <code>Context</code> for the current request
* @return <code>false</code> so that processing continues
* @throws Exception if thrown by the Action class
*/
public boolean execute(ActionContext actionCtx) throws Exception {
// Skip processing if the current request is valid
Boolean valid = actionCtx.getFormValid();
if ((valid != null) && valid.booleanValue()) {
return (false);
}
// Acquire configuration objects that we need
ActionConfig actionConfig = actionCtx.getActionConfig();
ModuleConfig moduleConfig = actionConfig.getModuleConfig();
// Cache an ForwardConfig back to our input page
ForwardConfig forwardConfig;
String input = actionConfig.getInput();
if (moduleConfig.getControllerConfig().getInputForward()) {
if (LOG.isTraceEnabled()) {
LOG.trace("Finding ForwardConfig for '" + input + "'");
}
forwardConfig = actionConfig.findForwardConfig(input);
if (forwardConfig == null) {
forwardConfig = moduleConfig.findForwardConfig(input);
}
} else {
if (LOG.isTraceEnabled()) {
LOG.trace("Delegating to forward() for '" + input + "'");
}
forwardConfig = forward(actionCtx, moduleConfig, input);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Forwarding back to " + forwardConfig);
}
actionCtx.setForwardConfig(forwardConfig);
return (false);
}
use of org.apache.struts.config.ModuleConfig in project sonar-java by SonarSource.
the class AbstractSelectModule method execute.
// ------------------------------------------------------ Instance Variables
// ---------------------------------------------------------- Public Methods
/**
* <p>Cache the <code>ModuleConfig</code> and <code>MessageResources</code>
* instances for the sub-application module to be used for processing this
* request.</p>
*
* @param actionCtx The <code>Context</code> for the current request
* @return <code>false</code> so that processing continues
* @throws IllegalArgumentException if no valid ModuleConfig or
* MessageResources can be identified for
* this request
* @throws Exception if thrown by the Action class
*/
public boolean execute(ActionContext actionCtx) throws Exception {
String prefix = getPrefix(actionCtx);
// Cache the corresponding ModuleConfig and MessageResources instances
ModuleConfig moduleConfig = (ModuleConfig) actionCtx.getApplicationScope().get(Globals.MODULE_KEY + prefix);
if (moduleConfig == null) {
throw new IllegalArgumentException("No module config for prefix '" + prefix + "'");
}
actionCtx.setModuleConfig(moduleConfig);
String key = Globals.MESSAGES_KEY + prefix;
MessageResources messageResources = (MessageResources) actionCtx.getApplicationScope().get(key);
if (messageResources == null) {
throw new IllegalArgumentException("No message resources found in application scope under " + key);
}
actionCtx.setMessageResources(messageResources);
return (false);
}
use of org.apache.struts.config.ModuleConfig in project sonar-java by SonarSource.
the class AbstractSetContentType method execute.
// ---------------------------------------------------------- Public Methods
/**
* <p>Check to see if the content type is set, and if so, set it for this
* response.</p>
*
* @param actionCtx The <code>Context</code> for the current request
* @return <code>false</code> so that processing continues
* @throws Exception if thrown by the Action class
*/
public boolean execute(ActionContext actionCtx) throws Exception {
// Retrieve the ModuleConfig instance
ModuleConfig moduleConfig = actionCtx.getModuleConfig();
// If the content type is configured, set it for the response
String contentType = moduleConfig.getControllerConfig().getContentType();
if (contentType != null) {
setContentType(actionCtx, contentType);
}
return (false);
}
use of org.apache.struts.config.ModuleConfig in project sonar-java by SonarSource.
the class ActionServlet method destroyModules.
// ------------------------------------------------------ Protected Methods
/**
* <p>Gracefully terminate use of any modules associated with this
* application (if any).</p>
*
* @since Struts 1.1
*/
protected void destroyModules() {
ArrayList values = new ArrayList();
Enumeration names = getServletContext().getAttributeNames();
while (names.hasMoreElements()) {
values.add(names.nextElement());
}
Iterator keys = values.iterator();
while (keys.hasNext()) {
String name = (String) keys.next();
Object value = getServletContext().getAttribute(name);
if (!(value instanceof ModuleConfig)) {
continue;
}
ModuleConfig config = (ModuleConfig) value;
if (this.getProcessorForModule(config) != null) {
this.getProcessorForModule(config).destroy();
}
getServletContext().removeAttribute(name);
PlugIn[] plugIns = (PlugIn[]) getServletContext().getAttribute(Globals.PLUG_INS_KEY + config.getPrefix());
if (plugIns != null) {
for (int i = 0; i < plugIns.length; i++) {
int j = plugIns.length - (i + 1);
plugIns[j].destroy();
}
getServletContext().removeAttribute(Globals.PLUG_INS_KEY + config.getPrefix());
}
}
}
use of org.apache.struts.config.ModuleConfig in project sonar-java by SonarSource.
the class ActionServlet method init.
/**
* <p>Initialize this servlet. Most of the processing has been factored
* into support methods so that you can override particular functionality
* at a fairly granular level.</p>
*
* @throws ServletException if we cannot configure ourselves correctly
*/
public void init() throws ServletException {
final String configPrefix = "config/";
final int configPrefixLength = configPrefix.length() - 1;
// to the developer
try {
initInternal();
initOther();
initServlet();
initChain();
getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this);
initModuleConfigFactory();
// Initialize modules as needed
ModuleConfig moduleConfig = initModuleConfig("", config);
initModuleMessageResources(moduleConfig);
initModulePlugIns(moduleConfig);
initModuleFormBeans(moduleConfig);
initModuleForwards(moduleConfig);
initModuleExceptionConfigs(moduleConfig);
initModuleActions(moduleConfig);
moduleConfig.freeze();
Enumeration names = getServletConfig().getInitParameterNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
if (!name.startsWith(configPrefix)) {
continue;
}
String prefix = name.substring(configPrefixLength);
moduleConfig = initModuleConfig(prefix, getServletConfig().getInitParameter(name));
initModuleMessageResources(moduleConfig);
initModulePlugIns(moduleConfig);
initModuleFormBeans(moduleConfig);
initModuleForwards(moduleConfig);
initModuleExceptionConfigs(moduleConfig);
initModuleActions(moduleConfig);
moduleConfig.freeze();
}
this.initModulePrefixes(this.getServletContext());
this.destroyConfigDigester();
} catch (UnavailableException ex) {
throw ex;
} catch (Throwable t) {
// The follow error message is not retrieved from internal message
// resources as they may not have been able to have been
// initialized
log.error("Unable to initialize Struts ActionServlet due to an " + "unexpected exception or error thrown, so marking the " + "servlet as unavailable. Most likely, this is due to an " + "incorrect or missing library dependency.", t);
throw new UnavailableException(t.getMessage());
}
}
Aggregations