Ejemplo n.º 1
0
 /**
  * Generates html page containing the NGL canvas.
  *
  * @param directory path to the job directory
  * @param inputName the input: either a PDB id or the file name as input by user
  * @param strucFile the file with the AU structure (can be cif or pdb and gzipped or not)
  * @param strucURI URL to reach auCifFile within the browser
  * @param title Page title [default: structure name]
  * @param size the canvas size
  * @param jsonURI path to the json dataURL
  * @param interfaces List of all interfaces to build the latticegraph
  * @param requestedIfaces subset of the interfaces to display
  * @param out Stream to output the HTML page
  * @param urlMolViewer path to the libURL
  * @throws StructureException For errors parsing the input structure
  * @throws IOException For errors reading or writing files
  */
 public static void generateHTMLPage(
     File directory,
     String inputName,
     File strucFile,
     String strucURI,
     String title,
     String size,
     String jsonURL,
     List<Interface> interfaces,
     Collection<Integer> requestedIfaces,
     PrintWriter out,
     String urlMolViewer)
     throws IOException, StructureException {
   logger.info("JSON URL for {}: {}", inputName, jsonURL);
   logger.info("Structure URL for {}: {}", inputName, strucURI);
   MustacheFactory mf = new DefaultMustacheFactory();
   String template = LatticeGUIMustache.expandTemplatePath(TEMPLATE_LATTICE_GUI_NGL_LAZY);
   Mustache mustache = mf.compile(template);
   LazyLatticeGUIMustache3D page = new LazyLatticeGUIMustache3D();
   page.setSize(size);
   page.setTitle(title);
   page.setDataURL(jsonURL);
   page.setLibURL(urlMolViewer);
   page.setStrucURL(strucURI);
   try {
     mustache.execute(out, page).flush();
   } catch (IOException e) {
     logger.error("Error generating output from template " + template, e);
   }
 }
Ejemplo n.º 2
0
  public void renderAndWrite() throws IOException, ConfigurationException {
    readConfig();
    removeOld();

    InputStreamReader reader;
    BufferedReader bufferedReader;
    File template = new File(templatePath);
    if (!template.isFile() || !template.exists()) {
      LOGGER.error("template for logstash config doesn't exist! ");
      throw new IOException("template for logstash config doesn't exist! ");
    }
    reader = new InputStreamReader(new FileInputStream(template));
    bufferedReader = new BufferedReader(reader);

    File newConf = new File(logstashConfPath);
    Writer writer = new OutputStreamWriter(new FileOutputStream(newConf));
    HashMap<String, Object> m = new HashMap<String, Object>();

    // Add redis host
    m.put("redisHost", redisHost);
    m.put("elasticSearchHost", elasticSearchHost);
    m.put("elasticSearchHttpPort", elasticSearchHttpPort);

    MustacheFactory mf = new DefaultMustacheFactory();
    // TODO: what's the meaning of this tag in mustache's compile
    Mustache mustache = mf.compile(bufferedReader, "example");
    mustache.execute(writer, m);
    writer.flush();

    bufferedReader.close();
    reader.close();
  }
Ejemplo n.º 3
0
 public String render(Review review) throws IOException {
   MustacheFactory mf = new DefaultMustacheFactory();
   Mustache mustache = mf.compile(TEMPLATE_MUSTACHE);
   Writer sink = new StringWriter();
   mustache.execute(sink, review).flush();
   return sink.toString();
 }
 public static void main(String[] args) {
   CompiledMustacheTemplates cmt = getInstance();
   Mustache m = cmt.getProcessesMustache();
   try {
     m.execute(new PrintWriter(System.out), BASFProcess.getNameToProcessMap().values()).flush();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Ejemplo n.º 5
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());
  }
Ejemplo n.º 6
0
  private Mustache customCompile(String filename, Res resource) {
    Map<String, Mustache> cache = partialCache.get();
    try {
      Mustache mustache = cache.get(filename);
      if (mustache == null) {
        String template = preprocess(resource.getContent());
        InputStreamReader reader =
            new InputStreamReader(new ByteArrayInputStream(template.getBytes()));
        mustache = mc.compile(reader, filename, SM, EM);
        cache.put(filename, mustache);
        mustache.init();
      }

      return mustache;
    } finally {
      cache.remove(filename);
    }
  }
Ejemplo n.º 7
0
 protected Writer handleFunction(Writer writer, Function function, Object[] scopes) {
   StringWriter sw = new StringWriter();
   runIdentity(sw);
   Object newtemplate = function.apply(sw.toString());
   if (newtemplate != null) {
     if (function instanceof TemplateFunction) {
       String templateText = newtemplate.toString();
       Mustache mustache = cf.getTemplate(templateText);
       if (mustache == null) {
         mustache =
             cf.compile(new StringReader(templateText), tc.file(), tc.startChars(), tc.endChars());
         cf.putTemplate(templateText, mustache);
       }
       writer = mustache.execute(writer, scopes);
     } else {
       try {
         writer.write(newtemplate.toString());
       } catch (IOException e) {
         throw new MustacheException("Failed to write function result", e);
       }
     }
   }
   return writer;
 }
Ejemplo n.º 8
0
 @Override
 public void handle(HttpServletRequest request, HttpServletResponse response, DataObject user)
     throws IOException, ServletException {
   if (request.getMethod().equals("POST")) {
     String fullname = request.getParameter("fullname");
     String email = request.getParameter("email");
     String password = request.getParameter("password");
     String password2 = request.getParameter("password2");
     if (email != null) {
       DataObject data = new DataObject();
       data.put("email", email);
       DataObject query = new DataObject();
       query.put("data", data);
       query = ds.fetch(query);
       DataList lista = query.getDataObject("response").getDataList("data");
       if (lista.size() == 0) {
         if (password != null) {
           if (password.equals(password2)) {
             DataObject obj = new DataObject();
             obj.put("fullname", fullname);
             obj.put("email", email);
             obj.put("password", password);
             obj.put("registeredAt", ZonedDateTime.now().toString());
             obj.put("confirmed", "false");
             obj.put("emailSent", "false");
             Address userAddr = new InternetAddress(email, fullname, "utf-8");
             DataObject dao = ds.addObj(obj);
             dao =
                 dao.getDataObject("response")
                     .getDataObject("data"); // System.out.println("dao:"+dao);
             String content =
                 MessageFormat.format(
                     Utils.textInputStreamToString(
                         LoginHandler.class.getResourceAsStream(
                             "/templates/confirmationMail.template"),
                         "utf-8"),
                     fullname,
                     TokenGenerator.nextTokenByUserId(dao.getNumId()),
                     email);
             MailSender.send(userAddr, "Cloudino confirmation email", content, dao.getNumId());
             logger.log(Level.FINE, "Register and send mail to: {0}", email);
             Map<String, Object> register = new HashMap<>();
             Map<String, Object> scope = new HashMap<>();
             scope.put("ctx", request.getContextPath());
             register.put("confirm", scope);
             response.setCharacterEncoding("utf-8");
             mustache.execute(response.getWriter(), register);
           }
         }
       } else {
         Map<String, Object> register = new HashMap<>();
         Map<String, Object> scope = new HashMap<>();
         scope.put("error", "Email was already registered");
         scope.put("ctx", request.getContextPath());
         register.put("register", scope);
         response.setCharacterEncoding("utf-8");
         mustache.execute(response.getWriter(), register);
       }
     }
   } else {
     Map<String, Object> register = new HashMap<>();
     Map<String, Object> scope = new HashMap<>();
     scope.put("ctx", request.getContextPath());
     register.put("register", scope);
     response.setCharacterEncoding("utf-8");
     mustache.execute(response.getWriter(), register);
   }
 }