comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/datacage/templating/FunctionResolver.java @ 4902:e1566938d04c

Added new functions to datacage templating language. * get minimum of location/distance: dc:fromValue($ld_mode, $ld_locations, $ld_from) - returns -Double.MAX_VALUE if no min exists. * get maximum of location/distance: dc:toValue($ld_mode, $ld_locations, $ld_to) - returns Double.MAX_VALUE if no max exists.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 29 Jan 2013 17:11:26 +0100
parents 2970046fcdca
children 5ab87837622f
comparison
equal deleted inserted replaced
4901:1071aacd042c 4902:e1566938d04c
75 return Boolean.FALSE; 75 return Boolean.FALSE;
76 } 76 }
77 catch (Exception e) { 77 catch (Exception e) {
78 log.error(e); 78 log.error(e);
79 throw new XPathFunctionException(e); 79 throw new XPathFunctionException(e);
80 }
81 }
82 });
83 }
84
85 static {
86 /** Implementation for getting the minimum value of location or distance
87 * dc:fromValue. */
88 FUNCTIONS.addFunction("fromValue", 3, new XPathFunction() {
89 @Override
90 public Object evaluate(List args) throws XPathFunctionException {
91 Object mode = args.get(0);
92 Object locations = args.get(1);
93 Object from = args.get(2);
94
95 if (!(mode instanceof String)){
96 return -Double.MAX_VALUE;
97 }
98
99 if (mode.equals("locations")) {
100 if (!(locations instanceof String)) {
101 return -Double.MAX_VALUE;
102 }
103 else {
104 String loc = ((String)locations).replace(" ", "");
105 String[] split = loc.split(",");
106 return split[0];
107 }
108 }
109 else if (mode.equals("distance")) {
110 if (!(from instanceof String)) {
111 return -Double.MAX_VALUE;
112 }
113 String f = (String)from;
114 try {
115 return Double.parseDouble(f);
116 }
117 catch(NumberFormatException nfe) {
118 return -Double.MAX_VALUE;
119 }
120 }
121 else {
122 return -Double.MAX_VALUE;
123 }
124 }
125 });
126 }
127
128 static {
129 /** Implementation for getting the maximum value of location or distance
130 * dc:toValue. */
131 FUNCTIONS.addFunction("toValue", 3, new XPathFunction() {
132 @Override
133 public Object evaluate(List args) throws XPathFunctionException {
134 Object mode = args.get(0);
135 Object locations = args.get(1);
136 Object to = args.get(2);
137
138 if (!(mode instanceof String)){
139 return Double.MAX_VALUE;
140 }
141
142 if (mode.equals("locations")) {
143 if (!(locations instanceof String)) {
144 return Double.MAX_VALUE;
145 }
146 else {
147 String loc = ((String)locations).replace(" ", "");
148 String[] split = loc.split(",");
149 return split[split.length - 1];
150 }
151 }
152 else if (mode.equals("distance")) {
153 if (!(to instanceof String)) {
154 return Double.MAX_VALUE;
155 }
156 else {
157 String t = (String)to;
158 try {
159 return Double.parseDouble(t);
160 }
161 catch(NumberFormatException nfe) {
162 return Double.MAX_VALUE;
163 }
164 }
165 }
166 else {
167 return Double.MAX_VALUE;
80 } 168 }
81 } 169 }
82 }); 170 });
83 } 171 }
84 172

http://dive4elements.wald.intevation.org