Package freemarker.template

Examples of freemarker.template.SimpleHash


    public static class LazyLoadingModel implements TemplateHashModel {
        private final SimpleHash eagerModel;
        private final ODatabaseDocumentTx db;

        public LazyLoadingModel(final Map<String, Object> eagerModel, final ODatabaseDocumentTx db) {
            this.eagerModel = new SimpleHash(eagerModel);
            this.db = db;
        }
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;

            // create a variable "attributes" which his a list of all the
            // attributes, but at the same time, is a map keyed by name
            Map attributeMap = new LinkedHashMap();
            for (int i = 0; i < ft.getAttributeCount(); i++) {
                AttributeDescriptor type = ft.getDescriptor(i);

                Map attribute = new HashMap();
                attribute.put("name", type.getLocalName());
                attribute.put("type", type.getType().getBinding().getName());
                attribute.put("isGeometry", Boolean.valueOf(Geometry.class.isAssignableFrom(type.getType().getBinding())));

                attributeMap.put(type.getLocalName(), attribute);
            }

            // build up the result, feature type is represented by its name an
            // attributes
            SimpleHash map = new SimpleHash();
            map.put("attributes", new SequenceMapModel(attributeMap, this));
            map.put("name", ft.getTypeName());
            return map;
        } else if (object instanceof SimpleFeature) {

            SimpleFeature feature = (SimpleFeature) object;

            // create the model
            SimpleHash map = new SimpleHash();

            // next create the Map representing the per attribute useful
            // properties for a template
            Map attributeMap = new FeatureAttributesMap(feature);
            map.putAll(attributeMap);

            Catalog cat = getCatalog();

            if (cat != null){
                NamespaceInfo ns = cat.getNamespaceByURI(
                        feature.getFeatureType().getName().getNamespaceURI()
                        );

                if (ns != null){
                    FeatureTypeInfo info = cat.getResourceByName(
                            ns.getPrefix(),
                            feature.getFeatureType().getName().getLocalPart(),
                            FeatureTypeInfo.class
                            );

                    if (info != null){
                        map.put("type", info);
                    }
                }
            }

            if (map.get("type") == null){
                map.put("type", buildDummyFeatureTypeInfo(feature));
            }

            // Add the metadata after setting the attributes so they aren't masked by feature attributes
            map.put("fid", feature.getID());
            map.put("typeName", feature.getFeatureType().getTypeName());

            // create a variable "attributes" which his a list of all the
            // attributes, but at the same time, is a map keyed by name
            map.put("attributes", new SequenceMapModel(attributeMap, this));

            return map;
        }

        return super.wrap(object);
View Full Code Here

            if (template != null) {
                ftlTemplatesCache.put(path, template);  
            }
        }
       
        SimpleHash templateContext = new SimpleHash();
        templateContext.putAll(templateRoot);
      if (params != null) {
           Set entrySet = params.entrySet();
           Iterator iter = entrySet.iterator();
           while (iter.hasNext()) {
                 Map.Entry entry = (Map.Entry)iter.next();
                 String key = (String)entry.getKey();
                Object val = entry.getValue();
                if (val != null) {
                    templateContext.put(key, val);
                }
           }
        }
        template.process(templateContext, writer);
    }
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", templateFeatureCollectionFactory.createTemplateFeatureCollection((FeatureCollection) object, this));
            map.put("type", wrap(((FeatureCollection) object).getSchema()));

            return map;
        } else if (object instanceof ComplexType) {
           
            return buildType ((ComplexType) object);
View Full Code Here

            attributeMap.put(descr.getName().toString(), attribute);
        }

        // build up the result, feature type is represented by its name an
        // attributes
        SimpleHash map = new SimpleHash();
        map.put("attributes", new SequenceMapModel(attributeMap, this));
        map.put("name", ft.getName().getLocalPart());
        map.put("namespace", getNamespace(ft.getName()));
        map.put("prefix", getPrefix(ft.getName()));
       
        return map;
    }
View Full Code Here

        return map;
    }
   
    private SimpleHash buildComplex(ComplexAttribute att){
        // create the model
        SimpleHash map = new SimpleHash();

        // next create the Map representing the per attribute useful
        // properties for a template
        Map attributeMap = new FeatureAttributesMap(att);
        map.putAll(attributeMap);

        Catalog cat = getCatalog();

        FeatureTypeInfo info = null;
        if (cat != null){
            info = cat.getResourceByName(
                        att.getType().getName().getNamespaceURI(),
                        att.getType().getName().getLocalPart(),
                        FeatureTypeInfo.class
                        );

            if (info != null){
               map.put("type", info);
           }
        }

        if (info == null){
            map.put("type", buildDummyFeatureTypeInfo(att));
        }
       
        // Add the metadata after setting the attributes so they aren't masked by feature attributes
        if (att.getIdentifier() != null) {
            map.put("fid", att.getIdentifier().getID());
        } else {
            map.put("fid", "");
        }
        map.put("typeName", att.getType().getName().getLocalPart());
       
        // create a variable "attributes" which his a list of all the
        // attributes, but at the same time, is a map keyed by name
        map.put("attributes", new SequenceMapModel(attributeMap, this));

        return map;
    }
View Full Code Here

    }
   
    public void renderHead(IHeaderResponse response) {
        try {
            //render css
            SimpleHash model = new SimpleHash();
            model.put("markupId", getMarkupId());
            response.renderString( renderTemplate("OL-css.ftl", model) );
           
            //TODO: point back to GeoServer
            response.renderJavascriptReference("http://openlayers.org/api/OpenLayers.js")
           
            model.put("layers", layer.getName());
            model.put("styles", style.getName());
           
            bbox(layer, model);
           
            //render
            model.put("ran", rand.nextInt());
            response.renderOnLoadJavascript(renderTemplate("OL-onload.ftl", model));
        }
        catch( Exception e ) {
            throw new RuntimeException(e);
        }
View Full Code Here

                //no style specified and layer did not change, do not change style
            }
        }
       
        try {
            SimpleHash model = new SimpleHash();
            model.put("markupId", getMarkupId());
            model.put("layers", layer.getName());
            model.put("styles", style.getName());
            bbox(layer, model);
            model.put("ran", rand.nextInt());
            model.put("layerChanged", !layer.equals(this.layer));
           
            target.appendJavascript(renderTemplate("OL-update.ftl", model));
           
            this.layer = layer;
            this.style = style;
View Full Code Here

        final ObjectWrapper wrapper = configuration.getObjectWrapper();
        configuration.setObjectWrapper(new ObjectWrapper() {
            public TemplateModel wrap(Object obj) throws TemplateModelException {
                TemplateModel model = wrapper.wrap(obj);
                if ( model instanceof SimpleHash ) {
                    SimpleHash hash = (SimpleHash) model;
                    if ( hash.get( "page" ) == null ) {
                        PageInfo pageInfo = (PageInfo) request.getAttributes().get( PageInfo.KEY );
                        if ( pageInfo != null ) {
                            hash.put( "page", pageInfo );   
                        }
                    }
                }
                return model;
            }
View Full Code Here

        @Override
        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;
                    }   
                }
            }
           
            if ( object != null && clazz.isAssignableFrom( object.getClass() ) ) {
                HashMap map = new HashMap();
               
                ClassProperties cp = OwsUtils.getClassProperties(clazz);
                for ( String p : cp.properties() ) {
                    if ( "Class".equals( p ) ) continue;
                    Object value = OwsUtils.get(object, p);
                    if ( value == null ) {
                        value = "null";
                    }
                   
                    map.put( Character.toLowerCase(p.charAt(0)) + p.substring(1), value.toString());   
                   
                }
          
                SimpleHash model = new SimpleHash();
                model.put( "properties", new MapModel(map, this) );
                model.put( "className", clazz.getSimpleName() );
               
                wrapInternal(map, model, (T) object);
                return model;
            }
           
View Full Code Here

TOP

Related Classes of freemarker.template.SimpleHash

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.