Minimized calls to getDefaultValue
This commit is contained in:
parent
9d3452304c
commit
4e3f021ec3
7 changed files with 31 additions and 27 deletions
|
@ -46,10 +46,11 @@ public class Abbreviate implements ValueRenderer {
|
|||
public String render(Template template, String valueId, String differentiator) {
|
||||
var mark = "...";
|
||||
var max = -1;
|
||||
if (template.hasDefaultValue(valueId)) {
|
||||
var defaultValue = template.getDefaultValue(valueId);
|
||||
if (defaultValue != null) {
|
||||
var properties = new Properties();
|
||||
try {
|
||||
properties.load(new StringReader(template.getDefaultValue(valueId)));
|
||||
properties.load(new StringReader(defaultValue));
|
||||
mark = properties.getProperty("mark", mark);
|
||||
max = Integer.parseInt(properties.getProperty("max", String.valueOf(max)));
|
||||
} catch (IOException | NumberFormatException ignore) {
|
||||
|
|
|
@ -46,11 +46,12 @@ public class DateTimeIso implements ValueRenderer {
|
|||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (template.hasDefaultValue(valueId)) {
|
||||
var defaultValue = template.getDefaultValue(valueId);
|
||||
if (defaultValue != null) {
|
||||
var properties = new Properties();
|
||||
try {
|
||||
var tz = "tz";
|
||||
properties.load(new StringReader(template.getDefaultValue(valueId)));
|
||||
properties.load(new StringReader(defaultValue));
|
||||
if (properties.containsKey(tz)) {
|
||||
return ZonedDateTime.now().format(
|
||||
RenderUtils.ISO_8601_FORMATTER.withZone(ZoneId.of(properties.getProperty(tz))));
|
||||
|
|
|
@ -47,10 +47,11 @@ public class Mask implements ValueRenderer {
|
|||
var mask = "*";
|
||||
var unmasked = 0;
|
||||
var fromStart = false;
|
||||
if (template.hasDefaultValue(valueId)) {
|
||||
var defaultValue = template.getDefaultValue(valueId);
|
||||
if (defaultValue != null) {
|
||||
var properties = new Properties();
|
||||
try {
|
||||
properties.load(new StringReader(template.getDefaultValue(valueId)));
|
||||
properties.load(new StringReader(defaultValue));
|
||||
mask = properties.getProperty("mask", mask);
|
||||
unmasked = Integer.parseInt(properties.getProperty("unmasked", "0"));
|
||||
fromStart = "true".equalsIgnoreCase(properties.getProperty("fromStart", "false"));
|
||||
|
|
|
@ -45,10 +45,11 @@ public class QrCode implements ValueRenderer {
|
|||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
var size = "150x150";
|
||||
if (template.hasDefaultValue(valueId)) {
|
||||
var defaultValue = template.getDefaultValue(valueId);
|
||||
if (defaultValue != null) {
|
||||
var properties = new Properties();
|
||||
try {
|
||||
properties.load(new StringReader(template.getDefaultValue(valueId)));
|
||||
properties.load(new StringReader(defaultValue));
|
||||
size = properties.getProperty("size", size);
|
||||
} catch (IOException ignore) {
|
||||
// do nothing
|
||||
|
|
|
@ -201,13 +201,17 @@ public final class RenderUtils {
|
|||
var sum = 0;
|
||||
boolean isSecond = false;
|
||||
int digit;
|
||||
char c;
|
||||
for (int i = len - 1; i >= 0; i--) {
|
||||
c = cc.charAt(i);
|
||||
if (c >= '0' && c <= '9') {
|
||||
digit = cc.charAt(i) - '0';
|
||||
if (isSecond) {
|
||||
digit = digit * 2;
|
||||
}
|
||||
sum += digit / 10;
|
||||
sum += digit % 10;
|
||||
}
|
||||
|
||||
isSecond = !isSecond;
|
||||
}
|
||||
|
@ -339,8 +343,10 @@ public final class RenderUtils {
|
|||
if (src == null || src.isBlank()) {
|
||||
return src;
|
||||
}
|
||||
return fetchUrl(String.format("https://api.qrserver.com/v1/create-qr-code/?format=svg&size=%s&data=%s", size,
|
||||
StringUtils.encodeUrl(src.trim())), src);
|
||||
return fetchUrl(String.format("https://api.qrserver.com/v1/create-qr-code/?format=svg&size=%s&data=%s",
|
||||
StringUtils.encodeUrl(size),
|
||||
StringUtils.encodeUrl(src.trim())),
|
||||
src);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,10 +46,10 @@ public class Uptime implements ValueRenderer {
|
|||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
var properties = new Properties();
|
||||
|
||||
if (template.hasDefaultValue(valueId)) {
|
||||
var defaultValue = template.getDefaultValue(valueId);
|
||||
if (defaultValue != null) {
|
||||
try {
|
||||
properties.load(new StringReader(template.getDefaultValue(valueId)));
|
||||
properties.load(new StringReader(defaultValue));
|
||||
} catch (IOException ignore) {
|
||||
// ignore
|
||||
}
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* The settings file is used to specify which projects to include in your build.
|
||||
*
|
||||
* Detailed information about configuring a multi-project build in Gradle can be found
|
||||
* in the user manual at https://docs.gradle.org/8.0.2/userguide/multi_project_builds.html
|
||||
* This project uses @Incubating APIs which are subject to change.
|
||||
*/
|
||||
plugins {
|
||||
id("com.gradle.enterprise") version "3.12.5"
|
||||
}
|
||||
|
||||
rootProject.name = "rife2-template-renderers"
|
||||
include("lib")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue