kwin commented on code in PR #187:
URL: https://github.com/apache/maven-doxia/pull/187#discussion_r1438615161


##########
doxia-core/src/main/java/org/apache/maven/doxia/util/XmlValidator.java:
##########
@@ -65,57 +86,42 @@ public class XmlValidator {
      */
     public void validate(String content) throws ParseException {
         try {
-            // 1 if there's a doctype
-            boolean hasDoctype = false;
-            Matcher matcher = PATTERN_DOCTYPE.matcher(content);
-            if (matcher.find()) {
-                hasDoctype = true;
-            }
-
-            // 2 check for an xmlns instance
-            boolean hasXsd = false;
-            matcher = PATTERN_TAG.matcher(content);
-            if (matcher.find()) {
-                String value = matcher.group(2);
-
-                if 
(value.contains(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI)) {
-                    hasXsd = true;
-                }
-            }
-
-            // 3 validate content
-            getXmlReader(hasXsd && hasDoctype).parse(new InputSource(new 
StringReader(content)));
-        } catch (IOException | SAXException e) {
+            getXmlReader().parse(new InputSource(new StringReader(content)));
+        } catch (IOException | SAXException | ParserConfigurationException e) {
             throw new ParseException("Error validating the model", e);
         }
     }
 
     /**
-     * @param hasDtdAndXsd to flag the <code>ErrorHandler</code>.
      * @return an xmlReader instance.
      * @throws SAXException if any
+     * @throws ParserConfigurationException
      */
-    private XMLReader getXmlReader(boolean hasDtdAndXsd) throws SAXException {
+    public XMLReader getXmlReader() throws SAXException, 
ParserConfigurationException {
         if (xmlReader == null) {

Review Comment:
   I am not sure if caching is wise here, as SAXParser/SAXParserFactory is not 
not thread-safe AFAIK 
(https://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.5/api/javax/xml/parsers/SAXParserFactory.html).
 At least this should be documented in the javadoc that the returned XMLReader 
needs to be synchronized somehow to be used among multiple threads.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to