{
log.debug("No forwardConfig or no path, so pass to next command.");
return (false);
}
ServletWebContext swcontext = (ServletWebContext) context;
ComponentDefinition definition = null;
try
{
definition = TilesUtil.getDefinition(forwardConfig.getPath(),
swcontext.getRequest(),
swcontext.getContext());
}
catch (FactoryNotFoundException ex)
{
// this is not a serious error, so log at low priority
log.debug("Tiles DefinitionFactory not found, so pass to next command.");
return false;
}
// Do we do a forward (original behavior) or an include ?
boolean doInclude = false;
ComponentContext tileContext = null;
// Get current tile context if any.
// If context exists, we will do an include
tileContext = ComponentContext.getContext(swcontext.getRequest());
doInclude = (tileContext != null);
// Controller associated to a definition, if any
Controller controller = null;
// Computed uri to include
String uri = null;
if (definition != null)
{
// We have a "forward config" definition.
// We use it to complete missing attribute in context.
// We also get uri, controller.
uri = definition.getPath();
controller = definition.getOrCreateController();
if (tileContext == null) {
tileContext =
new ComponentContext(definition.getAttributes());
ComponentContext.setContext(tileContext, swcontext.getRequest());
} else {
tileContext.addMissing(definition.getAttributes());
}
}
// Process definition set in Action, if any. This may override the
// values for uri or controller found using the ForwardConfig, and
// may augment the tileContext with additional attributes.
// :FIXME: the class DefinitionsUtil is deprecated, but I can't find
// the intended alternative to use.
definition = DefinitionsUtil.getActionDefinition(swcontext.getRequest());
if (definition != null) { // We have a definition.
// We use it to complete missing attribute in context.
// We also overload uri and controller if set in definition.
if (definition.getPath() != null) {
log.debug("Override forward uri "
+ uri
+ " with action uri "
+ definition.getPath());
uri = definition.getPath();
}
if (definition.getOrCreateController() != null) {
log.debug("Override forward controller with action controller");
controller = definition.getOrCreateController();
}
if (tileContext == null) {
tileContext =
new ComponentContext(definition.getAttributes());
ComponentContext.setContext(tileContext, swcontext.getRequest());
} else {
tileContext.addMissing(definition.getAttributes());
}
}
if (uri == null) {
log.debug("no uri computed, so pass to next command");
return false;
}
// Execute controller associated to definition, if any.
if (controller != null) {
log.trace("Execute controller: " + controller);
controller.execute(
tileContext,
swcontext.getRequest(),
swcontext.getResponse(),
swcontext.getContext());
}
// If request comes from a previous Tile, do an include.
// This allows to insert an action in a Tile.