Skip to content

Commit

Permalink
Log incorrect feature type
Browse files Browse the repository at this point in the history
Signed-off-by: Jarno Elovirta <[email protected]>
  • Loading branch information
jelovirt committed Jul 22, 2024
1 parent 74b5387 commit 70112b8
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 12 deletions.
9 changes: 7 additions & 2 deletions src/main/java/org/dita/dost/platform/ImportAntLibAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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",
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/org/dita/dost/platform/ImportStringsAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/dita/dost/platform/ImportXSLAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/dita/dost/platform/InsertAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/
package org.dita.dost.platform;

import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.*;
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/dita/dost/platform/Integrator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -649,7 +650,14 @@ private Collection<File> relativize(final Collection<Value> 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());
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/dita/dost/platform/Value.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

0 comments on commit 70112b8

Please sign in to comment.