diff --git a/pom.xml b/pom.xml index 6aeb3bd1f52..dd4d92c4f0d 100644 --- a/pom.xml +++ b/pom.xml @@ -655,7 +655,7 @@ org.apache.opennlp opennlp-tools - 1.9.1 + 2.5.9 org.xmlunit diff --git a/src/main/java/edu/harvard/iq/dataverse/util/Organizations.java b/src/main/java/edu/harvard/iq/dataverse/util/Organizations.java index 475afdb48b8..970cc88b0f8 100644 --- a/src/main/java/edu/harvard/iq/dataverse/util/Organizations.java +++ b/src/main/java/edu/harvard/iq/dataverse/util/Organizations.java @@ -7,6 +7,7 @@ import java.util.Locale; import java.util.logging.Level; import java.util.logging.Logger; +import javax.xml.parsers.DocumentBuilderFactory; import opennlp.tools.namefind.NameFinderME; import opennlp.tools.namefind.TokenNameFinderModel; import opennlp.tools.tokenize.TokenizerME; @@ -30,6 +31,7 @@ class Organizations { }; private static final Logger logger = Logger.getLogger(FirstNames.class.getCanonicalName()); + private static final String JDK_DOCUMENT_BUILDER_FACTORY = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"; private static List organizationNameFinders = new ArrayList(); private static List tokenizers = new ArrayList(); @@ -189,6 +191,18 @@ private void loadOrganizationModel(String modelFileName) throws IOException { InputStream fis = this.getClass().getClassLoader().getResourceAsStream(modelFileName); TokenNameFinderModel organizationModel = new TokenNameFinderModel(fis); - organizationNameFinders.add(new NameFinderME(organizationModel)); + String documentBuilderFactoryProperty = DocumentBuilderFactory.class.getName(); + String previousDocumentBuilderFactory = System.getProperty(documentBuilderFactoryProperty); + try { + // OpenNLP 2.x sets JAXP security attributes that the external Xerces dependency does not recognize. + System.setProperty(documentBuilderFactoryProperty, JDK_DOCUMENT_BUILDER_FACTORY); + organizationNameFinders.add(new NameFinderME(organizationModel)); + } finally { + if (previousDocumentBuilderFactory == null) { + System.clearProperty(documentBuilderFactoryProperty); + } else { + System.setProperty(documentBuilderFactoryProperty, previousDocumentBuilderFactory); + } + } } }