Package freemarker.ext.beans

Examples of freemarker.ext.beans.BeansWrapper


  public void testExec() throws Exception{
    List<Tag> tags = tagDao.findTag(50,TagDao.SORT_ALPH);
   
    List<Object> args = new ArrayList<Object>();   
    CollectionModel cm = new CollectionModel(tags,new BeansWrapper());
    args.add(cm);
   
    ComputeTagCloudMethod method = new ComputeTagCloudMethod();
    SimpleHash map = (SimpleHash)method.exec(args);
    assertEquals(6,map.size());
View Full Code Here


  private final Logger logger = LoggerFactory.getLogger(BeangleFreemarkerManager.class);

  @Override
  protected ObjectWrapper createObjectWrapper(ServletContext servletContext) {
    BeansWrapper wrapper = new BeangleObjectWrapper(altMapWrapper);
    // cacheBeanWrapper should be false in most case.
    wrapper.setUseCache(cacheBeanWrapper);
    return wrapper;
  }
View Full Code Here

  public Writer getWriter(Writer writer, Map params) throws TemplateModelException, IOException {
    Component bean = getBean();
    // Container container = (Container)
    // stack.getContext().get(ActionContext.CONTAINER);
    // container.inject(bean);
    BeansWrapper objectWrapper = BeansWrapper.getDefaultInstance();

    for (Iterator iterator = params.entrySet().iterator(); iterator.hasNext();) {
      Map.Entry<String, Object> entry = (Map.Entry<String, Object>) iterator.next();
      String key = entry.getKey();
      Object value = entry.getValue();
      if (value != null) {
        Method m = ComponentHelper.getWriteMethod(bean, key);
        if (null != m) {
          if (value instanceof TemplateModel) {
            try {
              value = objectWrapper.unwrap((TemplateModel) value);
            } catch (TemplateModelException e) {
              logger.error("failed to unwrap [" + value + "] it will be ignored", e);
            }
          }
          try {
View Full Code Here

    }
   
    public Object exec(List arguments) throws TemplateModelException {
        Context cx = Context.getCurrentContext();
        Object[] args = arguments.toArray();
        BeansWrapper wrapper = getWrapper();
        for (int i = 0; i < args.length; i++) {
            args[i] = wrapper.unwrap((TemplateModel)args[i]);
        }
        return wrapper.wrap(((Function)getScriptable()).call(cx,
                ScriptableObject.getTopLevelScope(fnThis), fnThis, args));
    }
View Full Code Here

   
    public void setUp() throws Exception {
        dataModel.put("message", "Hello, world!");
       
        if (testName.equals("bean-maps")) {
            BeansWrapper w1 = new BeansWrapper();
            BeansWrapper w2 = new BeansWrapper();
            BeansWrapper w3 = new BeansWrapper();
            BeansWrapper w4 = new BeansWrapper();
            BeansWrapper w5 = new BeansWrapper();
            BeansWrapper w6 = new BeansWrapper();
            BeansWrapper w7 = new BeansWrapper();
   
            w1.setExposureLevel(BeansWrapper.EXPOSE_PROPERTIES_ONLY);
            w2.setExposureLevel(BeansWrapper.EXPOSE_PROPERTIES_ONLY);
            w3.setExposureLevel(BeansWrapper.EXPOSE_NOTHING);
            w4.setExposureLevel(BeansWrapper.EXPOSE_NOTHING);
            w5.setExposureLevel(BeansWrapper.EXPOSE_ALL);
            w6.setExposureLevel(BeansWrapper.EXPOSE_ALL);
   
            w1.setMethodsShadowItems(true);
            w2.setMethodsShadowItems(false);
            w3.setMethodsShadowItems(true);
            w4.setMethodsShadowItems(false);
            w5.setMethodsShadowItems(true);
            w6.setMethodsShadowItems(false);
   
            w7.setSimpleMapWrapper(true);
   
            Object test = getTestBean();
   
            dataModel.put("m1", w1.wrap(test));
            dataModel.put("m2", w2.wrap(test));
            dataModel.put("m3", w3.wrap(test));
            dataModel.put("m4", w4.wrap(test));
            dataModel.put("m5", w5.wrap(test));
            dataModel.put("m6", w6.wrap(test));
            dataModel.put("m7", w7.wrap(test));
   
            dataModel.put("s1", w1.wrap("hello"));
            dataModel.put("s2", w1.wrap("world"));
            dataModel.put("s3", w5.wrap("hello"));
            dataModel.put("s4", w5.wrap("world"));
View Full Code Here

            try {
                result = (List) listClass.newInstance();
            } catch (Exception e) {
                throw new TemplateModelException("Error instantiating an object of type " + listClass.getName() + "\n" + e.getMessage());
            }
            BeansWrapper bw = BeansWrapper.getDefaultInstance();
            for (int i=0; i<list.size(); i++) {
                Object elem = list.get(i);
                if (elem instanceof TemplateModel) {
                    elem = bw.unwrap((TemplateModel) elem);
                }
                result.add(elem);
            }
            unwrappedList = result;
        }
View Full Code Here

            } catch (Exception e) {
                throw new TemplateModelException("Error instantiating map of type " + mapClass.getName() + "\n" + e.getMessage());
            }
            // Create a copy to maintain immutability semantics and
            // Do nested unwrapping of elements if necessary.
            BeansWrapper bw = BeansWrapper.getDefaultInstance();
            for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
                Map.Entry entry = (Map.Entry) it.next();
                Object key = entry.getKey();
                Object value = entry.getValue();
                if (value instanceof TemplateModel) {
                    value = bw.unwrap((TemplateModel) value);
                }
                m.put(key, value);
            }
            unwrappedMap=m;
        }
View Full Code Here

    throws
        TemplateModelException,
        InvocationTargetException,
        IllegalAccessException
    {
        BeansWrapper bwrapper =
            wrapper instanceof BeansWrapper
            ? (BeansWrapper)wrapper
            : BeansWrapper.getDefaultInstance();
        if(args != null && !args.isEmpty()) {
            Object[] aarg = new Object[1];
            for (Iterator iter = args.entrySet().iterator(); iter.hasNext();)
            {
                Map.Entry entry = (Map.Entry) iter.next();
                Object arg = bwrapper.unwrap((TemplateModel)entry.getValue());
                aarg[0] = arg;
                Method m = (Method)propertySetters.get(entry.getKey());
                if (m == null) {
                    if (dynaSetter == null) {
                        throw new TemplateModelException("Unknown property "
View Full Code Here

            }
        }

        public Object exec(List arguments) throws TemplateModelException {
            ObjectWrapper ow = env.getObjectWrapper();
            BeansWrapper bw =
                ow instanceof BeansWrapper
                ? (BeansWrapper)ow
                : BeansWrapper.getDefaultInstance();
            return bw.newInstance(cl, arguments);
        }
View Full Code Here

    return json;
  }

  private String getFromFreemarkerTemplate(Map<String, Object> model, String templateId)
      throws TemplateNotFoundException {
    BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
    TemplateHashModel staticModels = wrapper.getStaticModels();
    Object servicesStatic = null;
    try {
      servicesStatic = staticModels.get(CoreServices.class.getName());
    } catch (TemplateModelException e) {
      throw new JibeRuntimeException("Services class can not be inserted into template model", e);
View Full Code Here

TOP

Related Classes of freemarker.ext.beans.BeansWrapper

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.