Examples of VelocityContext


Examples of org.apache.flex.forks.velocity.VelocityContext

    if (template != null)
    {
      try
      {
        // create a velocity context
        VelocityContext velocityContext = VelocityManager.getCodeGenContext();

        //  SourceCodeBuffer tracks line number change during codegen
        SourceCodeBuffer out = new SourceCodeBuffer((int) source.size());

        //  create SourceCode wrappers for scripts
        Set<SourceCode> scriptSet = new LinkedHashSet<SourceCode>();
        for (Iterator iter = info.getScripts().iterator(); iter.hasNext(); )
        {
          Script script = (Script) iter.next();
          if (!script.isEmbedded())
          {
            scriptSet.add(new SourceCode(script.getText(), script.getXmlLineNumber(), out, map));
          }
          else
          {
            // use Source.getName() to construct the new VirtualFile name
            String n = source.getName().replace('\\', '/') + ":" + script.getXmlLineNumber() + "," + script.getEndXmlLineNumber();
            VirtualFile f = new TextFile(script.getText(), n, source.getParent(), MimeMappings.AS, source.getLastModified());

                        // line number map is for error reporting, so the names must come from error reporting...
                        LineNumberMap m = new LineNumberMap(source.getNameForReporting(), n);

                        m.put(script.getXmlLineNumber(), 1, (script.getEndXmlLineNumber() - script.getXmlLineNumber()));
                        // C: add this so that when unexpected EOF occurs, (last line + 1) maps to the last line
                        //    in the original XML Script block.
                        m.put(script.getEndXmlLineNumber(), script.getEndXmlLineNumber() - script.getXmlLineNumber() + 1, 1);

                        // 'n' must match 'n' in the include directive...
                        source.addSourceFragment(n, f, m);

                        // 'n' must match 'n' in the addSourceFragment call.
                        scriptSet.add(new SourceCode("include \"" + n + "\";", script.getXmlLineNumber(), out, map));
                    }
                }

                //  create SourceCode wrappers for metadata entries
                Set<SourceCode> metadataSet = new LinkedHashSet<SourceCode>();
                for (Iterator iter = info.getMetadata().iterator(); iter.hasNext(); )
                {
                    Script script = (Script)iter.next();
                    metadataSet.add(new SourceCode(script.getText(), script.getXmlLineNumber(), out, map));
                }

                //  create SourceCode wrappers for variable declarations
                Map<String, SourceCode> varDeclMap = new LinkedHashMap<String, SourceCode>();
                for (Iterator iter = info.getVarDecls().values().iterator(); iter.hasNext(); )
                {
                    DocumentInfo.VarDecl varDecl = (DocumentInfo.VarDecl)iter.next();
                    varDeclMap.put(varDecl.name, new SourceCode(varDecl.className, varDecl.line, out, map));
                }

                int superClassLineNumber = 1;

                Set<SourceCode> importNameSet = new LinkedHashSet<SourceCode>();
                for (Iterator i = info.getImportNames().iterator(); i.hasNext();)
                {
                    DocumentInfo.NameInfo importName = (DocumentInfo.NameInfo) i.next();
                    importNameSet.add(new SourceCode(importName.getName(), importName.getLine(), out, map));

                    if (importName.getName().equals(info.getQualifiedSuperClassName()))
                    {
                        superClassLineNumber = importName.getLine();
                    }
                }
                for (Iterator<String> i = bogusImports.iterator(); i.hasNext();)
                {
                    String importName = i.next();
                    importNameSet.add(new SourceCode(importName, 1, out, map));
                }

                Set<SourceCode> interfaceNameSet = new LinkedHashSet<SourceCode>();
                for (Iterator i = info.getInterfaceNames().iterator(); i.hasNext();)
                {
                    DocumentInfo.NameInfo interfaceName = (DocumentInfo.NameInfo) i.next();
                    interfaceNameSet.add(new SourceCode(interfaceName.getName(), interfaceName.getLine(), out, map));
                }

                // register values
                velocityContext.put("imports", importNameSet);
                velocityContext.put("variables", varDeclMap.entrySet());
                velocityContext.put("scripts", scriptSet);
                velocityContext.put("classMetaData", metadataSet);
                velocityContext.put("bindingManagementVariables", FrameworkDefs.bindingManagementVars);

                // C: should really give line number mappings to superclass name and interface names.
                velocityContext.put("superClassName", new SourceCode(info.getQualifiedSuperClassName(), superClassLineNumber, out, map));
                velocityContext.put("interfaceNames", interfaceNameSet);

                velocityContext.put("className", info.getClassName());
                velocityContext.put("packageName", info.getPackageName());

                // run the template!
                //long s2 = System.currentTimeMillis();
                //VelocityManager.parseTime += s2 - start;
                template.merge(velocityContext, out);
View Full Code Here

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

Examples of org.apache.velocity.VelocityContext

        + 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

Examples of org.apache.velocity.VelocityContext

    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

Examples of org.apache.velocity.VelocityContext

    public VelocityUtils() {
    }

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

Examples of org.apache.velocity.VelocityContext

    }

    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

Examples of org.apache.velocity.VelocityContext

            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

Examples of org.apache.velocity.VelocityContext

        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

Examples of org.apache.velocity.VelocityContext

        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

Examples of org.apache.velocity.VelocityContext

    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
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.