- hgen.end(inner);
-
- // Navigation - Using older Nav to work with decrepit IE versions
-
- Mark nav = hgen.divID("nav");
- hgen.incr("h2").text("Related Links").end();
- hgen.incr(UL);
- String aaf_help = env.getProperty(AAF_URL_AAF_HELP,null);
- if(aaf_help!=null) {
- hgen.leaf(LI).leaf(A,"href="+env.getProperty(AAF_URL_AAF_HELP),"target=_blank").text("AAF WIKI").end(2);
- String sub = env.getProperty(AAF_URL_AAF_HELP+".sub");
- if(sub!=null) {
- hgen.incr(UL,"style=margin-left:5%");
- for(String s : Split.splitTrim(',', sub)) {
- hgen.leaf(LI).leaf(A,"href="+env.getProperty(AAF_URL_AAF_HELP+".sub."+s),"target=_blank").text(s.replace('+', ' ')).end(2);
- }
- hgen.end();
- }
- }
- aaf_help = env.getProperty(AAF_URL_CADI_HELP,null);
- if(aaf_help!=null) {
- hgen.leaf(LI).leaf(A,"href="+aaf_help,"target=_blank").text("CADI WIKI").end(2);
- }
- String tools = env.getProperty(AAFURL_TOOLS);
- if(tools!=null) {
- hgen.hr()
- .incr(HTMLGen.UL,"style=margin-left:5%")
- .leaf(HTMLGen.H3).text("Related Tools").end();
+ private static synchronized List<String> getThemeFiles(Env env, String theme) {
+ if(themes==null) {
+ themes = new TreeMap<>();
+ File themeD = new File("theme");
+ if(themeD.exists() && themeD.isDirectory()) {
+ for (File t : themeD.listFiles()) {
+ if(t.isDirectory()) {
+ List<String> la = new ArrayList<>();
+ for(File f : t.listFiles()) {
+ if(f.isFile()) {
+ if(f.getName().endsWith(".props")) {
+ Properties props;
+ if(themeProps == null) {
+ themeProps = new TreeMap<>();
+ props = null;
+ } else {
+ props = themeProps.get(t.getName());
+ }
+ if(props==null) {
+ props = new Properties();
+ themeProps.put(t.getName(), props);
+ }
+
+ try {
+ FileInputStream fis = new FileInputStream(f);
+ try {
+ props.load(fis);
+ } finally {
+ fis.close();
+ }
+ } catch (IOException e) {
+ env.error().log(e);
+ }
+ } else {
+ la.add(f.getName());
+ }
+ }
+ }
+ themes.put(t.getName(),la);
+ }
+ }
+ }
+ }
+ return themes.get(theme);
+ }
+
+ protected Imports getImports(Env env, String theme, int backdots, BROWSER browser) {
+ List<String> ls = getThemeFiles(env,theme);
+ Imports imp = new Imports(backdots);
+ String prefix = "theme/" + theme + '/';
+ for(String f : ls) {
+ if(f.endsWith(".js")) {
+ imp.js(prefix + f);
+ } else if(f.endsWith(".css")) {
+ if(f.endsWith("iPhone.css")) {
+ if(BROWSER.iPhone.equals(browser)) {
+ imp.css(prefix + f);
+ }
+ } else if (f.endsWith("Desktop.css")){
+ if(!BROWSER.iPhone.equals(browser)) {
+ imp.css(prefix + f);
+ }
+ // Make Console specific to Console page
+ } else if (!"console.js".equals(f)) {
+ imp.css(prefix + f);
+ }
+ }
+ }
+ return imp;
+ }
+
+ @Override
+ public void code(final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
+ // Note: I found that App Storage saves everything about the page, or not. Thus, if you declare the page uncacheable, none of the
+ // Artifacts, like JPGs are stored, which makes this feature useless for Server driven elements
+ cache.dynamic(hgen, new DynamicCode<HTMLGen,AAF_GUI,AuthzTrans>() {
+ @Override
+ public void code(AAF_GUI state, AuthzTrans trans, final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
+ switch(browser(trans,browserSlot)) {
+ case ieOld:
+ case ie:
+ hgen.directive("!DOCTYPE html");
+ hgen.directive("meta", "http-equiv=X-UA-Compatible","content=IE=11");
+ default:
+ }
+ }
+ });
+ hgen.html();
+ final String title = env.getProperty(AAF_GUI_TITLE,"Authentication/Authorization Framework");
+ final String defaultTheme = env.get(sTheme,"onap");
+
+ Mark head = hgen.head();
+ hgen.leaf(TITLE).text(title).end();
+ cache.dynamic(hgen, new DynamicCode<HTMLGen,AAF_GUI,AuthzTrans>() {
+ @Override
+ public void code(AAF_GUI state, AuthzTrans trans, final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
+ BROWSER browser = browser(trans,browserSlot);
+ String theme = null;
+ Cookie[] cookies = trans.hreq().getCookies();
+ if(cookies!=null) {
+ for(Cookie c : cookies) {
+ if(AAF_GUI_THEME.equals(c.getName())) {
+ theme=c.getValue();
+ if(!(themes.containsKey(theme))) {
+ theme = defaultTheme;
+ }
+ break;
+ }
+ }
+ }
+
+ if(theme==null) {
+ for(String t : themes.keySet()) {
+ if(!t.equals(defaultTheme) && trans.fish(new AAFPermission(null,trans.user()+":id", AAF_GUI_THEME, t))) {
+ theme=t;
+ break;
+ }
+ }
+ if(theme==null) {
+ theme = defaultTheme;
+ }
+ Cookie cookie = new Cookie(AAF_GUI_THEME,theme);
+ cookie.setMaxAge(604_800); // one week
+ trans.hresp().addCookie(cookie);
+ }
+ trans.setProperty(Page.AAF_THEME, theme);
+
+ hgen.imports(getImports(env,theme,backdots,browser));
+ switch(browser) {
+ case ie:
+ case ieOld:
+ hgen.js().text("document.createElement('header');")
+ .text("document.createElement('nav');")
+ .done();
+ break;
+ default:
+ }
+
+ }
+ });
+ hgen.end(head);
+
+ Mark body = hgen.body();
+ Mark header = hgen.header();
+ cache.dynamic(hgen, new DynamicCode<HTMLGen,AAF_GUI,AuthzTrans>() {
+ @Override
+ public void code(AAF_GUI state, AuthzTrans trans,Cache<HTMLGen> cache, HTMLGen xgen)
+ throws APIException, IOException {
+ // Obtain Server Info, and print
+ // AT&T Only
+ String env = trans.getProperty(Config.AAF_ENV,"N/A");
+ xgen.leaf(H1).text(title + " on " + env).end();
+ xgen.leaf("p","id=version").text("AAF Version: " + state.deployedVersion).end();
+
+ // Obtain User Info, and print
+ TaggedPrincipal p = trans.getUserPrincipal();
+ String user,secured;
+ if (p==null) {
+ user = "please choose a Login Authority";
+ secured = "NOT Secure!";
+ } else {
+ user = p.personalName();
+ secured = p.tag();
+ }
+ xgen.leaf("p","id=welcome").text("Welcome, ")
+ .text(user)
+ .text("<sup>")
+ .text(secured)
+ .text("</sup>").end();
+
+ switch(browser(trans,browserSlot)) {
+ case ieOld:
+ case ie:
+ xgen.incr("h5").text("This app is Mobile First HTML5. Internet Explorer "
+ + " does not support all HTML5 standards. Old, non TSS-Standard versions may not function correctly.").br()
+ .text(" For best results, use a highly compliant HTML5 browser like Firefox.")
+ .end();
+ break;
+ default:
+ }
+ }
+ });
+
+ hgen.hr();
+
+ int cIdx;
+ ContentCode nc;
+ // If BreadCrumbs, put here
+ if (content.length>0 && content[0] instanceof BreadCrumbs) {
+ nc = content[0];
+ Mark ctnt = hgen.divID(nc.idattrs());
+ nc.code(cache, hgen);
+ hgen.end(ctnt);
+ cIdx = 1;
+ } else {
+ cIdx = 0;
+ }
+
+ hgen.end(header);
+
+ hgen.divID("pageContent");
+ Mark inner = hgen.divID("inner");
+ // Content
+ for (int i=cIdx;i<content.length;++i) {
+ nc = content[i];
+ Mark ctnt = hgen.divID(nc.idattrs());
+ nc.code(cache, hgen);
+ hgen.end(ctnt);
+ }