Exemplo n.º 1
0
  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());
  }
Exemplo n.º 2
0
  @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;
  }