comparison flys-aft/src/main/java/de/intevation/aft/Sync.java @ 4083:44dc38ca8492

Added an optional XSL transformation to fix the raw DIPS files. flys-aft/trunk@3513 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 21 Dec 2011 14:56:29 +0000
parents 97de7a552b79
children 859b4781554a
comparison
equal deleted inserted replaced
4082:d13011e53022 4083:44dc38ca8492
3 import java.io.File; 3 import java.io.File;
4 4
5 import java.sql.SQLException; 5 import java.sql.SQLException;
6 6
7 import org.w3c.dom.Document; 7 import org.w3c.dom.Document;
8
9 import org.apache.log4j.Logger;
8 10
9 import javax.xml.xpath.XPathConstants; 11 import javax.xml.xpath.XPathConstants;
10 12
11 import de.intevation.utils.XML; 13 import de.intevation.utils.XML;
12 14
13 import de.intevation.db.ConnectionBuilder; 15 import de.intevation.db.ConnectionBuilder;
14 16
15 public class Sync 17 public class Sync
16 { 18 {
19 private static Logger log = Logger.getLogger(Sync.class);
20
17 public static final String FLYS = "flys"; 21 public static final String FLYS = "flys";
18 public static final String AFT = "aft"; 22 public static final String AFT = "aft";
19 23
20 public static final String XPATH_DIPS = "/sync/dips/@file"; 24 public static final String XPATH_DIPS = "/sync/dips/file/text()";
25 public static final String XPATH_REPAIR = "/sync/dips/repair/text()";
21 26
22 public static final String CONFIG_FILE = 27 public static final String CONFIG_FILE =
23 System.getProperty("config.file", "config.xml"); 28 System.getProperty("config.file", "config.xml");
24 29
25 public static void main(String [] args) { 30 public static void main(String [] args) {
26 31
27 File configFile = new File(CONFIG_FILE); 32 File configFile = new File(CONFIG_FILE);
28 33
29 if (!configFile.isFile() || !configFile.canRead()) { 34 if (!configFile.isFile() || !configFile.canRead()) {
30 System.err.println("cannot read config file"); 35 log.error("cannot read config file");
31 System.exit(1); 36 System.exit(1);
32 } 37 }
33 38
34 Document config = XML.parseDocument(configFile, Boolean.FALSE); 39 Document config = XML.parseDocument(configFile, Boolean.FALSE);
35 40
36 if (config == null) { 41 if (config == null) {
37 System.err.println("cannot load config"); 42 log.error("Cannot load config file.");
38 System.exit(1); 43 System.exit(1);
39 } 44 }
40 45
41 String dipsF = (String)XML.xpath( 46 String dipsF = (String)XML.xpath(
42 config, XPATH_DIPS, XPathConstants.STRING, null, null); 47 config, XPATH_DIPS, XPathConstants.STRING, null, null);
43 48
44 if (dipsF == null || dipsF.length() == 0) { 49 if (dipsF == null || dipsF.length() == 0) {
45 System.err.println("Cannot find path to DiPS xml in config."); 50 log.error("Cannot find path to DIPS XML in config.");
46 System.exit(1); 51 System.exit(1);
47 } 52 }
48 53
49 File dipsFile = new File(dipsF); 54 File dipsFile = new File(dipsF);
50 55
51 if (!dipsFile.isFile() || !dipsFile.canRead()) { 56 if (!dipsFile.isFile() || !dipsFile.canRead()) {
52 System.err.println("Cannot find '" + dipsF + "'"); 57 log.error("Cannot find '" + dipsF + "'");
53 System.exit(1); 58 System.exit(1);
54 } 59 }
55 60
56 Document dips = XML.parseDocument(dipsFile, Boolean.FALSE); 61 Document dips = XML.parseDocument(dipsFile, Boolean.FALSE);
57 62
58 if (dips == null) { 63 if (dips == null) {
59 System.err.println("Cannot load DiPs document."); 64 log.error("Cannot load DIPS document.");
60 System.exit(1); 65 System.exit(1);
61 } 66 }
67
68 String repairF = (String)XML.xpath(
69 config, XPATH_REPAIR, XPathConstants.STRING, null, null);
70
71 if (repairF != null && repairF.length() > 0) {
72 File repairFile = new File(repairF);
73 if (!repairFile.isFile() || !repairFile.canRead()) {
74 log.warn("Cannot open DIPS repair XSLT file.");
75 }
76 else {
77 Document fixed = XML.transform(dips, repairFile);
78 if (fixed == null) {
79 log.warn("Fixing DIPS failed");
80 }
81 else {
82 dips = fixed;
83 }
84 }
85 }
86
62 87
63 ConnectionBuilder aftConnectionBuilder = 88 ConnectionBuilder aftConnectionBuilder =
64 new ConnectionBuilder(AFT, config); 89 new ConnectionBuilder(AFT, config);
65 90
66 ConnectionBuilder flysConnectionBuilder = 91 ConnectionBuilder flysConnectionBuilder =
74 dips); 99 dips);
75 Rivers rivers = new Rivers(); 100 Rivers rivers = new Rivers();
76 rivers.sync(syncContext); 101 rivers.sync(syncContext);
77 } 102 }
78 catch (SQLException sqle) { 103 catch (SQLException sqle) {
79 sqle.printStackTrace(); 104 log.error("syncing failed", sqle);
80 System.err.println("syncing failed: " + sqle.getMessage());
81 } 105 }
82 finally { 106 finally {
83 if (syncContext != null) { 107 if (syncContext != null) {
84 syncContext.close(); 108 syncContext.close();
85 } 109 }

http://dive4elements.wald.intevation.org