From 2ebd13014f98d349aa147185dac2dd860fccf225 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 15 Feb 2020 14:37:10 +0100 Subject: [PATCH] =?utf8?q?WIP:Ported=20app=20to=20Thymeleaf=203.0.x=20-=20?= =?utf8?q?=C3=9Cberfl=C3=BCssiger=20code=20(simple-mapper)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../ImportVariablesAttributeProcessor.java | 84 ------------------- 1 file changed, 84 deletions(-) diff --git a/src/main/java/de/juplo/thymeleaf/ImportVariablesAttributeProcessor.java b/src/main/java/de/juplo/thymeleaf/ImportVariablesAttributeProcessor.java index 8835e37..5f3cb5b 100644 --- a/src/main/java/de/juplo/thymeleaf/ImportVariablesAttributeProcessor.java +++ b/src/main/java/de/juplo/thymeleaf/ImportVariablesAttributeProcessor.java @@ -6,8 +6,6 @@ import de.juplo.simplemapper.SimpleMapper; import java.io.IOException; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -292,86 +290,4 @@ public class ImportVariablesAttributeProcessor extends AbstractAttributeTagProce Map variables = new HashMap<>(); return variables; } - - - static Object convert(JsonParser parser) throws IOException - { - JsonToken token = parser.getCurrentToken(); - if (token == null) - fail(parser, "unexpected EOF"); - - switch (token) - { - case VALUE_STRING: return parser.getText(); - case VALUE_NUMBER_INT: return parser.getIntValue(); - case VALUE_NUMBER_FLOAT: return parser.getDoubleValue(); - case START_OBJECT: return convertObject(parser); - case START_ARRAY: return convertArray(parser); - case VALUE_TRUE: return Boolean.TRUE; - case VALUE_FALSE: return Boolean.FALSE; - case VALUE_NULL: return null; - } - - fail(parser, "unexpected token " + token.toString()); - return null; // << Will never be reached, because fail always throws an exception - } - - static Map convertObject(JsonParser parser) throws IOException - { - JsonToken token = parser.nextToken(); - if (token == null) - fail(parser, "unexpected EOF"); - - Map map = new LinkedHashMap<>(); - - while (!JsonToken.END_OBJECT.equals(token)) - { - if (!JsonToken.FIELD_NAME.equals(token)) - fail(parser, "expected a field-name"); - - String name = parser.getText(); - parser.nextToken(); - Object value = convert(parser); - map.put(name, value); - - token = parser.nextToken(); - if (token == null) - fail(parser, "unexpected EOF"); - } - - return map; - } - - static List convertArray(JsonParser parser) throws IOException - { - JsonToken token = parser.nextToken(); - if (token == null) - fail(parser, "unexpected EOF"); - - List list = new LinkedList<>(); - - while (!JsonToken.END_ARRAY.equals(token)) - { - list.add(convert(parser)); - - token = parser.nextToken(); - if (token == null) - fail(parser, "unexpected EOF"); - } - - return list; - } - - static void fail(JsonParser parser, String message) - { - JsonLocation location = parser.getCurrentLocation(); - LOG.error( - "{} at char-offset {} (line {}, column {})", - message, - location.getCharOffset(), - location.getLineNr(), - location.getColumnNr() - ); - throw new RuntimeException("Cannot parse JSON: " + message); - } } -- 2.20.1