Initial commit
This commit is contained in:
commit
ffe05f5b2e
23 changed files with 1116 additions and 0 deletions
52
lib/src/main/java/rife2/render/Capitalize.java
Normal file
52
lib/src/main/java/rife2/render/Capitalize.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 java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* <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 (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) {
|
||||
var value = template.getValue(differentiator);
|
||||
return value.substring(0, 1).toUpperCase(Locale.getDefault()) + value.substring(1);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
50
lib/src/main/java/rife2/render/Lowercase.java
Normal file
50
lib/src/main/java/rife2/render/Lowercase.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 java.util.Locale;
|
||||
|
||||
/**
|
||||
* <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 (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) {
|
||||
return template.getValue(differentiator).toLowerCase(Locale.getDefault());
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
80
lib/src/main/java/rife2/render/SwapCase.java
Normal file
80
lib/src/main/java/rife2/render/SwapCase.java
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* <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 s the String to swap the case of
|
||||
* @return the modified String or null
|
||||
*/
|
||||
public static String swapCase(String s) {
|
||||
if (s == null || s.isEmpty()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
var buffer = s.toCharArray();
|
||||
var whitespace = true;
|
||||
|
||||
for (var i = 0; i < buffer.length; i++) {
|
||||
var ch = buffer[i];
|
||||
if (Character.isUpperCase(ch) || Character.isTitleCase(ch)) {
|
||||
buffer[i] = Character.toLowerCase(ch);
|
||||
whitespace = false;
|
||||
} else if (Character.isLowerCase(ch)) {
|
||||
if (whitespace) {
|
||||
buffer[i] = Character.toTitleCase(ch);
|
||||
whitespace = false;
|
||||
} else {
|
||||
buffer[i] = Character.toUpperCase(ch);
|
||||
}
|
||||
} else {
|
||||
whitespace = Character.isWhitespace(ch);
|
||||
}
|
||||
}
|
||||
return new String(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String render(Template template, String valueId, String differentiator) {
|
||||
if (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) {
|
||||
return swapCase(template.getValue(differentiator));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
48
lib/src/main/java/rife2/render/Trim.java
Normal file
48
lib/src/main/java/rife2/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 rife2.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 (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) {
|
||||
return template.getValue(differentiator).trim();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
51
lib/src/main/java/rife2/render/Uncapitalize.java
Normal file
51
lib/src/main/java/rife2/render/Uncapitalize.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* <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 (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) {
|
||||
var value = template.getValue(differentiator);
|
||||
return value.substring(0, 1).toLowerCase(Locale.getDefault()) + value.substring(1);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
50
lib/src/main/java/rife2/render/Uppercase.java
Normal file
50
lib/src/main/java/rife2/render/Uppercase.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 java.util.Locale;
|
||||
|
||||
/**
|
||||
* <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 (differentiator != null && !differentiator.isBlank() && template.hasValueId(differentiator)) {
|
||||
return template.getValue(differentiator).toUpperCase(Locale.getDefault());
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue