+public final class Gigi extends HttpServlet {
+
+ private class MenuBuilder {
+
+ private LinkedList<Menu> categories = new LinkedList<Menu>();
+
+ private HashMap<String, Page> pages = new HashMap<String, Page>();
+
+ private MenuCollector rootMenu;
+
+ public MenuBuilder() {}
+
+ private void putPage(String path, Page p, String category) {
+ pages.put(path, p);
+ if (category == null) {
+ return;
+ }
+ Menu m = getMenu(category);
+ m.addItem(new PageMenuItem(p, path.replaceFirst("/?\\*$", "")));
+
+ }
+
+ private Menu getMenu(String category) {
+ Menu m = null;
+ for (Menu menu : categories) {
+ if (menu.getMenuName().equals(category)) {
+ m = menu;
+ break;
+ }
+ }
+ if (m == null) {
+ m = new Menu(category);
+ categories.add(m);
+ }
+ return m;
+ }
+
+ public MenuCollector generateMenu() throws ServletException {
+ putPage("/denied", new AccessDenied(), null);
+ putPage("/error", new PageNotFound(), null);
+ putPage("/login", new LoginPage(), null);
+ getMenu("SomeCA.org").addItem(new SimpleMenuItem("https://" + ServerConstants.getWwwHostNamePort() + "/login", "Password Login") {
+
+ @Override
+ public boolean isPermitted(AuthorizationContext ac) {
+ return ac == null;
+ }
+ });
+ getMenu("SomeCA.org").addItem(new SimpleMenuItem("https://" + ServerConstants.getSecureHostNamePort() + "/login", "Certificate Login") {
+
+ @Override
+ public boolean isPermitted(AuthorizationContext ac) {
+ return ac == null;
+ }
+ });
+ putPage("/", new MainPage(), null);
+ putPage("/roots", new RootCertPage(truststore), "SomeCA.org");
+
+ putPage("/secure", new TestSecure(), null);
+ putPage(Verify.PATH, new Verify(), null);
+ putPage(Certificates.PATH + "/*", new Certificates(), "Certificates");
+ putPage(RegisterPage.PATH, new RegisterPage(), "SomeCA.org");
+ putPage(CertificateAdd.PATH, new CertificateAdd(), "Certificates");
+ putPage(MailOverview.DEFAULT_PATH, new MailOverview(), "Certificates");
+ putPage(DomainOverview.PATH + "*", new DomainOverview(), "Certificates");
+
+ putPage(AssurePage.PATH + "/*", new AssurePage(), "Web of Trust");
+ putPage(MyPoints.PATH, new MyPoints(), "Web of Trust");
+ putPage(MyListingPage.PATH, new MyListingPage(), "Web of Trust");
+ putPage(RequestTTPPage.PATH, new RequestTTPPage(), "Web of Trust");
+
+ putPage(TTPAdminPage.PATH + "/*", new TTPAdminPage(), "Admin");
+ putPage(CreateOrgPage.DEFAULT_PATH, new CreateOrgPage(), "Organisation Admin");
+ putPage(ViewOrgPage.DEFAULT_PATH + "/*", new ViewOrgPage(), "Organisation Admin");
+
+ putPage(SupportEnterTicketPage.PATH, new SupportEnterTicketPage(), "Support Console");
+ putPage(FindUserPage.PATH, new FindUserPage(), "Support Console");
+ putPage(FindDomainPage.PATH, new FindDomainPage(), "Support Console");
+
+ putPage(SupportUserDetailsPage.PATH + "*", new SupportUserDetailsPage(), null);
+ putPage(ChangePasswordPage.PATH, new ChangePasswordPage(), "My Account");
+ putPage(LogoutPage.PATH, new LogoutPage(), "My Account");
+ putPage(History.PATH, new History(false), "My Account");
+ putPage(History.SUPPORT_PATH, new History(true), null);
+ putPage(UserTrainings.PATH, new UserTrainings(false), "My Account");
+ putPage(MyDetails.PATH, new MyDetails(), "My Account");
+ putPage(UserTrainings.SUPPORT_PATH, new UserTrainings(true), null);
+
+ putPage(PasswordResetPage.PATH, new PasswordResetPage(), null);
+
+ if (testing) {
+ try {
+ Class<?> manager = Class.forName("org.cacert.gigi.pages.Manager");
+ Page p = (Page) manager.getMethod("getInstance").invoke(null);
+ String pa = (String) manager.getField("PATH").get(null);
+ putPage(pa + "/*", p, "Gigi test server");
+ } catch (ReflectiveOperationException e) {
+ e.printStackTrace();
+ }
+ }
+
+ try {
+ putPage("/wot/rules", new StaticPage("Web of Trust Rules", AssurePage.class.getResourceAsStream("Rules.templ")), "Web of Trust");
+ } catch (UnsupportedEncodingException e) {
+ throw new ServletException(e);
+ }
+ baseTemplate = new Template(Gigi.class.getResource("Gigi.templ"));
+ rootMenu = new MenuCollector();
+
+ Menu languages = new Menu("Language");
+ for (Locale l : Language.getSupportedLocales()) {
+ languages.addItem(new SimpleMenuItem("?lang=" + l.toString(), l.getDisplayName(l)));
+ }
+ categories.add(languages);
+ for (Menu menu : categories) {
+ menu.prepare();
+ rootMenu.put(menu);
+ }
+
+ // rootMenu.prepare();
+ return rootMenu;
+ }
+
+ public Map<String, Page> getPages() {
+ return Collections.unmodifiableMap(pages);
+ }
+ }