Examples of TemplateRenderer


Examples of br.com.caelum.vraptor.templates.plugins.TemplateRenderer

  }
 
  @Override
  public Template use(String templateName){
   
    TemplateRenderer renderer = plugin.getRenderer(templateName);
    Template template = new DefaultTemplate(renderer, response, result);
    for(TemplateDecorator decorator : decorators){
      decorator.decorate(template);
    }
    return template;
View Full Code Here

Examples of cn.webwheel.template.TemplateRenderer

    }

    private void handle(HttpExchange httpExchange, String path, String query, Map<String, Object> params) throws IOException {
        if (path.toLowerCase().endsWith(".html") || path.toLowerCase().endsWith(".htm")) {

            TemplateRenderer renderer;
            StringWriter sw = new StringWriter();
            String rCharset;
            try {
                renderer = rendererFactory.create(path, null, null);
                rCharset = renderer.charset == null ? "utf-8" : renderer.charset;

                StringBuilder sb = new StringBuilder();
                File file = new File(root, path);
                char[] buf = new char[8192];
                int rd;
                InputStreamReader reader = new InputStreamReader(new FileInputStream(file), rCharset);
                try {
                    while ((rd = reader.read(buf)) != -1) {
                        sb.append(buf, 0, rd);
                    }
                } finally {
                    reader.close();
                }
                Map<String, Object> ctx = null;
                Pattern pat = Pattern.compile("<script.*?>\\s*var _model\\s*=\\s*(.+?);?\\s*</script>",
                        Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
                Matcher matcher = pat.matcher(sb.toString());
                if (matcher.find()) {
                    Map<String, Object> map = mapper.readValue(matcher.group(1), Map.class);
                    if (map.size() == 1) {
                        ctx = (Map) map.entrySet().iterator().next().getValue();
                    } else if (map.size() > 1) {
                        String mi = null;
                        try {
                            Object o = params.get("_model");
                            if (o instanceof String[]) {
                                mi = ((String[]) o)[0];
                            }
                        } catch (Exception ignored) {
                        }
                        ctx = (Map) map.get(mi);
                        if (ctx == null) {
                            ModelSelectDlg dlg = new ModelSelectDlg(path, map.keySet());
                            dlg.setVisible(true);
                            if (dlg.selected != null) {
                                ctx = (Map) map.get(dlg.selected);
                            }
                        }
                    }
                }
                if (ctx == null) ctx = Collections.emptyMap();
                renderer.render(sw, ctx);
            } catch (Exception e) {
                except(httpExchange, e);
                return;
            }

View Full Code Here

Examples of cn.webwheel.template.TemplateRenderer

    }

    private void renderResource(HttpExchange httpExchange, String resource, Map<String, Object> ctx) throws Exception {
        byte[] data;
        if (ctx != null) {
            TemplateRenderer renderer = rendererFactory.create(resource, new FileVisitor() {
                @Override
                public String read(File root, String file, String charset) throws IOException {
                    InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream(file), "utf-8");
                    try {
                        StringBuilder sb = new StringBuilder();
                        int rd;
                        char[] buf = new char[4096];
                        while ((rd = reader.read(buf)) != -1) {
                            sb.append(buf, 0, rd);
                        }
                        return sb.toString();
                    } finally {
                        reader.close();
                    }
                }
            }, null);
            StringWriter sw = new StringWriter();
            try {
                renderer.render(sw, ctx);
            } catch (IOException e) {
                throw e;
            } catch (Exception e) {
                throw new IOException(e);
            }
View Full Code Here

Examples of com.trendrr.strest.contrib.templating.TemplateRenderer

   * @param filename
   * @param params
   * @return
   */
  public String renderTemplate(String filename, DynMap params) {
    TemplateRenderer renderer = TemplateLookup.getRenderer(this.getServerConfig());
    return renderer.renderTemplateFile(filename, params);
  }
View Full Code Here

Examples of gap.hapax.TemplateRenderer

                                                ClassDescriptor cd, PrintWriter out)
        throws ODStateException, IOException, TemplateException
    {
        if (null != xtm && null != pkg && null != imports && null != cd && null != out){

            TemplateRenderer template = Templates.GetTemplate(xtm);
            TemplateDataDictionary top = new gap.hapax.AbstractData();

            DefineDescription(xtm,top);

            DefinePrimitives(top);

            DefineClass(pkg,cd,imports,top);

            try {
                template.render(top,out);
            }
            catch (TemplateException exc){
                throw new TemplateException("In template '"+xtm.source+"'.",exc);
            }
        }
View Full Code Here

Examples of gap.hapax.TemplateRenderer

                                                      ClassDescriptor cd, PrintWriter out)
        throws ODStateException, IOException, TemplateException
    {
        if (null != xtm && null != pkg && null != imports && null != cd && null != out){

            TemplateRenderer template = Templates.GetTemplate(xtm);
            TemplateDataDictionary top = new gap.hapax.AbstractData();

            DefineDescription(xtm,top);

            DefinePrimitives(top);

            DefineClass(pkg,cd,imports,top);

            try {
                template.render(top,out);

                return true;
            }
            catch (TemplateException exc){
                throw new TemplateException("In template '"+xtm.source+"'.",exc);
View Full Code Here

Examples of gap.hapax.TemplateRenderer

    public final static void GenerateWebXml(TemplateName xtm, Services servlets, File webXml)
        throws ODStateException, IOException, TemplateException
    {
        if (null != xtm && null != servlets && null != webXml){

            TemplateRenderer template = Templates.GetTemplate(xtm);
            TemplateDataDictionary top = new gap.hapax.AbstractData();
            TemplateDataDictionary servlet;

            for (ClassName servletClassName : servlets){
                ClassDescriptor cd = Classes.ForServlet(servletClassName.getName());
                if (null != cd){
                    servlet = top.addSection(TemplateNames.WebXmlSection);
                    servlet.setVariable(TemplateNames.WebXmlSectionName,cd.getName());
                    servlet.setVariable(TemplateNames.WebXmlSectionClass,servletClassName.getName());
                    servlet.setVariable(TemplateNames.WebXmlSectionUrl,WebXmlPathStar(cd));
                    servlet.setVariable(TemplateNames.WebXmlSectionLoad,"-1");
                }
                else
                    throw new IllegalStateException("Missing class descriptor for '"+servletClassName+"'");
            }

            PrintWriter out = new PrintWriter(new FileWriter(webXml));
            try {
                template.render(top,out);

                return;
            }
            catch (TemplateException exc){
                throw new TemplateException("In template '"+xtm.source+"'.",exc);
View Full Code Here

Examples of gap.hapax.TemplateRenderer

    {
        if (null != xtm && null != pkg && null != imports && null != parent && null != field
            && null != parentClassName && null != childClassName && null != listClassName
            && null != listType && null != out)
        {
            TemplateRenderer template = Templates.GetTemplate(xtm);
            TemplateDataDictionary top = new gap.hapax.AbstractData();

            DefineDescription(xtm,top);

            DefinePrimitives(top);

            DefineImports(top,imports);

            DefineClass(pkg,parent,imports,top,TemplateNames.PrefixParent);

            Class childClass = FieldClass(PackageName(pkg),childClassName,imports);

            switch(listType){
            case ListPrimitive:{
                Primitive child = Primitive.For(childClassName,childClass);
                if (null != child){
                    DefineClass(PackageFor(child,childClass),child,ImportsFor(child,parent,imports),top,TemplateNames.PrefixChild);

                    top.setVariable(TemplateNames.ListClassName,listClassName);
                    top.setVariable(TemplateNames.ListType,"Primitive");

                    try {
                        template.render(top,out);
                    }
                    catch (TemplateException exc){
                        throw new TemplateException("In template '"+xtm.source+"'.",exc);
                    }
                }
                else
                    throw new TemplateException("Primitive type not found for name '"+childClassName+"'.");
 
            }
                break;
            case ListShort:
            case ListLong:{
                ClassDescriptor child = Classes.For(childClassName);
                if (null != child){

                    DefineClass(PackageFor(child,pkg),child,ImportsFor(child,imports),top,TemplateNames.PrefixChild);

                    top.setVariable(TemplateNames.ListClassName,listClassName);
                    if (gap.data.List.Type.ListShort == listType)
                        top.setVariable(TemplateNames.ListType,"Short");
                    else
                        top.setVariable(TemplateNames.ListType,"Long");

                    try {
                        template.render(top,out);
                    }
                    catch (TemplateException exc){
                        throw new TemplateException("In template '"+xtm.source+"'.",exc);
                    }
                }
                else if (null != childClass){

                    DefineClass(pkg,childClass,imports,top,TemplateNames.PrefixChild);

                    top.setVariable(TemplateNames.ListClassName,listClassName);
                    if (gap.data.List.Type.ListShort == listType)
                        top.setVariable(TemplateNames.ListType,"Short");
                    else
                        top.setVariable(TemplateNames.ListType,"Long");

                    try {
                        template.render(top,out);
                    }
                    catch (TemplateException exc){
                        throw new TemplateException("In template '"+xtm.source+"'.",exc);
                    }
                }
View Full Code Here

Examples of gap.hapax.TemplateRenderer

    {
        if (null != xtm && null != pkg && null != imports && null != parent && null != field
            && null != parentClassName && null != mapClassName && null != mapType
            && null != mapChild && null != out)
        {
            TemplateRenderer template = Templates.GetTemplate(xtm);
            TemplateDataDictionary top = new gap.hapax.AbstractData();

            DefineDescription(xtm,top);

            DefinePrimitives(top);

            DefineImports(top,imports);

            DefineClass(pkg,parent,imports,top,TemplateNames.PrefixParent);

            Class childClass = FieldClass(PackageName(pkg),mapChild.childValueClassName,imports);

            switch (mapType){
            case MapPrimitive:{
                Primitive child = Primitive.For(mapChild.childValueClassName,childClass);
                if (null != child){
                    DefineClass(PackageFor(child,childClass),child,ImportsFor(child,parent,imports),top,TemplateNames.PrefixChild);

                    top.setVariable(TemplateNames.MapClassName,mapClassName);
                    top.setVariable(TemplateNames.MapKeyType,mapChild.childKeyFieldType);
                    top.setVariable(TemplateNames.MapPValueType,child.local);

                    try {
                        template.render(top,out);
                    }
                    catch (TemplateException exc){
                        throw new TemplateException("In template '"+xtm.source+"'.",exc);
                    }
                }
                else
                    throw new TemplateException("Primitive type not found for name '"+mapChild.childValueClassName+"'.");
            }
                break;
            case MapShort: //(fall-through)
            case MapLong:{
                ClassDescriptor child = Classes.For(mapChild.childValueClassName);
                if (null != child){

                    DefineClass(PackageFor(child,pkg),child,ImportsFor(child,imports),top,TemplateNames.PrefixChild);

                    top.setVariable(TemplateNames.MapClassName,mapClassName);
                    top.setVariable(TemplateNames.MapKeyType,mapChild.childKeyFieldType);
                    top.setVariable(TemplateNames.MapKeyFieldName,mapChild.childKeyFieldName);
                    top.setVariable(TemplateNames.MapKeyFieldNameCamel,Camel(mapChild.childKeyFieldName));

                    try {
                        template.render(top,out);
                    }
                    catch (TemplateException exc){
                        throw new TemplateException("In template '"+xtm.source+"'.",exc);
                    }
                }
                else if (null != childClass){

                    DefineClass(pkg,childClass,imports,top,TemplateNames.PrefixChild);

                    top.setVariable(TemplateNames.MapClassName,mapClassName);
                    top.setVariable(TemplateNames.MapKeyType,mapChild.childKeyFieldType);
                    top.setVariable(TemplateNames.MapKeyFieldName,mapChild.childKeyFieldName);
                    top.setVariable(TemplateNames.MapKeyFieldNameCamel,Camel(mapChild.childKeyFieldName));

                    try {
                        template.render(top,out);
                    }
                    catch (TemplateException exc){
                        throw new TemplateException("In template '"+xtm.source+"'.",exc);
                    }
                }
View Full Code Here

Examples of org.expressme.webwind.renderer.TemplateRenderer

    }

    @Mapping("/")
    public Renderer index() throws Exception {
        List<Post> posts = DbUtils.queryForList("select id, title, content, creation from Post order by id desc");
        return new TemplateRenderer("/index.htm", "posts", posts);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.