From 75703fc7a31e960fad5335ee38361cf0a5b65962 Mon Sep 17 00:00:00 2001 From: Greg Gibeling Date: Wed, 25 Sep 2024 16:35:41 -0700 Subject: [PATCH] G2-1648 Implement & use file extensions as paths --- .../com/g2forge/joint/md/MD2HTMLConversionType.java | 7 ++++--- .../g2forge/joint/md/TestMD2HTMLConversionType.java | 4 ++-- .../joint/plantuml/PlantUMLConversionType.java | 11 ++++++----- .../ssg/staticcontent/StaticContentComponent.java | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/jo-md/src/main/java/com/g2forge/joint/md/MD2HTMLConversionType.java b/jo-md/src/main/java/com/g2forge/joint/md/MD2HTMLConversionType.java index ff7122c..2f25811 100644 --- a/jo-md/src/main/java/com/g2forge/joint/md/MD2HTMLConversionType.java +++ b/jo-md/src/main/java/com/g2forge/joint/md/MD2HTMLConversionType.java @@ -11,12 +11,13 @@ import com.g2forge.alexandria.java.core.helpers.HCollection; import com.g2forge.alexandria.java.function.IFunction1; -import com.g2forge.alexandria.java.io.Filename; +import com.g2forge.alexandria.java.io.HPath; import com.g2forge.alexandria.java.io.dataaccess.PathDataSink; import com.g2forge.alexandria.java.io.dataaccess.PathDataSource; import com.g2forge.alexandria.java.text.escape.IEscaper; import com.g2forge.alexandria.java.text.escape.SequenceEscaper; import com.g2forge.alexandria.media.MediaType; +import com.g2forge.alexandria.path.path.filename.Filename; import com.g2forge.joint.core.IConversion; import com.g2forge.joint.core.IConversionContext; import com.g2forge.joint.core.copy.FileConversion; @@ -124,8 +125,8 @@ protected String convertToTargetURI(final URI uri, final String path) { @Override public Path computeOutputRelative(FileConversion conversion) { final Path inputRelative = conversion.getInputRelative(); - if (new Filename(inputRelative).getFullName().equals("README")) return Filename.modifyFilename(inputRelative, "index." + MediaType.HTML.getFileExtensions().getDefaultExtension()); - else return Filename.replaceLastExtension(inputRelative, MediaType.HTML.getFileExtensions().getDefaultExtension()); + if (Filename.fromPath(inputRelative).getPrefix().toString().equals("README")) return HPath.replaceFilename(inputRelative, "index." + MediaType.HTML.getFileExtensions().getDefaultExtension()); + else return Filename.replaceExtension(inputRelative, MediaType.HTML.getFileExtensions().getDefaultExtension()); } @Override diff --git a/jo-md/src/test/java/com/g2forge/joint/md/TestMD2HTMLConversionType.java b/jo-md/src/test/java/com/g2forge/joint/md/TestMD2HTMLConversionType.java index 8b347d4..f7b3a4e 100644 --- a/jo-md/src/test/java/com/g2forge/joint/md/TestMD2HTMLConversionType.java +++ b/jo-md/src/test/java/com/g2forge/joint/md/TestMD2HTMLConversionType.java @@ -12,9 +12,9 @@ import org.junit.rules.TestName; import com.g2forge.alexandria.java.function.IFunction1; -import com.g2forge.alexandria.java.io.Filename; import com.g2forge.alexandria.media.IMediaType; import com.g2forge.alexandria.media.MediaType; +import com.g2forge.alexandria.path.path.filename.Filename; import com.g2forge.alexandria.test.HAssert; import com.g2forge.joint.core.ExtendedMediaType; @@ -28,7 +28,7 @@ public class TestMD2HTMLConversionType { if (inputMediaType == MediaType.Markdown) outputMediaType = MediaType.HTML; else if (inputMediaType == ExtendedMediaType.PlantUML) outputMediaType = MediaType.PNG; else outputMediaType = inputMediaType; - return (outputMediaType == null) ? path : Filename.replaceLastExtension(path, outputMediaType.getFileExtensions().getDefaultExtension()); + return (outputMediaType == null) ? path : Filename.replaceExtension(path, outputMediaType.getFileExtensions().getDefaultExtension()); }; @Rule diff --git a/jo-plantuml/src/main/java/com/g2forge/joint/plantuml/PlantUMLConversionType.java b/jo-plantuml/src/main/java/com/g2forge/joint/plantuml/PlantUMLConversionType.java index 3bea345..7848969 100644 --- a/jo-plantuml/src/main/java/com/g2forge/joint/plantuml/PlantUMLConversionType.java +++ b/jo-plantuml/src/main/java/com/g2forge/joint/plantuml/PlantUMLConversionType.java @@ -9,8 +9,9 @@ import com.g2forge.alexandria.java.core.helpers.HStream; import com.g2forge.alexandria.java.core.marker.ISingleton; -import com.g2forge.alexandria.java.io.Filename; +import com.g2forge.alexandria.java.io.HPath; import com.g2forge.alexandria.java.io.HTextIO; +import com.g2forge.alexandria.path.path.filename.Filename; import com.g2forge.joint.core.IConversionContext; import com.g2forge.joint.core.copy.FileConversion; import com.g2forge.joint.core.copy.IFileConversionType; @@ -33,14 +34,14 @@ protected PlantUMLConversionType() {} @Override public Path computeOutputRelative(FileConversion conversion) { final Path inputRelative = conversion.getInputRelative(); - final Filename filename = new Filename(inputRelative); - if (filename.getComponents().size() > 2) return Filename.modifyFilename(inputRelative, filename.getFullName()); - else return Filename.modifyFilename(inputRelative, filename.getFirstName() + FileFormat.PNG.getFileSuffix()); + final Filename filename = Filename.fromPath(inputRelative); + if (filename.size() > 2) return HPath.replaceFilename(inputRelative, filename.getPrefix().toString()); + else return HPath.replaceFilename(inputRelative, filename.getFirst() + FileFormat.PNG.getFileSuffix()); } @Override public void convert(IConversionContext context, FileConversion conversion, Path input, Path output) throws IOException { - final String extension = "." + new Filename(output).getLastExtension(); + final String extension = "." + Filename.fromPath(output).getLast(); final FileFormat format = HStream.findOne(Stream.of(FileFormat.values()).filter(f -> f.getFileSuffix().toLowerCase().equals(extension))); if (!Files.isRegularFile(output) || (Files.getLastModifiedTime(output).compareTo(Files.getLastModifiedTime(input)) <= 0)) { diff --git a/jo-ssg/src/main/java/com/g2forge/joint/ssg/staticcontent/StaticContentComponent.java b/jo-ssg/src/main/java/com/g2forge/joint/ssg/staticcontent/StaticContentComponent.java index 2c924d9..cba4866 100644 --- a/jo-ssg/src/main/java/com/g2forge/joint/ssg/staticcontent/StaticContentComponent.java +++ b/jo-ssg/src/main/java/com/g2forge/joint/ssg/staticcontent/StaticContentComponent.java @@ -17,8 +17,8 @@ import com.g2forge.alexandria.annotations.note.NoteType; import com.g2forge.alexandria.java.core.helpers.HCollection; import com.g2forge.alexandria.java.function.IConsumer1; -import com.g2forge.alexandria.java.io.Filename; import com.g2forge.alexandria.media.IMediaType; +import com.g2forge.alexandria.path.path.filename.Filename; import com.g2forge.joint.core.IComponent; import com.g2forge.joint.core.IConversion; import com.g2forge.joint.core.copy.CopyComponent; @@ -123,7 +123,7 @@ public void map(IConsumer1 consumer) { break; default: - final IMediaType mediaType = getConfiguration().getRegistry().computeMediaType(new Filename(entry.getRelative())); + final IMediaType mediaType = getConfiguration().getRegistry().computeMediaType(Filename.fromPath(entry.getRelative())); retVal.conversionType(getConfiguration().getTypes().getOrDefault(mediaType, CopyConversionType.create())); break; }