Package org.apache.velocity

Examples of org.apache.velocity.VelocityContext


    }
    return context;
  }

  public static VelocityContext getVelocityContext(){
    VelocityContext context = velocityContext.get();
    if(context == null){
      context = new VelocityContext();
      velocityContext.set(context);
    }
    return context;
  }
View Full Code Here


        + projectName.substring(1);

    this.useJPA = useJPA;

    // 往上下文中填入数据
    this.context = new VelocityContext();
    Map<String, String> contextMap = new HashMap<String, String>();
    contextMap.put("projectName", this.projectName);
    contextMap.put("packageName", packageName);
    if (this.useJPA)
      contextMap.put("entityName", this.projectName);
View Full Code Here

    this.useJPA = true;

    this.packageNamePath = packageName.replace(".", File.separator);

    // 往上下文中填入数据
    this.context = new VelocityContext();
    Map<String, String> contextMap = new HashMap<String, String>();
    contextMap.put("packageName", packageName);
    contextMap.put("entityName", entityName);
    context.put("context", contextMap);
    context.put("useJPA", this.useJPA);
View Full Code Here

    public VelocityUtils() {
    }

    public static String getRenderedTemplate(String templateName, Map contextMap) {
        return getRenderedTemplate(templateName, ((Context) (new VelocityContext(contextMap))));
    }
View Full Code Here

    }

    public static String getRenderedContent(String templateContent, Map contextMap) {
        try {
            StringWriter tempWriter = new StringWriter();
            VelocityContext context = new VelocityContext(contextMap);

            VelocityManager.getInstance().getVelocityEngine().evaluate(context, tempWriter, "getRenderedContent", templateContent);
            return tempWriter.toString();
        } catch (Exception e) {
            log.error("Error occurred rendering template content", e);
View Full Code Here

            while (st.hasMoreTokens()) {
                String classname = st.nextToken();

                try {
                    VelocityContext velocityContext = (VelocityContext) ObjectFactory.getObjectFactory()
                            .buildBean(Class.forName(classname));
                    contextList.add(velocityContext);
                } catch (Exception e) {
                    log.warn("Warning.  " + e.getClass().getName() + " caught while attempting to instantiate a chained VelocityContext, "
                            + classname + " -- skipping");
View Full Code Here

        IBindingFactory bfact = BindingDirectory.getFactory(Site.class);
        IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
        uctx.setDocument(new FileInputStream(m_configFile), m_configFile.getName(), null);
        uctx.pushObject(this);
        Object obj = uctx.unmarshalElement();
        VelocityContext vctx = new VelocityContext();
        List actives = new ArrayList();
        vctx.put("actives", actives);
        if (obj instanceof Menu) {
           
            // handle basic linkages with source relative to configuration file
            Menu menu = (Menu)obj;
            menu.setLinkages("");
            menu.loadContent(m_configFile.getAbsoluteFile().getParentFile());
           
            // generate single-menu site image
            vctx.put("menu", menu);
            addValues(menu.getValues(), vctx);
            recurseChildren(menu.getChildren(), vctx, actives);
           
        } else {
           
            // generate multiple-menu site image
            Site site = (Site)obj;
            ArrayList menus = site.getChildren();
            site.initialize(m_sourceRoot);
            vctx.put("site", site);
            addValues(site.getValues(), vctx);
            for (int i = 0; i < menus.size(); i++) {
                Menu menu = (Menu)menus.get(i);
                vctx.put("menu", menu);
                String[] priors = addValues(menu.getValues(), vctx);
                recurseChildren(menu.getChildren(), vctx, actives);
                if (priors != null) {
                    restoreValues(menu.getValues(), priors, vctx);
                }
View Full Code Here

        StringWriter writer = new StringWriter();

        VelocityEngine engine = new VelocityEngine();
        engine.init();

        VelocityContext velocityContext = new VelocityContext();

        velocityContext.put("test1", "@test1@");
        velocityContext.put("test2", "@test2@");

        assertTrue(engine.evaluate(velocityContext, writer, "mylogtag", "$test1$test2"));
        assertEquals(
            "@test1@@test2@",
            writer.getBuffer().toString());
View Full Code Here

    private Context createContext( PortletRequest  request,
                                   PortletResponse response,
                                   Map             context )
    {
        VelocityContext ctx = new VelocityContext(  );

        /* Inherited context */
        if ( context != null )
        {
            putAll( context, ctx );
View Full Code Here

                "performing " + methodName + " with templateFile '" + templateFile + "' and templateObjects '" +
                templateObjects + "'");
        }
        ExceptionUtils.checkEmpty("templateFile", templateFile);
        ExceptionUtils.checkNull("output", output);
        this.velocityContext = new VelocityContext();
        this.loadVelocityContext(templateObjects);

        Template template = (Template)this.discoveredTemplates.get(templateFile);
        if (template == null)
        {
View Full Code Here

TOP

Related Classes of org.apache.velocity.VelocityContext

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.