Skip to content

Commit

Permalink
Use XML API instead of setting parameter globally (#554)
Browse files Browse the repository at this point in the history
This has lesser implications. Also, some more declarations can be made "final".
Thx @blackwinter.
  • Loading branch information
dr0i committed Aug 30, 2024
1 parent e277f8a commit ee17957
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@
public final class XmlDecoder extends DefaultObjectPipe<Reader, XmlReceiver> {

private static final String SAX_PROPERTY_LEXICAL_HANDLER = "http://xml.org/sax/properties/lexical-handler";
private XMLReader saxReader;
private final SAXParserFactory parserFactory = SAXParserFactory.newInstance();
private static final String TOTAL_ENTITY_SIZE_LIMIT = "http://www.oracle.com/xml/jaxp/properties/totalEntitySizeLimit";
private final XMLReader saxReader;

/**
* Creates an instance of {@link XmlDecoder} by obtaining a new instance of an
* {@link org.xml.sax.XMLReader}.
*/
public XmlDecoder() {
try {
final SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
saxReader = parserFactory.newSAXParser().getXMLReader();
}
Expand All @@ -71,14 +72,13 @@ public XmlDecoder() {
*
* Defaults to "50,000,000". Set to "0" to allow unlimited entities.
*
* @param size the size of the allowed entities. Set to "0" if entities should be unlimited.
* @param totalEntitySizeLimit the size of the allowed entities. Set to "0" if entities should be unlimited.
*/
public void setTotalEntitySizeLimit(final String size) {
public void setTotalEntitySizeLimit(final String totalEntitySizeLimit) {
try {
System.setProperty("jdk.xml.totalEntitySizeLimit", size);
saxReader = parserFactory.newSAXParser().getXMLReader();
saxReader.setProperty(TOTAL_ENTITY_SIZE_LIMIT, totalEntitySizeLimit);
}
catch (final ParserConfigurationException | SAXException e) {
catch (final SAXException e) {
throw new MetafactureException(e);
}
}
Expand Down

0 comments on commit ee17957

Please sign in to comment.