1
2
3
4
5
6
7 package nl.mineleni.cbsviewer.servlet.wms;
8
9 import java.io.File;
10 import java.util.List;
11
12 import javax.xml.bind.JAXBContext;
13 import javax.xml.bind.JAXBElement;
14 import javax.xml.bind.JAXBException;
15 import javax.xml.bind.Unmarshaller;
16
17 import nl.mineleni.cbsviewer.servlet.wms.xml.AttributeValueFilter;
18 import nl.mineleni.cbsviewer.servlet.wms.xml.FilterList;
19
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23
24
25
26
27
28
29
30
31 public class AttributeValuesFilter {
32
33
34 private static final Logger LOGGER = LoggerFactory
35 .getLogger(AttributeValuesFilter.class);
36
37
38
39
40 private transient List<AttributeValueFilter> filters;
41
42
43 private transient boolean hasFilters;
44
45
46
47
48 public AttributeValuesFilter() {
49 try {
50 final JAXBContext jc = JAXBContext
51 .newInstance("nl.mineleni.cbsviewer.servlet.wms.xml");
52 final Unmarshaller u = jc.createUnmarshaller();
53 final File f = new File(this.getClass().getClassLoader()
54 .getResource("AttributeValuesFilter.xml").getFile());
55 @SuppressWarnings("unchecked")
56 final JAXBElement<FilterList> element = (JAXBElement<FilterList>) u
57 .unmarshal(f);
58 final FilterList fList = element.getValue();
59 this.filters = fList.getFilter();
60 this.hasFilters = (!this.filters.isEmpty());
61 } catch (final JAXBException e) {
62 LOGGER.error(
63 "Er is een fout opgetreden bij het inlezen van de filters.",
64 e);
65 }
66 }
67
68
69
70
71
72
73
74
75 public String filterValue(final Object input) {
76 if (null != input) {
77 for (final AttributeValueFilter filter : this.filters) {
78 if (input.toString().equals(filter.getInputAttributeValue())) {
79 return filter.getOutputAttributeValue();
80 }
81 }
82 return input.toString();
83 }
84 return null;
85 }
86
87
88
89
90
91
92 public boolean hasFilters() {
93 return this.hasFilters;
94 }
95
96 }