Package freemarker.ext.beans

Examples of freemarker.ext.beans.CollectionModel


      new ArrayList<Map<String,String>>();

    //if the filepath is an empty string (which is the case if the calling
    // macro could not find a grammar URL), just return an empty list
    if(filepath.equals("")) {
      return new CollectionModel(listOfJapeDocs,new DefaultObjectWrapper());
    }

    JapeDocParser parser = new JapeDocParser();
    try {
      listOfJapeDocs = parser.parse(filepath);
    } catch(Exception ex) {
      throw new GateRuntimeException("Problem parsing JAPE File "+filepath,ex);
    }

    // convert the docstrings according to the required format conversion!
    Converter converter = ConverterFactory.getConverter(fromFormat, toFormat);
    for(Map<String,String> entry : listOfJapeDocs) {
      entry.put("docstring",converter.convert(entry.get("docstring")));
    }

    return new CollectionModel(listOfJapeDocs,new DefaultObjectWrapper());
  }
View Full Code Here


  /**
   * 特殊包装set和map
   */
  public TemplateModel wrap(Object obj) throws TemplateModelException {
    if (obj == null) { return super.wrap(null); }
    if (obj instanceof List<?>) { return new CollectionModel((Collection<?>) obj, this); }
    // 使得set等集合可以排序
    if (obj instanceof Collection<?>) { return new SimpleSequence((Collection<?>) obj, this); }
    if (obj instanceof Map<?, ?>) {
      if (altMapWrapper) {
        return new FriendlyMapModel((Map<?, ?>) obj, this);
View Full Code Here

    }

    public void testValueStackMode() throws Exception {
        ScopesHashModel model = new ScopesHashModel(ObjectWrapper.BEANS_WRAPPER, null, null, ActionContext.getContext().getValueStack());

        CollectionModel stringList = null;

        stringList = (CollectionModel) model.get("stringList");
        assertEquals("one", stringList.get(0).toString());

        assertEquals("one", model.get("stringList[0]").toString());
        assertEquals("one", model.get("beanList[0].name").toString());
    }
View Full Code Here

    }

    public void testValueStackMode() throws Exception {
        ScopesHashModel model = new ScopesHashModel(ObjectWrapper.BEANS_WRAPPER, null, null, ActionContext.getContext().getValueStack());

        CollectionModel stringList = null;

        stringList = (CollectionModel) model.get("stringList");
        assertEquals("one", stringList.get(0).toString());

        assertEquals("one", model.get("stringList[0]").toString());
        assertEquals("one", model.get("beanList[0].name").toString());
    }
View Full Code Here

    }

    public void testValueStackMode() throws Exception {
        ScopesHashModel model = new ScopesHashModel(ObjectWrapper.BEANS_WRAPPER, null, null, ActionContext.getContext().getValueStack());

        CollectionModel stringList = null;

        stringList = (CollectionModel) model.get("stringList");
        assertEquals("one", stringList.get(0).toString());

        assertEquals("one", model.get("stringList[0]").toString());
        assertEquals("one", model.get("beanList[0].name").toString());
    }
View Full Code Here

        public TemplateModel wrap(Object object) throws TemplateModelException {
            if ( object instanceof Collection ) {
                Collection c = (Collection) object;
                if (c.isEmpty()) {
                    SimpleHash hash = new SimpleHash();
                    hash.put( "values", new CollectionModel( c, this ) );
                    return hash;
                }
                else {
                    Object o = c.iterator().next();
                    if ( clazz.isAssignableFrom( o.getClass() ) ) {
                        SimpleHash hash = new SimpleHash();
                        hash.put( "values", new CollectionModel( c, this ) );
                        return hash;
                    }   
                }
            }
           
View Full Code Here

        Configuration cfg = super.createConfiguration(data, clazz);
        cfg.setClassForTemplateLoading(getClass(), "templates");
        cfg.setObjectWrapper(new ObjectToMapWrapper<RulesList>(RulesList.class) {
                  @Override
                  protected void wrapInternal(Map properties, SimpleHash model, RulesList object) {
                      properties.put( "rules", new CollectionModel( object.rules, new ObjectToMapWrapper(RulesList.class) ) );
                  }
              });
        return cfg;
      }
View Full Code Here

    public TemplateModel wrap(Object object) throws TemplateModelException {
        // check for feature collection
        if (object instanceof FeatureCollection) {
            // create a model with just one variable called 'features'
            SimpleHash map = new SimpleHash();
            map.put("features", new CollectionModel(DataUtilities.list((FeatureCollection) object), this));
            map.put("type", wrap(((FeatureCollection) object).getSchema()));

            return map;
        } else if (object instanceof SimpleFeatureType) {
            SimpleFeatureType ft = (SimpleFeatureType) object;
View Full Code Here

        public void execute(Environment environment, Map map, TemplateModel[] templateModels,
                            TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException {
            Object property = invokeMethod(map);

            String alias = ((SimpleScalar) map.get("alias")).getAsString();
            CollectionModel list = (CollectionModel) environment.getVariable(alias);
            ArrayList<Object> result = new ArrayList<Object>();
            if (list != null) {
                TemplateModelIterator iterator = list.iterator();
                while (iterator.hasNext()) {
                    Object o = iterator.next();
                    result.add(o);
                }
            }

            if (property instanceof Collection) {
                result.addAll((Collection<?>) property);
            } else {
                result.add(property);
            }
            environment.setVariable(alias, new CollectionModel(result, new DefaultObjectWrapper()));
        }
View Full Code Here

     */
    protected static class CopyTemplateFeatureCollectionFactory implements TemplateFeatureCollectionFactory<CollectionModel> {
               
        @SuppressWarnings("unchecked")
        public CollectionModel createTemplateFeatureCollection(FeatureCollection collection, BeansWrapper wrapper) {
            return new CollectionModel(DataUtilities.list(collection), wrapper);
        }
View Full Code Here

TOP

Related Classes of freemarker.ext.beans.CollectionModel

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.