Added EncodeBase64 and EncodeUnicode
This commit is contained in:
parent
070fbda221
commit
78fca0e1c3
4 changed files with 110 additions and 0 deletions
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
|
@ -15,6 +15,8 @@
|
|||
<pattern value="rife2.render.EncodeHtmlEntities" />
|
||||
<pattern value="rife2.render.Rot13" />
|
||||
<pattern value="rife2.render.Year" />
|
||||
<pattern value="rife2.render.EncodeBase64" />
|
||||
<pattern value="rife2.render.EncodeUnicode" />
|
||||
</component>
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="PDMPlugin">
|
||||
|
|
|
@ -7,12 +7,18 @@ This project provides a set of template renderers.
|
|||
|
||||
- **rife.render.Capitalize**
|
||||
- Capitalizes a template value.
|
||||
- **rife.render.EncodeBase64**
|
||||
- Encodes a template value to Base64.
|
||||
- **rife.render.EncodeHtml**
|
||||
- Encodes a template value to HTML.
|
||||
- **rife.render.EncodeHtmlEntities**
|
||||
- Encodes a template value to HTML decimal entities.
|
||||
- **rife.render.EncodeJson**
|
||||
- Encodes a template value to JSON.
|
||||
- **rife.render.EncodeQp**
|
||||
- Converts a template value to a quoted-printable string.
|
||||
- **rife.render.EncodeUnicode**
|
||||
- Encodes a template value to Unicode escape codes.
|
||||
- **rife.render.EncodeUrl**
|
||||
- URL-encodes a template value.
|
||||
- **rife.render.EncodeXml**
|
||||
|
|
52
lib/src/main/java/rife2/render/EncodeBase64.java
Normal file
52
lib/src/main/java/rife2/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 rife2.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 (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) {
|
||||
return StringUtils.encodeBase64(template.getValue(differentiator).getBytes(StandardCharsets.UTF_8));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
50
lib/src/main/java/rife2/render/EncodeUnicode.java
Normal file
50
lib/src/main/java/rife2/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 rife2.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 (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) {
|
||||
return StringUtils.encodeUnicode(template.getValue(differentiator));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue