import java.io.IOException;
import java.io.InputStream;
import java.time.format.DateTimeFormatter;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import org.thymeleaf.Configuration;
import org.thymeleaf.TemplateProcessingParameters;
import org.thymeleaf.context.IContext;
+import org.thymeleaf.context.VariablesMap;
import org.thymeleaf.dom.Element;
import org.thymeleaf.processor.ProcessorResult;
import org.thymeleaf.processor.attr.AbstractAttrProcessor;
public ImportVariablesAttrProcessor()
{
- super("crumb");
+ super("variables");
}
new TemplateProcessingParameters(
config,
templateName,
- (IContext)null // << We will not execute the template, hence we need no context
- );
+ new IContext() // << We will not execute the template, hence we need no context
+ {
+ @Override
+ public VariablesMap<String, Object> getVariables()
+ {
+ return new VariablesMap<>();
+ }
+
+ @Override
+ public Locale getLocale()
+ {
+ return Locale.getDefault();
+ }
+
+ @Override
+ public void addContextExecutionInfo(String templateName)
+ {
+ }
+ });
for (ITemplateResolver t_resolver : config.getTemplateResolvers())
{
if (!"JSON".equals(resolution.getTemplateMode()))
continue;
IResourceResolver r_resolver = resolution.getResourceResolver();
- InputStream is = r_resolver.getResourceAsStream(params, templateName);
+ InputStream is =
+ r_resolver.getResourceAsStream(params, resolution.getResourceName());
if (is == null)
continue;
token = parser.nextToken();
if (token == null)
fail(parser, "unexpected EOF");
- if (!JsonToken.END_OBJECT.equals(token))
+ if (JsonToken.END_OBJECT.equals(token))
{
LOG.warn("found empty object for {}", templateName);
break;
fail(parser, "expected a field-name");
String var_name = parser.getText();
+ parser.nextToken();
Object var_value = convert(parser);
LOG.debug(
static Object convert(JsonParser parser) throws IOException
{
- JsonToken token = parser.nextToken();
+ JsonToken token = parser.getCurrentToken();
if (token == null)
fail(parser, "unexpected EOF");
if (token == null)
fail(parser, "unexpected EOF");
- Map<String, Object> map = new HashMap<>();
+ Map<String, Object> map = new LinkedHashMap<>();
while (!JsonToken.END_OBJECT.equals(token))
{
if (!JsonToken.FIELD_NAME.equals(token))
fail(parser, "expected a field-name");
- map.put(parser.getText(), convert(parser));
+ String name = parser.getText();
+ parser.nextToken();
+ Object value = convert(parser);
+ map.put(name, value);
token = parser.nextToken();
if (token == null)
package de.juplo.thymeproxy;
+import de.juplo.thymeleaf.JuploDialect;
import java.util.HashMap;
import java.util.Map;
import org.apache.http.impl.client.CloseableHttpClient;
return resolver;
}
+ @Bean
+ public TemplateResolver jsonTemplateResolver(
+ IResourceResolver resources,
+ Environment env
+ )
+ {
+ TemplateResolver resolver = new TemplateResolver();
+ resolver.setResourceResolver(resources);
+ resolver.setPrefix("http://localhost:8080/thymeleaf/");
+ resolver.setSuffix(".json");
+ resolver.setTemplateMode("JSON");
+ resolver.setCharacterEncoding("UTF-8");
+ resolver.setCacheable(Boolean.valueOf(env.getProperty("thymeproxy.cacheable")));
+ return resolver;
+ }
+
@Bean
public UrlResourceResolver thymeleafResourceResolver()
{
return new UrlResourceResolver();
}
+ @Bean
+ public JuploDialect juploDialect()
+ {
+ return new JuploDialect();
+ }
+
public static void main(String[] args)
{