20
20
import javax .xml .XMLConstants ;
21
21
import javax .xml .parsers .DocumentBuilder ;
22
22
import javax .xml .parsers .DocumentBuilderFactory ;
23
+ import javax .xml .parsers .ParserConfigurationException ;
23
24
import javax .xml .validation .Schema ;
24
25
import javax .xml .validation .SchemaFactory ;
25
26
@@ -408,6 +409,10 @@ private void createRB(String xmlfileName) {
408
409
String urls = filenameToURL (xmlfileName );
409
410
DocumentBuilderFactory dfactory = DocumentBuilderFactory .newInstance ();
410
411
dfactory .setNamespaceAware (true );
412
+ trySettingFeature (dfactory , "http://apache.org/xml/features/disallow-doctype-decl" , true );
413
+ trySettingFeature (dfactory , "http://xml.org/sax/features/external-general-entities" , false );
414
+ trySettingFeature (dfactory , "http://xml.org/sax/features/external-parameter-entities" , false );
415
+ trySettingFeature (dfactory , "http://apache.org/xml/features/nonvalidating/load-external-dtd" , false );
411
416
Document doc = null ;
412
417
413
418
if (xliff10 ) {
@@ -416,6 +421,8 @@ private void createRB(String xmlfileName) {
416
421
} else {
417
422
try {
418
423
SchemaFactory schemaFactory = SchemaFactory .newInstance (XMLConstants .W3C_XML_SCHEMA_NS_URI );
424
+ schemaFactory .setProperty (XMLConstants .ACCESS_EXTERNAL_DTD , "" );
425
+ schemaFactory .setProperty (XMLConstants .ACCESS_EXTERNAL_SCHEMA , "" );
419
426
Schema schema = schemaFactory .newSchema ();
420
427
421
428
dfactory .setSchema (schema );
@@ -1303,4 +1310,13 @@ private void writeBOM(OutputStream buffer) {
1303
1310
System .exit (1 );
1304
1311
}
1305
1312
}
1313
+
1314
+ private static void trySettingFeature (DocumentBuilderFactory dfactory , String name , boolean value ) {
1315
+ try {
1316
+ dfactory .setFeature (name , value );
1317
+ } catch (ParserConfigurationException e ) {
1318
+ e .printStackTrace ();
1319
+ System .exit (1 );
1320
+ }
1321
+ }
1306
1322
}
0 commit comments