closes #190
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.mustangproject.validator;
|
||||
|
||||
import org.mustangproject.XMLTools;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package org.mustangproject.validator;
|
||||
|
||||
import org.dom4j.io.XMLWriter;
|
||||
|
||||
public class XMLTools extends XMLWriter {
|
||||
public String escapeAttributeEntities(String s) {
|
||||
return super.escapeAttributeEntities(s);
|
||||
}
|
||||
public String escapeElementEntities(String s) {
|
||||
return super.escapeElementEntities(s);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import javax.xml.xpath.XPathConstants;
|
||||
import javax.xml.xpath.XPathExpression;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
|
||||
import org.mustangproject.XMLTools;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Document;
|
||||
@@ -61,7 +62,7 @@ public class XMLValidator extends Validator {
|
||||
// file existence must have been checked before
|
||||
|
||||
try {
|
||||
zfXML = new String(Files.readAllBytes(Paths.get(name)));
|
||||
zfXML = new String(XMLTools.removeBOM(Files.readAllBytes(Paths.get(name))));
|
||||
} catch (IOException e) {
|
||||
|
||||
ValidationResultItem vri = new ValidationResultItem(ESeverity.exception, e.getMessage()).setSection(9)
|
||||
@@ -112,8 +113,6 @@ public class XMLValidator extends Validator {
|
||||
failedRules = 0;
|
||||
|
||||
|
||||
ByteArrayInputStream xmlByteInputStream = new ByteArrayInputStream(zfXML.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
if (zfXML.isEmpty()) {
|
||||
ValidationResultItem res = new ValidationResultItem(ESeverity.exception,
|
||||
"XML data not found in " + filename
|
||||
@@ -145,8 +144,8 @@ public class XMLValidator extends Validator {
|
||||
// document.getElementsByTagNameNS("*",...
|
||||
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
|
||||
Document doc = db.parse(xmlByteInputStream);
|
||||
InputSource is = new InputSource(new StringReader(zfXML));
|
||||
Document doc = db.parse(is);
|
||||
|
||||
Element root = doc.getDocumentElement();
|
||||
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package org.mustangproject.validator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.MessageDigest;
|
||||
@@ -22,11 +18,13 @@ import org.dom4j.DocumentException;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
import org.mustangproject.XMLTools;
|
||||
import org.riversun.bigdoc.bin.BigFileSearcher;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
//abstract class
|
||||
@@ -165,8 +163,12 @@ public class ZUGFeRDValidator {
|
||||
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
|
||||
Document doc = db.parse(file);
|
||||
|
||||
byte[] content=Files.readAllBytes(file.toPath());
|
||||
content= XMLTools.removeBOM(content);
|
||||
String s=new String(content);
|
||||
InputSource is = new InputSource(new StringReader(s));
|
||||
Document doc = db.parse(is);
|
||||
|
||||
Element root = doc.getDocumentElement();
|
||||
isXML=true;//no exception so far
|
||||
@@ -176,6 +178,8 @@ public class ZUGFeRDValidator {
|
||||
// probably no xml file, sth like SAXParseException content not allowed in prolog
|
||||
// ignore isXML is already false
|
||||
// in the tests, this may error-out anyway
|
||||
//ex.printStackTrace();
|
||||
|
||||
}
|
||||
if (isXML) {
|
||||
pdfValidity = true;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8"?><!-- the document starts with an invisible utf8 byte order mark, which is valid-->
|
||||
<rsm:CrossIndustryInvoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100" xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100" xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100">
|
||||
<rsm:ExchangedDocumentContext>
|
||||
<ram:GuidelineSpecifiedDocumentContextParameter>
|
||||
|
||||
Reference in New Issue
Block a user