package com.sun.identity.admin; import org.jdom.input.SAXBuilder; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import javax.servlet.ServletContext; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import org.jdom.Namespace; public class NavigationRules { private Map navigationRules = new HashMap(); public Map getNavigationRules() { return navigationRules; } public void setNavigationRules(Map navigationRules) { this.navigationRules = navigationRules; } public static class NavigationRule { private String fromViewId; private Map navigationCases = new HashMap(); public String getFromViewId() { return fromViewId; } public void setFromViewId(String fromViewId) { this.fromViewId = fromViewId; } public Map getNavigationCases() { return navigationCases; } public void setNavigationCases(Map navigationCases) { this.navigationCases = navigationCases; } } public static class NavigationCase { public String getFromOutcome() { return fromOutcome; } public void setFromOutcome(String fromOutcome) { this.fromOutcome = fromOutcome; } public String getToViewId() { return toViewId; } public void setToViewId(String toViewId) { this.toViewId = toViewId; } private String fromOutcome; private String toViewId; } public NavigationRules() { FacesContext fc = FacesContext.getCurrentInstance(); ExternalContext ec = fc.getExternalContext(); ServletContext sc = (ServletContext) ec.getContext(); URL u; try { u = sc.getResource("/WEB-INF/faces-config.xml"); } catch (MalformedURLException mfue) { throw new RuntimeException(mfue); } InputStream is; try { is = u.openStream(); } catch (IOException ioe) { throw new RuntimeException(ioe); } SAXBuilder parser = new SAXBuilder(); Document d; try { d = parser.build(is); } catch (JDOMException je) { throw new RuntimeException(je); } catch (IOException ioe) { throw new RuntimeException(ioe); } Namespace ns = Namespace.getNamespace("http://java.sun.com/xml/ns/javaee"); Element rootElement = d.getRootElement(); List nrElements = rootElement.getChildren("navigation-rule", ns); for (Element nrElement: nrElements) { NavigationRule nr = new NavigationRule(); Element fvidElement = nrElement.getChild("from-view-id", ns); String fromViewId = null; if (fvidElement != null) { fromViewId = fvidElement.getText(); } nr.setFromViewId(fromViewId); List ncElements = nrElement.getChildren("navigation-case", ns); for (Element ncElement: ncElements) { NavigationCase nc = new NavigationCase(); Element foElement = ncElement.getChild("from-outcome", ns); String fromOutcome = foElement.getText(); nc.setFromOutcome(fromOutcome); Element tvidElement = ncElement.getChild("to-view-id", ns); String toViewId = tvidElement.getText(); nc.setToViewId(toViewId); nr.getNavigationCases().put(fromOutcome, nc); } navigationRules.put(fromViewId, nr); } } }