private void addNavigationCasesForRule(String fromViewId,
List<Node> navigationCases,
NavigationHandler navHandler) {
if (navigationCases != null && !navigationCases.isEmpty()) {
ApplicationAssociate associate =
ApplicationAssociate.getCurrentInstance();
for (Node navigationCase : navigationCases) {
if (navigationCase.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
NodeList children = navigationCase.getChildNodes();
String outcome = null;
String action = null;
String condition = null;
String toViewId = null;
Map<String,List<String>> parameters = null;
boolean redirect = false;
boolean includeViewParams = false;
for (int i = 0, size = children.getLength(); i < size; i++) {
Node n = children.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE) {
if (FROM_OUTCOME.equals(n.getLocalName())) {
outcome = getNodeText(n);
} else if (FROM_ACTION.equals(n.getLocalName())) {
action = getNodeText(n);
} else if (IF.equals(n.getLocalName())) {
String expression = getNodeText(n);
if (ELUtils.isExpression(expression) && !ELUtils.isMixedExpression(expression)) {
condition = expression;
}
else {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.log(Level.WARNING,
"jsf.config.navigation.if_invalid_expression",
new String[] { expression, fromViewId });
}
}
} else if (TO_VIEW_ID.equals(n.getLocalName())) {
String toViewIdString = getNodeText(n);
if (toViewIdString.charAt(0) != '/' && toViewIdString.charAt(0) != '#') {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.log(Level.WARNING,
"jsf.config.navigation.to_view_id_leading_slash",
new String[] { toViewIdString,
fromViewId });
}
toViewId = '/' + toViewIdString;
} else {
toViewId = toViewIdString;
}
} else if (REDIRECT.equals(n.getLocalName())) {
parameters = processParameters(n.getChildNodes());
includeViewParams = isIncludeViewParams(n);
redirect = true;
}
}
}
NavigationCase cnc =
new NavigationCase(fromViewId,
action,
outcome,
condition,
toViewId,
parameters,
redirect,
includeViewParams);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE,
MessageFormat.format("Adding NavigationCase: {0}",
cnc.toString()));
}
// if the top-level NavigationHandler is an instance of
// ConfigurableNavigationHandler, add the NavigationCases to
// that instance as well as adding them to the application associate.
// We have to add them to the ApplicationAssociate in the case
// where the top-level NavigationHandler may be custom and delegates
// to the default NavigationHandler implementation. In 1.2, they
// could be guaranteed that the default implementation had all
// defined navigation mappings.
if (navHandler instanceof ConfigurableNavigationHandler) {
ConfigurableNavigationHandler cnav = (ConfigurableNavigationHandler) navHandler;
Set<NavigationCase> cases = cnav.getNavigationCases().get(fromViewId);
if (cases == null) {
cases = new LinkedHashSet<NavigationCase>();
cnav.getNavigationCases().put(fromViewId, cases);
}
cases.add(cnc);
}
associate.addNavigationCase(cnc);
}
}