Skip to content

Commit 85a3ed9

Browse files
pdurbinffritze
authored andcommitted
bump opennlp-tools version
1 parent f4e1912 commit 85a3ed9

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/main/java/edu/harvard/iq/dataverse/util/Organizations.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.Locale;
88
import java.util.logging.Level;
99
import java.util.logging.Logger;
10+
import javax.xml.parsers.DocumentBuilderFactory;
1011
import opennlp.tools.namefind.NameFinderME;
1112
import opennlp.tools.namefind.TokenNameFinderModel;
1213
import opennlp.tools.tokenize.TokenizerME;
@@ -30,6 +31,7 @@ class Organizations {
3031
};
3132

3233
private static final Logger logger = Logger.getLogger(FirstNames.class.getCanonicalName());
34+
private static final String JDK_DOCUMENT_BUILDER_FACTORY = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl";
3335
private static List<NameFinderME> organizationNameFinders = new ArrayList<NameFinderME>();
3436
private static List<TokenizerME> tokenizers = new ArrayList<TokenizerME>();
3537

@@ -189,6 +191,18 @@ private void loadOrganizationModel(String modelFileName) throws IOException {
189191
InputStream fis = this.getClass().getClassLoader().getResourceAsStream(modelFileName);
190192
TokenNameFinderModel organizationModel = new TokenNameFinderModel(fis);
191193

192-
organizationNameFinders.add(new NameFinderME(organizationModel));
194+
String documentBuilderFactoryProperty = DocumentBuilderFactory.class.getName();
195+
String previousDocumentBuilderFactory = System.getProperty(documentBuilderFactoryProperty);
196+
try {
197+
// OpenNLP 2.x sets JAXP security attributes that the external Xerces dependency does not recognize.
198+
System.setProperty(documentBuilderFactoryProperty, JDK_DOCUMENT_BUILDER_FACTORY);
199+
organizationNameFinders.add(new NameFinderME(organizationModel));
200+
} finally {
201+
if (previousDocumentBuilderFactory == null) {
202+
System.clearProperty(documentBuilderFactoryProperty);
203+
} else {
204+
System.setProperty(documentBuilderFactoryProperty, previousDocumentBuilderFactory);
205+
}
206+
}
193207
}
194208
}

0 commit comments

Comments
 (0)