From 34897eebd22c3de968b64f09bb4a371d96cb0b89 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 3 Feb 2020 03:02:01 +0000 Subject: CTAN sync 202002030302 --- .../main/java/org/islandoftex/texplate/Main.java | 36 -- .../exceptions/InvalidKeySetException.java | 37 -- .../exceptions/InvalidTemplateException.java | 34 -- .../exceptions/TemplateMergingException.java | 37 -- .../islandoftex/texplate/model/Configuration.java | 150 -------- .../org/islandoftex/texplate/model/Template.java | 252 ------------- .../texplate/model/TemplateProcessing.java | 391 --------------------- .../texplate/model/handlers/BooleanHandler.java | 26 -- .../texplate/model/handlers/CSVListHandler.java | 30 -- .../texplate/model/handlers/Handler.java | 20 -- .../islandoftex/texplate/util/HandlerUtils.java | 31 -- .../islandoftex/texplate/util/MergingUtils.java | 186 ---------- .../islandoftex/texplate/util/MessageUtils.java | 84 ----- .../org/islandoftex/texplate/util/PathUtils.java | 129 ------- .../islandoftex/texplate/util/ValidatorUtils.java | 75 ---- .../main/kotlin/org/islandoftex/texplate/Main.kt | 23 ++ .../org/islandoftex/texplate/TemplateProcessing.kt | 228 ++++++++++++ .../texplate/exceptions/InvalidKeySetException.kt | 30 ++ .../exceptions/InvalidTemplateException.kt | 27 ++ .../exceptions/TemplateMergingException.kt | 30 ++ .../islandoftex/texplate/model/Configuration.kt | 67 ++++ .../org/islandoftex/texplate/model/Template.kt | 90 +++++ .../texplate/model/handlers/BooleanHandler.kt | 20 ++ .../texplate/model/handlers/CSVListHandler.kt | 22 ++ .../islandoftex/texplate/model/handlers/Handler.kt | 18 + .../org/islandoftex/texplate/util/HandlerUtils.kt | 25 ++ .../org/islandoftex/texplate/util/MergingUtils.kt | 126 +++++++ .../org/islandoftex/texplate/util/MessageUtils.kt | 72 ++++ .../org/islandoftex/texplate/util/PathUtils.kt | 69 ++++ .../islandoftex/texplate/util/ValidatorUtils.kt | 54 +++ .../texplate/templates/texplate-article.toml | 54 +++ .../texplate/templates/texplate-standalone.toml | 45 +++ 32 files changed, 1000 insertions(+), 1518 deletions(-) delete mode 100644 support/texplate/source/main/java/org/islandoftex/texplate/Main.java delete mode 100644 support/texplate/source/main/java/org/islandoftex/texplate/exceptions/InvalidKeySetException.java delete mode 100644 support/texplate/source/main/java/org/islandoftex/texplate/exceptions/InvalidTemplateException.java delete mode 100644 support/texplate/source/main/java/org/islandoftex/texplate/exceptions/TemplateMergingException.java delete mode 100644 support/texplate/source/main/java/org/islandoftex/texplate/model/Configuration.java delete mode 100644 support/texplate/source/main/java/org/islandoftex/texplate/model/Template.java delete mode 100644 support/texplate/source/main/java/org/islandoftex/texplate/model/TemplateProcessing.java delete mode 100644 support/texplate/source/main/java/org/islandoftex/texplate/model/handlers/BooleanHandler.java delete mode 100644 support/texplate/source/main/java/org/islandoftex/texplate/model/handlers/CSVListHandler.java delete mode 100644 support/texplate/source/main/java/org/islandoftex/texplate/model/handlers/Handler.java delete mode 100644 support/texplate/source/main/java/org/islandoftex/texplate/util/HandlerUtils.java delete mode 100644 support/texplate/source/main/java/org/islandoftex/texplate/util/MergingUtils.java delete mode 100644 support/texplate/source/main/java/org/islandoftex/texplate/util/MessageUtils.java delete mode 100644 support/texplate/source/main/java/org/islandoftex/texplate/util/PathUtils.java delete mode 100644 support/texplate/source/main/java/org/islandoftex/texplate/util/ValidatorUtils.java create mode 100644 support/texplate/source/main/kotlin/org/islandoftex/texplate/Main.kt create mode 100644 support/texplate/source/main/kotlin/org/islandoftex/texplate/TemplateProcessing.kt create mode 100644 support/texplate/source/main/kotlin/org/islandoftex/texplate/exceptions/InvalidKeySetException.kt create mode 100644 support/texplate/source/main/kotlin/org/islandoftex/texplate/exceptions/InvalidTemplateException.kt create mode 100644 support/texplate/source/main/kotlin/org/islandoftex/texplate/exceptions/TemplateMergingException.kt create mode 100644 support/texplate/source/main/kotlin/org/islandoftex/texplate/model/Configuration.kt create mode 100644 support/texplate/source/main/kotlin/org/islandoftex/texplate/model/Template.kt create mode 100644 support/texplate/source/main/kotlin/org/islandoftex/texplate/model/handlers/BooleanHandler.kt create mode 100644 support/texplate/source/main/kotlin/org/islandoftex/texplate/model/handlers/CSVListHandler.kt create mode 100644 support/texplate/source/main/kotlin/org/islandoftex/texplate/model/handlers/Handler.kt create mode 100644 support/texplate/source/main/kotlin/org/islandoftex/texplate/util/HandlerUtils.kt create mode 100644 support/texplate/source/main/kotlin/org/islandoftex/texplate/util/MergingUtils.kt create mode 100644 support/texplate/source/main/kotlin/org/islandoftex/texplate/util/MessageUtils.kt create mode 100644 support/texplate/source/main/kotlin/org/islandoftex/texplate/util/PathUtils.kt create mode 100644 support/texplate/source/main/kotlin/org/islandoftex/texplate/util/ValidatorUtils.kt create mode 100644 support/texplate/source/main/resources/org/islandoftex/texplate/templates/texplate-article.toml create mode 100644 support/texplate/source/main/resources/org/islandoftex/texplate/templates/texplate-standalone.toml (limited to 'support/texplate/source/main') diff --git a/support/texplate/source/main/java/org/islandoftex/texplate/Main.java b/support/texplate/source/main/java/org/islandoftex/texplate/Main.java deleted file mode 100644 index 5c27aab23c..0000000000 --- a/support/texplate/source/main/java/org/islandoftex/texplate/Main.java +++ /dev/null @@ -1,36 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -package org.islandoftex.texplate; - -import org.islandoftex.texplate.model.TemplateProcessing; -import org.islandoftex.texplate.util.MessageUtils; -import picocli.CommandLine; - -/** - * The main class. The application logic is enclosed in the template processing - * class. - * - * @version 1.0 - * @since 1.0 - */ -public class Main { - - /** - * Main method. Note that it simply passes the control to the template - * processing class. - * - * @param args The command line arguments. - */ - public static void main(String[] args) { - - // draw the application logo in the - // terminal (please have fixed fonts - // in your terminal for a nice display) - MessageUtils.drawLogo(); - - // calls the command line processing method - // and performs the actual application logic - int exitCode = new CommandLine(new TemplateProcessing()).execute(args); - System.exit(exitCode); - } - -} diff --git a/support/texplate/source/main/java/org/islandoftex/texplate/exceptions/InvalidKeySetException.java b/support/texplate/source/main/java/org/islandoftex/texplate/exceptions/InvalidKeySetException.java deleted file mode 100644 index 3d113a2599..0000000000 --- a/support/texplate/source/main/java/org/islandoftex/texplate/exceptions/InvalidKeySetException.java +++ /dev/null @@ -1,37 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -package org.islandoftex.texplate.exceptions; - -/** - * Handles exceptions when the context map contains invalid keys. - * - * @version 1.0 - * @since 1.0 - */ -public class InvalidKeySetException extends Exception { - - /** - * Constructor. - */ - public InvalidKeySetException() { - } - - /** - * Constructor. - * - * @param message Message to be attached to the exception. - */ - public InvalidKeySetException(String message) { - super(message); - } - - /** - * Constructor. - * - * @param message Message to be attached to the exception. - * @param cause The throwable cause to be forwarded. - */ - public InvalidKeySetException(String message, Throwable cause) { - super(message, cause); - } - -} diff --git a/support/texplate/source/main/java/org/islandoftex/texplate/exceptions/InvalidTemplateException.java b/support/texplate/source/main/java/org/islandoftex/texplate/exceptions/InvalidTemplateException.java deleted file mode 100644 index 73c8276998..0000000000 --- a/support/texplate/source/main/java/org/islandoftex/texplate/exceptions/InvalidTemplateException.java +++ /dev/null @@ -1,34 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -package org.islandoftex.texplate.exceptions; - -/** - * Handles exceptions when the template is somehow invalid. - * - * @version 1.0 - * @since 1.0 - */ -public class InvalidTemplateException extends Exception { - - public InvalidTemplateException() { - } - - /** - * Constructor. - * - * @param message Message to be attached to the exception. - */ - public InvalidTemplateException(String message) { - super(message); - } - - /** - * Constructor. - * - * @param message Message to be attached to the exception. - * @param cause The throwable cause to be forwarded. - */ - public InvalidTemplateException(String message, Throwable cause) { - super(message, cause); - } - -} diff --git a/support/texplate/source/main/java/org/islandoftex/texplate/exceptions/TemplateMergingException.java b/support/texplate/source/main/java/org/islandoftex/texplate/exceptions/TemplateMergingException.java deleted file mode 100644 index 86dd99af00..0000000000 --- a/support/texplate/source/main/java/org/islandoftex/texplate/exceptions/TemplateMergingException.java +++ /dev/null @@ -1,37 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -package org.islandoftex.texplate.exceptions; - -/** - * Handles exceptions when the template merging failed. - * - * @version 1.0 - * @since 1.0 - */ -public class TemplateMergingException extends Exception { - - /** - * Constructor. - */ - public TemplateMergingException() { - } - - /** - * Constructor. - * - * @param message Message to be attached to the exception. - */ - public TemplateMergingException(String message) { - super(message); - } - - /** - * Constructor. - * - * @param message Message to be attached to the exception. - * @param cause The throwable cause to be forwarded. - */ - public TemplateMergingException(String message, Throwable cause) { - super(message, cause); - } - -} diff --git a/support/texplate/source/main/java/org/islandoftex/texplate/model/Configuration.java b/support/texplate/source/main/java/org/islandoftex/texplate/model/Configuration.java deleted file mode 100644 index a0f8e83702..0000000000 --- a/support/texplate/source/main/java/org/islandoftex/texplate/model/Configuration.java +++ /dev/null @@ -1,150 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -package org.islandoftex.texplate.model; - -import com.moandjiezana.toml.Toml; -import io.vavr.control.Try; -import org.islandoftex.texplate.exceptions.InvalidTemplateException; - -import java.nio.file.Path; -import java.util.Map; - -/** - * The configuration model. - * - * @version 1.0 - * @since 1.0 - */ -public class Configuration { - - // template of the template - private String template; - - // map of variables for the configuration - private Map map; - - /** - * Constructor. - */ - public Configuration() { - } - - /** - * Constructor. - * - * @param template The template. - * @param map The map. - */ - public Configuration(String template, Map map) { - this.template = template; - this.map = map; - } - - /** - * Gets the template. - * - * @return The template. - */ - public String getTemplate() { - return template; - } - - /** - * Sets the template. - * - * @param template The template. - */ - public void setTemplate(String template) { - this.template = template; - } - - /** - * Gets the map. - * - * @return The map. - */ - public Map getMap() { - return map; - } - - /** - * Sets the map. - * - * @param map The map. - */ - public void setMap(Map map) { - this.map = map; - } - - /** - * Checks whether the configuration is valid. - * - * @return A boolean value indicating whether the configuration is valid. - */ - private boolean isValid() { - return !(template == null || map == null); - } - - /** - * Reads the configuration from path. - * - * @param path The path. - * @return Configuration. - * @throws InvalidTemplateException The configuration is invalid. - */ - private static Configuration readFromPath(Path path) - throws InvalidTemplateException { - - // the actual configuration - Configuration configuration; - - // the default message - String message = "The provided configuration file looks invalid. " - + "Please make sure the configuration has a valid syntax and " - + "try again. "; - - try { - - // gets the configuration - configuration = new Toml().read(path.toFile()). - to(Configuration.class); - - } catch (Exception exception) { - - // the configuration - // seems invalid - throw new InvalidTemplateException(message + "In this particular " - + "scenario, there is a possibility that the configuration " - + "file does not follow the TOML specification. Please " - + "refer to the user manual for further details and a " - + "possible fix. Also, the raised exception message can " - + "give us some hints on what happened.", exception); - } - - // checks whether the - // configuration is valid - if (configuration.isValid()) { - - // returns the configuration - return configuration; - } else { - - // the configuration - // is invalid - throw new InvalidTemplateException(message + "Specifically, some " - + "mandatory fields are either absent or empty in the " - + "configuration file. It is quite important to strictly " - + "follow the configuration specification, as detailed in " - + "the user manual, or the tool will not work at all."); - } - } - - /** - * Gets the configuration from a path. - * - * @param path The path. - * @return The configuration. - */ - public static Try of(Path path) { - return Try.of(() -> readFromPath(path)); - } -} diff --git a/support/texplate/source/main/java/org/islandoftex/texplate/model/Template.java b/support/texplate/source/main/java/org/islandoftex/texplate/model/Template.java deleted file mode 100644 index ca92e04658..0000000000 --- a/support/texplate/source/main/java/org/islandoftex/texplate/model/Template.java +++ /dev/null @@ -1,252 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -package org.islandoftex.texplate.model; - -import com.moandjiezana.toml.Toml; -import io.vavr.control.Try; -import org.islandoftex.texplate.exceptions.InvalidTemplateException; - -import java.nio.file.Path; -import java.util.List; -import java.util.Map; - -/** - * The template model. - * - * @version 1.0 - * @since 1.0 - */ -public class Template { - - // name of the template - private String name; - - // description of the template - private String description; - - // list of authors who wrote the template - private List authors; - - // list of requirements for the template - private List requirements; - - // the document to be configured - private String document; - - // the map handlers - private Map handlers; - - /** - * Constructor. - */ - public Template() { - } - - /** - * Constructor. - * - * @param name Name of the template. - * @param description Description of the template. - * @param authors List of authors of the template. - * @param requirements List of requirements for the template. - * @param document The document to be configured. - * @param handlers The optional map handlers. - */ - public Template(String name, String description, List authors, - List requirements, String document, - Map handlers) { - this.name = name; - this.description = description; - this.authors = authors; - this.requirements = requirements; - this.document = document; - this.handlers = handlers; - } - - /** - * Gets the template name. - * - * @return The template name. - */ - public String getName() { - return name; - } - - /** - * Sets the template name. - * - * @param name The template name. - */ - public void setName(String name) { - this.name = name; - } - - /** - * Gets the template description. - * - * @return The template description. - */ - public String getDescription() { - return description; - } - - /** - * Sets the template description. - * - * @param description The template description. - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * Gets the template authors. - * - * @return The template authors. - */ - public List getAuthors() { - return authors; - } - - /** - * Sets the template authors. - * - * @param authors The template authors. - */ - public void setAuthors(List authors) { - this.authors = authors; - } - - /** - * Gets the template requirements. - * - * @return The template requirements. - */ - public List getRequirements() { - return requirements; - } - - /** - * Sets the template requirements. - * - * @param requirements The template requirements. - */ - public void setRequirements(List requirements) { - this.requirements = requirements; - } - - /** - * Gets the template document. - * - * @return The template document. - */ - public String getDocument() { - return document; - } - - /** - * Sets the template document. - * - * @param document The template document. - */ - public void setDocument(String document) { - this.document = document; - } - - /** - * Gets the map handlers. - * - * @return The map handlers. - */ - public Map getHandlers() { - return handlers; - } - - /** - * Sets the map handlers. - * - * @param handlers The map handlers. - */ - public void setHandlers(Map handlers) { - this.handlers = handlers; - } - - /** - * Checks whether the template is valid. - * - * @return A boolean value indicating whether the template is valid. - */ - private boolean isValid() { - return !((name == null) || (description == null) - || (authors == null) || (requirements == null) - || (document == null) || name.trim().isEmpty() - || description.trim().isEmpty() || authors.isEmpty() - || document.trim().isEmpty()); - } - - /** - * Reads the template from the provided path. - * - * @param path The path to the template file. - * @return The template object from the provided path. - * @throws InvalidTemplateException The template is invalid. - */ - private static Template readFromPath(Path path) - throws InvalidTemplateException { - - // the actual template - Template template; - - // the exception message, in case the - // conversion fails or if there are - // missing elements from the template - String message = "The provided template file looks invalid. Please " - + "make sure the template has a valid syntax and try again. "; - - try { - - // reads the file and converts - // the TOML format into the object - template = new Toml().read(path.toFile()).to(Template.class); - - } catch (Exception exception) { - - // throws the new exception and - // attaches the original cause - throw new InvalidTemplateException(message + "In this particular " - + "scenario, there is a possibility that the template " - + "file does not follow the TOML specification. Please " - + "refer to the user manual for further details and a " - + "possible fix. Also, the raised exception message can " - + "give us some hints on what happened.", exception); - } - - // the conversion hasn't failed, but we need - // to check whether the template is valid - if (template.isValid()) { - - // everything went fine, so - // simply return the template - return template; - } else { - - // the template is invalid, so we - // need to throw an exception - throw new InvalidTemplateException(message + "Specifically, some " - + "mandatory fields are either absent or empty in the " - + "template file. It is quite important to strictly " - + "follow the template specification, as detailed in the " - + "user manual, or the tool will not work at all."); - } - } - - /** - * Returns the template from the provided path. - * - * @param path The path in which the template is retrieved. - * @return The corresponding template, enclosed in a Try object. - */ - public static Try