Renamed package from rife2 to rife
This commit is contained in:
parent
de9351746b
commit
5bd48a4031
16 changed files with 16 additions and 16 deletions
50
lib/src/main/java/rife/render/Capitalize.java
Normal file
50
lib/src/main/java/rife/render/Capitalize.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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 rife.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
import rife.tools.Localization;
|
||||
|
||||
/**
|
||||
* <p>Capitalizes a template value.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.Capitalize:valueId/-->
|
||||
* {{v render:rife.render.Capitalize:valueId/}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @since 1.0
|
||||
*/
|
||||
public class Capitalize implements ValueRenderer {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (template.hasValueId(differentiator)) {
|
||||
var value = template.getValue(differentiator);
|
||||
return value.substring(0, 1).toUpperCase(Localization.getLocale()) + value.substring(1);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
52
lib/src/main/java/rife/render/EncodeBase64.java
Normal file
52
lib/src/main/java/rife/render/EncodeBase64.java
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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 rife.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
import rife.tools.StringUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* <p>Encodes a template value to Base64.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.EncodeBase64:valueId/-->
|
||||
* {{v render:rife.render.EncodeBase64:valueId/}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @see StringUtils#encodeBase64(byte[])
|
||||
* @since 1.0
|
||||
*/
|
||||
public class EncodeBase64 implements ValueRenderer {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (template.hasValueId(differentiator)) {
|
||||
return StringUtils.encodeBase64(template.getValue(differentiator).getBytes(StandardCharsets.UTF_8));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
50
lib/src/main/java/rife/render/EncodeHtml.java
Normal file
50
lib/src/main/java/rife/render/EncodeHtml.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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 rife.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
import rife.tools.StringUtils;
|
||||
|
||||
/**
|
||||
* <p>Encodes a template value to HTML.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.EncodeHtml:valueId/-->
|
||||
* {{v render:rife.render.EncodeHtml:valueId/}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @see StringUtils#encodeHtml(String)
|
||||
* @since 1.0
|
||||
*/
|
||||
public class EncodeHtml implements ValueRenderer {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (template.hasValueId(differentiator)) {
|
||||
return StringUtils.encodeHtml(template.getValue(differentiator));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
68
lib/src/main/java/rife/render/EncodeHtmlEntities.java
Normal file
68
lib/src/main/java/rife/render/EncodeHtmlEntities.java
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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 rife.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
|
||||
/**
|
||||
* <p>Encodes a template value to HTML decimal entities</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.EncodeHtmlEntities:valueId/-->
|
||||
* {{v render:rife.render.EncodeHtmlEntities:valueId/}}
|
||||
* </pre>
|
||||
*
|
||||
* <p>For example {@code john@doe.com} would be encoded to:</p>
|
||||
*
|
||||
* <pre>&#106;&#111;&#104;&#110;&#64;&#100;&#111;&#101;&#46;&#99;&#111;&#109;</pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @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 (template.hasValueId(differentiator)) {
|
||||
return toHtmlEntities(template.getValue(differentiator));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
50
lib/src/main/java/rife/render/EncodeJson.java
Normal file
50
lib/src/main/java/rife/render/EncodeJson.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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 rife.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
import rife.tools.StringUtils;
|
||||
|
||||
/**
|
||||
* <p>Encodes a template value to JSON.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.EncodeJson:valueId/-->
|
||||
* {{v render:rife.render.EncodeJson:valueId/}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @see StringUtils#encodeJson(String)
|
||||
* @since 1.0
|
||||
*/
|
||||
public class EncodeJson implements ValueRenderer {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (template.hasValueId(differentiator)) {
|
||||
return StringUtils.encodeJson(template.getValue(differentiator));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
85
lib/src/main/java/rife/render/EncodeQp.java
Normal file
85
lib/src/main/java/rife/render/EncodeQp.java
Normal file
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* 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 rife.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
import rife.tools.Localization;
|
||||
|
||||
/**
|
||||
* <p>Converts a template value to a quoted-printable string.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.EncodeQp:valueId/-->
|
||||
* {{v render:rife.render.EncodeQp:valueId/}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @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(Localization.getLocale()));
|
||||
}
|
||||
}
|
||||
|
||||
return buff.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (template.hasValueId(differentiator)) {
|
||||
return toQuotedPrintable(template.getValue(differentiator));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
50
lib/src/main/java/rife/render/EncodeUnicode.java
Normal file
50
lib/src/main/java/rife/render/EncodeUnicode.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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 rife.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
import rife.tools.StringUtils;
|
||||
|
||||
/**
|
||||
* <p>Encodes a template value to Unicode escape codes.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.EncodeUnicode:valueId/-->
|
||||
* {{v render:rife.render.EncodeUnicode:valueId/}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @see StringUtils#encodeUnicode(String)
|
||||
* @since 1.0
|
||||
*/
|
||||
public class EncodeUnicode implements ValueRenderer {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (template.hasValueId(differentiator)) {
|
||||
return StringUtils.encodeUnicode(template.getValue(differentiator));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
50
lib/src/main/java/rife/render/EncodeUrl.java
Normal file
50
lib/src/main/java/rife/render/EncodeUrl.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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 rife.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
import rife.tools.StringUtils;
|
||||
|
||||
/**
|
||||
* <p>URL-encodes a template value.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.EncodeUrl:valueId/-->
|
||||
* {{v render:rife.render.EncodeUrl:valueId/}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @see StringUtils#encodeUrl(String)
|
||||
* @since 1.0
|
||||
*/
|
||||
public class EncodeUrl implements ValueRenderer {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (template.hasValueId(differentiator)) {
|
||||
return StringUtils.encodeUrl(template.getValue(differentiator));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
50
lib/src/main/java/rife/render/EncodeXml.java
Normal file
50
lib/src/main/java/rife/render/EncodeXml.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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 rife.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
import rife.tools.StringUtils;
|
||||
|
||||
/**
|
||||
* <p>Encodes a template value to XML.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.EncodeXml:valueId/-->
|
||||
* {{v render:rife.render.EncodeXml:valueId/}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @see StringUtils#encodeXml(String)
|
||||
* @since 1.0
|
||||
*/
|
||||
public class EncodeXml implements ValueRenderer {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (template.hasValueId(differentiator)) {
|
||||
return StringUtils.encodeXml(template.getValue(differentiator));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
49
lib/src/main/java/rife/render/Lowercase.java
Normal file
49
lib/src/main/java/rife/render/Lowercase.java
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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 rife.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
import rife.tools.Localization;
|
||||
|
||||
/**
|
||||
* <p>Converts a template value to lowercase.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.Lowercase:valueId/-->
|
||||
* {{v render:rife.render.Lowercase:valueId/}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @since 1.0
|
||||
*/
|
||||
public class Lowercase implements ValueRenderer {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (template.hasValueId(differentiator)) {
|
||||
return template.getValue(differentiator).toLowerCase(Localization.getLocale());
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
86
lib/src/main/java/rife/render/Rot13.java
Normal file
86
lib/src/main/java/rife/render/Rot13.java
Normal file
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* 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 rife.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
|
||||
/**
|
||||
* <p>Translates a template value to/from ROT13.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.Rot13:valueId/-->
|
||||
* {{v render:rife.render.Rot13:valueId/}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @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 (template.hasValueId(differentiator)) {
|
||||
return rot13(template.getValue(differentiator));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
78
lib/src/main/java/rife/render/SwapCase.java
Normal file
78
lib/src/main/java/rife/render/SwapCase.java
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* 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 rife.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
|
||||
/**
|
||||
* <p>Swap case of a template value.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.SwapCase:valueId/-->
|
||||
* {{v render:rife.render.SwapCase:valueId/}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @since 1.0
|
||||
*/
|
||||
public class SwapCase implements ValueRenderer {
|
||||
/**
|
||||
* Swaps the case of a String.
|
||||
*
|
||||
* @param src the String to swap the case of
|
||||
* @return the modified String or null
|
||||
*/
|
||||
public static String swapCase(final String src) {
|
||||
if (src == null || src.isEmpty()) {
|
||||
return src;
|
||||
}
|
||||
|
||||
int offset = 0;
|
||||
var len = src.length();
|
||||
var buff = new int[len];
|
||||
for (var i = 0; i < len; ) {
|
||||
int newCodePoint;
|
||||
var curCodePoint = src.codePointAt(i);
|
||||
if (Character.isUpperCase(curCodePoint) || Character.isTitleCase(curCodePoint)) {
|
||||
newCodePoint = Character.toLowerCase(curCodePoint);
|
||||
} else if (Character.isLowerCase(curCodePoint)) {
|
||||
newCodePoint = Character.toUpperCase(curCodePoint);
|
||||
} else {
|
||||
newCodePoint = curCodePoint;
|
||||
}
|
||||
buff[offset++] = newCodePoint;
|
||||
i += Character.charCount(newCodePoint);
|
||||
}
|
||||
return new String(buff, 0, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (template.hasValueId(differentiator)) {
|
||||
return swapCase(template.getValue(differentiator));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
48
lib/src/main/java/rife/render/Trim.java
Normal file
48
lib/src/main/java/rife/render/Trim.java
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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 rife.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
|
||||
/**
|
||||
* <p>Removes leading and trailing whitespace from a template value.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.Trim:valueId/-->
|
||||
* {{v render:rife.render.Trim:valueId/}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @since 1.0
|
||||
*/
|
||||
public class Trim implements ValueRenderer {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (template.hasValueId(differentiator)) {
|
||||
return template.getValue(differentiator).trim();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
50
lib/src/main/java/rife/render/Uncapitalize.java
Normal file
50
lib/src/main/java/rife/render/Uncapitalize.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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 rife.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
import rife.tools.Localization;
|
||||
|
||||
/**
|
||||
* <p>Un-capitalizes a template value.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.Uncapitalize:valueId/-->
|
||||
* {{v render:rife.render.Uncapitalize:valueId/}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @since 1.0
|
||||
*/
|
||||
public class Uncapitalize implements ValueRenderer {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (template.hasValueId(differentiator)) {
|
||||
var value = template.getValue(differentiator);
|
||||
return value.substring(0, 1).toLowerCase(Localization.getLocale()) + value.substring(1);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
49
lib/src/main/java/rife/render/Uppercase.java
Normal file
49
lib/src/main/java/rife/render/Uppercase.java
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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 rife.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
import rife.tools.Localization;
|
||||
|
||||
/**
|
||||
* <p>Convert a template value to uppercase.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.Uppercase:valueId/-->
|
||||
* {{v render:rife.render.Uppercase:valueId/}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @since 1.0
|
||||
*/
|
||||
public class Uppercase implements ValueRenderer {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (template.hasValueId(differentiator)) {
|
||||
return template.getValue(differentiator).toUpperCase(Localization.getLocale());
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
44
lib/src/main/java/rife/render/Year.java
Normal file
44
lib/src/main/java/rife/render/Year.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* 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 rife.render;
|
||||
|
||||
import rife.template.Template;
|
||||
import rife.template.ValueRenderer;
|
||||
|
||||
/**
|
||||
* <p>Renders the current year.</p>
|
||||
*
|
||||
* <p>Usage:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <!--v render:rife.render.Year/-->
|
||||
* {{v render:rife.render.Year}}
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
* @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();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue