Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
essiembre committed May 17, 2017
2 parents 572c12e + ba5700f commit c83fdea
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
4 changes: 2 additions & 2 deletions norconex-commons-lang/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.norconex.commons</groupId>
<artifactId>norconex-commons-lang</artifactId>
<version>1.13.0</version>
<version>1.13.1</version>
<packaging>jar</packaging>
<name>Norconex Commons Lang</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<site.baseurl/>
<currentStableVersion>1.13.0</currentStableVersion>
<currentStableVersion>1.13.1</currentStableVersion>
</properties>
<inceptionYear>2008</inceptionYear>

Expand Down
8 changes: 8 additions & 0 deletions norconex-commons-lang/src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
</properties>
<body>

<release version="1.13.1" date="2017-05-16" description="Bugfix release">
<action dev="essiembre" type="fix">
Fixed XMLConfigurationUtil reporting a validation error when
encountering attributes from the XML Namespace
("http://www.w3.org/XML/1998/namespace"), such as xml:space="preserve".
</action>
</release>

<release version="1.13.0" date="2017-04-25" description="Feature release">
<action dev="essiembre" type="add">
New "exec" package containing classes moved from Norconex JEF API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.StringWriter;
import java.util.List;

import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
Expand All @@ -35,9 +36,16 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.xerces.xni.NamespaceContext;
import org.xml.sax.Attributes;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.XMLFilterImpl;
import org.xml.sax.helpers.XMLReaderFactory;

import com.norconex.commons.lang.time.DurationParser;
import com.norconex.commons.lang.time.DurationParserException;
Expand Down Expand Up @@ -407,7 +415,10 @@ private static int doValidate(Class<?> clazz, Object source) {
Validator validator = schema.newValidator();
LogErrorHandler seh = new LogErrorHandler(clazz);
validator.setErrorHandler(seh);
validator.validate(new StreamSource(reader));
SAXSource saxSource = new SAXSource(new W3XMLNamespaceFilter(
XMLReaderFactory.createXMLReader()),
new InputSource(reader));
validator.validate(saxSource);
return seh.errorCount;
} catch (SAXException | IOException e) {
throw new ConfigurationException(
Expand Down Expand Up @@ -496,8 +507,7 @@ public static void assertWriteRead(IXMLConfigurable xmlConfiurable)
// Read
XMLConfiguration xml = newXMLConfiguration(
new StringReader(out.toString()));
IXMLConfigurable readConfigurable =
(IXMLConfigurable) newInstance(xml);
IXMLConfigurable readConfigurable = newInstance(xml);

if (!xmlConfiurable.equals(readConfigurable)) {
LOG.error("BEFORE: " + xmlConfiurable);
Expand Down Expand Up @@ -661,7 +671,30 @@ public void fatalError(SAXParseException e) throws SAXException {
LOG.fatal(msg(e));
}
private String msg(SAXParseException e) {
return "(XML) " + clazz.getSimpleName() + ": " + e.getMessage();
return "(XML Validation) "
+ clazz.getSimpleName() + ": " + e.getMessage();
}
}

// Filter out "xml:" name space so attributes like xml:space="preserve"
// are validated OK.
private static class W3XMLNamespaceFilter extends XMLFilterImpl {
public W3XMLNamespaceFilter(XMLReader parent) {
super(parent);
}
@Override
public void startElement(
String uri, String localName, String qName, Attributes atts)
throws SAXException {
for (int i = 0; i < atts.getLength(); i++) {
if (NamespaceContext.XML_URI.equals(atts.getURI(i))) {
AttributesImpl modifiedAtts = new AttributesImpl(atts);
modifiedAtts.removeAttribute(i);
super.startElement(uri, localName, qName, modifiedAtts);
return;
}
}
super.startElement(uri, localName, qName, atts);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
* <p>
* A version of {@link XMLStreamWriter} that adds convenience methods
* for adding simple elements and typed attributes, as well as offering
* pretty-printing. Can be used on its own or as a wrapper to an existing
* <code>XMLStreamWriter</code> instance.
* pretty-printing. Can be used on its own with a Writer,
* or as a wrapper to an existing <code>XMLStreamWriter</code> instance.
* </p>
*
* @author Pascal Essiembre
Expand Down

0 comments on commit c83fdea

Please sign in to comment.