[ 
https://issues.apache.org/jira/browse/DOXIA-716?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17801362#comment-17801362
 ] 

ASF GitHub Bot commented on DOXIA-716:
--------------------------------------

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.





> Update and unify XMLReader creation and configuration
> -----------------------------------------------------
>
>                 Key: DOXIA-716
>                 URL: https://issues.apache.org/jira/browse/DOXIA-716
>             Project: Maven Doxia
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 2.0.0-M8
>            Reporter: Michael Osipov
>            Assignee: Michael Osipov
>            Priority: Major
>             Fix For: 2.0.0-M9
>
>
> * {{XMLReaderFactory}} is deprecated from Java 9
> * Force XML Schema as main language if both DTD and XSD are provided
> * Force {{Locale#ROOT}} for portability
> * Remove old Xerces hack



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to