Package freemarker.template

Examples of freemarker.template.TemplateHashModel


        env.process();
    }
   
    public static void addAllOfbizTransforms(Map<String, Object> context) {
        BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
        TemplateHashModel staticModels = wrapper.getStaticModels();
        if (context == null) {
            context = FastMap.newInstance();
        }
        context.put("Static", staticModels);
        context.putAll(ftlTransforms);
View Full Code Here


                Map fmcontext = new HashMap();

                NodeModel nodeModel = NodeModel.parse(ins);
                fmcontext.put("doc", nodeModel);
                BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
                TemplateHashModel staticModels = wrapper.getStaticModels();
                fmcontext.put("Static", staticModels);

                template.process(fmcontext, outWriter);
                s = outWriter.toString();
            } catch(Exception ex) {
View Full Code Here

                    Template template = new Template("FMImportFilter", templateReader, config);
                    NodeModel nodeModel = NodeModel.wrap(this.rootNodeForTemplate);

                    Map<String, Object> context = FastMap.newInstance();
                    BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
                    TemplateHashModel staticModels = wrapper.getStaticModels();
                    context.put("Static", staticModels);

                    context.put("doc", nodeModel);
                    template.process(context, outWriter);
                    String s = outWriter.toString();
View Full Code Here

    }

    ServletContext context = event.getServletContext();

    try {
      TemplateHashModel staticModels = BeansWrapper.getDefaultInstance()
          .getStaticModels();
      context.setAttribute("Constants", staticModels
          .get("${package}.Constants"));
      context.setAttribute("JSONUtil", staticModels
          .get("com.googlecode.jsonplugin.JSONUtil"));
      context.setAttribute("JptLocalizedTextUtil", staticModels
          .get("${package}.util.JptLocalizedTextUtil"));

    } catch (Exception e) {
      if (logger.isDebugEnabled()) {
        logger.debug(e);
View Full Code Here

public class ErrorMessagesTest {

    @Test
    public void getterMessage() throws TemplateModelException {
        BeansWrapper bw = new BeansWrapperBuilder(Configuration.VERSION_2_3_0).build();
        TemplateHashModel thm = (TemplateHashModel) bw.wrap(new TestBean());
        try {
            thm.get("foo");
        } catch (TemplateModelException e) {
            e.printStackTrace();
            final String msg = e.getMessage();
            assertTrue(msg.contains("\"foo\""));
            assertTrue(msg.contains("existing sub-variable"));
        }
        assertNull(thm.get("bar"));
    }
View Full Code Here

    }
   
    public DebugModel[] get(String[] keys) throws TemplateModelException, RemoteException
    {
        DebugModel[] dm = new DebugModel[keys.length];
        TemplateHashModel h = (TemplateHashModel)model;
        for (int i = 0; i < keys.length; i++)
        {
            dm[i] = getDebugModel(h.get(keys[i]));
        }
        return dm;
    }
View Full Code Here

        final BeansWrapper bw = new BeansWrapper();

        assertTrue(((TemplateBooleanModel) bw.wrap(Boolean.TRUE)).getAsBoolean());
        assertFalse(((TemplateBooleanModel) bw.wrap(Boolean.FALSE)).getAsBoolean());
       
        TemplateHashModel tm = (TemplateHashModel) bw.wrap(Boolean.TRUE);
        assertNotNull(tm.get("hashCode"));
        assertNotNull(tm.get("class"));
        bw.setExposureLevel(BeansWrapper.EXPOSE_PROPERTIES_ONLY);
        assertNull(tm.get("hashCode"));
        assertNotNull(tm.get("class"));
        bw.setExposureLevel(BeansWrapper.EXPOSE_NOTHING);
        assertNull(tm.get("hashCode"));
        assertNull(tm.get("class"));
        bw.setExposureLevel(BeansWrapper.EXPOSE_ALL);
        assertNotNull(tm.get("hashCode"));
        assertNotNull(tm.get("class"));
       
        assertSame(tm, bw.wrap(Boolean.TRUE));
    }
View Full Code Here

    private boolean isSimpleMapWrapper(BeansWrapper bw) throws TemplateModelException {
        return bw.wrap(new HashMap()) instanceof SimpleMapModel;
    }
   
    private boolean exposesFields(BeansWrapper bw) throws TemplateModelException {
        TemplateHashModel thm = (TemplateHashModel) bw.wrap(new C());
        TemplateScalarModel r = (TemplateScalarModel) thm.get("foo");
        if (r == null) return false;
        assertEquals("FOO", r.getAsString());
        return true;
    }
View Full Code Here

        assertEquals("FOO", r.getAsString());
        return true;
    }

    private boolean exposesProperties(BeansWrapper bw) throws TemplateModelException {
        TemplateHashModel thm = (TemplateHashModel) bw.wrap(new C());
        TemplateScalarModel r = (TemplateScalarModel) thm.get("bar");
        if (r == null) return false;
        assertEquals("BAR", r.getAsString());
        return true;
    }
View Full Code Here

        assertEquals("BAR", r.getAsString());
        return true;
    }

    private boolean exposesMethods(BeansWrapper bw) throws TemplateModelException {
        TemplateHashModel thm = (TemplateHashModel) bw.wrap(new C());
        return thm.get("getBar") != null;
    }
View Full Code Here

TOP

Related Classes of freemarker.template.TemplateHashModel

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.