Abbreviates a template value with ellipses.
+ *Abbreviate a template value with ellipses.
* *Usage:
* @@ -36,18 +36,7 @@ import rife.template.ValueRenderer; */ public class Abbreviate implements ValueRenderer { /** - *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 0da04e6..3fe35c6 100644 --- a/src/main/java/rife/render/DateIso.java +++ b/src/main/java/rife/render/DateIso.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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; /** - *
Renders the current date in ISO 8601 format.
+ *Return the current date in ISO 8601 format.
* *Usage:
* @@ -38,12 +38,7 @@ import java.time.ZonedDateTime; */ public class DateIso implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 e8513bb..9a8bb63 100644 --- a/src/main/java/rife/render/DateTimeIso.java +++ b/src/main/java/rife/render/DateTimeIso.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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; /** - *Renders the current date and time in ISO 8601 format.
+ *Return the current date and time in ISO 8601 format.
* *Usage:
* @@ -39,15 +39,7 @@ import java.time.ZonedDateTime; */ public class DateTimeIso implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 2bdbd54..a420201 100644 --- a/src/main/java/rife/render/DateTimeRfc2822.java +++ b/src/main/java/rife/render/DateTimeRfc2822.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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; /** - *Renders the current date and time in RFC 2822 format.
+ *Return the current date and time in RFC 2822 format.
* *Usage:
* @@ -38,12 +38,7 @@ import java.time.ZonedDateTime; */ public class DateTimeRfc2822 implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 e00b24c..fd2e62a 100644 --- a/src/main/java/rife/render/EncodeBase64.java +++ b/src/main/java/rife/render/EncodeBase64.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,12 +40,7 @@ import java.nio.charset.StandardCharsets; */ public class EncodeBase64 implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 b67959d..858b6dd 100644 --- a/src/main/java/rife/render/EncodeHtml.java +++ b/src/main/java/rife/render/EncodeHtml.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,12 +38,7 @@ import rife.tools.StringUtils; */ public class EncodeHtml implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 cee3e8b..4f84839 100644 --- a/src/main/java/rife/render/EncodeHtmlEntities.java +++ b/src/main/java/rife/render/EncodeHtmlEntities.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,12 +36,7 @@ import rife.template.ValueRenderer; */ public class EncodeHtmlEntities implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 27de902..1122356 100644 --- a/src/main/java/rife/render/EncodeJs.java +++ b/src/main/java/rife/render/EncodeJs.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,12 +38,7 @@ import rife.tools.StringUtils; */ public class EncodeJs implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 8e17b29..7356650 100644 --- a/src/main/java/rife/render/EncodeJson.java +++ b/src/main/java/rife/render/EncodeJson.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,12 +38,7 @@ import rife.tools.StringUtils; */ public class EncodeJson implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 afd2a48..60166a1 100644 --- a/src/main/java/rife/render/EncodeUnicode.java +++ b/src/main/java/rife/render/EncodeUnicode.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,12 +38,7 @@ import rife.tools.StringUtils; */ public class EncodeUnicode implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 b977353..6692636 100644 --- a/src/main/java/rife/render/EncodeUrl.java +++ b/src/main/java/rife/render/EncodeUrl.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,12 +38,7 @@ import rife.tools.StringUtils; */ public class EncodeUrl implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 00b0faa..743e084 100644 --- a/src/main/java/rife/render/EncodeXml.java +++ b/src/main/java/rife/render/EncodeXml.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,12 +38,7 @@ import rife.tools.StringUtils; */ public class EncodeXml implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 fec124d..f2025eb 100644 --- a/src/main/java/rife/render/FormatCreditCard.java +++ b/src/main/java/rife/render/FormatCreditCard.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,12 +36,7 @@ import rife.template.ValueRenderer; */ public class FormatCreditCard implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 6f9f2ec..aa7858c 100644 --- a/src/main/java/rife/render/Lowercase.java +++ b/src/main/java/rife/render/Lowercase.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,12 +37,7 @@ import rife.tools.Localization; */ public class Lowercase implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 fe0a709..97647eb 100644 --- a/src/main/java/rife/render/Mask.java +++ b/src/main/java/rife/render/Mask.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,30 +35,8 @@ import rife.template.ValueRenderer; * @since 1.0 */ public class Mask implements ValueRenderer { - /** - *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.
* @@ -185,7 +154,7 @@ public final class RenderUtils { return StringUtils.encodeHtml(src); } case "js" -> { - return encodeJs(src); + return RenderUtils.encodeJs(src); } case "json" -> { return StringUtils.encodeJson(src); @@ -227,11 +196,6 @@ 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); } } @@ -248,9 +212,8 @@ public final class RenderUtils { public static String fetchUrl(String url, String defaultContent) { try { var fetchUrl = new URL(url); - HttpURLConnection connection = null; try { - connection = (HttpURLConnection) fetchUrl.openConnection(); + var connection = (HttpURLConnection) fetchUrl.openConnection(); connection.setRequestProperty("User-Agent", DEFAULT_USER_AGENT); var code = connection.getResponseCode(); if (code >= 200 && code <= 399) { @@ -266,15 +229,10 @@ 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) { + } catch (MalformedURLException ignore) { // do nothing } - return defaultContent; } @@ -372,20 +330,21 @@ public final class RenderUtils { return src; } - 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('-'); + 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 } - } 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 } } } @@ -403,7 +362,7 @@ public final class RenderUtils { if (src != null && !src.isBlank()) { try { properties.load(new StringReader(src)); - } catch (IOException ignored) { + } catch (IOException ignore) { // ignore } } @@ -460,7 +419,7 @@ public final class RenderUtils { for (var i = 0; i < len; i++) { var inChar = src.charAt(i); - if (inChar >= 'A' && inChar <= 'Z') { + if ((inChar >= 'A') && (inChar <= 'Z')) { inChar += (char) 13; if (inChar > 'Z') { @@ -468,7 +427,7 @@ public final class RenderUtils { } } - if (inChar >= 'a' && inChar <= 'z') { + if ((inChar >= 'a') && (inChar <= 'z')) { inChar += (char) 13; if (inChar > 'z') { @@ -634,7 +593,7 @@ public final class RenderUtils { return true; } } - } catch (NumberFormatException ignored) { + } catch (NumberFormatException ignore) { // do nothing } return false; diff --git a/src/main/java/rife/render/Rot13.java b/src/main/java/rife/render/Rot13.java index 75e3dd7..d3a33c4 100644 --- a/src/main/java/rife/render/Rot13.java +++ b/src/main/java/rife/render/Rot13.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,12 +36,7 @@ import rife.template.ValueRenderer; */ public class Rot13 implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 204d7c6..3ddd62e 100644 --- a/src/main/java/rife/render/ShortenUrl.java +++ b/src/main/java/rife/render/ShortenUrl.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,12 +38,7 @@ import rife.template.ValueRenderer; */ public class ShortenUrl implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 1fd996a..c059a6a 100644 --- a/src/main/java/rife/render/SwapCase.java +++ b/src/main/java/rife/render/SwapCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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; /** - *Swaps case of a template value.
+ *Swap case of a template value.
* *Usage:
* @@ -35,13 +35,9 @@ import rife.template.ValueRenderer; * @since 1.0 */ public class SwapCase implements ValueRenderer { + /** - * 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 + * {@inheritDoc} */ @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 01bf5b2..9f99269 100644 --- a/src/main/java/rife/render/TimeIso.java +++ b/src/main/java/rife/render/TimeIso.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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; /** - *Renders the current time in ISO 8601 format.
+ *Return the current time in ISO 8601 format.
* *Usage:
* @@ -38,12 +38,7 @@ import java.time.ZonedDateTime; */ public class TimeIso implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 a0951b4..fb97e31 100644 --- a/src/main/java/rife/render/Trim.java +++ b/src/main/java/rife/render/Trim.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,12 +36,7 @@ import rife.template.ValueRenderer; */ public class Trim implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 20b0aad..bef0dfe 100644 --- a/src/main/java/rife/render/Uncapitalize.java +++ b/src/main/java/rife/render/Uncapitalize.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,12 +37,7 @@ import rife.tools.StringUtils; */ public class Uncapitalize implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 92e57a5..47a7eb5 100644 --- a/src/main/java/rife/render/Uppercase.java +++ b/src/main/java/rife/render/Uppercase.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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; /** - *Converts a template value to uppercase.
+ *Convert a template value to uppercase.
* *Usage:
* @@ -37,12 +37,7 @@ import rife.tools.Localization; */ public class Uppercase implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 14bb2de..09ffc3e 100644 --- a/src/main/java/rife/render/Uptime.java +++ b/src/main/java/rife/render/Uptime.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,12 +38,7 @@ import java.lang.management.ManagementFactory; */ public class Uptime implements ValueRenderer { /** - * 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 + * {@inheritDoc} */ @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 cb8c8f5..c7fe2e3 100644 --- a/src/main/java/rife/render/Year.java +++ b/src/main/java/rife/render/Year.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,13 +37,9 @@ import java.time.ZonedDateTime; * @since 1.0 */ public class Year implements ValueRenderer { + /** - * 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 + * {@inheritDoc} */ @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 27081c2..cd59296 100644 --- a/src/test/java/rife/render/DisableOnCiCondition.java +++ b/src/test/java/rife/render/DisableOnCiCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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 8c369d6..b243ee7 100644 --- a/src/test/java/rife/render/DisabledOnCi.java +++ b/src/test/java/rife/render/DisabledOnCi.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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 2759ff6..cebd066 100644 --- a/src/test/java/rife/render/TestCase.java +++ b/src/test/java/rife/render/TestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,9 +40,6 @@ class TestCase { var bean = new ValueBean("this IS a TEST."); t.setBean(bean); assertThat(t.getContent()).isEqualTo(bean.getValue() + ": this is a test."); - bean = new ValueBean(""); - t.setBean(bean); - assertThat(t.getContent()).isEqualTo(bean.getValue() + ": "); } @Test @@ -57,8 +54,6 @@ class TestCase { var t = TemplateFactory.TXT.get("trim"); t.setAttribute(FOO, "\t" + SAMPLE_TEXT + " \n"); assertThat(t.getContent()).isEqualTo(SAMPLE_TEXT); - t.setAttribute(FOO, ""); - assertThat(t.getContent()).isEmpty(); } @Test @@ -73,7 +68,5 @@ class TestCase { var t = TemplateFactory.TXT.get("uppercase"); t.setAttribute("bar", SAMPLE_TEXT); assertThat(t.getContent()).isEqualTo(SAMPLE_TEXT.toUpperCase(Localization.getLocale())); - t.setAttribute("bar", ""); - assertThat(t.getContent()).isEmpty(); } } \ No newline at end of file diff --git a/src/test/java/rife/render/TestDateTime.java b/src/test/java/rife/render/TestDateTime.java index bfb8cc7..55bb519 100644 --- a/src/test/java/rife/render/TestDateTime.java +++ b/src/test/java/rife/render/TestDateTime.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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 bc390d4..251b046 100644 --- a/src/test/java/rife/render/TestEncode.java +++ b/src/test/java/rife/render/TestEncode.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,10 +55,6 @@ 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 eb1840b..706c648 100644 --- a/src/test/java/rife/render/TestFormat.java +++ b/src/test/java/rife/render/TestFormat.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import rife.template.TemplateFactory; @@ -44,9 +45,7 @@ class TestFormat { t.setAttribute(TestCase.FOO, "374380141731053"); assertThat(t.getContent()).as("UK AMEX").isEqualTo("1053"); t.setAttribute(TestCase.FOO, "000000000000001"); - assertThat(t.getContent()).as("000000000000001").isEmpty(); - t.setAttribute(TestCase.FOO, ""); - assertThat(t.getContent()).as("").isEmpty(); + assertThat(t.getContent()).isEmpty(); } @Test diff --git a/src/test/java/rife/render/TestRenderUtils.java b/src/test/java/rife/render/TestRenderUtils.java index f1f8c46..6854bf5 100644 --- a/src/test/java/rife/render/TestRenderUtils.java +++ b/src/test/java/rife/render/TestRenderUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023 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,7 +17,6 @@ package rife.render; -import org.assertj.core.api.AutoCloseableSoftAssertions; import org.junit.jupiter.api.Test; import java.util.Properties; @@ -36,28 +35,11 @@ class TestRenderUtils { assertThat(RenderUtils.abbreviate(TestCase.SAMPLE_TEXT, -1, "")).as("max=-1") .isEqualTo(TestCase.SAMPLE_TEXT); - - 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(); - p.put(RenderUtils.ENCODING_PROPERTY, "blah"); - assertThat(RenderUtils.encode(TestCase.SAMPLE_TEXT, p)).as("invalid encoding").isEqualTo(TestCase.SAMPLE_TEXT); - p.put(RenderUtils.ENCODING_PROPERTY, "json"); - assertThat(RenderUtils.encode("This is a \"•test\"", p)).as("json").isEqualTo("This is a \\\"\\u2022test\\\""); p.put(RenderUtils.ENCODING_PROPERTY, "html"); assertThat(RenderUtils.encode("", p)).as("html").isEqualTo("<a test &>"); p.put(RenderUtils.ENCODING_PROPERTY, "js"); @@ -70,22 +52,8 @@ class TestRenderUtils { assertThat(RenderUtils.encode("Joe's Café & Bar", p)).as("xml").isEqualTo("Joe's Café & Bar"); } - @Test - void testEncodeJs() { - assertThat(RenderUtils.encodeJs("")).isEmpty(); - } - - @Test - void testFetchUrl() { - var s = "default"; - assertThat(RenderUtils.fetchUrl("blah", s)).isEqualTo(s); - assertThat(RenderUtils.fetchUrl("https://www.google.com/404", s)).isEqualTo(s); - assertThat(RenderUtils.fetchUrl("https://www.notreallythere.com/", s)).isEqualTo(s); - } - @Test void testHtmlEntities() { - assertThat(RenderUtils.htmlEntities("")).isEmpty(); assertThat(RenderUtils.htmlEntities(SAMPLE_GERMAN)) .isEqualTo("Möchten Sie ein paar Äpfel?"); } @@ -94,8 +62,6 @@ class TestRenderUtils { void testMask() { var foo = "4342256562440179"; - assertThat(RenderUtils.mask("", " ", 2, false)).isEmpty(); - assertThat(RenderUtils.mask(foo, "?", 4, false)).as("mask=?") .isEqualTo("????????????0179"); @@ -108,43 +74,27 @@ class TestRenderUtils { @Test void testNormalize() { - 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,