private String getDefaultTemplate(BinaryResource binaryResource, String uuid) throws IOException { MustacheFactory mf = new DefaultMustacheFactory(); Mustache mustache = mf.compile("com/docdoku/server/viewers/default_viewer.mustache"); Map<Object, Object> scopes = new HashMap<>(); scopes.put("uriResource", ViewerUtils.getURI(binaryResource, uuid)); scopes.put("fileName", binaryResource.getName()); StringWriter templateWriter = new StringWriter(); mustache.execute(templateWriter, scopes).flush(); return ViewerUtils.getViewerTemplate( dataManager, binaryResource, uuid, templateWriter.toString()); }
@Override public String getHtmlForViewer(BinaryResource binaryResource, String uuid) { String template; DocumentViewer documentViewerSelected = selectViewerForTemplate(binaryResource); try { if (documentViewerSelected != null) { template = documentViewerSelected.renderHtmlForViewer(binaryResource, uuid); } else { template = getDefaultTemplate(binaryResource, uuid); } } catch (Exception e) { LOGGER.log(Level.INFO, null, e); template = new StringBuilder() .append("<p>") .append("Can't render ") .append(binaryResource.getName()) .append("</p>") .toString(); } return template; }