Skip to content

Commit

Permalink
Reuse XmlValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-o committed Dec 30, 2023
1 parent c8edfef commit ce01ba0
Showing 1 changed file with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@
package org.apache.maven.doxia.xsd;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.apache.maven.doxia.util.XmlValidator;
import org.codehaus.plexus.testing.PlexusTest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -161,20 +159,11 @@ protected void setValidate(boolean validate) {
private XMLReader getXMLReader() {
if (xmlReader == null) {
try {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setNamespaceAware(true);
SAXParser parser = parserFactory.newSAXParser();
// If both DTD and XSD are provided, force XSD
parser.setProperty(
"http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
// Always force language-neutral exception messages for MessagesErrorHandler
parser.setProperty("http://apache.org/xml/properties/locale", Locale.ROOT);
xmlReader = parser.getXMLReader();
xmlReader.setFeature("http://xml.org/sax/features/validation", validate);
xmlReader.setFeature("http://apache.org/xml/features/validation/dynamic", validate);
xmlReader.setFeature("http://apache.org/xml/features/validation/schema", validate);
xmlReader.setErrorHandler(new MessagesErrorHandler());
xmlReader.setEntityResolver(getEntityResolver());
XmlValidator validator = new XmlValidator();
validator.setValidate(validate);
validator.setDefaultHandler(new MessagesErrorHandler());
validator.setEntityResolver(getEntityResolver());
xmlReader = validator.getXmlReader();
} catch (SAXNotRecognizedException e) {
fail("SAXNotRecognizedException: " + e.getMessage());
} catch (SAXNotSupportedException e) {
Expand Down

0 comments on commit ce01ba0

Please sign in to comment.