diff gwt-client/src/main/java/org/dive4elements/river/client/server/ChartServiceHelper.java @ 9567:86e522bc7f36

jUnit-Tests completed
author gernotbelger
date Mon, 05 Nov 2018 13:21:57 +0100
parents 4809e23ffd27
children
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/ChartServiceHelper.java	Mon Nov 05 10:19:12 2018 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/ChartServiceHelper.java	Mon Nov 05 13:21:57 2018 +0100
@@ -10,32 +10,26 @@
 
 import java.util.Map;
 
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
 import org.apache.log4j.Logger;
-
 import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
 import org.dive4elements.artifacts.common.utils.XMLUtils;
 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
-
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
 public class ChartServiceHelper {
 
-    private static final Logger log =
-        Logger.getLogger(ChartServiceHelper.class);
-
+    private static final Logger log = Logger.getLogger(ChartServiceHelper.class);
 
-    /** The default chart width if no value is specified in the request.*/
-    public static final int DEFAULT_CHART_WIDTH  = 600;
+    /** The default chart width if no value is specified in the request. */
+    public static final int DEFAULT_CHART_WIDTH = 600;
 
-    /** The default chart height if no value is specified in the request.*/
+    /** The default chart height if no value is specified in the request. */
     public static final int DEFAULT_CHART_HEIGHT = 400;
 
-
     private ChartServiceHelper() {
     }
 
@@ -44,21 +38,19 @@
      * chart settings. The document is created using the information that are
      * contained in the request object.
      *
-     * @param req The request document.
+     * @param req
+     *            The request document.
      *
      * @return a document to adjust chart settings.
      */
-    protected static Document getChartAttributes(Map<String, String> req) {
+    public static Document getChartAttributes(final Map<String, String> req) {
         log.debug("ChartServiceHelper.getChartAttributes");
 
-        Document doc = XMLUtils.newDocument();
+        final Document doc = XMLUtils.newDocument();
 
-        ElementCreator ec = new ElementCreator(
-            doc,
-            ArtifactNamespaceContext.NAMESPACE_URI,
-            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+        final ElementCreator ec = new ElementCreator(doc, ArtifactNamespaceContext.NAMESPACE_URI, ArtifactNamespaceContext.NAMESPACE_PREFIX);
 
-        Element attributes = ec.create("attributes");
+        final Element attributes = ec.create("attributes");
 
         appendChartSize(req, attributes, ec);
         appendFormat(req, attributes, ec);
@@ -72,30 +64,28 @@
         return doc;
     }
 
-
     /**
      * This method extracts the size (width/height) of a chart from request
      * object and append those values - if they exist - to the attribute
      * document used to adjust chart settings.
      *
-     * @param req The request object that might contain the chart size.
-     * @param attributes The attributes element used to adjust chart settings.
-     * @param ec The ElementCreator that might be used to create new Elements.
+     * @param req
+     *            The request object that might contain the chart size.
+     * @param attributes
+     *            The attributes element used to adjust chart settings.
+     * @param ec
+     *            The ElementCreator that might be used to create new Elements.
      */
-    protected static void appendChartSize(
-        Map<String, String> req,
-        Element             attributes,
-        ElementCreator      ec)
-    {
+    protected static void appendChartSize(final Map<String, String> req, final Element attributes, final ElementCreator ec) {
         log.debug("ChartServiceHelper.appendChartSize");
 
-        Element size = ec.create("size");
+        final Element size = ec.create("size");
 
-        String width  = req.get("width");
+        String width = req.get("width");
         String height = req.get("height");
 
         if (width == null || height == null) {
-            width  = String.valueOf(DEFAULT_CHART_WIDTH);
+            width = String.valueOf(DEFAULT_CHART_WIDTH);
             height = String.valueOf(DEFAULT_CHART_HEIGHT);
         }
 
@@ -105,27 +95,25 @@
         attributes.appendChild(size);
     }
 
-
     /**
      * This method extracts the x range for the chart from request object and
      * appends those range - if it exists - to the attribute document used to
      * adjust the chart settings.
      *
-     * @param req The request object that might contain the chart size.
-     * @param doc The attribute document used to adjust chart settings.
-     * @param ec The ElementCreator that might be used to create new Elements.
+     * @param req
+     *            The request object that might contain the chart size.
+     * @param doc
+     *            The attribute document used to adjust chart settings.
+     * @param ec
+     *            The ElementCreator that might be used to create new Elements.
      */
-    protected static void appendXRange(
-        Map<String, String> req,
-        Element             attributes,
-        ElementCreator      ec)
-    {
+    protected static void appendXRange(final Map<String, String> req, final Element attributes, final ElementCreator ec) {
         log.debug("ChartServiceHelper.appendXRange");
 
-        Element range = ec.create("xrange");
+        final Element range = ec.create("xrange");
 
-        String from = req.get("minx");
-        String to   = req.get("maxx");
+        final String from = req.get("minx");
+        final String to = req.get("maxx");
 
         if (from != null && to != null) {
             ec.addAttr(range, "from", from, true);
@@ -135,27 +123,25 @@
         }
     }
 
-
     /**
      * This method extracts the x range for the chart from request object and
      * appends those range - if it exists - to the attribute document used to
      * adjust the chart settings.
      *
-     * @param req The request object that might contain the chart size.
-     * @param doc The attribute document used to adjust chart settings.
-     * @param ec The ElementCreator that might be used to create new Elements.
+     * @param req
+     *            The request object that might contain the chart size.
+     * @param doc
+     *            The attribute document used to adjust chart settings.
+     * @param ec
+     *            The ElementCreator that might be used to create new Elements.
      */
-    protected static void appendYRange(
-        Map<String, String> req,
-        Element             attributes,
-        ElementCreator      ec)
-    {
+    protected static void appendYRange(final Map<String, String> req, final Element attributes, final ElementCreator ec) {
         log.debug("ChartServiceHelper.appendYRange");
 
-        Element range = ec.create("yrange");
+        final Element range = ec.create("yrange");
 
-        String from = req.get("miny");
-        String to   = req.get("maxy");
+        final String from = req.get("miny");
+        final String to = req.get("maxy");
 
         if (from != null && to != null) {
             ec.addAttr(range, "from", from, true);
@@ -165,30 +151,29 @@
         }
     }
 
-
     /**
      * This method extracts the format string from request object and appends
      * those format - if existing - to the attribute document used to adjust
      * the chart settings.
      *
-     * @param req The request object that might contain the chart format.
-     * @param doc The attribute document used to adjust chart settings.
-     * @param ec The ElementCreator that might be used to create new Elements.
+     * @param req
+     *            The request object that might contain the chart format.
+     * @param doc
+     *            The attribute document used to adjust chart settings.
+     * @param ec
+     *            The ElementCreator that might be used to create new Elements.
      */
-    private static void appendFormat(
-        Map<String, String> req,
-        Element             attributes,
-        ElementCreator      ec
+    private static void appendFormat(final Map<String, String> req, final Element attributes, final ElementCreator ec
 
     ) {
         log.debug("ChartServiceHelper.appendFormat");
 
-        String formatStr = req.get("format");
+        final String formatStr = req.get("format");
         if (formatStr == null || formatStr.length() == 0) {
             return;
         }
 
-        Element format = ec.create("format");
+        final Element format = ec.create("format");
         ec.addAttr(format, "value", formatStr, true);
 
         attributes.appendChild(format);
@@ -199,19 +184,22 @@
      * those format - if existing - to the attribute document used to adjust
      * the chart settings.
      *
-     * @param req The request object that might contain the chart export flag.
-     * @param doc The attribute document used to adjust chart settings.
-     * @param ec The ElementCreator that might be used to create new Elements.
+     * @param req
+     *            The request object that might contain the chart export flag.
+     * @param doc
+     *            The attribute document used to adjust chart settings.
+     * @param ec
+     *            The ElementCreator that might be used to create new Elements.
      */
-    private static void appendExport( final Map<String, String> req, final Element attributes, final ElementCreator ec ) {
-        
+    private static void appendExport(final Map<String, String> req, final Element attributes, final ElementCreator ec) {
+
         final String exportStr = req.get("export");
-        if (exportStr == null || exportStr.isEmpty()) 
+        if (exportStr == null || exportStr.isEmpty())
             return;
-        
+
         final Element format = ec.create("export");
         ec.addAttr(format, "value", exportStr, true);
-        
+
         attributes.appendChild(format);
     }
 
@@ -220,20 +208,19 @@
      * appends this km - if it exists - to the attribute document used to
      * adjust the chart settings.
      *
-     * @param req The request object that might contain the chart size.
-     * @param doc The attribute document used to adjust chart settings.
-     * @param ec The ElementCreator that might be used to create new Elements.
+     * @param req
+     *            The request object that might contain the chart size.
+     * @param doc
+     *            The attribute document used to adjust chart settings.
+     * @param ec
+     *            The ElementCreator that might be used to create new Elements.
      */
-    protected static void appendCurrentKm(
-        Map<String, String> req,
-        Element             attributes,
-        ElementCreator      ec)
-    {
+    protected static void appendCurrentKm(final Map<String, String> req, final Element attributes, final ElementCreator ec) {
         log.debug("ChartServiceHelper.appendCurrentKm");
- 
-        Element currentKm = ec.create("currentKm");
 
-        String km = req.get("km");
+        final Element currentKm = ec.create("currentKm");
+
+        final String km = req.get("km");
 
         if (km != null) {
             ec.addAttr(currentKm, "km", km, true);

http://dive4elements.wald.intevation.org