Abbreviate a template value with ellipses.
+ *Abbreviates a template value with ellipses.
* *Usage:
* @@ -36,7 +36,18 @@ import rife.template.ValueRenderer; */ public class Abbreviate implements ValueRenderer { /** - * {@inheritDoc} + *Returns the template value abbreviated with ellipses.
+ * + *Two parameters can be specified:
+ *mark
: the string that will be used to abbreviate the value. Default is ...
max
: the maximum number of characters to render. Default is -1
(no abbreviation).Capitalizes words of a template value.
+ * + *Usage:
+ * + *+ * <!--v render:rife.render.CapitalizeWords:valueId/--> + * {{v render:rife.render.CapitalizeWords:valueId/}} + *+ * + * @author Erik C. Thauvin + * @see rife.render.CapitalizeWords + * @since 1.2 + */ +public class CapitalizeWords implements ValueRenderer { + /** + * Returns the template value by capitalizing it. + * + * @param template the template containing the value to be rendered + * @param valueId the identifier of the value to render + * @param differentiator a string used to differentiate the rendering + * @return the capitalized and encoded value + */ + @Override + public String render(Template template, String valueId, String differentiator) { + return template.getEncoder().encode(RenderUtils.capitalizeWords(template.getValueOrAttribute(differentiator))); + } +} diff --git a/src/main/java/rife/render/DateIso.java b/src/main/java/rife/render/DateIso.java index 3fe35c6..0da04e6 100644 --- a/src/main/java/rife/render/DateIso.java +++ b/src/main/java/rife/render/DateIso.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import rife.template.ValueRenderer; import java.time.ZonedDateTime; /** - *
Return the current date in ISO 8601 format.
+ *Renders the current date in ISO 8601 format.
* *Usage:
* @@ -38,7 +38,12 @@ import java.time.ZonedDateTime; */ public class DateIso implements ValueRenderer { /** - * {@inheritDoc} + * Returns the current date in ISO 8601 format, encoded according to the template's encoding rules. + * + * @param template the template that is currently being rendered + * @param valueId the value id that triggers the rendering of this value renderer + * @param differentiator a differentiator that may be used to differentiate the rendering of this value renderer + * @return the current date in ISO 8601 format, encoded according to the template's encoding rules */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/DateTimeIso.java b/src/main/java/rife/render/DateTimeIso.java index 9a8bb63..e8513bb 100644 --- a/src/main/java/rife/render/DateTimeIso.java +++ b/src/main/java/rife/render/DateTimeIso.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import java.time.ZoneId; import java.time.ZonedDateTime; /** - *Return the current date and time in ISO 8601 format.
+ *Renders the current date and time in ISO 8601 format.
* *Usage:
* @@ -39,7 +39,15 @@ import java.time.ZonedDateTime; */ public class DateTimeIso implements ValueRenderer { /** - * {@inheritDoc} + * Renders the current date and time in ISO 8601 format. + * + *Additionally, it allows specifying a time zone through the template's default value properties with the key + * {@code tz}. If no time zone is specified, the system default time zone is used.
+ * + * @param template the template that is currently being rendered + * @param valueId the id of the value to be rendered + * @param differentiator a differentiator that may be used to differentiate the rendering of this value renderer + * @return the current date and time in ISO 8601 format */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/DateTimeRfc2822.java b/src/main/java/rife/render/DateTimeRfc2822.java index a420201..2bdbd54 100644 --- a/src/main/java/rife/render/DateTimeRfc2822.java +++ b/src/main/java/rife/render/DateTimeRfc2822.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import rife.template.ValueRenderer; import java.time.ZonedDateTime; /** - *Return the current date and time in RFC 2822 format.
+ *Renders the current date and time in RFC 2822 format.
* *Usage:
* @@ -38,7 +38,12 @@ import java.time.ZonedDateTime; */ public class DateTimeRfc2822 implements ValueRenderer { /** - * {@inheritDoc} + * Returns the current date and time in RFC 2822 format. + * + * @param template the template instance + * @param valueId the value id + * @param differentiator the differentiator + * @return the current date and time in RFC 2822 format */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/EncodeBase64.java b/src/main/java/rife/render/EncodeBase64.java index fd2e62a..e00b24c 100644 --- a/src/main/java/rife/render/EncodeBase64.java +++ b/src/main/java/rife/render/EncodeBase64.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,7 +40,12 @@ import java.nio.charset.StandardCharsets; */ public class EncodeBase64 implements ValueRenderer { /** - * {@inheritDoc} + * Returns the template value encoded to Base64. + * + * @param template the template that contains the value + * @param valueId the id of the value + * @param differentiator the differentiator to use + * @return the Base64-encoded value */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/EncodeHtml.java b/src/main/java/rife/render/EncodeHtml.java index 858b6dd..b67959d 100644 --- a/src/main/java/rife/render/EncodeHtml.java +++ b/src/main/java/rife/render/EncodeHtml.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,12 @@ import rife.tools.StringUtils; */ public class EncodeHtml implements ValueRenderer { /** - * {@inheritDoc} + * Returns the template value encoded to HTML. + * + * @param template the template containing the value to be rendered + * @param valueId the identifier of the value to render + * @param differentiator a string used to differentiate the rendering + * @return the HTML-encoded value */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/EncodeHtmlEntities.java b/src/main/java/rife/render/EncodeHtmlEntities.java index 4f84839..cee3e8b 100644 --- a/src/main/java/rife/render/EncodeHtmlEntities.java +++ b/src/main/java/rife/render/EncodeHtmlEntities.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,12 @@ import rife.template.ValueRenderer; */ public class EncodeHtmlEntities implements ValueRenderer { /** - * {@inheritDoc} + * Returns the template value encoded to HTML decimal entities. + * + * @param template the template instance + * @param valueId the value id + * @param differentiator the differentiator + * @return the encoded value */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/EncodeJs.java b/src/main/java/rife/render/EncodeJs.java index 1122356..27de902 100644 --- a/src/main/java/rife/render/EncodeJs.java +++ b/src/main/java/rife/render/EncodeJs.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,12 @@ import rife.tools.StringUtils; */ public class EncodeJs implements ValueRenderer { /** - * {@inheritDoc} + * Returns the template value encoded to JavaScript/ECMAScript. + * + * @param template the template that contains the value + * @param valueId the id of the value + * @param differentiator the differentiator to use + * @return the JavaScript/ECMAScript-encoded value */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/EncodeJson.java b/src/main/java/rife/render/EncodeJson.java index 7356650..8e17b29 100644 --- a/src/main/java/rife/render/EncodeJson.java +++ b/src/main/java/rife/render/EncodeJson.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,12 @@ import rife.tools.StringUtils; */ public class EncodeJson implements ValueRenderer { /** - * {@inheritDoc} + * Returns the template value encoded to JSON. + * + * @param template the template that contains the value + * @param valueId the id of the value + * @param differentiator the differentiator to use + * @return the JSON-encoded value */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/EncodeUnicode.java b/src/main/java/rife/render/EncodeUnicode.java index 60166a1..afd2a48 100644 --- a/src/main/java/rife/render/EncodeUnicode.java +++ b/src/main/java/rife/render/EncodeUnicode.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,12 @@ import rife.tools.StringUtils; */ public class EncodeUnicode implements ValueRenderer { /** - * {@inheritDoc} + * Returns the template value encoded to Unicode escape codes. + * + * @param template the template that contains the value + * @param valueId the id of the value + * @param differentiator the differentiator to use + * @return the Unicode escape codes-encoded value */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/EncodeUrl.java b/src/main/java/rife/render/EncodeUrl.java index 6692636..b977353 100644 --- a/src/main/java/rife/render/EncodeUrl.java +++ b/src/main/java/rife/render/EncodeUrl.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,12 @@ import rife.tools.StringUtils; */ public class EncodeUrl implements ValueRenderer { /** - * {@inheritDoc} + * Returns the template value encoded to URL. + * + * @param template the template that contains the value + * @param valueId the id of the value + * @param differentiator the differentiator to use + * @return the URL-encoded value */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/EncodeXml.java b/src/main/java/rife/render/EncodeXml.java index 743e084..00b0faa 100644 --- a/src/main/java/rife/render/EncodeXml.java +++ b/src/main/java/rife/render/EncodeXml.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,12 @@ import rife.tools.StringUtils; */ public class EncodeXml implements ValueRenderer { /** - * {@inheritDoc} + * Returns the template value encoded to XML. + * + * @param template the template that contains the value + * @param valueId the id of the value + * @param differentiator the differentiator to use + * @return the XML-encoded value */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/FormatCreditCard.java b/src/main/java/rife/render/FormatCreditCard.java index f2025eb..fec124d 100644 --- a/src/main/java/rife/render/FormatCreditCard.java +++ b/src/main/java/rife/render/FormatCreditCard.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,12 @@ import rife.template.ValueRenderer; */ public class FormatCreditCard implements ValueRenderer { /** - * {@inheritDoc} + * Returns the last 4 digits of the template credit number value. + * + * @param template the {@link Template} + * @param valueId the value id + * @param differentiator the differentiator + * @return the formatted value */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/Lowercase.java b/src/main/java/rife/render/Lowercase.java index aa7858c..6f9f2ec 100644 --- a/src/main/java/rife/render/Lowercase.java +++ b/src/main/java/rife/render/Lowercase.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,12 @@ import rife.tools.Localization; */ public class Lowercase implements ValueRenderer { /** - * {@inheritDoc} + * Returns the template value converted to lowercase. + * + * @param template the template that contains the value + * @param valueId the id of the value + * @param differentiator the differentiator to use + * @return the lowercase value */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/Mask.java b/src/main/java/rife/render/Mask.java index 637e012..fe0a709 100644 --- a/src/main/java/rife/render/Mask.java +++ b/src/main/java/rife/render/Mask.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,8 +35,30 @@ import rife.template.ValueRenderer; * @since 1.0 */ public class Mask implements ValueRenderer { + /** - * {@inheritDoc} + *Renders a template value with characters of the value masked using the specified mask.
+ * + *The mask is specified as a template default value with the following syntax:
+ * + *+ * mask=<mask>[,unmasked=<unmasked>][,fromStart=<fromStart>] + *+ * + *
Where:
+ * + **
0
false
Encodes the source {@code String} to the specified encoding.
* @@ -196,6 +227,11 @@ public final class RenderUtils { case '"' -> sb.append("\\\""); case '\\' -> sb.append("\\\\"); case '/' -> sb.append("\\/"); + case '\b' -> sb.append("\\b"); + case '\n' -> sb.append(("\\n")); + case '\t' -> sb.append("\\t"); + case '\f' -> sb.append("\\f"); + case '\r' -> sb.append("\\r"); default -> sb.append(c); } } @@ -212,8 +248,9 @@ public final class RenderUtils { public static String fetchUrl(String url, String defaultContent) { try { var fetchUrl = new URL(url); + HttpURLConnection connection = null; try { - var connection = (HttpURLConnection) fetchUrl.openConnection(); + connection = (HttpURLConnection) fetchUrl.openConnection(); connection.setRequestProperty("User-Agent", DEFAULT_USER_AGENT); var code = connection.getResponseCode(); if (code >= 200 && code <= 399) { @@ -229,10 +266,15 @@ public final class RenderUtils { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, "An IO error occurred while connecting to " + fetchUrl.getHost(), ioe); } + } finally { + if (connection != null) { + connection.disconnect(); + } } } catch (MalformedURLException ignored) { // do nothing } + return defaultContent; } @@ -330,21 +372,20 @@ public final class RenderUtils { return src; } - var normalized = Normalizer.normalize(src.trim(), Normalizer.Form.NFD); - var sb = new StringBuilder(normalized.length()); - boolean space = false; - for (var c : normalized.toCharArray()) { - if (c <= '\u007F') { // ascii only - if (!space && c == ' ') { - space = true; - sb.append('-'); - } else { - space = false; - if (c >= '0' && c <= '9' || c >= 'a' && c <= 'z') { - sb.append(c); - } else if (c >= 'A' && c <= 'Z') { - sb.append((char) (c + 32)); // lowercase + var normalized = Normalizer.normalize(src.trim(), Normalizer.Form.NFD).toCharArray(); + + var sb = new StringBuilder(normalized.length); + for (var i = 0; i < normalized.length; i++) { + var c = normalized[i]; + if (c <= '\u007F') { // ASCII only + if (" &()-_=[{]}\\|;:,<.>/".indexOf(c) != -1) { // common separators + if (!sb.isEmpty() && i != normalized.length - 1 && sb.charAt(sb.length() - 1) != '-') { + sb.append('-'); } + } else if (c >= '0' && c <= '9' || c >= 'a' && c <= 'z') { // letters & digits + sb.append(c); + } else if (c >= 'A' && c <= 'Z') { // uppercase letters + sb.append((char) (c + 32)); // make lowercase } } } @@ -598,4 +639,5 @@ public final class RenderUtils { } return false; } + } \ No newline at end of file diff --git a/src/main/java/rife/render/Rot13.java b/src/main/java/rife/render/Rot13.java index d3a33c4..75e3dd7 100644 --- a/src/main/java/rife/render/Rot13.java +++ b/src/main/java/rife/render/Rot13.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,12 @@ import rife.template.ValueRenderer; */ public class Rot13 implements ValueRenderer { /** - * {@inheritDoc} + * Returns the template value translated to/from ROT13. + * + * @param template the template that contains the value + * @param valueId the id of the value + * @param differentiator the differentiator to use + * @return the ROT13 value */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/ShortenUrl.java b/src/main/java/rife/render/ShortenUrl.java index 3ddd62e..204d7c6 100644 --- a/src/main/java/rife/render/ShortenUrl.java +++ b/src/main/java/rife/render/ShortenUrl.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,12 @@ import rife.template.ValueRenderer; */ public class ShortenUrl implements ValueRenderer { /** - * {@inheritDoc} + * Returns the template value shortened using is.gid. + * + * @param template the template that contains the value + * @param valueId the id of the value + * @param differentiator the differentiator to use + * @return the template shortened value */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/SwapCase.java b/src/main/java/rife/render/SwapCase.java index c059a6a..1fd996a 100644 --- a/src/main/java/rife/render/SwapCase.java +++ b/src/main/java/rife/render/SwapCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import rife.template.Template; import rife.template.ValueRenderer; /** - *Swap case of a template value.
+ *Swaps case of a template value.
* *Usage:
* @@ -35,9 +35,13 @@ import rife.template.ValueRenderer; * @since 1.0 */ public class SwapCase implements ValueRenderer { - /** - * {@inheritDoc} + * Returns the template value with swapped case. + * + * @param template the template that contains the value + * @param valueId the id of the value + * @param differentiator the differentiator to use + * @return the swapped case value */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/TimeIso.java b/src/main/java/rife/render/TimeIso.java index 9f99269..01bf5b2 100644 --- a/src/main/java/rife/render/TimeIso.java +++ b/src/main/java/rife/render/TimeIso.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import rife.template.ValueRenderer; import java.time.ZonedDateTime; /** - *Return the current time in ISO 8601 format.
+ *Renders the current time in ISO 8601 format.
* *Usage:
* @@ -38,7 +38,12 @@ import java.time.ZonedDateTime; */ public class TimeIso implements ValueRenderer { /** - * {@inheritDoc} + * Returns the current time in ISO 8601 format. + * + * @param template the template that is currently being rendered + * @param valueId the id of the value to be rendered + * @param differentiator a differentiator that may be used to differentiate the rendering of this value renderer + * @return the current time in ISO 8601 format */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/Trim.java b/src/main/java/rife/render/Trim.java index fb97e31..a0951b4 100644 --- a/src/main/java/rife/render/Trim.java +++ b/src/main/java/rife/render/Trim.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,12 @@ import rife.template.ValueRenderer; */ public class Trim implements ValueRenderer { /** - * {@inheritDoc} + * Renders the template value by removing leading and trailing whitespace. + * + * @param template the template instance + * @param valueId the id of the value to render + * @param differentiator an optional differentiator to use for cache invalidation + * @return the trimmed value, or the original value if it is {@code null} or empty */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/Uncapitalize.java b/src/main/java/rife/render/Uncapitalize.java index bef0dfe..20b0aad 100644 --- a/src/main/java/rife/render/Uncapitalize.java +++ b/src/main/java/rife/render/Uncapitalize.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,12 @@ import rife.tools.StringUtils; */ public class Uncapitalize implements ValueRenderer { /** - * {@inheritDoc} + * Returns the un-capitalized template value. + * + * @param template the template to render + * @param valueId the id of the value to render + * @param differentiator the differentiator to use for the value lookup + * @return the un-capitalized value */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/Uppercase.java b/src/main/java/rife/render/Uppercase.java index 47a7eb5..92e57a5 100644 --- a/src/main/java/rife/render/Uppercase.java +++ b/src/main/java/rife/render/Uppercase.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ import rife.template.ValueRenderer; import rife.tools.Localization; /** - *Convert a template value to uppercase.
+ *Converts a template value to uppercase.
* *Usage:
* @@ -37,7 +37,12 @@ import rife.tools.Localization; */ public class Uppercase implements ValueRenderer { /** - * {@inheritDoc} + * Returns the template value converted to uppercase. + * + * @param template the template that contains the value + * @param valueId the id of the value + * @param differentiator the differentiator to use + * @return the uppercased value */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/Uptime.java b/src/main/java/rife/render/Uptime.java index 09ffc3e..14bb2de 100644 --- a/src/main/java/rife/render/Uptime.java +++ b/src/main/java/rife/render/Uptime.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,12 @@ import java.lang.management.ManagementFactory; */ public class Uptime implements ValueRenderer { /** - * {@inheritDoc} + * Renders the server uptime. + * + * @param template the template that is currently being rendered + * @param valueId the id of the value to render + * @param differentiator a differentiator that may be used to differentiate the rendering of this value renderer + * @return the server uptime */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/main/java/rife/render/Year.java b/src/main/java/rife/render/Year.java index c7fe2e3..cb8c8f5 100644 --- a/src/main/java/rife/render/Year.java +++ b/src/main/java/rife/render/Year.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,9 +37,13 @@ import java.time.ZonedDateTime; * @since 1.0 */ public class Year implements ValueRenderer { - /** - * {@inheritDoc} + * Renders the current year. + * + * @param template the template that is currently being rendered + * @param valueId the id of the value to render + * @param differentiator a differentiator that may be used to differentiate the rendering of this value renderer + * @return the current year */ @Override public String render(Template template, String valueId, String differentiator) { diff --git a/src/test/java/rife/render/DisableOnCiCondition.java b/src/test/java/rife/render/DisableOnCiCondition.java index cd59296..27081c2 100644 --- a/src/test/java/rife/render/DisableOnCiCondition.java +++ b/src/test/java/rife/render/DisableOnCiCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/test/java/rife/render/DisabledOnCi.java b/src/test/java/rife/render/DisabledOnCi.java index b243ee7..8c369d6 100644 --- a/src/test/java/rife/render/DisabledOnCi.java +++ b/src/test/java/rife/render/DisabledOnCi.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ import java.lang.annotation.Target; * @author Erik C. Thauvin * @since 1.0 */ -@Target({ ElementType.TYPE, ElementType.METHOD }) +@Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @ExtendWith(DisableOnCiCondition.class) public @interface DisabledOnCi { diff --git a/src/test/java/rife/render/TestCase.java b/src/test/java/rife/render/TestCase.java index ae88154..2759ff6 100644 --- a/src/test/java/rife/render/TestCase.java +++ b/src/test/java/rife/render/TestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/test/java/rife/render/TestDateTime.java b/src/test/java/rife/render/TestDateTime.java index 55bb519..bfb8cc7 100644 --- a/src/test/java/rife/render/TestDateTime.java +++ b/src/test/java/rife/render/TestDateTime.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/test/java/rife/render/TestEncode.java b/src/test/java/rife/render/TestEncode.java index 251b046..bc390d4 100644 --- a/src/test/java/rife/render/TestEncode.java +++ b/src/test/java/rife/render/TestEncode.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,6 +55,10 @@ class TestEncode { t.setAttribute(TestCase.FOO, "'\"\\/"); assertThat(t.getContent()).isEqualTo("\\'\\\"\\\\\\/"); + t = TemplateFactory.TXT.get("encodeJs"); + t.setAttribute(TestCase.FOO, "This is\f\b a\r\n\ttest"); + assertThat(t.getContent()).isEqualTo("This is\\f\\b a\\r\\n\\ttest"); + t = TemplateFactory.HTML.get("encodeJs"); t.setAttribute(TestCase.FOO, '"' + TestCase.SAMPLE_TEXT + '"'); assertThat(t.getContent()).as("with unicode") diff --git a/src/test/java/rife/render/TestFormat.java b/src/test/java/rife/render/TestFormat.java index 970d728..eb1840b 100644 --- a/src/test/java/rife/render/TestFormat.java +++ b/src/test/java/rife/render/TestFormat.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/test/java/rife/render/TestRenderUtils.java b/src/test/java/rife/render/TestRenderUtils.java index 712dd6a..f1f8c46 100644 --- a/src/test/java/rife/render/TestRenderUtils.java +++ b/src/test/java/rife/render/TestRenderUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package rife.render; +import org.assertj.core.api.AutoCloseableSoftAssertions; import org.junit.jupiter.api.Test; import java.util.Properties; @@ -39,6 +40,17 @@ class TestRenderUtils { assertThat(RenderUtils.abbreviate("", 10, "")).as("").isEmpty(); } + @Test + void testCapitalizeWords() { + assertThat(RenderUtils.capitalizeWords("hello world")).isEqualTo("Hello World"); + assertThat(RenderUtils.capitalizeWords("java programming")).isEqualTo("Java Programming"); + assertThat(RenderUtils.capitalizeWords("TEST")).isEqualTo("Test"); + assertThat(RenderUtils.capitalizeWords("multiple spaces")).isEqualTo("Multiple Spaces"); + assertThat(RenderUtils.capitalizeWords("white\t\fspaces")).isEqualTo("White\t\fSpaces"); + assertThat(RenderUtils.capitalizeWords("")).isEmpty(); + assertThat(RenderUtils.capitalizeWords(null)).isNull(); + } + @Test void testEncode() { var p = new Properties(); @@ -96,8 +108,14 @@ class TestRenderUtils { @Test void testNormalize() { - assertThat(RenderUtils.normalize("")).isEmpty(); - assertThat(RenderUtils.normalize(SAMPLE_GERMAN)).isEqualTo("mochten-sie-ein-paar-apfel"); + assertThat(RenderUtils.normalize("")).as("empty").isEmpty(); + assertThat(RenderUtils.normalize(" &()-_=[{]}\\|;:,<.>/")).as("blank").isEmpty(); + assertThat(RenderUtils.normalize(SAMPLE_GERMAN)).as("greman").isEqualTo("mochten-sie-ein-paar-apfel"); + assertThat(RenderUtils.normalize("foo bar,