private void loadFiles(final IBasicFile[] jsonFiles, final JSONArray result, final String type) throws IOException { Arrays.sort( jsonFiles, new Comparator<IBasicFile>() { @Override public int compare(IBasicFile file1, IBasicFile file2) { if (file1 == null && file2 == null) { return 0; } else { return file1.getFullPath().toLowerCase().compareTo(file2.getFullPath().toLowerCase()); } } }); IReadAccess access = CdeEnvironment.getPluginSystemReader(SYSTEM_CDF_DD_TEMPLATES); for (int i = 0; i < jsonFiles.length; i++) { final JSONObject template = new JSONObject(); String imgResourcePath = resoureUrl + "unknown.png"; if (access.fileExists(jsonFiles[i].getName().replace(".cdfde", ".png"))) { imgResourcePath = resoureUrl + jsonFiles[i].getName().replace(".cdfde", ".png"); } template.put("img", imgResourcePath); template.put("type", type); template.put("structure", JsonUtils.readJsonFromInputStream(jsonFiles[i].getContents())); result.add(template); } }
public MobileDashboard( IParameterProvider pathParams, DashboardDesignerContentGenerator generator) { super(pathParams, generator); IPentahoSession userSession = PentahoSessionHolder.getSession(); final ISolutionRepository solutionRepository = PentahoSystem.get(ISolutionRepository.class, userSession); final String absRoot = pathParams.hasParameter("root") ? !pathParams.getParameter("root").toString().isEmpty() ? "http://" + pathParams.getParameter("root").toString() : "" : ""; final boolean absolute = (!absRoot.isEmpty()) || pathParams.hasParameter("absolute") && pathParams.getParameter("absolute").equals("true"); final RenderMobileLayout layoutRenderer = new RenderMobileLayout(); final RenderComponents componentsRenderer = new RenderComponents(); try { final JSONObject json = (JSONObject) JsonUtils.readJsonFromInputStream( solutionRepository.getResourceInputStream(dashboardLocation, true)); json.put("settings", getWcdf().toJSON()); final JXPathContext doc = JXPathContext.newContext(json); final StringBuilder dashboardBody = new StringBuilder(); dashboardBody.append(layoutRenderer.render(doc)); dashboardBody.append(componentsRenderer.render(doc)); // set all dashboard members this.content = replaceTokens(dashboardBody.toString(), absolute, absRoot); this.header = renderHeaders(pathParams, this.content.toString()); this.loaded = new Date(); } catch (Exception e) { logger.error(e); } }