Expand this template. Unresolved variables are removed. If all values remain unresolved, the result is an empty string. @param variables containing the values for expansion. @return the expanded template.
(Map<String, ?> variables)
| 186 | * @return the expanded template. |
| 187 | */ |
| 188 | public String expand(Map<String, ?> variables) { |
| 189 | String name = this.name.expand(variables); |
| 190 | |
| 191 | if (this.pure) { |
| 192 | return name; |
| 193 | } |
| 194 | |
| 195 | List<String> expanded = new ArrayList<>(); |
| 196 | for (Template template : this.values) { |
| 197 | String result = template.expand(variables); |
| 198 | if (result == null) { |
| 199 | continue; |
| 200 | } |
| 201 | |
| 202 | /* |
| 203 | * check for an iterable result, and if one is there, we need to split it into individual |
| 204 | * values |
| 205 | */ |
| 206 | if (result.contains(",")) { |
| 207 | /* we need to split it */ |
| 208 | expanded.addAll(Arrays.asList(result.split(","))); |
| 209 | } else { |
| 210 | expanded.add(result); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | return this.queryString(name, Collections.unmodifiableList(expanded)); |
| 215 | } |
| 216 | |
| 217 | private String queryString(String name, List<String> values) { |
| 218 | if (this.pure) { |