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.wfsv.response.v1_1_0;
06:
07: import freemarker.ext.beans.CollectionModel;
08: import freemarker.template.SimpleHash;
09: import freemarker.template.SimpleSequence;
10: import freemarker.template.TemplateModel;
11: import freemarker.template.TemplateModelException;
12: import org.geoserver.template.FeatureWrapper;
13: import org.geotools.data.postgis.FeatureDiffReader;
14: import java.util.Arrays;
15: import java.util.HashMap;
16:
17: /**
18: * Extends the FeatureWrapper so that FeatureDiffReaders can be provided to the
19: * template as well
20: *
21: * @author Andrea Aime - TOPP
22: */
23: public class FeatureDiffWrapper extends FeatureWrapper {
24:
25: public TemplateModel wrap(Object object)
26: throws TemplateModelException {
27: if (object instanceof FeatureDiffReader[]) {
28: HashMap map = new HashMap();
29: map.put("queryDiffs", new SimpleSequence(Arrays
30: .asList((FeatureDiffReader[]) object), this ));
31:
32: return new SimpleHash(map);
33: } else if (object instanceof FeatureDiffReader) {
34: HashMap map = new HashMap();
35: FeatureDiffReader reader = (FeatureDiffReader) object;
36: map.put("differences", new CollectionModel(
37: new FeatureDiffCollection(reader), this ));
38: map.put("fromVersion", reader.getFromVersion());
39: map.put("toVersion", reader.getToVersion());
40: map.put("typeName", reader.getSchema().getTypeName());
41:
42: return new SimpleHash(map);
43: }
44:
45: return super.wrap(object);
46: }
47: }
|