Skip to content
Permalink
Browse files
docbook-schemas 5.2 compatibility (although it's not out yet, so we s…
…till use 5.1)
  • Loading branch information
ddekany committed Sep 11, 2021
1 parent d62e1ad commit f375bd8510d5db1bde9f5a3ae2e74fb79888a159
Showing 2 changed files with 19 additions and 5 deletions.
@@ -58,7 +58,8 @@
<groupId>org.docbook</groupId>
<artifactId>docbook-schemas</artifactId>
<version>5.1-1</version>
<!-- We just need the docbook.rng resource from this artifact, so we exclude all dependencies: -->
<!-- We just need the docbook.rng resource from this artifact, so we exclude all dependencies. -->
<!-- These exclusions can be removed starting from 5.2. -->
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
@@ -20,6 +20,8 @@

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -101,10 +103,11 @@ public static Document load(File f, DocgenValidationOptions validationOps)
SchemaReader scemaReader = new AutoSchemaReader();
Schema schema;
try {
URL rngUrl = getRequiredResource(
"/org/docbook/schemas/5.0/rng/docbook.rng",
"/schema/5.0/rng/docbook.rng");
schema = scemaReader.createSchema(
ValidationDriver.uriOrFileInputSource(
RelaxNGValidator.class.getResource(
"/schema/5.0/rng/docbook.rng").toString()),
ValidationDriver.uriOrFileInputSource(rngUrl.toString()),
schemaProps.toPropertyMap());
} catch (IncorrectSchemaException e) {
throw new BugException(
@@ -185,5 +188,15 @@ public static Document load(File f, DocgenValidationOptions validationOps)

return domBuilder.getDocument();
}


private static URL getRequiredResource(String... resourceAndFallbacks) throws IOException {
for (String attemptedResource : resourceAndFallbacks) {
URL url = RelaxNGValidator.class.getResource(attemptedResource);
if (url != null) {
return url;
}
}
throw new IOException("Resource was not found on any of these locations: " + Arrays.asList(resourceAndFallbacks));
}

}

0 comments on commit f375bd8

Please sign in to comment.