You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2021/09/11 09:02:24 UTC
[freemarker-docgen] branch master updated: docbook-schemas 5.2
compatibility (although it's not out yet, so we still use 5.1)
This is an automated email from the ASF dual-hosted git repository.
ddekany pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/freemarker-docgen.git
The following commit(s) were added to refs/heads/master by this push:
new f375bd8 docbook-schemas 5.2 compatibility (although it's not out yet, so we still use 5.1)
f375bd8 is described below
commit f375bd8510d5db1bde9f5a3ae2e74fb79888a159
Author: ddekany <dd...@apache.org>
AuthorDate: Sat Sep 11 10:48:48 2021 +0200
docbook-schemas 5.2 compatibility (although it's not out yet, so we still use 5.1)
---
freemarker-docgen-core/pom.xml | 3 ++-
.../freemarker/docgen/core/RelaxNGValidator.java | 21 +++++++++++++++++----
2 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/freemarker-docgen-core/pom.xml b/freemarker-docgen-core/pom.xml
index c67591c..979d131 100644
--- a/freemarker-docgen-core/pom.xml
+++ b/freemarker-docgen-core/pom.xml
@@ -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>
diff --git a/freemarker-docgen-core/src/main/java/org/freemarker/docgen/core/RelaxNGValidator.java b/freemarker-docgen-core/src/main/java/org/freemarker/docgen/core/RelaxNGValidator.java
index c6f9843..161e5ec 100644
--- a/freemarker-docgen-core/src/main/java/org/freemarker/docgen/core/RelaxNGValidator.java
+++ b/freemarker-docgen-core/src/main/java/org/freemarker/docgen/core/RelaxNGValidator.java
@@ -20,6 +20,8 @@ package org.freemarker.docgen.core;
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 @@ final class RelaxNGValidator {
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 @@ final class RelaxNGValidator {
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));
+ }
+
}