From 791081dd1c06fb9fed4543bc79d878f7fd6e265c Mon Sep 17 00:00:00 2001 From: chochos Date: Wed, 21 Sep 2011 22:17:05 +0000 Subject: [PATCH] Changed to DTD to make all 3 top elements optional, and also to allow for empty templates. ConfigParser now uses the internal j8583.dtd if available in the classpath. git-svn-id: https://j8583.svn.sourceforge.net/svnroot/j8583/j8583@95 db60a039-f72e-0410-b1d2-baa000846441 --- .../com/solab/iso8583/parse/ConfigParser.java | 17 +++++++++++++++++ .../resources/com/solab/iso8583/parse/j8583.dtd | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/solab/iso8583/parse/ConfigParser.java b/src/main/java/com/solab/iso8583/parse/ConfigParser.java index fb76749..b8eff9b 100644 --- a/src/main/java/com/solab/iso8583/parse/ConfigParser.java +++ b/src/main/java/com/solab/iso8583/parse/ConfigParser.java @@ -32,6 +32,8 @@ import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; import org.xml.sax.SAXException; import com.solab.iso8583.CustomField; @@ -97,6 +99,21 @@ public class ConfigParser { Document doc = null; try { docb = docfact.newDocumentBuilder(); + docb.setEntityResolver(new EntityResolver() { + @Override + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException, IOException { + if (systemId.indexOf("j8583.dtd") >= 0) { + URL dtd = getClass().getResource("j8583.dtd"); + if (dtd == null) { + log.warn("Cannot find j8583.dtd in classpath. j8583 config files will not be validated."); + } else { + return new InputSource(dtd.toString()); + } + } + return null; + } + }); doc = docb.parse(stream); } catch (ParserConfigurationException ex) { log.error("ISO8583 Cannot parse XML configuration", ex); diff --git a/src/main/resources/com/solab/iso8583/parse/j8583.dtd b/src/main/resources/com/solab/iso8583/parse/j8583.dtd index b886a63..833fc14 100644 --- a/src/main/resources/com/solab/iso8583/parse/j8583.dtd +++ b/src/main/resources/com/solab/iso8583/parse/j8583.dtd @@ -1,9 +1,9 @@ - + - +