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) {
|
public String render(Template template, String valueId, String differentiator) {
|
||||||
var mark = "...";
|
var mark = "...";
|
||||||
var max = -1;
|
var max = -1;
|
||||||
if (template.hasDefaultValue(valueId)) {
|
var defaultValue = template.getDefaultValue(valueId);
|
||||||
|
if (defaultValue != null) {
|
||||||
var properties = new Properties();
|
var properties = new Properties();
|
||||||
try {
|
try {
|
||||||
properties.load(new StringReader(template.getDefaultValue(valueId)));
|
properties.load(new StringReader(defaultValue));
|
||||||
mark = properties.getProperty("mark", mark);
|
mark = properties.getProperty("mark", mark);
|
||||||
max = Integer.parseInt(properties.getProperty("max", String.valueOf(max)));
|
max = Integer.parseInt(properties.getProperty("max", String.valueOf(max)));
|
||||||
} catch (IOException | NumberFormatException ignore) {
|
} catch (IOException | NumberFormatException ignore) {
|
||||||
|
|
|
@ -46,11 +46,12 @@ public class DateTimeIso implements ValueRenderer {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String render(Template template, String valueId, String differentiator) {
|
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();
|
var properties = new Properties();
|
||||||
try {
|
try {
|
||||||
var tz = "tz";
|
var tz = "tz";
|
||||||
properties.load(new StringReader(template.getDefaultValue(valueId)));
|
properties.load(new StringReader(defaultValue));
|
||||||
if (properties.containsKey(tz)) {
|
if (properties.containsKey(tz)) {
|
||||||
return ZonedDateTime.now().format(
|
return ZonedDateTime.now().format(
|
||||||
RenderUtils.ISO_8601_FORMATTER.withZone(ZoneId.of(properties.getProperty(tz))));
|
RenderUtils.ISO_8601_FORMATTER.withZone(ZoneId.of(properties.getProperty(tz))));
|
||||||
|
|
|
@ -47,10 +47,11 @@ public class Mask implements ValueRenderer {
|
||||||
var mask = "*";
|
var mask = "*";
|
||||||
var unmasked = 0;
|
var unmasked = 0;
|
||||||
var fromStart = false;
|
var fromStart = false;
|
||||||
if (template.hasDefaultValue(valueId)) {
|
var defaultValue = template.getDefaultValue(valueId);
|
||||||
|
if (defaultValue != null) {
|
||||||
var properties = new Properties();
|
var properties = new Properties();
|
||||||
try {
|
try {
|
||||||
properties.load(new StringReader(template.getDefaultValue(valueId)));
|
properties.load(new StringReader(defaultValue));
|
||||||
mask = properties.getProperty("mask", mask);
|
mask = properties.getProperty("mask", mask);
|
||||||
unmasked = Integer.parseInt(properties.getProperty("unmasked", "0"));
|
unmasked = Integer.parseInt(properties.getProperty("unmasked", "0"));
|
||||||
fromStart = "true".equalsIgnoreCase(properties.getProperty("fromStart", "false"));
|
fromStart = "true".equalsIgnoreCase(properties.getProperty("fromStart", "false"));
|
||||||
|
|
|
@ -45,10 +45,11 @@ public class QrCode implements ValueRenderer {
|
||||||
@Override
|
@Override
|
||||||
public String render(Template template, String valueId, String differentiator) {
|
public String render(Template template, String valueId, String differentiator) {
|
||||||
var size = "150x150";
|
var size = "150x150";
|
||||||
if (template.hasDefaultValue(valueId)) {
|
var defaultValue = template.getDefaultValue(valueId);
|
||||||
|
if (defaultValue != null) {
|
||||||
var properties = new Properties();
|
var properties = new Properties();
|
||||||
try {
|
try {
|
||||||
properties.load(new StringReader(template.getDefaultValue(valueId)));
|
properties.load(new StringReader(defaultValue));
|
||||||
size = properties.getProperty("size", size);
|
size = properties.getProperty("size", size);
|
||||||
} catch (IOException ignore) {
|
} catch (IOException ignore) {
|
||||||
// do nothing
|
// do nothing
|
||||||
|
|
|
@ -201,13 +201,17 @@ public final class RenderUtils {
|
||||||
var sum = 0;
|
var sum = 0;
|
||||||
boolean isSecond = false;
|
boolean isSecond = false;
|
||||||
int digit;
|
int digit;
|
||||||
|
char c;
|
||||||
for (int i = len - 1; i >= 0; i--) {
|
for (int i = len - 1; i >= 0; i--) {
|
||||||
digit = cc.charAt(i) - '0';
|
c = cc.charAt(i);
|
||||||
if (isSecond) {
|
if (c >= '0' && c <= '9') {
|
||||||
digit = digit * 2;
|
digit = cc.charAt(i) - '0';
|
||||||
|
if (isSecond) {
|
||||||
|
digit = digit * 2;
|
||||||
|
}
|
||||||
|
sum += digit / 10;
|
||||||
|
sum += digit % 10;
|
||||||
}
|
}
|
||||||
sum += digit / 10;
|
|
||||||
sum += digit % 10;
|
|
||||||
|
|
||||||
isSecond = !isSecond;
|
isSecond = !isSecond;
|
||||||
}
|
}
|
||||||
|
@ -339,8 +343,10 @@ public final class RenderUtils {
|
||||||
if (src == null || src.isBlank()) {
|
if (src == null || src.isBlank()) {
|
||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
return fetchUrl(String.format("https://api.qrserver.com/v1/create-qr-code/?format=svg&size=%s&data=%s", size,
|
return fetchUrl(String.format("https://api.qrserver.com/v1/create-qr-code/?format=svg&size=%s&data=%s",
|
||||||
StringUtils.encodeUrl(src.trim())), src);
|
StringUtils.encodeUrl(size),
|
||||||
|
StringUtils.encodeUrl(src.trim())),
|
||||||
|
src);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -46,10 +46,10 @@ public class Uptime implements ValueRenderer {
|
||||||
@Override
|
@Override
|
||||||
public String render(Template template, String valueId, String differentiator) {
|
public String render(Template template, String valueId, String differentiator) {
|
||||||
var properties = new Properties();
|
var properties = new Properties();
|
||||||
|
var defaultValue = template.getDefaultValue(valueId);
|
||||||
if (template.hasDefaultValue(valueId)) {
|
if (defaultValue != null) {
|
||||||
try {
|
try {
|
||||||
properties.load(new StringReader(template.getDefaultValue(valueId)));
|
properties.load(new StringReader(defaultValue));
|
||||||
} catch (IOException ignore) {
|
} catch (IOException ignore) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
/*
|
plugins {
|
||||||
* This file was generated by the Gradle 'init' task.
|
id("com.gradle.enterprise") version "3.12.5"
|
||||||
*
|
}
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
rootProject.name = "rife2-template-renderers"
|
rootProject.name = "rife2-template-renderers"
|
||||||
include("lib")
|
include("lib")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue