use of org.apache.struts.config.ActionConfig in project sonar-java by SonarSource.
the class ModuleConfigImpl method freeze.
/**
* <p> Freeze the configuration of this module. After this method
* returns, any attempt to modify the configuration will return an
* IllegalStateException. </p>
*/
public void freeze() {
super.freeze();
ActionConfig[] aconfigs = findActionConfigs();
for (int i = 0; i < aconfigs.length; i++) {
aconfigs[i].freeze();
}
matcher = new ActionConfigMatcher(aconfigs);
getControllerConfig().freeze();
ExceptionConfig[] econfigs = findExceptionConfigs();
for (int i = 0; i < econfigs.length; i++) {
econfigs[i].freeze();
}
FormBeanConfig[] fbconfigs = findFormBeanConfigs();
for (int i = 0; i < fbconfigs.length; i++) {
fbconfigs[i].freeze();
}
ForwardConfig[] fconfigs = findForwardConfigs();
for (int i = 0; i < fconfigs.length; i++) {
fconfigs[i].freeze();
}
MessageResourcesConfig[] mrconfigs = findMessageResourcesConfigs();
for (int i = 0; i < mrconfigs.length; i++) {
mrconfigs[i].freeze();
}
PlugInConfig[] piconfigs = findPlugInConfigs();
for (int i = 0; i < piconfigs.length; i++) {
piconfigs[i].freeze();
}
}
use of org.apache.struts.config.ActionConfig in project sonar-java by SonarSource.
the class ModuleConfigImpl method addActionConfig.
/**
* </p> Ad d a new <code>ActionConfig</code> instance to the set
* associated with this module. </p>
*
* @param config The new configuration instance to be added
* @throws IllegalStateException if this module configuration has been
* frozen
*/
public void addActionConfig(ActionConfig config) {
throwIfConfigured();
config.setModuleConfig(this);
String path = config.getPath();
if (actionConfigs.containsKey(path)) {
log.warn("Overriding ActionConfig of path " + path);
}
String actionId = config.getActionId();
if ((actionId != null) && !actionId.equals("")) {
if (actionConfigIds.containsKey(actionId)) {
if (log.isWarnEnabled()) {
ActionConfig otherConfig = (ActionConfig) actionConfigIds.get(actionId);
StringBuffer msg = new StringBuffer("Overriding actionId[");
msg.append(actionId);
msg.append("] for path[");
msg.append(otherConfig.getPath());
msg.append("] with path[");
msg.append(path);
msg.append("]");
log.warn(msg);
}
}
actionConfigIds.put(actionId, config);
}
actionConfigs.put(path, config);
actionConfigList.add(config);
}
use of org.apache.struts.config.ActionConfig in project sonar-java by SonarSource.
the class ActionServlet method processActionConfigClass.
/**
* <p>Checks if the current actionConfig is using the correct class based
* on the class of its ancestor ActionConfig.</p>
*
* @param actionConfig The action config to check.
* @param moduleConfig The config for the current module.
* @return The config object using the correct class as determined by the
* config's ancestor and its own overridden value.
* @throws ServletException if an instance of the action config class
* cannot be created.
*/
protected ActionConfig processActionConfigClass(ActionConfig actionConfig, ModuleConfig moduleConfig) throws ServletException {
String ancestor = actionConfig.getExtends();
if (ancestor == null) {
// Nothing to do, then
return actionConfig;
}
// Make sure that this config is of the right class
ActionConfig baseConfig = moduleConfig.findActionConfig(ancestor);
if (baseConfig == null) {
throw new UnavailableException("Unable to find " + "action config for '" + ancestor + "' to extend.");
}
// Was our actionConfig's class overridden already?
if (actionConfig.getClass().equals(ActionMapping.class)) {
// Ensure that our config is using the correct class
if (!baseConfig.getClass().equals(actionConfig.getClass())) {
// Replace the config with an instance of the correct class
ActionConfig newActionConfig = null;
String baseConfigClassName = baseConfig.getClass().getName();
try {
newActionConfig = (ActionConfig) RequestUtils.applicationInstance(baseConfigClassName);
// copy the values
BeanUtils.copyProperties(newActionConfig, actionConfig);
// copy the forward and exception configs, too
ForwardConfig[] forwards = actionConfig.findForwardConfigs();
for (int i = 0; i < forwards.length; i++) {
newActionConfig.addForwardConfig(forwards[i]);
}
ExceptionConfig[] exceptions = actionConfig.findExceptionConfigs();
for (int i = 0; i < exceptions.length; i++) {
newActionConfig.addExceptionConfig(exceptions[i]);
}
} catch (Exception e) {
handleCreationException(baseConfigClassName, e);
}
// replace actionConfig with newActionConfig
moduleConfig.removeActionConfig(actionConfig);
moduleConfig.addActionConfig(newActionConfig);
actionConfig = newActionConfig;
}
}
return actionConfig;
}
use of org.apache.struts.config.ActionConfig in project sonar-java by SonarSource.
the class AbstractCreateAction method execute.
// ---------------------------------------------------------- Public Methods
/**
* <p>Create (if necessary) and cache an <code>Action</code> for this
* request.</p>
*
* @param actionCtx The <code>Context</code> for the current request
* @return <code>false</code> so that processing continues
* @throws Exception if there are any problems instantiating the Action
* class.
*/
public boolean execute(ActionContext actionCtx) throws Exception {
// Skip processing if the current request is not valid
Boolean valid = actionCtx.getFormValid();
if ((valid == null) || !valid.booleanValue()) {
LOG.trace("Invalid form; not going to execute.");
return (false);
}
// Check to see if an action has already been created
if (actionCtx.getAction() != null) {
LOG.trace("already have an action [" + actionCtx.getAction() + "]");
return (false);
}
// Look up the class name for the desired Action
ActionConfig actionConfig = actionCtx.getActionConfig();
String type = actionConfig.getType();
if (type == null) {
String command = actionConfig.getCommand();
if ((command == null) && (actionConfig.getForward() == null) && (actionConfig.getInclude() == null)) {
LOG.error("no type or command for " + actionConfig.getPath());
} else {
LOG.trace("no type for " + actionConfig.getPath());
}
return (false);
}
// Create (if necessary) and cache an Action instance
Action action = getAction(actionCtx, type, actionConfig);
if (LOG.isTraceEnabled()) {
LOG.trace("setting action to " + action);
}
actionCtx.setAction(action);
return (false);
}
use of org.apache.struts.config.ActionConfig in project sonar-java by SonarSource.
the class AbstractExceptionHandler method execute.
// ---------------------------------------------------------- Public Methods
/**
* <p>Invoke the appropriate <code>Action</code> for this request, and
* cache the returned <code>ActionForward</code>.</p>
*
* @param actionCtx The <code>Context</code> for the current request
* @return <code>false</code> if a <code>ForwardConfig</code> is returned,
* else <code>true</code> to complete processing
* @throws Exception if thrown by the Action class and not declared by an
* Exception Handler
*/
public boolean execute(ActionContext actionCtx) throws Exception {
// Look up the exception that was thrown
Exception exception = actionCtx.getException();
if (exception == null) {
LOG.warn("No Exception found in ActionContext");
return (true);
}
// Look up the local or global exception handler configuration
ExceptionConfig exceptionConfig = null;
ActionConfig actionConfig = actionCtx.getActionConfig();
ModuleConfig moduleConfig = actionCtx.getModuleConfig();
if (actionConfig != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("See if actionConfig " + actionConfig + " has an exceptionConfig for " + exception.getClass().getName());
}
exceptionConfig = actionConfig.findException(exception.getClass());
} else if (moduleConfig != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("No action yet, see if moduleConfig " + moduleConfig + " has an exceptionConfig " + exception.getClass().getName());
}
exceptionConfig = moduleConfig.findException(exception.getClass());
}
// Handle the exception in the configured manner
if (exceptionConfig == null) {
LOG.warn("Unhandled exception", exception);
throw exception;
}
ForwardConfig forwardConfig = handle(actionCtx, exception, exceptionConfig, actionConfig, moduleConfig);
if (forwardConfig != null) {
actionCtx.setForwardConfig(forwardConfig);
return (false);
} else {
return (true);
}
}
Aggregations