Encodes a template value to HTML.
- * - *Usage:
- * - *- * <!--v render:rife.render.EncodeHtml:valueId/--> - * {{v render:rife.render.EncodeHtml:valueId}} - *- * - * @author Erik C. Thauvin - * @see StringUtils#encodeHtml(String) - * @since 1.0 - */ -public class EncodeHtml implements ValueRenderer { - /** - * {@inheritDoc} - */ - @Override - public String render(Template template, String valueId, String differentiator) { - if (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) { - return StringUtils.encodeHtml(template.getValue(differentiator)); - } else { - return ""; - } - } -} diff --git a/lib/src/main/java/rife2/render/EncodeHtmlEntities.java b/lib/src/main/java/rife2/render/EncodeHtmlEntities.java deleted file mode 100644 index 01fef1d..0000000 --- a/lib/src/main/java/rife2/render/EncodeHtmlEntities.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package rife2.render; - -import rife.template.Template; -import rife.template.ValueRenderer; - -/** - *
Encodes a template value to HTML decimal entities
- * - *Usage:
- * - *- * <!--v render:rife.render.EncodeHtmlEntities:valueId/--> - * {{v render:rife.render.EncodeHtmlEntities:valueId}} - *- * - *
For example {@code john@doe.com} would be encoded to:
- * - *john@doe.com- * - * @author Erik C. Thauvin - * @since 1.0 - */ -public class EncodeHtmlEntities implements ValueRenderer { - /** - * Converts a text string to HTML decimal entities. - * - * @param text the String to convert. - * @return the converted string. - */ - public static String toHtmlEntities(String text) { - var buff = new StringBuilder(text.length() * 6); - - for (var i = 0; i < text.length(); i++) { - buff.append("").append((int) text.charAt(i)).append(';'); - } - - return buff.toString(); - } - - /** - * {@inheritDoc} - */ - @Override - public String render(Template template, String valueId, String differentiator) { - if (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) { - return toHtmlEntities(template.getValue(differentiator)); - } else { - return ""; - } - } -} diff --git a/lib/src/main/java/rife2/render/EncodeJson.java b/lib/src/main/java/rife2/render/EncodeJson.java deleted file mode 100644 index c80f150..0000000 --- a/lib/src/main/java/rife2/render/EncodeJson.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package rife2.render; - -import rife.template.Template; -import rife.template.ValueRenderer; -import rife.tools.StringUtils; - -/** - *
Encodes a template value to JSON.
- * - *Usage:
- * - *- * <!--v render:rife.render.EncodeJson:valueId/--> - * {{v render:rife.render.EncodeJson:valueId}} - *- * - * @author Erik C. Thauvin - * @see StringUtils#encodeJson(String) - * @since 1.0 - */ -public class EncodeJson implements ValueRenderer { - /** - * {@inheritDoc} - */ - @Override - public String render(Template template, String valueId, String differentiator) { - if (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) { - return StringUtils.encodeJson(template.getValue(differentiator)); - } else { - return ""; - } - } -} diff --git a/lib/src/main/java/rife2/render/EncodeQp.java b/lib/src/main/java/rife2/render/EncodeQp.java deleted file mode 100644 index b902db4..0000000 --- a/lib/src/main/java/rife2/render/EncodeQp.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package rife2.render; - -import rife.template.Template; -import rife.template.ValueRenderer; - -import java.util.Locale; - -/** - *
Converts a template value to a quoted-printable string.
- * - *Usage:
- * - *- * <!--v render:rife.render.EncodeQp:valueId/--> - * {{v render:rife.render.EncodeQp:valueId}} - *- * - * @author Erik C. Thauvin - * @since 1.0 - */ -public class EncodeQp implements ValueRenderer { - /** - * Converts the given String to a quoted-printable string. - * - * @param src the source String - * @return the quoted-printable String - */ - public static String toQuotedPrintable(String src) { - if (src == null || src.isEmpty()) { - return src; - } - - char c; - var buff = new StringBuilder(src.length()); - String hex; - - for (var i = 0; i < src.length(); i++) { - c = src.charAt(i); - - if (((c > 47) && (c < 58)) || ((c > 64) && (c < 91)) || ((c > 96) && (c < 123))) { - buff.append(c); - } else { - hex = Integer.toString(c, 16); - - buff.append('='); - - if (hex.length() == 1) { - buff.append('0'); - } - - buff.append(hex.toUpperCase(Locale.getDefault())); - } - } - - return buff.toString(); - } - - /** - * {@inheritDoc} - */ - @Override - public String render(Template template, String valueId, String differentiator) { - if (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) { - return toQuotedPrintable(template.getValue(differentiator)); - } else { - return ""; - } - } -} diff --git a/lib/src/main/java/rife2/render/EncodeUrl.java b/lib/src/main/java/rife2/render/EncodeUrl.java deleted file mode 100644 index 408ce5a..0000000 --- a/lib/src/main/java/rife2/render/EncodeUrl.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package rife2.render; - -import rife.template.Template; -import rife.template.ValueRenderer; -import rife.tools.StringUtils; - -/** - *
URL-encodes a template value.
- * - *Usage:
- * - *- * <!--v render:rife.render.EncodeUrl:valueId/--> - * {{v render:rife.render.EncodeUrl:valueId}} - *- * - * @author Erik C. Thauvin - * @see StringUtils#encodeUrl(String) - * @since 1.0 - */ -public class EncodeUrl implements ValueRenderer { - /** - * {@inheritDoc} - */ - @Override - public String render(Template template, String valueId, String differentiator) { - if (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) { - return StringUtils.encodeUrl(template.getValue(differentiator)); - } else { - return ""; - } - } -} diff --git a/lib/src/main/java/rife2/render/EncodeXml.java b/lib/src/main/java/rife2/render/EncodeXml.java deleted file mode 100644 index 05a5abf..0000000 --- a/lib/src/main/java/rife2/render/EncodeXml.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package rife2.render; - -import rife.template.Template; -import rife.template.ValueRenderer; -import rife.tools.StringUtils; - -/** - *
Encodes a template value to XML.
- * - *Usage:
- * - *- * <!--v render:rife.render.EncodeXml:valueId/--> - * {{v render:rife.render.EncodeXml:valueId}} - *- * - * @author Erik C. Thauvin - * @see StringUtils#encodeXml(String) - * @since 1.0 - */ -public class EncodeXml implements ValueRenderer { - /** - * {@inheritDoc} - */ - @Override - public String render(Template template, String valueId, String differentiator) { - if (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) { - return StringUtils.encodeXml(template.getValue(differentiator)); - } else { - return ""; - } - } -} diff --git a/lib/src/main/java/rife2/render/Rot13.java b/lib/src/main/java/rife2/render/Rot13.java deleted file mode 100644 index 3f9823c..0000000 --- a/lib/src/main/java/rife2/render/Rot13.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package rife2.render; - -import rife.template.Template; -import rife.template.ValueRenderer; - -/** - *
Translates a template value to/from ROT13.
- * - *Usage:
- * - *- * <!--v render:rife.render.Rot13:valueId/--> - * {{v render:rife.render.Rot13:valueId}} - *- * - * @author Erik C. Thauvin - * @since 1.0 - */ -public class Rot13 implements ValueRenderer { - /** - * Translates a String to/from ROT13. - * - * @param src The source String. - * @return The translated String. - */ - public static String rot13(String src) { - if (src == null || src.isEmpty()) { - return ""; - } else { - var output = new StringBuilder(src.length()); - - for (var i = 0; i < src.length(); i++) { - var inChar = src.charAt(i); - - if ((inChar >= 'A') && (inChar <= 'Z')) { - inChar += (char) 13; - - if (inChar > 'Z') { - inChar -= (char) 26; - } - } - - if ((inChar >= 'a') && (inChar <= 'z')) { - inChar += (char) 13; - - if (inChar > 'z') { - inChar -= (char) 26; - } - } - - output.append(inChar); - } - - return output.toString(); - } - } - - /** - * {@inheritDoc} - */ - @Override - public String render(Template template, String valueId, String differentiator) { - if (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) { - return rot13(template.getValue(differentiator)); - } else { - return ""; - } - } -} diff --git a/lib/src/main/java/rife2/render/Year.java b/lib/src/main/java/rife2/render/Year.java deleted file mode 100644 index d37cd31..0000000 --- a/lib/src/main/java/rife2/render/Year.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package rife2.render; - -import rife.template.Template; -import rife.template.ValueRenderer; - -/** - *
Renders the current year.
- * - *Usage:
- * - *- * <!--v render:rife.render.Year/--> - * {{v render:rife.render.Year}} - *- * - * @author Erik C. Thauvin - * @since 1.0 - */ -public class Year implements ValueRenderer { - /** - * {@inheritDoc} - */ - @Override - public String render(Template template, String valueId, String differentiator) { - return java.time.Year.now().toString(); - } -}