Expand the template. @param variables containing the values for expansion. @return a fully qualified URI with the variables expanded.
(Map<String, ?> variables)
| 96 | * @return a fully qualified URI with the variables expanded. |
| 97 | */ |
| 98 | public String expand(Map<String, ?> variables) { |
| 99 | if (variables == null) { |
| 100 | throw new IllegalArgumentException("variable map is required."); |
| 101 | } |
| 102 | |
| 103 | /* resolve all expressions within the template */ |
| 104 | StringBuilder resolved = null; |
| 105 | for (TemplateChunk chunk : this.templateChunks) { |
| 106 | String expanded; |
| 107 | if (chunk instanceof Expression) { |
| 108 | expanded = this.resolveExpression((Expression) chunk, variables); |
| 109 | } else { |
| 110 | /* chunk is a literal value */ |
| 111 | expanded = chunk.getValue(); |
| 112 | } |
| 113 | if (expanded == null) { |
| 114 | continue; |
| 115 | } |
| 116 | |
| 117 | /* append it to the result */ |
| 118 | if (resolved == null) { |
| 119 | resolved = new StringBuilder(); |
| 120 | } |
| 121 | resolved.append(expanded); |
| 122 | } |
| 123 | |
| 124 | if (resolved == null) { |
| 125 | /* entire template is unresolved */ |
| 126 | return null; |
| 127 | } |
| 128 | |
| 129 | return resolved.toString(); |
| 130 | } |
| 131 | |
| 132 | protected String resolveExpression(Expression expression, Map<String, ?> variables) { |
| 133 | String resolved = null; |
nothing calls this directly
no test coverage detected