use of org.apache.struts.config.ForwardConfig in project sonarqube by SonarSource.
the class ActionServlet method initModuleForwards.
/**
* <p>Initialize the forwards for the specified module.</p>
*
* @param config ModuleConfig information for this module
* @throws ServletException if initialization cannot be performed
*/
protected void initModuleForwards(ModuleConfig config) throws ServletException {
if (log.isDebugEnabled()) {
log.debug("Initializing module path '" + config.getPrefix() + "' forwards");
}
// Process forwards extensions.
ForwardConfig[] forwards = config.findForwardConfigs();
for (int i = 0; i < forwards.length; i++) {
ForwardConfig forward = forwards[i];
processForwardExtension(forward, config, null);
}
for (int i = 0; i < forwards.length; i++) {
ForwardConfig forward = forwards[i];
// Verify that required fields are all present for the forward
if (forward.getPath() == null) {
handleValueRequiredException("path", forward.getName(), "global forward");
}
}
}
use of org.apache.struts.config.ForwardConfig in project sonarqube by SonarSource.
the class ActionServlet method initModuleActions.
/**
* <p>Initialize the action configs for the specified module.</p>
*
* @param config ModuleConfig information for this module
* @throws ServletException if initialization cannot be performed
* @since Struts 1.3
*/
protected void initModuleActions(ModuleConfig config) throws ServletException {
if (log.isDebugEnabled()) {
log.debug("Initializing module path '" + config.getPrefix() + "' action configs");
}
// Process ActionConfig extensions.
ActionConfig[] actionConfigs = config.findActionConfigs();
for (int i = 0; i < actionConfigs.length; i++) {
ActionConfig actionConfig = actionConfigs[i];
processActionConfigExtension(actionConfig, config);
}
for (int i = 0; i < actionConfigs.length; i++) {
ActionConfig actionConfig = actionConfigs[i];
// Verify that required fields are all present for the forward
// configs
ForwardConfig[] forwards = actionConfig.findForwardConfigs();
for (int j = 0; j < forwards.length; j++) {
ForwardConfig forward = forwards[j];
if (forward.getPath() == null) {
handleValueRequiredException("path", forward.getName(), "action forward");
}
}
// ... and the exception configs
ExceptionConfig[] exceptions = actionConfig.findExceptionConfigs();
for (int j = 0; j < exceptions.length; j++) {
ExceptionConfig exception = exceptions[j];
if (exception.getKey() == null) {
handleValueRequiredException("key", exception.getType(), "action exception config");
}
}
}
}
use of org.apache.struts.config.ForwardConfig in project sonarqube 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.ForwardConfig in project sonarqube by SonarSource.
the class RequestProcessor method processForwardConfig.
/**
* <p>Forward or redirect to the specified destination, by the specified
* mechanism. This method uses a <code>ForwardConfig</code> object
* instead an <code>ActionForward</code>.</p>
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
* @param forward The ForwardConfig controlling where we go next
* @throws IOException if an input/output error occurs
* @throws ServletException if a servlet exception occurs
*/
protected void processForwardConfig(HttpServletRequest request, HttpServletResponse response, ForwardConfig forward) throws IOException, ServletException {
if (forward == null) {
return;
}
if (log.isDebugEnabled()) {
log.debug("processForwardConfig(" + forward + ")");
}
String forwardPath = forward.getPath();
String uri;
// If the forward can be unaliased into an action, then use the path of the action
String actionIdPath = RequestUtils.actionIdURL(forward, request, servlet);
if (actionIdPath != null) {
forwardPath = actionIdPath;
ForwardConfig actionIdForward = new ForwardConfig(forward);
actionIdForward.setPath(actionIdPath);
forward = actionIdForward;
}
// processing (ie. they're absolute)
if (forwardPath.startsWith("/")) {
// get module relative uri
uri = RequestUtils.forwardURL(request, forward, null);
} else {
uri = forwardPath;
}
if (forward.getRedirect()) {
// only prepend context path for relative uri
if (uri.startsWith("/")) {
uri = request.getContextPath() + uri;
}
response.sendRedirect(response.encodeRedirectURL(uri));
} else {
doForward(uri, request, response);
}
}
use of org.apache.struts.config.ForwardConfig in project sonarqube by SonarSource.
the class AbstractExecuteAction 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> 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 not valid
Boolean valid = actionCtx.getFormValid();
if ((valid == null) || !valid.booleanValue()) {
return (false);
}
// Acquire the resources we will need to send to the Action
Action action = actionCtx.getAction();
if (action == null) {
return (false);
}
ActionConfig actionConfig = actionCtx.getActionConfig();
ActionForm actionForm = actionCtx.getActionForm();
// Execute the Action for this request, caching returned ActionForward
ForwardConfig forwardConfig = execute(actionCtx, action, actionConfig, actionForm);
actionCtx.setForwardConfig(forwardConfig);
return (false);
}
Aggregations