generate ZF XSLTs from schematron when building
This commit is contained in:
@@ -133,7 +133,6 @@
|
||||
<configuration>
|
||||
<schematronDirectory>${basedir}/src/main/resources/schematron</schematronDirectory>
|
||||
<xsltDirectory>${basedir}/src/main/resources/xslt</xsltDirectory>
|
||||
<schematronPattern>**/XRechnung-CII-validation.sch</schematronPattern><!-- the xrechnung refers to fragments also called ...sch, which will cause the build to fail if not excluded -->
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
@@ -235,6 +234,31 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-zf-schematron-xml-dependencies</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
|
||||
<configuration>
|
||||
<outputDirectory>${basedir}/xslt/ZF_211/</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>/schematron/ZF_211/</directory>
|
||||
<includes>
|
||||
<include>*.xml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<licenses>
|
||||
|
||||
@@ -180,23 +180,23 @@ public class XMLValidator extends Validator {
|
||||
if (isMiniumum) {
|
||||
LOGGER.debug("is Minimum");
|
||||
validateSchema(zfXML.getBytes(StandardCharsets.UTF_8), "zf2/MINIMUM/FACTUR-X_MINIMUM.xsd", 18, EPart.fx);
|
||||
xsltFilename = "/xslt/zugferd21_minimum.xsl";
|
||||
xsltFilename = "/xslt/ZF_211/FACTUR-X_MINIMUM.xslt";
|
||||
} else if (isBasicWithoutLines) {
|
||||
LOGGER.debug("is Basic/WL");
|
||||
validateSchema(zfXML.getBytes(StandardCharsets.UTF_8), "zf2/BASIC-WL/FACTUR-X_BASIC-WL.xsd", 18, EPart.fx);
|
||||
xsltFilename = "/xslt/zugferd21_basicwl.xsl";
|
||||
xsltFilename = "/xslt/ZF_211/FACTUR-X_BASIC-WL.xslt";
|
||||
} else if (isBasic) {
|
||||
LOGGER.debug("is Basic");
|
||||
validateSchema(zfXML.getBytes(StandardCharsets.UTF_8), "zf2/BASIC/FACTUR-X_BASIC.xsd", 18, EPart.fx);
|
||||
xsltFilename = "/xslt/zugferd21_basic.xsl";
|
||||
xsltFilename = "/xslt/ZF_211/FACTUR-X_BASIC.xslt";
|
||||
} else if (isEN16931) {
|
||||
LOGGER.debug("is EN16931");
|
||||
validateSchema(zfXML.getBytes(StandardCharsets.UTF_8), "zf2/EN16931/FACTUR-X_EN16931.xsd", 18, EPart.fx);
|
||||
xsltFilename = "/xslt/zugferd21_en16931.xsl";
|
||||
xsltFilename = "/xslt/ZF_211/FACTUR-X_EN16931.xslt";
|
||||
} else if (isExtended) {
|
||||
LOGGER.debug("is EXTENDED");
|
||||
validateSchema(zfXML.getBytes(StandardCharsets.UTF_8), "zf2/EXTENDED/FACTUR-X_EXTENDED.xsd", 18, EPart.fx);
|
||||
xsltFilename = "/xslt/zugferd21_extended.xsl";
|
||||
xsltFilename = "/xslt/ZF_211/FACTUR-X_EXTENDED.xslt";
|
||||
} /*
|
||||
* ISchematronResource aResSCH = SchematronResourceXSLT.fromFile(new File(
|
||||
* "/Users/jstaerk/workspace/ZUV/src/main/resources/ZUGFeRDSchematronStylesheet.xsl"
|
||||
@@ -280,77 +280,9 @@ public class XMLValidator extends Validator {
|
||||
|
||||
}
|
||||
|
||||
protected String getXRValidationResult(String xml) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
TransformerFactory factory = TransformerFactory.newInstance();
|
||||
|
||||
try {
|
||||
// Use the factory to create a template containing the xsl file
|
||||
Templates template = factory.newTemplates(new StreamSource(
|
||||
this.getClass().getResourceAsStream("/xslt/XRechnung-CII-validation.xsl")));
|
||||
|
||||
// Use the template to create a transformer
|
||||
Transformer xformer = template.newTransformer();
|
||||
|
||||
// Prepare the input and output files
|
||||
|
||||
Source source = new StreamSource(new ByteArrayInputStream(xml.getBytes()));
|
||||
Result result = new StreamResult(baos);
|
||||
|
||||
// Apply the xsl file to the source file and write the result
|
||||
// to the output file
|
||||
xformer.transform(source, result);
|
||||
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error(ex.getMessage(), ex);
|
||||
}
|
||||
return baos.toString();
|
||||
|
||||
}
|
||||
|
||||
public void validateXR(String xml) throws IrrecoverableValidationError {
|
||||
|
||||
/*
|
||||
DocumentBuilderFactory docbfactory = DocumentBuilderFactory.newInstance();
|
||||
try {
|
||||
DocumentBuilder builder = docbfactory.newDocumentBuilder();
|
||||
InputSource is = new InputSource(new StringReader(getXRValidationResult(xml)));
|
||||
Document docXMP = builder.parse(is);
|
||||
|
||||
XPathFactory xpathFactory = XPathFactory.newInstance();
|
||||
|
||||
// Create XPath object XPath xpath = xpathFactory.newXPath(); XPathExpression
|
||||
|
||||
XPath xpath = xpathFactory.newXPath();
|
||||
// xpath.compile("//*[local-name()=\"GuidelineSpecifiedDocumentContextParameter\"]/[local-name()=\"ID\"]");
|
||||
// evaluate expression result on XML document ndList = (NodeList)
|
||||
|
||||
// get the first element
|
||||
XPathExpression xpr = xpath.compile(
|
||||
"//*[local-name()=\"failed-assert\"]");
|
||||
NodeList nodes = (NodeList) xpr.evaluate(docXMP, XPathConstants.NODESET);
|
||||
for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) {
|
||||
String loc=nodes.item(nodeIndex).getAttributes().getNamedItem("location").getTextContent();
|
||||
NodeList failedSubNodes=nodes.item(nodeIndex).getChildNodes();
|
||||
for (int failedSubNodeIndex = 0; failedSubNodeIndex < nodes.getLength(); failedSubNodeIndex++) {
|
||||
|
||||
if (failedSubNodes.item(failedSubNodeIndex).getNodeName().equals("svrl:text")) {
|
||||
context.addResultItem(
|
||||
new ValidationResultItem(ESeverity.warning, failedSubNodes.item(failedSubNodeIndex).getTextContent())
|
||||
.setLocation(loc).setSection(27).setPart(EPart.xr));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error(ex.getMessage(), ex);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
validateSchematron(xml, "/xslt/XRechnung-CII-validation.xslt",27, ESeverity.notice);
|
||||
validateSchematron(xml, "/xslt/XR/XRechnung-CII-validation.xslt",27, ESeverity.notice);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,13 @@
|
||||
|
||||
<!-- Abstract CEN BII patterns -->
|
||||
<!-- ========================= -->
|
||||
<include href="abstract/XRechnung-model.sch" />
|
||||
<!-- in the original these includes are mistakenly called .sch but that has to be changed manually
|
||||
since they are no complete schematrons which otherwise conflicts with ph-schematron -->
|
||||
<include href="abstract/XRechnung-model.part" />
|
||||
|
||||
<!-- Data Binding parameters -->
|
||||
<!-- ======================= -->
|
||||
<include href="CII/XRechnung-CII-model.sch" />
|
||||
<include href="CII/XRechnung-CII-model.part" />
|
||||
|
||||
|
||||
</schema>
|
||||
|
||||
Reference in New Issue
Block a user