Package groovy.text

Examples of groovy.text.Template


     *            If the request specified an invalid template source file
     */
    protected Template getTemplate(File file) throws ServletException {

        String key = file.getAbsolutePath();
        Template template = null;

        /*
         * Test cache for a valid template bound to the key.
         */
        if (verbose) {
View Full Code Here


        //
        // Get the requested template.
        //
        long getMillis = System.currentTimeMillis();
        Template template = getTemplate(file);
        getMillis = System.currentTimeMillis() - getMillis;

        //
        // Create new binding for the current request.
        //
        ServletBinding binding = new ServletBinding(request, response, servletContext);
        setVariables(binding);

        //
        // Prepare the response buffer content type _before_ getting the writer.
        // and set status code to ok
        //
        response.setContentType(CONTENT_TYPE_TEXT_HTML+"; charset="+encoding);
        response.setStatus(HttpServletResponse.SC_OK);

        //
        // Get the output stream writer from the binding.
        //
        Writer out = (Writer) binding.getVariable("out");
        if (out == null) {
            out = response.getWriter();
        }

        //
        // Evaluate the template.
        //
        if (verbose) {
            log("Making template \"" + name + "\"...");
        }
        // String made = template.make(binding.getVariables()).toString();
        // log(" = " + made);
        long makeMillis = System.currentTimeMillis();
        template.make(binding.getVariables()).writeTo(out);
        makeMillis = System.currentTimeMillis() - makeMillis;

        if (generateBy) {
            StringBuffer sb = new StringBuffer(100);
            sb.append("\n<!-- Generated by Groovy TemplateServlet [create/get=");
View Full Code Here

     *            If the request specified an invalid template source file
     */
    protected Template getTemplate(File file) throws ServletException {

        String key = file.getAbsolutePath();
        Template template = null;

        /*
         * Test cache for a valid template bound to the key.
         */
        if (verbose) {
View Full Code Here

        //
        // Get the requested template.
        //
        long getMillis = System.currentTimeMillis();
        Template template = getTemplate(file);
        getMillis = System.currentTimeMillis() - getMillis;

        //
        // Create new binding for the current request.
        //
        ServletBinding binding = new ServletBinding(request, response, servletContext);
        setVariables(binding);

        //
        // Prepare the response buffer content type _before_ getting the writer.
        // and set status code to ok
        //
        response.setContentType(CONTENT_TYPE_TEXT_HTML+"; charset="+encoding);
        response.setStatus(HttpServletResponse.SC_OK);

        //
        // Get the output stream writer from the binding.
        //
        Writer out = (Writer) binding.getVariable("out");
        if (out == null) {
            out = response.getWriter();
        }

        //
        // Evaluate the template.
        //
        if (verbose) {
            log("Making template \"" + name + "\"...");
        }
        // String made = template.make(binding.getVariables()).toString();
        // log(" = " + made);
        long makeMillis = System.currentTimeMillis();
        template.make(binding.getVariables()).writeTo(out);
        makeMillis = System.currentTimeMillis() - makeMillis;

        if (generateBy) {
            StringBuffer sb = new StringBuffer(100);
            sb.append("\n<!-- Generated by Groovy TemplateServlet [create/get=");
View Full Code Here

  String applyClassTemplates(GroovyClassDoc classDoc) {
    String templatePath = (String) classTemplatePaths.get(0); // todo (iterate)
     
    String templateWithBindingApplied = "";
    try {
      Template t = (Template) classTemplates.get(templatePath);
      if (t == null) {
        t = engine.createTemplate(resourceManager.getReader(templatePath));
        classTemplates.put(templatePath, t);
      }
      Map binding = new HashMap();
          binding.put("classDoc", classDoc);
         
          templateWithBindingApplied = t.make(binding).toString();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return templateWithBindingApplied;
  }
View Full Code Here

  String applyPackageTemplate(String template, GroovyPackageDoc packageDoc) {
    String templatePath = template;
     
    String templateWithBindingApplied = "";
    try {
      Template t = (Template) packageTemplates.get(templatePath);
      if (t == null) {
        t = engine.createTemplate(resourceManager.getReader(templatePath));
        packageTemplates.put(templatePath, t);
      }

      Map binding = new HashMap();
          binding.put("packageDoc", packageDoc);
         
          templateWithBindingApplied = t.make(binding).toString();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return templateWithBindingApplied;
  }
View Full Code Here

  String applyRootDocTemplate(String template, GroovyRootDoc rootDoc) {
    String templatePath = template;
     
    String templateWithBindingApplied = "";
    try {
      Template t = (Template) docTemplates.get(templatePath);
      if (t == null) {
        t = engine.createTemplate(resourceManager.getReader(templatePath));
        docTemplates.put(templatePath, t);
      }

      Map binding = new HashMap();
          binding.put("rootDoc", rootDoc);
         
          templateWithBindingApplied = t.make(binding).toString();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return templateWithBindingApplied;
  }
View Full Code Here

            }
        });
    }

    private Template compile(String filename, String templateText) throws IOException, ClassNotFoundException {
        Template template = getTemplateFromCache(filename);

        if (template == null) {
            // real compile
            template = engine.createTemplate(templateText);
            putTemplateToCache(filename, template);
View Full Code Here

    protected void renderPageWithEngine(GroovyPagesTemplateEngine engine, HttpServletRequest request,
            HttpServletResponse response, GroovyPageScriptSource scriptSource) throws Exception {
        request.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE);
        GSPResponseWriter out = createResponseWriter(response);
        try {
            Template template = engine.createTemplate(scriptSource);
            if (template instanceof GroovyPageTemplate) {
                ((GroovyPageTemplate)template).setAllowSettingContentType(true);
            }
            template.make().writeTo(out);
        }
        catch(Exception e) {
            out.setError();
            throw e;
        }
View Full Code Here

     * @param url The URL of the page
     * @return An array where the index is the line number witin the compiled GSP and the value is the line number within the source
     */
    public int[] calculateLineNumbersForPage(ServletContext context, String url) {
        try {
            Template t = createTemplate(url);
            if (t instanceof GroovyPageTemplate) {
                return ((GroovyPageTemplate)t).getMetaInfo().getLineNumbers();
            }
        }
        catch (Exception e) {
View Full Code Here

TOP

Related Classes of groovy.text.Template

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.