01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.geoserver.template;
06:
07: import freemarker.ext.beans.BeansWrapper;
08: import freemarker.ext.beans.MapModel;
09: import freemarker.template.TemplateModel;
10: import freemarker.template.TemplateModelException;
11: import freemarker.template.TemplateSequenceModel;
12: import java.util.ArrayList;
13: import java.util.HashSet;
14: import java.util.Map;
15: import java.util.Set;
16:
17: /**
18: * A freemarker model that's at the same time a sequence and a map
19: */
20: public class SequenceMapModel extends MapModel implements
21: TemplateSequenceModel {
22: private ArrayList list;
23:
24: public SequenceMapModel(Map map, BeansWrapper wrapper) {
25: super (map, wrapper);
26:
27: this .list = new ArrayList(map.values());
28: }
29:
30: public TemplateModel get(int index) throws TemplateModelException {
31: return wrap(list.get(index));
32: }
33:
34: protected Set keySet() {
35: // override, just return the map contents
36: Set set = new HashSet();
37: set.addAll(((Map) object).keySet());
38:
39: return set;
40: }
41: }
|