Search in sources :

Example 1 with FiredRule

use of com.helger.schematron.svrl.jaxb.FiredRule in project ph-schematron by phax.

the class PSXPathValidationHandlerSVRL method onFiredRule.

@Override
public void onFiredRule(@Nonnull final PSRule aRule, @Nonnull final String sContext, @Nonnull final int nNodeIndex, @Nonnull final int nNodeCount) {
    final FiredRule aRetRule = new FiredRule();
    aRetRule.setContext(sContext);
    aRetRule.setFlag(aRule.getFlag());
    aRetRule.setId(aRule.getID());
    if (aRule.hasLinkable())
        aRetRule.setRole(aRule.getLinkable().getRole());
    final PSRichGroup aRich = aRule.getRich();
    if (aRich != null) {
        aRetRule.setLang(aRich.getXmlLang());
        if (aRich.hasXmlSpace())
            aRetRule.setSpace(aRich.getXmlSpace().getID());
        aRetRule.setIcon(aRich.getIcon());
        aRetRule.setSee(aRich.getSee());
        aRetRule.setFpi(aRich.getFPI());
    }
    m_aSchematronOutput.getActivePatternAndFiredRuleAndFailedAssert().add(aRetRule);
}
Also used : FiredRule(com.helger.schematron.svrl.jaxb.FiredRule) PSRichGroup(com.helger.schematron.pure.model.PSRichGroup)

Example 2 with FiredRule

use of com.helger.schematron.svrl.jaxb.FiredRule in project mustangproject by ZUGFeRD.

the class XMLValidator method validateSchematron.

/**
 * validate using a xslt file generated from a schematron in the build preparation of this software
 * @param xml the xml to be checked
 * @param xsltFilename the filename of the intermediate XSLT file
 * @param section the error type code, if one arises
 * @param severity how serious a error should be treated - may only be notice
 * @throws IrrecoverableValidationError if anything happened that prevents further checks
 */
public void validateSchematron(String xml, String xsltFilename, int section, ESeverity severity) throws IrrecoverableValidationError {
    ISchematronResource aResSCH = null;
    aResSCH = SchematronResourceXSLT.fromClassPath(xsltFilename);
    if (aResSCH != null) {
        if (!aResSCH.isValidSchematron()) {
            throw new IllegalArgumentException(xsltFilename + " is invalid Schematron!");
        }
        final SchematronOutputType sout;
        try {
            sout = aResSCH.applySchematronValidationToSVRL(new StreamSource(new StringReader(xml)));
        } catch (final Exception e) {
            throw new IrrecoverableValidationError(e.getMessage());
        }
        final List<Object> failedAsserts = sout.getActivePatternAndFiredRuleAndFailedAssert();
        if (failedAsserts.size() > 0) {
            for (final Object object : failedAsserts) {
                if (object instanceof FailedAssert) {
                    final FailedAssert failedAssert = (FailedAssert) object;
                    LOGGER.info("FailedAssert ", failedAssert);
                    context.addResultItem(new ValidationResultItem(severity, SVRLHelper.getAsString(failedAssert.getText()) + " (From " + xsltFilename + ")").setLocation(failedAssert.getLocation()).setCriterion(failedAssert.getTest()).setSection(section).setPart(EPart.fx));
                    failedRules++;
                } else if (object instanceof FiredRule) {
                    firedRules++;
                }
            }
        }
        if (firedRules == 0) {
            context.addResultItem(new ValidationResultItem(ESeverity.error, "No rules matched, XML to minimal?").setSection(26).setPart(EPart.fx));
        }
    // for (String currentString : sout.getText()) {
    // schematronValidationString += "<output>" + currentString + "</output>";
    // }
    // schematronValidationString += new SVRLMarshaller ().getAsString (sout);
    // returns the complete SVRL
    }
}
Also used : SchematronOutputType(com.helger.schematron.svrl.jaxb.SchematronOutputType) ISchematronResource(com.helger.schematron.ISchematronResource) FiredRule(com.helger.schematron.svrl.jaxb.FiredRule) StreamSource(javax.xml.transform.stream.StreamSource) FailedAssert(com.helger.schematron.svrl.jaxb.FailedAssert) StringReader(java.io.StringReader) IOException(java.io.IOException)

Aggregations

FiredRule (com.helger.schematron.svrl.jaxb.FiredRule)2 ISchematronResource (com.helger.schematron.ISchematronResource)1 PSRichGroup (com.helger.schematron.pure.model.PSRichGroup)1 FailedAssert (com.helger.schematron.svrl.jaxb.FailedAssert)1 SchematronOutputType (com.helger.schematron.svrl.jaxb.SchematronOutputType)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 StreamSource (javax.xml.transform.stream.StreamSource)1