comparison src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 137:cd55975ba0c4

Done some minor reformatings.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 23 Jun 2011 16:59:29 +0200
parents acc9e5430177
children 8f30f7e802d6
comparison
equal deleted inserted replaced
136:7632850b9520 137:cd55975ba0c4
146 for(int i = 0; i < list.getLength(); i++) { 146 for(int i = 0; i < list.getLength(); i++) {
147 Element layerElement = (Element)list.item(i); 147 Element layerElement = (Element)list.item(i);
148 layerObj layer = new layerObj(map); 148 layerObj layer = new layerObj(map);
149 149
150 //The layer name. 150 //The layer name.
151 String lname = layerElement.getAttribute("name"); 151 String lname = layerElement.getAttribute("name");
152 lname = lname.replaceAll(" ", ""); 152 lname = lname.replaceAll(" ", "");
153 layer.setName(lname); 153 layer.setName(lname);
154 layer.setMetaData("wms_title", layerElement.getAttribute("name")); 154 layer.setMetaData("wms_title", layerElement.getAttribute("name"));
155 155
156 //The layer status. 156 //The layer status.
157 String stat = layerElement.getAttribute("status"); 157 String stat = layerElement.getAttribute("status");
182 layer.setType(MS_LAYER_TYPE.MS_LAYER_POLYGON); 182 layer.setType(MS_LAYER_TYPE.MS_LAYER_POLYGON);
183 } 183 }
184 layer.setTileitem(""); 184 layer.setTileitem("");
185 185
186 //The layer datasource. 186 //The layer datasource.
187 String con_type = layerElement.getAttribute("connection_type"); 187 String con_type = layerElement.getAttribute("connection_type");
188 if(con_type.equals("local")) { 188 if(con_type.equals("local")) {
189 String datasource = ""; 189 String datasource = "";
190 if(layerElement.hasAttribute("workspace")) { 190 if(layerElement.hasAttribute("workspace")) {
191 datasource = layerElement.getAttribute("workspace"); 191 datasource = layerElement.getAttribute("workspace");
192 datasource += File.separator; 192 datasource += File.separator;
193 } 193 }
194 datasource += layerElement.getAttribute("data_source"); 194 datasource += layerElement.getAttribute("data_source");
195 layer.setData(datasource); 195 layer.setData(datasource);
196 } 196 }
197 else if(con_type.equals("SDE")) { 197 else if(con_type.equals("SDE")) {
198 logger.info( 198 logger.info(
199 "SDE datasource found." + 199 "SDE datasource found." +
200 " Please edit password in mapfile."); 200 " Please edit password in mapfile.");
201 layer.setConnectionType( 201 layer.setConnectionType(
202 MS_CONNECTION_TYPE.MS_PLUGIN.swigValue(), 202 MS_CONNECTION_TYPE.MS_PLUGIN.swigValue(),
203 MS_BINDIR + "/ms/plugins/msplugin_sde_93.dll"); 203 MS_BINDIR + "/ms/plugins/msplugin_sde_93.dll");
204 layer.setConnection( 204 layer.setConnection(
205 layerElement.getAttribute("server") + "," + 205 layerElement.getAttribute("server") + "," +
206 "port:" + layerElement.getAttribute("instance") + "," + 206 "port:" + layerElement.getAttribute("instance") + "," +
207 layerElement.getAttribute("database") + "," + 207 layerElement.getAttribute("database") + "," +
208 layerElement.getAttribute("user") + ",<PASSWORD>"); 208 layerElement.getAttribute("user") + ",<PASSWORD>");
209 layer.setData( 209 layer.setData(
210 layerElement.getAttribute("data_source") + 210 layerElement.getAttribute("data_source") +
211 ",SHAPE," + 211 ",SHAPE," +
212 layerElement.getAttribute("version")); 212 layerElement.getAttribute("version"));
213 layer.setProcessing("CLOSE_CONNECTION=defer"); 213 layer.setProcessing("CLOSE_CONNECTION=defer");
214 layer.setProcessing("ATTRIBUTE_QUALIFIED=TRUE"); 214 layer.setProcessing("ATTRIBUTE_QUALIFIED=TRUE");
215 if(layerElement.hasAttribute("join_table")) { 215 if(layerElement.hasAttribute("join_table")) {
216 layer.setProcessing( 216 layer.setProcessing(
217 "JOINTABLE=" + 217 "JOINTABLE=" +
218 layerElement.getAttribute("join_table")); 218 layerElement.getAttribute("join_table"));
219 layer.setFilter( 219 layer.setFilter(
220 "where " + 220 "where " +
221 layerElement.getAttribute("definition_query") + 221 layerElement.getAttribute("definition_query") +
222 " AND " + 222 " AND " +
223 layerElement.getAttribute("join_table_target") + "." + 223 layerElement.getAttribute("join_table_target") + "." +
224 layerElement.getAttribute("join_field_target") + "=" + 224 layerElement.getAttribute("join_field_target") + "=" +
225 layerElement.getAttribute("join_table") + "." + 225 layerElement.getAttribute("join_table") + "." +
226 layerElement.getAttribute("join_field")); 226 layerElement.getAttribute("join_field"));
227 } 227 }
228 else { 228 else {
229 prefix = layerElement.getAttribute("data_source"); 229 prefix = layerElement.getAttribute("data_source");
230 } 230 }
231 } 231 }
232 layer.setTemplate("PleaseInsertAValidTemplateForGFI"); 232 layer.setTemplate("PleaseInsertAValidTemplateForGFI");
233 //Write classes. 233 //Write classes.
234 writeClass(layer, layerElement); 234 writeClass(layer, layerElement);
235 } 235 }
236 236
259 name += "-" + i; 259 name += "-" + i;
260 } 260 }
261 } 261 }
262 co.setName (name); 262 co.setName (name);
263 if(classElement.hasAttribute("field_count")) { 263 if(classElement.hasAttribute("field_count")) {
264 co.setExpression(createExpression(classElement)); 264 co.setExpression(createExpression(classElement));
265 } 265 }
266 //Write symbols and styles. 266 //Write symbols and styles.
267 NodeList l = classElement.getChildNodes(); 267 NodeList l = classElement.getChildNodes();
268 for (int j = 0; j < l.getLength(); j++) { 268 for (int j = 0; j < l.getLength(); j++) {
269 Element elem = (Element)l.item(j); 269 Element elem = (Element)l.item(j);
285 } 285 }
286 } 286 }
287 287
288 288
289 private String createExpression(Element ce) { 289 private String createExpression(Element ce) {
290 String expression = "("; 290 String expression = "(";
291 int count = 0; 291 int count = 0;
292 try { 292 try {
293 count = Integer.parseInt(ce.getAttribute("field_count")); 293 count = Integer.parseInt(ce.getAttribute("field_count"));
294 } 294 }
295 catch(NumberFormatException nfe) { 295 catch(NumberFormatException nfe) {
296 return ""; 296 return "";
297 } 297 }
298 if(count == 1) { 298 if(count == 1) {
299 try { 299 try {
300 Double.parseDouble(ce.getAttribute("value")); 300 Double.parseDouble(ce.getAttribute("value"));
301 String exp = ce.getAttribute("expression_field_0"); 301 String exp = ce.getAttribute("expression_field_0");
302 String pre = ""; 302 String pre = "";
303 if (!prefix.equals("") && !exp.startsWith(prefix)) { 303 if (!prefix.equals("") && !exp.startsWith(prefix)) {
304 pre = prefix + "."; 304 pre = prefix + ".";
305 } 305 }
306 expression += "[" + pre; 306 expression += "[" + pre;
307 expression += ce.getAttribute("expression_field_0") + "]"; 307 expression += ce.getAttribute("expression_field_0") + "]";
308 if(ce.hasAttribute("min_value")) { 308 if(ce.hasAttribute("min_value")) {
309 expression += " > " + ce.getAttribute("min_value"); 309 expression += " > " + ce.getAttribute("min_value");
310 expression += " AND ["; 310 expression += " AND [";
311 expression += ce.getAttribute("expression_field_0")+ "]"; 311 expression += ce.getAttribute("expression_field_0")+ "]";
312 } 312 }
313 expression += " " + ce.getAttribute("expression_operator"); 313 expression += " " + ce.getAttribute("expression_operator");
314 expression += " " + ce.getAttribute("value") + ")"; 314 expression += " " + ce.getAttribute("value") + ")";
315 } 315 }
316 catch(NumberFormatException nfe) { 316 catch(NumberFormatException nfe) {
317 String exp = ce.getAttribute("expression_field_0"); 317 String exp = ce.getAttribute("expression_field_0");
318 String pre = ""; 318 String pre = "";
319 if (!prefix.equals("") && !exp.startsWith(prefix)) { 319 if (!prefix.equals("") && !exp.startsWith(prefix)) {
320 pre = prefix + "."; 320 pre = prefix + ".";
321 } 321 }
322 expression += "\"[" + pre; 322 expression += "\"[" + pre;
323 expression += ce.getAttribute("expression_field_0") + "]\""; 323 expression += ce.getAttribute("expression_field_0") + "]\"";
324 expression += " " + ce.getAttribute("expression_operator"); 324 expression += " " + ce.getAttribute("expression_operator");
325 expression += " \"" + ce.getAttribute("value") + "\")"; 325 expression += " \"" + ce.getAttribute("value") + "\")";
326 } 326 }
327 catch(Exception e) { 327 catch(Exception e) {
328 e.printStackTrace(); 328 e.printStackTrace();
329 } 329 }
330 } 330 }
331 else { 331 else {
332 for (int i = 0; i < count; i++) { 332 for (int i = 0; i < count; i++) {
333 try { 333 try {
334 Double.parseDouble(ce.getAttribute("value_" + i)); 334 Double.parseDouble(ce.getAttribute("value_" + i));
335 String exp = ce.getAttribute("expression_field_" + i); 335 String exp = ce.getAttribute("expression_field_" + i);
336 String pre = ""; 336 String pre = "";
339 } 339 }
340 expression += "[" + pre; 340 expression += "[" + pre;
341 expression += ce.getAttribute("expression_field_" + i) + "]"; 341 expression += ce.getAttribute("expression_field_" + i) + "]";
342 expression += " " + ce.getAttribute("expression_operator"); 342 expression += " " + ce.getAttribute("expression_operator");
343 expression += " " + ce.getAttribute("value_" + i); 343 expression += " " + ce.getAttribute("value_" + i);
344 if (i < count - 1) { 344 if (i < count - 1) {
345 expression += " AND "; 345 expression += " AND ";
346 } 346 }
347 else { 347 else {
348 expression += ")"; 348 expression += ")";
349 } 349 }
350 } 350 }
351 catch (NumberFormatException nfe) { 351 catch (NumberFormatException nfe) {
352 String exp = ce.getAttribute("expression_field_" + i); 352 String exp = ce.getAttribute("expression_field_" + i);
353 String pre = ""; 353 String pre = "";
354 if (!prefix.equals("") && !exp.startsWith(prefix)) { 354 if (!prefix.equals("") && !exp.startsWith(prefix)) {
355 pre = prefix + "."; 355 pre = prefix + ".";
356 } 356 }
357 expression += "\"[" + pre; 357 expression += "\"[" + pre;
358 expression += ce.getAttribute("expression_field_" + i) + "]\""; 358 expression += ce.getAttribute("expression_field_" + i) + "]\"";
359 expression += " " + ce.getAttribute("expression_operator"); 359 expression += " " + ce.getAttribute("expression_operator");
360 expression += " " + ce.getAttribute("value_" + i); 360 expression += " " + ce.getAttribute("value_" + i);
361 if (i < count - 1) { 361 if (i < count - 1) {
362 expression += " AND "; 362 expression += " AND ";
363 } 363 }
364 else { 364 else {
365 expression += ")"; 365 expression += ")";
366 } 366 }
367 } 367 }
368 } 368 }
369 } 369 }
370 return expression; 370 return expression;
371 }
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394 private String createDoubleExpression (Element classElement, int count) {
395 String exp = "";
396 String op = classElement.getAttribute("expression_operator");
397 String op1 = "";
398 String op2 = "";
399 if (op.equals("<=")) {
400 op1 = ">=";
401 op2 = op;
402 for(int j = 0; j < count; j++) {
403 if (classElement.getAttribute("min_value").equals(
404 classElement.getAttribute("value"))) {
405 exp = "([" +
406 classElement.getAttribute(
407 "expression_field_" + j) +
408 "] == " +
409 classElement.getAttribute("value") +
410 ")";
411 }
412 else {
413 exp = "([";
414 exp += classElement.getAttribute(
415 "expression_field_" + j);
416 exp += "] " + op1;
417 exp += " " + classElement.getAttribute("min_value");
418 exp += " AND [" + classElement.getAttribute(
419 "expression_field_" + j);
420 exp += "] " + op2 + " ";
421 exp += classElement.getAttribute("value");
422 exp += ")";
423 }
424 }
425 }
426 else if (op.equals("=")) {
427 op1 = op;
428 for(int j = 0; j < count; j++) {
429 exp = "([" +
430 classElement.getAttribute("expression_field_" + j) +
431 "] == " +
432 classElement.getAttribute("value") + ")";
433 }
434 }
435 return exp;
436 }
437
438 private String createStringExpression (Element classElement, int count) {
439 String exp = "";
440 String op = classElement.getAttribute("expression_operator");
441 if (op.equals("=")) {
442 for(int j = 0; j < count; j++) {
443 exp = "(\"[";
444 exp += classElement.getAttribute(
445 "expression_field_" + j);
446 exp += "]\" " + op;
447 exp += " \"" + classElement.getAttribute("value");
448 exp += "\")";
449 }
450 }
451 return exp;
452 } 371 }
453 } 372 }
454 373
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)