Method from org.apache.struts.tiles.TilesRequestProcessor Detail: |
protected void doForward(String uri,
HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
if (response.isCommitted()) {
this.doInclude(uri, request, response);
} else {
super.doForward(uri, request, response);
}
}
Do a forward using request dispatcher.
Uri is a valid uri. If response has already been commited, do an include
instead. |
public DefinitionsFactory getDefinitionsFactory() {
return definitionsFactory;
}
Get associated definition factory. |
public void init(ActionServlet servlet,
ModuleConfig moduleConfig) throws ServletException {
super.init(servlet, moduleConfig);
this.initDefinitionsMapping();
}
Initialize this request processor instance. |
protected void initDefinitionsMapping() throws ServletException {
// Retrieve and set factory for this modules
definitionsFactory =
(
(TilesUtilStrutsImpl) TilesUtil
.getTilesUtil())
.getDefinitionsFactory(
getServletContext(),
moduleConfig);
if (definitionsFactory == null) { // problem !
log.info(
"Definition Factory not found for module '"
+ moduleConfig.getPrefix()
+ "'. "
+ "Have you declared the appropriate plugin in struts-config.xml ?");
return;
}
log.info(
"Tiles definition factory found for request processor '"
+ moduleConfig.getPrefix()
+ "'.");
}
Read component instance mapping configuration file.
This is where we read files properties. |
protected void internalModuleRelativeForward(String uri,
HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
if (processTilesDefinition(uri, false, request, response)) {
return;
}
super.internalModuleRelativeForward(uri, request, response);
}
Catch the call to a module relative forward.
If the specified uri is a tiles definition name, insert it.
Otherwise, parent processing is called.
Do a module relative forward to specified uri using request dispatcher.
Uri is relative to the current module. The real uri is computed by
prefixing the module name.
This method is used internally and is not part of the public
API. It is advised to not use it in subclasses. |
protected void internalModuleRelativeInclude(String uri,
HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
if (processTilesDefinition(uri, false, request, response)) {
return;
}
super.internalModuleRelativeInclude(uri, request, response);
}
Do a module relative include to specified uri using request dispatcher.
Uri is relative to the current module. The real uri is computed by
prefixing the module name.
This method is used internally and is not part of the public
API. It is advised to not use it in subclasses. |
protected void processForwardConfig(HttpServletRequest request,
HttpServletResponse response,
ForwardConfig forward) throws IOException, ServletException {
// Required by struts contract
if (forward == null) {
return;
}
if (log.isDebugEnabled()) {
log.debug(
"processForwardConfig("
+ forward.getPath()
+ ", "
+ forward.getContextRelative()
+ ")");
}
// Try to process the definition.
if (processTilesDefinition(forward.getPath(),
forward.getContextRelative(),
request,
response)) {
if (log.isDebugEnabled()) {
log.debug(
" '" + forward.getPath() + "' - processed as definition");
}
return;
}
if (log.isDebugEnabled()) {
log.debug(" '" + forward.getPath() + "' - processed as uri");
}
// forward doesn't contain a definition, let parent do processing
super.processForwardConfig(request, response, forward);
}
Overloaded method from Struts' RequestProcessor.
Forward or redirect to the specified destination by the specified
mechanism.
This method catches the Struts' actionForward call. It checks if the
actionForward is done on a Tiles definition name. If true, process the
definition and insert it. If false, call the original parent's method. |
protected boolean processTilesDefinition(String definitionName,
boolean contextRelative,
HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
// Do we do a forward (original behavior) or an include ?
boolean doInclude = false;
// Controller associated to a definition, if any
Controller controller = null;
// Computed uri to include
String uri = null;
ComponentContext tileContext = null;
try {
// Get current tile context if any.
// If context exist, we will do an include
tileContext = ComponentContext.getContext(request);
doInclude = (tileContext != null);
ComponentDefinition definition = null;
// Process tiles definition names only if a definition factory exist,
// and definition is found.
if (definitionsFactory != null) {
// Get definition of tiles/component corresponding to uri.
try {
definition =
definitionsFactory.getDefinition(
definitionName,
request,
getServletContext());
} catch (NoSuchDefinitionException ex) {
// Ignore not found
log.debug("NoSuchDefinitionException " + ex.getMessage());
}
if (definition != null) { // We have a 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, request);
} else {
tileContext.addMissing(definition.getAttributes());
}
}
}
// Process definition set in Action, if any.
definition = DefinitionsUtil.getActionDefinition(request);
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) {
uri = definition.getPath();
}
if (definition.getOrCreateController() != null) {
controller = definition.getOrCreateController();
}
if (tileContext == null) {
tileContext =
new ComponentContext(definition.getAttributes());
ComponentContext.setContext(tileContext, request);
} else {
tileContext.addMissing(definition.getAttributes());
}
}
} catch (java.lang.InstantiationException ex) {
log.error("Can't create associated controller", ex);
throw new ServletException(
"Can't create associated controller",
ex);
} catch (DefinitionsFactoryException ex) {
throw new ServletException(ex);
}
// Have we found a definition ?
if (uri == null) {
return false;
}
// Execute controller associated to definition, if any.
if (controller != null) {
try {
controller.execute(
tileContext,
request,
response,
getServletContext());
} catch (Exception e) {
throw new ServletException(e);
}
}
// If request comes from a previous Tile, do an include.
// This allows to insert an action in a Tile.
if (log.isDebugEnabled()) {
log.debug("uri=" + uri + " doInclude=" + doInclude);
}
if (doInclude) {
doInclude(uri, request, response);
} else {
doForward(uri, request, response); // original behavior
}
return true;
}
Process a Tile definition name.
This method tries to process the parameter definitionName as a definition name.
It returns true if a definition has been processed, or false otherwise.
Parameter contextRelative is not used in this implementation. |