1 /*
2 * Copyright (c) 2013, Dienst Landelijk Gebied - Ministerie van Economische Zaken
3 *
4 * Gepubliceerd onder de BSD 2-clause licentie,
5 * zie https://github.com/MinELenI/CBSviewer/blob/master/LICENSE.md voor de volledige licentie.
6 */
7 package nl.mineleni.cbsviewer.servlet.wms;
8
9 import nl.mineleni.cbsviewer.util.AvailableLayersBean;
10
11 /**
12 * Verzorgt de filterconfiguratie van attribuut namen.
13 *
14 * @author prinsmc
15 *
16 */
17 public class AttributesNamesFilter {
18 /**
19 * lijst met beschikbare filters.
20 */
21 private final transient AvailableLayersBean layers = new AvailableLayersBean();
22
23 /**
24 * Filtert de input.
25 *
26 * @param attribute
27 * een te filteren waarde
28 * @param layerID
29 * de identifier van de layer
30 *
31 * @return de gefilterde input zoals in de filtermapping beschreven.
32 */
33 public String filterValue(final String attribute, final String layerID) {
34 if (this.hasFilters(layerID)) {
35 final String[] aliases = this.layers.getLayerByID(layerID)
36 .getAliases().split(",\\s*");
37 final String[] attributes = this.layers.getLayerByID(layerID)
38 .getAttributes().split(",\\s*");
39
40 for (int i = 0; i < attributes.length; i++) {
41 if (attributes[i].equals(attribute)) {
42 return aliases[i];
43 }
44 }
45 }
46 return attribute;
47 }
48
49 /**
50 * Geeft aan of het filter inhoud heeft.
51 *
52 * @param layerID
53 * de identifier van de layer
54 *
55 * @return {@code true} als het filter inhoud heeft
56 */
57 private boolean hasFilters(final String layerID) {
58 return (null != this.layers.getLayerByID(layerID).getAliases());
59 }
60 }