Replace ' with " in xml attributes
Some automatically changes by the IDE: - remove unused imports - add final where possible
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package org.mustangproject.validator;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -8,7 +7,6 @@ import java.io.PrintWriter;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
@@ -16,14 +14,9 @@ import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import javax.xml.validation.Schema;
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathConstants;
|
||||
import javax.xml.xpath.XPathExpression;
|
||||
@@ -75,46 +68,47 @@ public class PDFValidator extends Validator {
|
||||
return Arrays.asList(arr).contains(targetValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() throws IrrecoverableValidationError {
|
||||
|
||||
zfXML = null;
|
||||
File file = new File(pdfFilename);
|
||||
final File file = new File(pdfFilename);
|
||||
// file existence must have been checked before
|
||||
BigFileSearcher searcher = new BigFileSearcher();
|
||||
final BigFileSearcher searcher = new BigFileSearcher();
|
||||
|
||||
byte[] pdfSignature = { '%', 'P', 'D', 'F' };
|
||||
final byte[] pdfSignature = { '%', 'P', 'D', 'F' };
|
||||
if (searcher.indexOf(file, pdfSignature) != 0) {
|
||||
context.addResultItem(
|
||||
new ValidationResultItem(ESeverity.fatal, "Not a PDF file "+pdfFilename).setSection(20).setPart(EPart.pdf));
|
||||
|
||||
}
|
||||
|
||||
long startPDFTime = Calendar.getInstance().getTimeInMillis();
|
||||
final long startPDFTime = Calendar.getInstance().getTimeInMillis();
|
||||
|
||||
// Step 1 Validate PDF
|
||||
|
||||
VeraGreenfieldFoundryProvider.initialise();
|
||||
// Default validator config
|
||||
ValidatorConfig validatorConfig = ValidatorFactory.defaultConfig();
|
||||
final ValidatorConfig validatorConfig = ValidatorFactory.defaultConfig();
|
||||
// Default features config
|
||||
FeatureExtractorConfig featureConfig = FeatureFactory.defaultConfig();
|
||||
final FeatureExtractorConfig featureConfig = FeatureFactory.defaultConfig();
|
||||
// Default plugins config
|
||||
PluginsCollectionConfig pluginsConfig = PluginsCollectionConfig.defaultConfig();
|
||||
final PluginsCollectionConfig pluginsConfig = PluginsCollectionConfig.defaultConfig();
|
||||
// Default fixer config
|
||||
MetadataFixerConfig fixerConfig = FixerFactory.defaultConfig();
|
||||
final MetadataFixerConfig fixerConfig = FixerFactory.defaultConfig();
|
||||
// Tasks configuring
|
||||
EnumSet tasks = EnumSet.noneOf(TaskType.class);
|
||||
final EnumSet tasks = EnumSet.noneOf(TaskType.class);
|
||||
tasks.add(TaskType.VALIDATE);
|
||||
// tasks.add(TaskType.EXTRACT_FEATURES);
|
||||
// tasks.add(TaskType.FIX_METADATA);
|
||||
// Creating processor config
|
||||
ProcessorConfig processorConfig = ProcessorFactory.fromValues(validatorConfig, featureConfig, pluginsConfig,
|
||||
final ProcessorConfig processorConfig = ProcessorFactory.fromValues(validatorConfig, featureConfig, pluginsConfig,
|
||||
fixerConfig, tasks);
|
||||
// Creating processor and output stream.
|
||||
ByteArrayOutputStream reportStream = new ByteArrayOutputStream();
|
||||
final ByteArrayOutputStream reportStream = new ByteArrayOutputStream();
|
||||
try (BatchProcessor processor = ProcessorFactory.fileBatchProcessor(processorConfig)) {
|
||||
// Generating list of files for processing
|
||||
List<File> files = new ArrayList<>();
|
||||
final List<File> files = new ArrayList<>();
|
||||
files.add(new File(pdfFilename));
|
||||
// starting the processor
|
||||
processor.process(files, ProcessorFactory.getHandler(FormatOption.MRR, true, reportStream, 100,
|
||||
@@ -122,25 +116,25 @@ public class PDFValidator extends Validator {
|
||||
|
||||
pdfReport = reportStream.toString("utf-8").replaceAll("<\\?xml version=\"1\\.0\" encoding=\"utf-8\"\\?>",
|
||||
"");
|
||||
} catch (VeraPDFException e) {
|
||||
ValidationResultItem vri = new ValidationResultItem(ESeverity.exception, e.getMessage()).setSection(6)
|
||||
} catch (final VeraPDFException e) {
|
||||
final ValidationResultItem vri = new ValidationResultItem(ESeverity.exception, e.getMessage()).setSection(6)
|
||||
.setPart(EPart.pdf);
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
final StringWriter sw = new StringWriter();
|
||||
final PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
vri.setStacktrace(sw.toString());
|
||||
context.addResultItem(vri);
|
||||
} catch (IOException excep) {
|
||||
} catch (final IOException excep) {
|
||||
context.addResultItem(new ValidationResultItem(ESeverity.exception, excep.getMessage()).setSection(7)
|
||||
.setPart(EPart.pdf).setStacktrace(excep.getStackTrace().toString()));
|
||||
}
|
||||
|
||||
// step 2 validate XMP
|
||||
ZUGFeRDImporter zi = new ZUGFeRDImporter(pdfFilename);
|
||||
String xmp = zi.getXMP();
|
||||
final ZUGFeRDImporter zi = new ZUGFeRDImporter(pdfFilename);
|
||||
final String xmp = zi.getXMP();
|
||||
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
Document docXMP;
|
||||
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
final Document docXMP;
|
||||
|
||||
if (xmp.length() == 0) {
|
||||
context.addResultItem(new ValidationResultItem(ESeverity.error, "Invalid XMP Metadata not found")
|
||||
@@ -153,15 +147,15 @@ public class PDFValidator extends Validator {
|
||||
* <zf:Version>1.0</zf:Version>
|
||||
*/
|
||||
try {
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
InputSource is = new InputSource(new StringReader(xmp));
|
||||
final DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
final InputSource is = new InputSource(new StringReader(xmp));
|
||||
docXMP = builder.parse(is);
|
||||
|
||||
XPathFactory xpathFactory = XPathFactory.newInstance();
|
||||
final XPathFactory xpathFactory = XPathFactory.newInstance();
|
||||
|
||||
// Create XPath object XPath xpath = xpathFactory.newXPath(); XPathExpression
|
||||
|
||||
XPath xpath = xpathFactory.newXPath();
|
||||
final XPath xpath = xpathFactory.newXPath();
|
||||
// xpath.compile("//*[local-name()=\"GuidelineSpecifiedDocumentContextParameter\"]/[local-name()=\"ID\"]");
|
||||
// evaluate expression result on XML document ndList = (NodeList)
|
||||
|
||||
@@ -179,7 +173,7 @@ public class PDFValidator extends Validator {
|
||||
boolean conformanceLevelValid=false;
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
|
||||
String[] valueArray = { "BASIC WL", "BASIC", "MINIMUM", "EN 16931", "COMFORT", "CIUS", "EXTENDED", "XRECHNUNG" };
|
||||
final String[] valueArray = { "BASIC WL", "BASIC", "MINIMUM", "EN 16931", "COMFORT", "CIUS", "EXTENDED", "XRECHNUNG" };
|
||||
if (stringArrayContains(valueArray, nodes.item(i).getTextContent())) {
|
||||
conformanceLevelValid=true;
|
||||
}
|
||||
@@ -220,7 +214,7 @@ public class PDFValidator extends Validator {
|
||||
}
|
||||
boolean documentFilenameValid=false;
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
String[] valueArray = { "factur-x.xml", "ZUGFeRD-invoice.xml", "zugferd-invoice.xml", "xrechnung.xml" };
|
||||
final String[] valueArray = { "factur-x.xml", "ZUGFeRD-invoice.xml", "zugferd-invoice.xml", "xrechnung.xml" };
|
||||
if (stringArrayContains(valueArray, nodes.item(i).getTextContent())) {
|
||||
documentFilenameValid=true;
|
||||
}
|
||||
@@ -246,7 +240,7 @@ public class PDFValidator extends Validator {
|
||||
|
||||
boolean versionValid=false;
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
String[] valueArray = { "1.0", "2p0", "1.2", "2.0" }; //1.2 and 2.0 are for xrechnung 1.2, 2p0 can be ZF 2.0, 2.1, 2.1.1
|
||||
final String[] valueArray = { "1.0", "2p0", "1.2", "2.0" }; //1.2 and 2.0 are for xrechnung 1.2, 2p0 can be ZF 2.0, 2.1, 2.1.1
|
||||
if (stringArrayContains(valueArray, nodes.item(i).getTextContent())) {
|
||||
versionValid=true;
|
||||
} // e.g. 1.0
|
||||
@@ -258,26 +252,26 @@ public class PDFValidator extends Validator {
|
||||
|
||||
}
|
||||
|
||||
} catch (SAXException e) {
|
||||
} catch (final SAXException e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
} catch (ParserConfigurationException e) {
|
||||
} catch (final ParserConfigurationException e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
} catch (XPathExpressionException e) {
|
||||
} catch (final XPathExpressionException e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
zfXML = zi.getUTF8();
|
||||
|
||||
// step 3 find signatures
|
||||
try {
|
||||
byte[] symtraxSignature = "Symtrax".getBytes("UTF-8");
|
||||
byte[] mustangSignature = "via mustangproject".getBytes("UTF-8");
|
||||
byte[] facturxpythonSignature = "by Alexis de Lattre".getBytes("UTF-8");
|
||||
byte[] intarsysSignature = "intarsys ".getBytes("UTF-8");
|
||||
byte[] konikSignature = "Konik".getBytes("UTF-8");
|
||||
byte[] pdfMachineSignature = "pdfMachine from Broadgun Software".getBytes("UTF-8");
|
||||
byte[] ghostscriptSignature = "%%Invocation:".getBytes("UTF-8");
|
||||
final byte[] symtraxSignature = "Symtrax".getBytes("UTF-8");
|
||||
final byte[] mustangSignature = "via mustangproject".getBytes("UTF-8");
|
||||
final byte[] facturxpythonSignature = "by Alexis de Lattre".getBytes("UTF-8");
|
||||
final byte[] intarsysSignature = "intarsys ".getBytes("UTF-8");
|
||||
final byte[] konikSignature = "Konik".getBytes("UTF-8");
|
||||
final byte[] pdfMachineSignature = "pdfMachine from Broadgun Software".getBytes("UTF-8");
|
||||
final byte[] ghostscriptSignature = "%%Invocation:".getBytes("UTF-8");
|
||||
|
||||
if (searcher.indexOf(file, symtraxSignature) != -1) {
|
||||
Signature = "Symtrax";
|
||||
@@ -297,13 +291,13 @@ public class PDFValidator extends Validator {
|
||||
|
||||
context.setSignature(Signature);
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
} catch (final UnsupportedEncodingException e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
// step 4:validate additional data
|
||||
HashMap<String, byte[]> additionalData=zi.getAdditionalData();
|
||||
for (String filename : additionalData.keySet()) {
|
||||
final HashMap<String, byte[]> additionalData=zi.getAdditionalData();
|
||||
for (final String filename : additionalData.keySet()) {
|
||||
// validating xml in byte[] additionalData.get(filename)
|
||||
LOGGER.info("validating additionalData " + filename);
|
||||
validateSchema(additionalData.get(filename), "ad/basic/additional_data_base_schema.xsd", 2, EPart.pdf);
|
||||
@@ -312,7 +306,7 @@ public class PDFValidator extends Validator {
|
||||
|
||||
//end
|
||||
|
||||
long endTime = Calendar.getInstance().getTimeInMillis();
|
||||
final long endTime = Calendar.getInstance().getTimeInMillis();
|
||||
if (!pdfReport.contains("validationReports compliant=\"1\"")) {
|
||||
context.setInvalid();
|
||||
}
|
||||
@@ -323,7 +317,7 @@ public class PDFValidator extends Validator {
|
||||
}
|
||||
context.addCustomXML(pdfReport + "<info><signature>"
|
||||
+ ((context.getSignature() != null) ? context.getSignature() : "unknown")
|
||||
+ "</signature><duration unit='ms'>" + (endTime - startPDFTime) + "</duration></info>");
|
||||
+ "</signature><duration unit=\"ms\">" + (endTime - startPDFTime) + "</duration></info>");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public class ValidationContext {
|
||||
|
||||
public ValidationContext(Logger log) {
|
||||
logger = log;
|
||||
results = new Vector<ValidationResultItem>();
|
||||
results = new Vector<>();
|
||||
}
|
||||
|
||||
public void addResultItem(ValidationResultItem vr) throws IrrecoverableValidationError {
|
||||
@@ -105,14 +105,14 @@ public class ValidationContext {
|
||||
res += "<messages>";
|
||||
}
|
||||
|
||||
for (ValidationResultItem validationResultItem : results) {
|
||||
for (final ValidationResultItem validationResultItem : results) {
|
||||
// xml and pdf are handled in their respective sections
|
||||
res += validationResultItem.getXMLOnce() + "\n";
|
||||
}
|
||||
if (results.size() > 0) {
|
||||
res += "</messages>";
|
||||
}
|
||||
res += "<summary status='" + (isValid ? "valid" : "invalid") + "'/>";
|
||||
res += "<summary status=\"" + (isValid ? "valid" : "invalid") + "\"/>";
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -121,9 +121,9 @@ public class ValidationContext {
|
||||
* @return the unique error types as comma separated string
|
||||
*/
|
||||
public String getCSVResult() {
|
||||
ArrayList<String> errorcodes = new ArrayList<String>();
|
||||
for (ValidationResultItem validationResultItem : results) {
|
||||
String errorCodeStr=Integer.toString(validationResultItem.getSection());
|
||||
final ArrayList<String> errorcodes = new ArrayList<>();
|
||||
for (final ValidationResultItem validationResultItem : results) {
|
||||
final String errorCodeStr=Integer.toString(validationResultItem.getSection());
|
||||
errorcodes.add(errorCodeStr);
|
||||
}
|
||||
return String.join(",", errorcodes);
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package org.mustangproject.validator;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import javax.print.attribute.standard.Severity;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.*;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathConstants;
|
||||
@@ -25,13 +25,14 @@ import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.helger.schematron.ISchematronResource;
|
||||
import com.helger.schematron.svrl.SVRLHelper;
|
||||
import com.helger.schematron.svrl.jaxb.FailedAssert;
|
||||
import com.helger.schematron.svrl.jaxb.FiredRule;
|
||||
import com.helger.schematron.svrl.jaxb.SchematronOutputType;
|
||||
import com.helger.schematron.ISchematronResource;
|
||||
import com.helger.schematron.xslt.SchematronResourceXSLT;
|
||||
import com.helger.schematron.svrl.SVRLHelper;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
public class XMLValidator extends Validator {
|
||||
|
||||
@@ -57,18 +58,19 @@ public class XMLValidator extends Validator {
|
||||
* @param name
|
||||
* @throws IrrecoverableValidationError
|
||||
*/
|
||||
@Override
|
||||
public void setFilename(String name) throws IrrecoverableValidationError { // from XML Filename
|
||||
filename = name;
|
||||
// file existence must have been checked before
|
||||
|
||||
try {
|
||||
zfXML = new String(XMLTools.removeBOM(Files.readAllBytes(Paths.get(name))), StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
|
||||
ValidationResultItem vri = new ValidationResultItem(ESeverity.exception, e.getMessage()).setSection(9)
|
||||
final ValidationResultItem vri = new ValidationResultItem(ESeverity.exception, e.getMessage()).setSection(9)
|
||||
.setPart(EPart.fx);
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
final StringWriter sw = new StringWriter();
|
||||
final PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
vri.setStacktrace(sw.toString());
|
||||
context.addResultItem(vri);
|
||||
@@ -108,13 +110,13 @@ public class XMLValidator extends Validator {
|
||||
*/
|
||||
@Override
|
||||
public void validate() throws IrrecoverableValidationError {
|
||||
long startXMLTime = Calendar.getInstance().getTimeInMillis();
|
||||
final long startXMLTime = Calendar.getInstance().getTimeInMillis();
|
||||
firedRules = 0;
|
||||
failedRules = 0;
|
||||
|
||||
|
||||
if (zfXML.isEmpty()) {
|
||||
ValidationResultItem res = new ValidationResultItem(ESeverity.exception,
|
||||
final ValidationResultItem res = new ValidationResultItem(ESeverity.exception,
|
||||
"XML data not found in " + filename
|
||||
+ ": did you specify a pdf or xml file and does the xml file contain an embedded XML file?")
|
||||
.setSection(3);
|
||||
@@ -139,33 +141,33 @@ public class XMLValidator extends Validator {
|
||||
*
|
||||
*/
|
||||
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setNamespaceAware(true); // otherwise we can not act namespace independently, i.e. use
|
||||
// document.getElementsByTagNameNS("*",...
|
||||
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
InputSource is = new InputSource(new StringReader(zfXML));
|
||||
Document doc = db.parse(is);
|
||||
final DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
final InputSource is = new InputSource(new StringReader(zfXML));
|
||||
final Document doc = db.parse(is);
|
||||
|
||||
Element root = doc.getDocumentElement();
|
||||
final Element root = doc.getDocumentElement();
|
||||
|
||||
NodeList ndList;
|
||||
final NodeList ndList;
|
||||
|
||||
// rootNode = document.getDocumentElement();
|
||||
// ApplicableSupplyChainTradeSettlement
|
||||
|
||||
// Create XPathFactory object
|
||||
XPathFactory xpathFactory = XPathFactory.newInstance();
|
||||
final XPathFactory xpathFactory = XPathFactory.newInstance();
|
||||
|
||||
// Create XPath object
|
||||
XPath xpath = xpathFactory.newXPath();
|
||||
XPathExpression expr = xpath.compile(
|
||||
final XPath xpath = xpathFactory.newXPath();
|
||||
final XPathExpression expr = xpath.compile(
|
||||
"//*[local-name()=\"GuidelineSpecifiedDocumentContextParameter\"]/*[local-name()=\"ID\"]/text()");
|
||||
// evaluate expression result on XML document
|
||||
ndList = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
|
||||
|
||||
for (int bookingIndex = 0; bookingIndex < ndList.getLength(); bookingIndex++) {
|
||||
Node booking = ndList.item(bookingIndex);
|
||||
final Node booking = ndList.item(bookingIndex);
|
||||
// if there is a attribute in the tag number:value
|
||||
// urn:ferd:CrossIndustryDocument:invoice:1p0:extended
|
||||
// setForeignReference(booking.getTextContent());
|
||||
@@ -301,24 +303,24 @@ public class XMLValidator extends Validator {
|
||||
}
|
||||
|
||||
|
||||
} catch (IrrecoverableValidationError er) {
|
||||
} catch (final IrrecoverableValidationError er) {
|
||||
throw er;
|
||||
} catch (Exception e) {
|
||||
ValidationResultItem vri = new ValidationResultItem(ESeverity.exception, e.getMessage()).setSection(22)
|
||||
} catch (final Exception e) {
|
||||
final ValidationResultItem vri = new ValidationResultItem(ESeverity.exception, e.getMessage()).setSection(22)
|
||||
.setPart(EPart.fx);
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
final StringWriter sw = new StringWriter();
|
||||
final PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
vri.setStacktrace(sw.toString());
|
||||
context.addResultItem(vri);
|
||||
}
|
||||
|
||||
}
|
||||
long endTime = Calendar.getInstance().getTimeInMillis();
|
||||
final long endTime = Calendar.getInstance().getTimeInMillis();
|
||||
|
||||
context.addCustomXML("<info><version>" + ((context.getVersion() != null) ? context.getVersion() : "invalid")
|
||||
+ "</version><profile>" + ((context.getProfile() != null) ? context.getProfile() : "invalid") +
|
||||
"</profile><validator version=\"" + XMLValidator.class.getPackage().getImplementationVersion() + "\"></validator><rules><fired>" + firedRules + "</fired><failed>" + failedRules + "</failed></rules>" + "<duration unit='ms'>" + (endTime - startXMLTime) + "</duration></info>");
|
||||
"</profile><validator version=\"" + XMLValidator.class.getPackage().getImplementationVersion() + "\"></validator><rules><fired>" + firedRules + "</fired><failed>" + failedRules + "</failed></rules>" + "<duration unit=\"ms\">" + (endTime - startXMLTime) + "</duration></info>");
|
||||
|
||||
}
|
||||
|
||||
@@ -352,20 +354,20 @@ public class XMLValidator extends Validator {
|
||||
throw new IllegalArgumentException(xsltFilename + " is invalid Schematron!");
|
||||
}
|
||||
|
||||
SchematronOutputType sout;
|
||||
final SchematronOutputType sout;
|
||||
try {
|
||||
sout = aResSCH
|
||||
.applySchematronValidationToSVRL(new StreamSource(new StringReader(xml)));
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
throw new IrrecoverableValidationError(e.getMessage());
|
||||
}
|
||||
|
||||
List<Object> failedAsserts = sout.getActivePatternAndFiredRuleAndFailedAssert();
|
||||
final List<Object> failedAsserts = sout.getActivePatternAndFiredRuleAndFailedAssert();
|
||||
if (failedAsserts.size() > 0) {
|
||||
for (Object object : failedAsserts) {
|
||||
for (final Object object : failedAsserts) {
|
||||
if (object instanceof FailedAssert) {
|
||||
|
||||
FailedAssert failedAssert = (FailedAssert) object;
|
||||
final FailedAssert failedAssert = (FailedAssert) object;
|
||||
LOGGER.info("FailedAssert ", failedAssert);
|
||||
|
||||
context.addResultItem(new ValidationResultItem(severity, SVRLHelper.getAsString(failedAssert.getText()))
|
||||
|
||||
@@ -9,8 +9,8 @@ public class PDFValidatorTest extends ResourceCase {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ZUGFeRDValidator.class.getCanonicalName()); // log
|
||||
|
||||
public void testPDFValidation() {
|
||||
ValidationContext vc = new ValidationContext(null);
|
||||
PDFValidator pv = new PDFValidator(vc);
|
||||
final ValidationContext vc = new ValidationContext(null);
|
||||
final PDFValidator pv = new PDFValidator(vc);
|
||||
|
||||
try {
|
||||
|
||||
@@ -25,10 +25,10 @@ public class PDFValidatorTest extends ResourceCase {
|
||||
pv.setFilename(tempFile.getAbsolutePath());
|
||||
pv.validate();
|
||||
String actual = pv.getXMLResult();
|
||||
assertEquals(true, actual.contains("summary status='valid"));
|
||||
assertEquals(false, actual.contains("summary status='invalid"));
|
||||
assertEquals(true, actual.contains("summary status=\"valid"));
|
||||
assertEquals(false, actual.contains("summary status=\"invalid"));
|
||||
|
||||
XMLValidator xv = new XMLValidator(vc);
|
||||
final XMLValidator xv = new XMLValidator(vc);
|
||||
xv.setStringContent(pv.getRawXML());
|
||||
xv.validate();
|
||||
actual = vc.getXMLResult();
|
||||
@@ -58,16 +58,16 @@ public class PDFValidatorTest extends ResourceCase {
|
||||
actual.contains("validationReports compliant=\"1\" nonCompliant=\"0\" failedJobs=\"0\">"));
|
||||
|
||||
assertEquals(false, actual.contains("<error"));
|
||||
} catch (IrrecoverableValidationError e) {
|
||||
} catch (final IrrecoverableValidationError e) {
|
||||
// ignore, will be in XML output anyway
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testPDFXMLValidation() {
|
||||
ValidationContext vc = new ValidationContext(null);
|
||||
final ValidationContext vc = new ValidationContext(null);
|
||||
try {
|
||||
PDFValidator pv = new PDFValidator(vc);
|
||||
final PDFValidator pv = new PDFValidator(vc);
|
||||
|
||||
File tempFile = getResourceAsFile("attributeBasedXMP_zugferd_2p0_EN16931_Einfach.pdf");// need a more
|
||||
// invalid file here
|
||||
@@ -99,7 +99,7 @@ public class PDFValidatorTest extends ResourceCase {
|
||||
xmlvres = xv.getXMLResult();
|
||||
assertEquals(true, pdfvres.contains("valid") && !pdfvres.contains("invalid"));
|
||||
assertEquals(true, xmlvres.contains("valid") && !xmlvres.contains("invalid"));
|
||||
} catch (IrrecoverableValidationError e) {
|
||||
} catch (final IrrecoverableValidationError e) {
|
||||
// ignore, will be in XML output anyway
|
||||
}
|
||||
|
||||
@@ -107,8 +107,8 @@ public class PDFValidatorTest extends ResourceCase {
|
||||
|
||||
public void testXMPValidation() {
|
||||
|
||||
ValidationContext vc = new ValidationContext(null);
|
||||
PDFValidator pv = new PDFValidator(vc);
|
||||
final ValidationContext vc = new ValidationContext(null);
|
||||
final PDFValidator pv = new PDFValidator(vc);
|
||||
try {
|
||||
|
||||
File tempFile = getResourceAsFile("invalidXMP.pdf");
|
||||
@@ -130,7 +130,7 @@ public class PDFValidatorTest extends ResourceCase {
|
||||
|
||||
assertEquals(false, actual.contains("<error"));// issue 18: "ConformanceLevel not found" should not be
|
||||
// reported since it's actually there
|
||||
} catch (IrrecoverableValidationError e) {
|
||||
} catch (final IrrecoverableValidationError e) {
|
||||
// ignore, will be in XML output anyway
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user