Skip to content
Permalink
Browse files

ActiveMQ6-112 Add defaults to the selector parser doc builder

  • Loading branch information...
mtaylor committed May 21, 2015
1 parent 879f4a6 commit 48d9951d879e0c8cbb59d4b64ab59d53ef88310d
@@ -18,6 +18,7 @@

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.StringReader;

import org.apache.xpath.CachedXPathAPI;
@@ -56,9 +57,7 @@ protected boolean evaluate(InputSource inputSource)
{
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder dbuilder = factory.newDocumentBuilder();
DocumentBuilder dbuilder = createDocumentBuilder();
Document doc = dbuilder.parse(inputSource);

//An XPath expression could return a true or false value instead of a node.
@@ -75,11 +74,22 @@ protected boolean evaluate(InputSource inputSource)
NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc, xpath);
return (iterator.nextNode() != null);
}

}
catch (Throwable e)
{
return false;
}
}

private DocumentBuilder createDocumentBuilder() throws ParserConfigurationException
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);

factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);

return factory.newDocumentBuilder();
}
}

0 comments on commit 48d9951

Please sign in to comment.
You can’t perform that action at this time.