Package org.rythmengine.template

Examples of org.rythmengine.template.ITemplate


     * @param args render args array
     */
    public void render(Writer w, File file, Object... args) {
        outputMode.set(OutputMode.writer);
        try {
            ITemplate t = getTemplate(file, args);
            t.render(w);
        } finally {
            renderCleanUp();
        }
    }
View Full Code Here


            TemplateClass tc = classes().getByTemplate(key, false);
            if (null == tc) {
                tc = new TemplateClass(new StringTemplateResource(template), this);
                //classes().add(key, tc);
            }
            ITemplate t = tc.asTemplate(this);
            setRenderArgs(t, args);
            return t.render();
        } finally {
            renderCleanUp();
        }
    }
View Full Code Here

     * @param args     the render args array
     * @return render result
     */
    public String substitute(String template, Object... args) {
        try {
            ITemplate t = getTemplate(BasicRythm.INSTANCE, template, args);
            return t.render();
        } finally {
            renderCleanUp();
        }
    }
View Full Code Here

     * @param args the render args array
     * @return render result
     */
    public String substitute(File file, Object... args) {
        try {
            ITemplate t = getTemplate(file, args, BasicRythm.INSTANCE);
            return t.render();
        } finally {
            renderCleanUp();
        }
    }
View Full Code Here

            TemplateClass tc = classes().getByTemplate(key);
            if (null == tc) {
                tc = new TemplateClass(template, this, new ToString(argClass));
                //classes().add(key, tc);
            }
            ITemplate t = tc.asTemplate(this);
            t.__setRenderArg(0, obj);
            return t.render();
        } finally {
            renderCleanUp();
        }
    }
View Full Code Here

            TemplateClass tc = classes().getByTemplate(key);
            if (null == tc) {
                tc = new TemplateClass(new ToStringTemplateResource(key), this, new AutoToString(c, key));
                //classes().add(key, tc);
            }
            ITemplate t = tc.asTemplate(this);
            t.__setRenderArg(0, obj);
            return t.render();
        } finally {
            renderCleanUp();
        }
    }
View Full Code Here

                        nonExistsTemplatesChecker = new NonExistsTemplatesChecker();
                    }
                    return "";
                }
            }
            ITemplate t = tc.asTemplate(this);
            setRenderArgs(t, args);
            return t.render();
        } finally {
            renderCleanUp();
        }
    }
View Full Code Here

        Sandbox.enterSafeZone(secureCode);
        RythmEvents.ENTER_INVOKE_TEMPLATE.trigger(this, (TemplateBase) caller);
        try {
            // try tag registry first
            ITemplate t = _tags.get(name);
            if (null == t) {
                t = _templates.get(name);
            }
            if (null == t) {
                // is calling self
                if (S.isEqual(name, caller.__getName())) t = caller;
            }

            if (null == t) {
                // try imported path
                TemplateClass tc = caller.__getTemplateClass(true);
                if (null != tc.importPaths) {
                    for (String s : tc.importPaths) {
                        String name0 = s + "." + name;
                        t = _tags.get(name0);
                        if (null == t) t = _templates.get(name0);
                        if (null != t) break;
                    }
                }

                // try relative path
                if (null == t) {
                    String callerName = tc.getTagName();
                    int pos = -1;
                    if (null != callerName) pos = callerName.lastIndexOf(".");
                    if (-1 != pos) {
                        String name0 = callerName.substring(0, pos) + "." + name;
                        t = _tags.get(name0);
                        if (null == t) t = _templates.get(name0);
                    }
                }

                // try load the tag from resource
                if (null == t) {
                    tc = resourceManager().tryLoadTemplate(name, tc);
                    if (null != tc) t = _templates.get(tc.getTagName());
                    if (null == t) {
                        if (ignoreNonExistsTag) {
                            if (logger.isDebugEnabled()) {
                                logger.debug("cannot find tag: " + name);
                            }
                            _nonExistsTags.add(name);
                            if (isDevMode() && nonExistsTemplatesChecker == null) {
                                nonExistsTemplatesChecker = new NonExistsTemplatesChecker();
                            }
                            return;
                        } else {
                            throw new NullPointerException("cannot find tag: " + name);
                        }
                    }
                    t = t.__cloneMe(this, caller);
                }
            }

            if (!(t instanceof JavaTagBase)) {
                // try refresh the tag loaded from template file under tag root
                // note Java source tags are not reloaded here
                String cn = t.getClass().getName();
                TemplateClass tc0 = classes().getByClassName(cn);
                if (null == tc0) {
                    System.out.println(t.getClass());
                    System.out.println(name);
                    System.out.println(cn);
                    System.out.println(caller.getClass());
                }
                t = tc0.asTemplate(caller, this);
            } else {
                t = t.__cloneMe(this, caller);
            }

            if (null != params) {
                if (t instanceof JavaTagBase) {
                    ((JavaTagBase) t).__setRenderArgs0(params);
                } else {
                    for (int i = 0; i < params.size(); ++i) {
                        ITag.__Parameter param = params.get(i);
                        if (null != param.name) t.__setRenderArg(param.name, param.value);
                        else t.__setRenderArg(i, param.value);
                    }
                }
            }
            if (null == body && null != params) {
                body = (ITag.__Body) params.getByName("__body");
                if (null == body) {
                    body = (ITag.__Body) params.getByName("_body");
                }
            }
            if (null != body) {
                t.__setRenderArg("__body", body);
                t.__setRenderArg("_body", body); // for compatibility
            }
            RythmEvents.ON_TAG_INVOCATION.trigger(this, F.T2((TemplateBase) caller, t));
            try {
                if (null != context) {
                    t.__setBodyContext(context);
                }
                t.__setSecureCode(secureCode).__call(line);
            } finally {
                RythmEvents.TAG_INVOKED.trigger(this, F.T2((TemplateBase) caller, t));
            }
        } finally {
            RythmEvents.EXIT_INVOKE_TEMPLATE.trigger(this, (TemplateBase) caller);
View Full Code Here

    }

    @Override
    protected void call(__ParameterList params, __Body body) {

        final ITemplate template = createTemplate();
       
        if (params.asMap().isEmpty()){
       
            final List<Object> templateArguments = new ArrayList<Object>();
           
            for (final Iterator<__Parameter> iter = params.iterator(); iter.hasNext();){
               
                final __Parameter param = iter.next();
               
                templateArguments.add(param.value);
               
            }
           
            template.__setRenderArgs(templateArguments.toArray());
           
        } else {
       
            template.__setRenderArgs(params.asMap());
           
        }
       
        if (body != null){
       
            try {
               
                templateSetBodyMethod.invoke(template, body);
               
            } catch (Exception e) {
               
                throw new IllegalStateException(e);
               
            }
       
        }
       
        this.p(template.render());
       
    }
View Full Code Here

       
    }
   
    protected ITemplate createTemplate(){
       
        ITemplate template = null;
       
        if (disableFileWrite) {
           
            template = Rythm.engine().getTemplate(templateString);
           
View Full Code Here

TOP

Related Classes of org.rythmengine.template.ITemplate

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.