Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/WstWriter.java @ 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 | edb323a4c286 |
children | ad5238e3e736 |
comparison
equal
deleted
inserted
replaced
7653:e609722a1e86 | 7654:197bd0958cba |
---|---|
137 */ | 137 */ |
138 public void addColumn(String name) { | 138 public void addColumn(String name) { |
139 if (name != null) { | 139 if (name != null) { |
140 cols++; | 140 cols++; |
141 | 141 |
142 int i = 0; | |
142 String basename = name; | 143 String basename = name; |
143 | |
144 int i = 0; | |
145 while (columnNames.contains(name)) { | 144 while (columnNames.contains(name)) { |
146 name = basename + "_" + i++; | 145 name = basename + "_" + i++; |
147 | |
148 if (name.length() > 9) { | |
149 name = name.substring(name.length() - 9); | |
150 } | |
151 } | 146 } |
152 | 147 |
153 columnNames.add(name); | 148 columnNames.add(name); |
154 } | 149 } |
155 } | 150 } |
162 */ | 157 */ |
163 protected void writeHeader(PrintWriter writer) { | 158 protected void writeHeader(PrintWriter writer) { |
164 logger.debug("WstWriter.writeHeader"); | 159 logger.debug("WstWriter.writeHeader"); |
165 | 160 |
166 writer.println(cols); | 161 writer.println(cols); |
162 | |
163 writer.print("*!column-bez-text "); | |
164 | |
165 List<String> quotedNames = new ArrayList<String>(columnNames.size()); | |
166 | |
167 for (String name: columnNames) { | |
168 if (name.contains(" ")) { | |
169 name = "'" + name + "'"; | |
170 } | |
171 quotedNames.add(name); | |
172 } | |
173 writer.println(StringUtils.join(quotedNames, " ")); | |
167 writer.print(" "); | 174 writer.print(" "); |
168 | 175 |
169 writer.print(StringUtils.join(columnNames, " ")); | 176 for (String columnName: columnNames) { |
177 if (columnName.length() > 9) { | |
178 writer.printf(locale, "%9s", | |
179 columnName.substring(columnName.length() - 9)); | |
180 } else { | |
181 writer.printf(locale, "%9s", columnName); | |
182 // This is weird but i was to lazy to lookup | |
183 // how to do this another way. | |
184 for (int i = 9 - columnName.length(); i > 0; i--) { | |
185 writer.print(" "); | |
186 } | |
187 } | |
188 } | |
170 | 189 |
171 writer.println(); | 190 writer.println(); |
172 | 191 |
173 writer.write("* KM "); | 192 writer.write("* KM "); |
174 writer.write(DEFAULT_UNIT); | 193 writer.write(DEFAULT_UNIT); |