private String jsonToHtml(SkysailResponse<List<?>> skysailResponse, Resource resource) { PresentationStyle styleOldp = ConverterUtils.evalPresentationStyle(resource); PresentationStyle style = skysailResponse.getPresentationStyleHint(); String page = rootTemplate; long executionTimeInNanos = skysailResponse.getExecutionTime(); float performance = new Long(1000000000) / executionTimeInNanos; page = page.replace("${performance}", String.format("%s", performance)); page = page.replace("${result}", calcResult(skysailResponse)); page = page.replace( "${message}", skysailResponse.getMessage() == null ? "no message available" : skysailResponse.getMessage()); page = page.replace("${linkedPages}", linkedPages(resource)); page = page.replace("${commands}", commands(resource)); page = page.replace("${presentations}", presentations(skysailResponse)); page = page.replace("${filterExpression}", getFilter()); page = page.replace("${history}", ""); page = page.replace( "${mainNav}", getMainNav(((SkysailApplication) resource.getApplication()).getBundleContext())); String username = "******"; // if (resource.getRequest().getChallengeResponse() != null) { // username = resource.getRequest().getChallengeResponse().getIdentifier(); // } Subject subject = SecurityUtils.getSubject(); if (subject.getPrincipal() != null) { username = subject.getPrincipal().toString(); } page = page.replace( "${username}", "<li><a href='#'><i class=\"icon-user icon-white\"></i> " + username + "</a></li>\n"); if (subject.getPrincipal() != null) { page = page.replace("${loginLogout}", "<a href='/logout?targetUri=/'>[Logout]</a>"); } else { page = page.replace("${loginLogout}", "<a href='/login?media=htmlform'>[Login]</a>"); } page = page.replace( "${productName}", ((SkysailApplication) resource.getApplication()).getConfigForKey("productName")); Object skysailResponseAsObject = skysailResponse.getData(); if (skysailResponseAsObject != null) { if (style.equals(PresentationStyle.LIST)) { StrategyContext context = new StrategyContext(new ListForContentStrategy()); page = context.createHtml(page, skysailResponseAsObject, skysailResponse); } else if (style.equals(PresentationStyle.LIST2)) { StrategyContext context = new StrategyContext( new ListForContentStrategy2( ((SkysailApplication) resource.getApplication()).getBundleContext(), resource)); page = context.createHtml(page, skysailResponseAsObject, skysailResponse); } else if (style.equals(PresentationStyle.TABLE)) { StrategyContext context = new StrategyContext(new TableForContentStrategy()); page = context.createHtml(page, skysailResponseAsObject, skysailResponse); } else if (style.equals(PresentationStyle.EDIT)) { StrategyContext context = new StrategyContext(new FormForContentStrategy()); page = context.createHtml(page, skysailResponseAsObject, skysailResponse); } else if (style.equals(PresentationStyle.D3_SIMPLE_GRAPH)) { page = createD3SimpleGraphForContent(skysailResponseAsObject, skysailResponse); } else if (style.equals(PresentationStyle.IFRAME)) { StrategyContext context = new StrategyContext(new IFrameForContentStrategy()); page = context.createHtml(page, skysailResponseAsObject, skysailResponse); } else if (style.equals(PresentationStyle.ACE_EDITOR)) { StrategyContext context = new StrategyContext(new AceEditorForContentStrategy()); page = context.createHtml(page, skysailResponseAsObject, skysailResponse); } } else { if (skysailResponse instanceof ConstraintViolationsResponse) { StrategyContext context = new StrategyContext(new FormForContentStrategy()); page = context.createHtml(page, skysailResponseAsObject, skysailResponse); } else { page = page.replace("${content}", ""); } } StringBuilder breadcrumb = getBreadcrumbHtml(resource); page = page.replace("${breadcrumb}", breadcrumb.toString()); String stacktrace = ""; if (skysailResponse instanceof FailureResponse) { Exception exception = ((FailureResponse<?>) skysailResponse).getException(); if (exception != null) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); exception.printStackTrace(pw); stacktrace = "<pre>" + sw.toString() + "</pre>"; } } page = page.replace("${stacktrace}", stacktrace); return page; }