jdk/make/tools/src/build/tools/cldrconverter/CLDRConverter.java
changeset 17466 e2c55878b26a
parent 16852 60207b2b4b42
child 19371 bb9611d0308c
--- a/jdk/make/tools/src/build/tools/cldrconverter/CLDRConverter.java	Mon May 13 22:16:55 2013 -0700
+++ b/jdk/make/tools/src/build/tools/cldrconverter/CLDRConverter.java	Tue May 14 14:32:15 2013 +0100
@@ -34,6 +34,8 @@
 import java.util.*;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
 
 
 /**
@@ -234,6 +236,17 @@
         }
     }
 
+    /**
+     * Configure the parser to allow access to DTDs on the file system.
+     */
+    private static void enableFileAccess(SAXParser parser) throws SAXNotSupportedException {
+        try {
+            parser.setProperty("http://javax.xml.XMLConstants/property/accessExternalDTD", "file");
+        } catch (SAXNotRecognizedException ignore) {
+            // property requires >= JAXP 1.5
+        }
+    }
+
     private static List<Bundle> readBundleList() throws Exception {
         ResourceBundle.Control defCon = ResourceBundle.Control.getControl(ResourceBundle.Control.FORMAT_DEFAULT);
         List<Bundle> retList = new ArrayList<>();
@@ -279,6 +292,7 @@
         SAXParserFactory factory = SAXParserFactory.newInstance();
         factory.setValidating(true);
         SAXParser parser = factory.newSAXParser();
+        enableFileAccess(parser);
         LDMLParseHandler handler = new LDMLParseHandler(id);
         File file = new File(SOURCE_FILE_DIR + File.separator + id + ".xml");
         if (!file.exists()) {
@@ -314,6 +328,7 @@
         SAXParserFactory factorySuppl = SAXParserFactory.newInstance();
         factorySuppl.setValidating(true);
         SAXParser parserSuppl = factorySuppl.newSAXParser();
+        enableFileAccess(parserSuppl);
         handlerSuppl = new SupplementDataParseHandler();
         File fileSupply = new File(SPPL_SOURCE_FILE);
         parserSuppl.parse(fileSupply, handlerSuppl);
@@ -322,6 +337,7 @@
         SAXParserFactory numberingParser = SAXParserFactory.newInstance();
         numberingParser.setValidating(true);
         SAXParser parserNumbering = numberingParser.newSAXParser();
+        enableFileAccess(parserNumbering);
         handlerNumbering = new NumberingSystemsParseHandler();
         File fileNumbering = new File(NUMBERING_SOURCE_FILE);
         parserNumbering.parse(fileNumbering, handlerNumbering);
@@ -330,6 +346,7 @@
         SAXParserFactory metazonesParser = SAXParserFactory.newInstance();
         metazonesParser.setValidating(true);
         SAXParser parserMetaZones = metazonesParser.newSAXParser();
+        enableFileAccess(parserMetaZones);
         handlerMetaZones = new MetaZonesParseHandler();
         File fileMetaZones = new File(METAZONES_SOURCE_FILE);
         parserNumbering.parse(fileMetaZones, handlerMetaZones);