Example #1
0
  /**
   * Validation of CitationStyle XML against 1) XML schema 2) Schematron schema
   *
   * @param xmlDocumentUrl is URI to XML to be validated
   * @throws IOException
   */
  public String validateCitationStyleXML(final String cs) throws IOException {
    String csFile = CitationUtil.getPathToCitationStyleXML(cs);
    logger.info("Document to be validated: " + csFile);

    // XML Schema validation
    logger.info("XML Schema validation...");
    String report =
        validateSchema(
            CitationUtil.getUriToResources()
                + CitationUtil.SCHEMAS_DIRECTORY
                + CITATIONSTYLE_XML_SCHEMA_FILE,
            csFile);
    if (report != null) {
      return report;
    }
    logger.info("OK");

    // Schematron validation
    logger.info("Schematron validation...");
    SchtrnValidator validator = new SchtrnValidator();
    validator.setEngineStylesheet(
        CitationUtil.getPathToSchemas() + SCHEMATRON_DIRECTORY + "schematron-diagnose.xsl");
    validator.setParams(new SchtrnParams());
    validator.setBaseXML(true);
    try {
      report = validator.validate(csFile, CitationUtil.getPathToSchemas() + SCHEMATRON_FILE);
    } catch (TransformerConfigurationException e1) {
      return "Schematron validation problem (TransformerConfigurationException): "
          + e1.getMessage();
    } catch (TransformerException e1) {
      return "Schematron validation problem (TransformerException): " + e1.getMessage();
    } catch (Exception e1) {
      return "Schematron validation problem: " + e1.getMessage();
    }
    if (report != null && report.contains("Report: ")) {
      return report;
    }
    logger.info("OK");

    return null;
  }