Package freemarker.ext.beans

Examples of freemarker.ext.beans.BeansWrapper


   */
  public void testGet() throws Exception {
    SchemaInfo schemaInfo = new SchemaInfo();
    schemaInfo.setProperty("filename", "something.xsd");
    schemaInfo.setProperty("location", "http://localhost:8080/something.xsd");
    SchemaInfoModel model = new SchemaInfoModel(schemaInfo, new BeansWrapper());
    assertEquals("something.xsd", model.get("filename").toString());
    assertEquals("http://localhost:8080/something.xsd", model.get("location").toString());
  }
View Full Code Here


  public void generate(Book b, File directory) throws IOException {
    // FreeMarker configuration
    Configuration cfg = new Configuration();
    cfg.setDirectoryForTemplateLoading(templateDir);
    cfg.setObjectWrapper(new BeansWrapper());

    List<String> dirTree = createDirTree(b, directory);

    StringBuffer sb = new BookToTOC().generateTOC(b, cfg, dirTree);
    File root = saveToFile(new File(directory, dirTree.get(0)), sb);
View Full Code Here

  }

  public void generate(Book book, File directory, String outputFileName) throws IOException {
    Configuration cfg = new Configuration();
    cfg.setDirectoryForTemplateLoading(templateDir);
    cfg.setObjectWrapper(new BeansWrapper());
    cfg.setDefaultEncoding("UTF-8");

    StringBuffer latex = new BookToLatex(parser).generateLatex(book, cfg);

    // print the latex document to an archive
View Full Code Here

            try {
                result = 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

    throws
        TemplateModelException,
        InvocationTargetException,
        IllegalAccessException
    {
        BeansWrapper bwrapper =
            wrapper instanceof BeansWrapper
            ? (BeansWrapper)wrapper
            : BeansWrapper.getDefaultInstance();
        if(args != null && !args.isEmpty()) {
            Object[] aarg = new Object[1];
            for (Map.Entry<String, TemplateModel> entry: args.entrySet()) {
                Object arg = bwrapper.unwrap(entry.getValue());
                aarg[0] = arg;
                Method m = 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 = null;
            if (env != null) ow = env.getObjectWrapper();
            BeansWrapper bw =
                ow instanceof BeansWrapper
                ? (BeansWrapper)ow
                        : BeansWrapper.getDefaultInstance();
                return bw.newInstance(cl, arguments);
        }
View Full Code Here

    {
        config = new Configuration();
        // No <#include> and <#import> support
        config.setTemplateLoader(NOOP_TEMPLATE_LOADER);
        // BeansWrapper is closest to the JSR-223 idea of handling bindings
        config.setObjectWrapper(new BeansWrapper());
    }
View Full Code Here

            cl = ClassUtil.forName(classname);
        }
        catch (Exception e) {
            throw new TemplateModelException(e.getMessage());
        }
        BeansWrapper bw = BeansWrapper.getDefaultInstance();
        Object obj = bw.newInstance(cl, args.subList(1, args.size()));
        return bw.wrap(obj);
    }
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

    }
   
    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] = unwrap(args[i], wrapper);
        }
        return wrapper.wrap(((Function)getScriptable()).call(cx,
                ScriptableObject.getTopLevelScope(fnThis), fnThis, args));
    }
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.