changeset 7654:197bd0958cba

(issue1620) Fix WstWriter Column Header format. - Size is always 9 for a name, fill with spaces if not. - column-bez-text is the longform if a name contains spaces it is quoted. This should enable more exotic waterlevel names which are needed for issue1020
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 05 Dec 2013 19:29:52 +0100
parents e609722a1e86
children 81ae2a4873f2
files artifacts/src/main/java/org/dive4elements/river/exports/WstWriter.java
diffstat 1 files changed, 26 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/WstWriter.java	Thu Dec 05 17:38:10 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/WstWriter.java	Thu Dec 05 19:29:52 2013 +0100
@@ -139,15 +139,10 @@
         if (name != null) {
             cols++;
 
+            int i = 0;
             String basename = name;
-
-            int i = 0;
             while (columnNames.contains(name)) {
                 name = basename + "_" + i++;
-
-                if (name.length() > 9) {
-                    name = name.substring(name.length() - 9);
-                }
             }
 
             columnNames.add(name);
@@ -164,9 +159,33 @@
         logger.debug("WstWriter.writeHeader");
 
         writer.println(cols);
+
+        writer.print("*!column-bez-text ");
+
+        List<String> quotedNames = new ArrayList<String>(columnNames.size());
+
+        for (String name: columnNames) {
+            if (name.contains(" ")) {
+                name = "'" + name + "'";
+            }
+            quotedNames.add(name);
+        }
+        writer.println(StringUtils.join(quotedNames, " "));
         writer.print("        ");
 
-        writer.print(StringUtils.join(columnNames, "  "));
+        for (String columnName: columnNames) {
+            if (columnName.length() > 9) {
+                writer.printf(locale, "%9s",
+                        columnName.substring(columnName.length() - 9));
+            } else {
+                writer.printf(locale, "%9s", columnName);
+                // This is weird but i was to lazy to lookup
+                // how to do this another way.
+                for (int i = 9 - columnName.length(); i > 0; i--) {
+                    writer.print(" ");
+                }
+            }
+        }
 
         writer.println();
 

http://dive4elements.wald.intevation.org