diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-14 11:27:29 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-14 11:27:29 +1300 |
commit | 503e44d8484fcbc61a341f35e7900def94553106 (patch) | |
tree | 3ba95c99912ab53ad2787e93258c8edbe23ac2c4 /src/org/traccar/web | |
parent | 766064092ca4f85eacfa741e1ff772ea5b981d1a (diff) | |
download | traccar-server-503e44d8484fcbc61a341f35e7900def94553106.tar.gz traccar-server-503e44d8484fcbc61a341f35e7900def94553106.tar.bz2 traccar-server-503e44d8484fcbc61a341f35e7900def94553106.zip |
More check style issues clean up
Diffstat (limited to 'src/org/traccar/web')
-rw-r--r-- | src/org/traccar/web/BaseServlet.java | 7 | ||||
-rw-r--r-- | src/org/traccar/web/JsonConverter.java | 49 |
2 files changed, 32 insertions, 24 deletions
diff --git a/src/org/traccar/web/BaseServlet.java b/src/org/traccar/web/BaseServlet.java index 6e06e95ba..cfdff40d3 100644 --- a/src/org/traccar/web/BaseServlet.java +++ b/src/org/traccar/web/BaseServlet.java @@ -33,7 +33,9 @@ public abstract class BaseServlet extends HttpServlet { public static final String USER_KEY = "user"; @Override - protected final void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + protected final void service( + HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + String command = req.getPathInfo(); if (command == null) { command = ""; @@ -52,7 +54,8 @@ public abstract class BaseServlet extends HttpServlet { } } - protected abstract boolean handle(String command, HttpServletRequest req, HttpServletResponse resp) throws Exception; + protected abstract boolean handle( + String command, HttpServletRequest req, HttpServletResponse resp) throws Exception; public long getUserId(HttpServletRequest req) { Long userId = (Long) req.getSession().getAttribute(USER_KEY); diff --git a/src/org/traccar/web/JsonConverter.java b/src/org/traccar/web/JsonConverter.java index d8681cc3a..b19894dd6 100644 --- a/src/org/traccar/web/JsonConverter.java +++ b/src/org/traccar/web/JsonConverter.java @@ -38,12 +38,15 @@ import org.traccar.helper.Log; import org.traccar.model.Factory; import org.traccar.model.MiscFormatter; -public class JsonConverter { +public final class JsonConverter { - private static final DateTimeFormatter dateFormat = ISODateTimeFormat.dateTime(); + private JsonConverter() { + } + + private static final DateTimeFormatter DATE_FORMAT = ISODateTimeFormat.dateTime(); public static Date parseDate(String value) { - return dateFormat.parseDateTime(value).toDate(); + return DATE_FORMAT.parseDateTime(value).toDate(); } public static <T extends Factory> T objectFromJson(Reader reader, T prototype) throws ParseException { @@ -63,26 +66,28 @@ public class JsonConverter { final String name = Introspector.decapitalize(method.getName().substring(3)); Class<?> parameterType = method.getParameterTypes()[0]; - if (json.containsKey(name)) try { - if (parameterType.equals(boolean.class)) { - method.invoke(object, json.getBoolean(name)); - } else if (parameterType.equals(int.class)) { - method.invoke(object, json.getJsonNumber(name).intValue()); - } else if (parameterType.equals(long.class)) { - if (json.get(name).getValueType() == JsonValue.ValueType.NUMBER) { - method.invoke(object, json.getJsonNumber(name).longValue()); + if (json.containsKey(name)) { + try { + if (parameterType.equals(boolean.class)) { + method.invoke(object, json.getBoolean(name)); + } else if (parameterType.equals(int.class)) { + method.invoke(object, json.getJsonNumber(name).intValue()); + } else if (parameterType.equals(long.class)) { + if (json.get(name).getValueType() == JsonValue.ValueType.NUMBER) { + method.invoke(object, json.getJsonNumber(name).longValue()); + } + } else if (parameterType.equals(double.class)) { + method.invoke(object, json.getJsonNumber(name).doubleValue()); + } else if (parameterType.equals(String.class)) { + method.invoke(object, json.getString(name)); + } else if (parameterType.equals(Date.class)) { + method.invoke(object, DATE_FORMAT.parseDateTime(json.getString(name)).toDate()); + } else if (parameterType.equals(Map.class)) { + method.invoke(object, MiscFormatter.fromJson(json.getJsonObject(name))); } - } else if (parameterType.equals(double.class)) { - method.invoke(object, json.getJsonNumber(name).doubleValue()); - } else if (parameterType.equals(String.class)) { - method.invoke(object, json.getString(name)); - } else if (parameterType.equals(Date.class)) { - method.invoke(object, dateFormat.parseDateTime(json.getString(name)).toDate()); - } else if (parameterType.equals(Map.class)) { - method.invoke(object, MiscFormatter.fromJson(json.getJsonObject(name))); + } catch (IllegalAccessException | InvocationTargetException error) { + Log.warning(error); } - } catch (IllegalAccessException | InvocationTargetException error) { - Log.warning(error); } } } @@ -119,7 +124,7 @@ public class JsonConverter { } else if (method.getReturnType().equals(Date.class)) { Date value = (Date) method.invoke(object); if (value != null) { - json.add(name, dateFormat.print(new DateTime(value))); + json.add(name, DATE_FORMAT.print(new DateTime(value))); } } else if (method.getReturnType().equals(Map.class)) { json.add(name, MiscFormatter.toJson((Map) method.invoke(object))); |