# HG changeset patch # User Sascha L. Teichmann # Date 1324479389 0 # Node ID 44dc38ca849250a504e676e6a9c68df7634973cc # Parent d13011e53022cb3091ff9e8a136795e89bf9ff30 Added an optional XSL transformation to fix the raw DIPS files. flys-aft/trunk@3513 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r d13011e53022 -r 44dc38ca8492 flys-aft/ChangeLog --- a/flys-aft/ChangeLog Tue Dec 20 14:36:36 2011 +0000 +++ b/flys-aft/ChangeLog Wed Dec 21 14:56:29 2011 +0000 @@ -1,3 +1,25 @@ +2011-12-20 Sascha L. Teichmann + + * doc/repair.xsl: Repair XSL transform which brings the + DIPS gauge numbers of the 15 FLYS gauges to the same + numbers as they are used in "Pegel Online". + + !!! The purpose of this script is to do more repairing !!! + + * doc/pegelstationen.xml: Sub document of repair. Used + for lookup the correct pegel numbers. + + * doc/conf.xml: Changed to optionally load the repair XSLT. + + * src/main/java/de/intevation/aft/Sync.java: Load the + repair XSL transformation if configured. + + * src/main/java/de/intevation/utils/XML.java: Added code + to make XSL transforms possible. + + * src/main/java/de/intevation/aft/River.java, + src/main/java/de/intevation/aft/Rivers.java: Fixed logging. + 2011-12-20 Sascha L. Teichmann * src/main/java/de/intevation/aft/River.java, diff -r d13011e53022 -r 44dc38ca8492 flys-aft/doc/conf.xml --- a/flys-aft/doc/conf.xml Tue Dec 20 14:36:36 2011 +0000 +++ b/flys-aft/doc/conf.xml Wed Dec 21 14:56:29 2011 +0000 @@ -1,7 +1,10 @@ - + + /the/path/to/the/dips/file + /the/path/to/the/xslt/to/repair/dips + diff -r d13011e53022 -r 44dc38ca8492 flys-aft/doc/pegelstationen.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-aft/doc/pegelstationen.xml Wed Dec 21 14:56:29 2011 +0000 @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff -r d13011e53022 -r 44dc38ca8492 flys-aft/doc/repair.xsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-aft/doc/repair.xsl Wed Dec 21 14:56:29 2011 +0000 @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r d13011e53022 -r 44dc38ca8492 flys-aft/src/main/java/de/intevation/aft/River.java --- a/flys-aft/src/main/java/de/intevation/aft/River.java Tue Dec 20 14:36:36 2011 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/River.java Wed Dec 21 14:56:29 2011 +0000 @@ -104,7 +104,6 @@ while (gaugesRs.next()) { int gaugeId = gaugesRs.getInt("id"); String name = gaugesRs.getString("name"); - System.err.println(name + ": " + gaugeId); } gaugesRs.close(); diff -r d13011e53022 -r 44dc38ca8492 flys-aft/src/main/java/de/intevation/aft/Rivers.java --- a/flys-aft/src/main/java/de/intevation/aft/Rivers.java Tue Dec 20 14:36:36 2011 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/Rivers.java Wed Dec 21 14:56:29 2011 +0000 @@ -51,7 +51,6 @@ if (id1 != null) { int id2 = aftRs.getInt("GEWAESSER_NR"); River river = new River(id1, id2, name); - System.err.println(river); commonRivers.add(river); } } diff -r d13011e53022 -r 44dc38ca8492 flys-aft/src/main/java/de/intevation/aft/Sync.java --- a/flys-aft/src/main/java/de/intevation/aft/Sync.java Tue Dec 20 14:36:36 2011 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/Sync.java Wed Dec 21 14:56:29 2011 +0000 @@ -6,6 +6,8 @@ import org.w3c.dom.Document; +import org.apache.log4j.Logger; + import javax.xml.xpath.XPathConstants; import de.intevation.utils.XML; @@ -14,10 +16,13 @@ public class Sync { + private static Logger log = Logger.getLogger(Sync.class); + public static final String FLYS = "flys"; public static final String AFT = "aft"; - public static final String XPATH_DIPS = "/sync/dips/@file"; + public static final String XPATH_DIPS = "/sync/dips/file/text()"; + public static final String XPATH_REPAIR = "/sync/dips/repair/text()"; public static final String CONFIG_FILE = System.getProperty("config.file", "config.xml"); @@ -27,14 +32,14 @@ File configFile = new File(CONFIG_FILE); if (!configFile.isFile() || !configFile.canRead()) { - System.err.println("cannot read config file"); + log.error("cannot read config file"); System.exit(1); } Document config = XML.parseDocument(configFile, Boolean.FALSE); if (config == null) { - System.err.println("cannot load config"); + log.error("Cannot load config file."); System.exit(1); } @@ -42,24 +47,44 @@ config, XPATH_DIPS, XPathConstants.STRING, null, null); if (dipsF == null || dipsF.length() == 0) { - System.err.println("Cannot find path to DiPS xml in config."); + log.error("Cannot find path to DIPS XML in config."); System.exit(1); } File dipsFile = new File(dipsF); if (!dipsFile.isFile() || !dipsFile.canRead()) { - System.err.println("Cannot find '" + dipsF + "'"); + log.error("Cannot find '" + dipsF + "'"); System.exit(1); } Document dips = XML.parseDocument(dipsFile, Boolean.FALSE); if (dips == null) { - System.err.println("Cannot load DiPs document."); + log.error("Cannot load DIPS document."); System.exit(1); } + String repairF = (String)XML.xpath( + config, XPATH_REPAIR, XPathConstants.STRING, null, null); + + if (repairF != null && repairF.length() > 0) { + File repairFile = new File(repairF); + if (!repairFile.isFile() || !repairFile.canRead()) { + log.warn("Cannot open DIPS repair XSLT file."); + } + else { + Document fixed = XML.transform(dips, repairFile); + if (fixed == null) { + log.warn("Fixing DIPS failed"); + } + else { + dips = fixed; + } + } + } + + ConnectionBuilder aftConnectionBuilder = new ConnectionBuilder(AFT, config); @@ -76,8 +101,7 @@ rivers.sync(syncContext); } catch (SQLException sqle) { - sqle.printStackTrace(); - System.err.println("syncing failed: " + sqle.getMessage()); + log.error("syncing failed", sqle); } finally { if (syncContext != null) { diff -r d13011e53022 -r 44dc38ca8492 flys-aft/src/main/java/de/intevation/utils/XML.java --- a/flys-aft/src/main/java/de/intevation/utils/XML.java Tue Dec 20 14:36:36 2011 +0000 +++ b/flys-aft/src/main/java/de/intevation/utils/XML.java Wed Dec 21 14:56:29 2011 +0000 @@ -26,6 +26,16 @@ import javax.xml.xpath.XPathFactory; import javax.xml.xpath.XPathVariableResolver; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; + +import javax.xml.transform.stream.StreamSource; + +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.dom.DOMResult; + public final class XML { /** Logger for this class. */ @@ -217,5 +227,32 @@ return null; } + + public static Document transform( + Document document, + File xformFile + ) { + try { + Transformer transformer = + TransformerFactory + .newInstance() + .newTransformer( + new StreamSource(xformFile)); + + DOMResult result = new DOMResult(); + + transformer.transform(new DOMSource(document), result); + + return (Document)result.getNode(); + } + catch (TransformerConfigurationException tce) { + log.error(tce, tce); + } + catch (TransformerException te) { + log.error(te, te); + } + + return null; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :