diff --git a/src/main/java/org/dita/dost/platform/ImportAntLibAction.java b/src/main/java/org/dita/dost/platform/ImportAntLibAction.java index a06d4727ee..ed89dd7a2a 100644 --- a/src/main/java/org/dita/dost/platform/ImportAntLibAction.java +++ b/src/main/java/org/dita/dost/platform/ImportAntLibAction.java @@ -11,7 +11,6 @@ import static javax.xml.XMLConstants.NULL_NS_URI; import static org.dita.dost.util.XMLUtils.AttributesBuilder; -import java.io.File; import org.dita.dost.util.FileUtils; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; @@ -29,7 +28,13 @@ final class ImportAntLibAction extends ImportAction { public void getResult(final ContentHandler retBuf) throws SAXException { final String templateFilePath = paramTable.get(FileGenerator.PARAM_TEMPLATE); for (final Value value : valueSet) { - final String path = ((Value.PathValue) value).baseDir() + File.separator + value.value(); + final String path; + if (value instanceof Value.PathValue pathValue) { + path = pathValue.getPath(); + } else { + logger.error("Ant import must be a file feature: " + value.value()); + continue; + } final String resolvedValue = FileUtils.getRelativeUnixPath(templateFilePath, path); if (FileUtils.isAbsolutePath(resolvedValue)) { // if resolvedValue is absolute path diff --git a/src/main/java/org/dita/dost/platform/ImportCatalogActionRelative.java b/src/main/java/org/dita/dost/platform/ImportCatalogActionRelative.java index f881fbbae6..d5bdecbbc1 100644 --- a/src/main/java/org/dita/dost/platform/ImportCatalogActionRelative.java +++ b/src/main/java/org/dita/dost/platform/ImportCatalogActionRelative.java @@ -9,7 +9,6 @@ import static org.dita.dost.util.Constants.OASIS_CATALOG_NAMESPACE; -import java.io.File; import org.dita.dost.util.FileUtils; import org.dita.dost.util.XMLUtils.AttributesBuilder; import org.xml.sax.ContentHandler; @@ -27,7 +26,13 @@ final class ImportCatalogActionRelative extends ImportAction { public void getResult(final ContentHandler buf) throws SAXException { final String templateFilePath = paramTable.get(FileGenerator.PARAM_TEMPLATE); for (final Value value : valueSet) { - final String path = ((Value.PathValue) value).baseDir() + File.separator + value.value(); + final String path; + if (value instanceof Value.PathValue pathValue) { + path = pathValue.getPath(); + } else { + logger.error("Catalog import must be a file feature: " + value.value()); + continue; + } buf.startElement( OASIS_CATALOG_NAMESPACE, "nextCatalog", diff --git a/src/main/java/org/dita/dost/platform/ImportStringsAction.java b/src/main/java/org/dita/dost/platform/ImportStringsAction.java index 0fdff5c9c3..0f9ba6b3df 100644 --- a/src/main/java/org/dita/dost/platform/ImportStringsAction.java +++ b/src/main/java/org/dita/dost/platform/ImportStringsAction.java @@ -10,7 +10,6 @@ import static javax.xml.XMLConstants.NULL_NS_URI; -import java.io.File; import org.dita.dost.util.FileUtils; import org.dita.dost.util.XMLUtils.AttributesBuilder; import org.xml.sax.ContentHandler; @@ -29,8 +28,14 @@ final class ImportStringsAction extends ImportAction { public void getResult(final ContentHandler buf) throws SAXException { final String templateFilePath = paramTable.get(FileGenerator.PARAM_TEMPLATE); for (final Value value : valueSet) { + final String path; + if (value instanceof Value.PathValue pathValue) { + path = pathValue.getPath(); + } else { + logger.error("String import must be a file feature: " + value.value()); + continue; + } buf.startElement(NULL_NS_URI, "stringfile", "stringfile", new AttributesBuilder().build()); - final String path = ((Value.PathValue) value).baseDir() + File.separator + value.value(); final char[] location = FileUtils.getRelativeUnixPath(templateFilePath, path).toCharArray(); buf.characters(location, 0, location.length); buf.endElement(NULL_NS_URI, "stringfile", "stringfile"); diff --git a/src/main/java/org/dita/dost/platform/ImportXSLAction.java b/src/main/java/org/dita/dost/platform/ImportXSLAction.java index b9e282a601..303f240cfc 100644 --- a/src/main/java/org/dita/dost/platform/ImportXSLAction.java +++ b/src/main/java/org/dita/dost/platform/ImportXSLAction.java @@ -8,7 +8,6 @@ */ package org.dita.dost.platform; -import java.io.File; import java.net.URI; import org.dita.dost.platform.Value.PathValue; import org.dita.dost.util.FileUtils; @@ -47,7 +46,7 @@ public void getResult(final ContentHandler buf) throws SAXException { private URI getHref(final PathValue value) { final Plugin features = featureTable.get(value.pluginId()); final URI pluginDir = features.pluginDir().toURI(); - final String path = value.baseDir() + File.separator + value.value(); + final String path = value.getPath(); final URI templateFile = URLUtils.toFile(path).toURI().normalize(); final URI template = pluginDir.relativize(templateFile); if (value.pluginId() == null || template.isAbsolute()) { diff --git a/src/main/java/org/dita/dost/platform/InsertAction.java b/src/main/java/org/dita/dost/platform/InsertAction.java index 4f07667d56..ec1ddb2d98 100644 --- a/src/main/java/org/dita/dost/platform/InsertAction.java +++ b/src/main/java/org/dita/dost/platform/InsertAction.java @@ -8,7 +8,6 @@ */ package org.dita.dost.platform; -import java.io.File; import java.io.IOException; import java.io.UncheckedIOException; import java.util.*; @@ -71,7 +70,12 @@ public void getResult(final ContentHandler retBuf) throws SAXException { setContentHandler(retBuf); try { for (final Value fileName : fileNameSet) { - currentFile = ((Value.PathValue) fileName).baseDir() + File.separator + fileName.value(); + if (fileName instanceof Value.PathValue pathValue) { + currentFile = pathValue.getPath(); + } else { + logger.error("Catalog import must be a file feature: " + fileName.value()); + continue; + } reader.parse(currentFile); } } catch (SAXException | RuntimeException e) { diff --git a/src/main/java/org/dita/dost/platform/Integrator.java b/src/main/java/org/dita/dost/platform/Integrator.java index 0bd25e4f73..528008a3b8 100644 --- a/src/main/java/org/dita/dost/platform/Integrator.java +++ b/src/main/java/org/dita/dost/platform/Integrator.java @@ -33,6 +33,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; +import java.util.stream.Stream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import javax.xml.XMLConstants; @@ -649,7 +650,14 @@ private Collection relativize(final Collection src) { final File base = new File(ditaDir, "dummy"); return src .stream() - .map(lib -> toFile(((Value.PathValue) lib).baseDir() + File.separator + lib.value())) + .flatMap(lib -> { + if (lib instanceof Value.PathValue path) { + return Stream.of(toFile(path.getPath())); + } else { + logger.error("Library import must be a file feature: " + lib.value()); + return Stream.empty(); + } + }) .map(libFile -> { if (!libFile.exists()) { throw new IllegalArgumentException("Library file not found: " + libFile.getAbsolutePath()); diff --git a/src/main/java/org/dita/dost/platform/Value.java b/src/main/java/org/dita/dost/platform/Value.java index 7813df8c67..9ef43c0af2 100644 --- a/src/main/java/org/dita/dost/platform/Value.java +++ b/src/main/java/org/dita/dost/platform/Value.java @@ -16,5 +16,9 @@ public sealed interface Value { record StringValue(String pluginId, String value) implements Value {} - record PathValue(String pluginId, File baseDir, String value) implements Value {} + record PathValue(String pluginId, File baseDir, String value) implements Value { + public String getPath() { + return baseDir + File.separator + value; + } + } }