Skip to content

Commit

Permalink
Fixes bugs in bean boxing, some performance enhancements.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom McClure committed Dec 3, 2015
1 parent 25af6c3 commit aa87674
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 148 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Release History

v3.1.2 - 2015-12-03 tmcclure

Fixes bugs in bean boxing.
Performance enhancements.

v3.1.1 - 2015-11-24 tmcclure

Revises calc filter to work with direct tag references.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Available from Maven Central:
<dependency>
<groupId>com.x5dev</groupId>
<artifactId>chunk-templates</artifactId>
<version>3.1.1</version>
<version>3.1.2</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>com.x5dev</groupId>
<artifactId>chunk-templates</artifactId>
<packaging>jar</packaging>
<version>3.1.1</version>
<version>3.1.2</version>
<name>Chunk Templates</name>
<description>Chunk Template Engine for Java</description>
<url>http://www.x5software.com/chunk/</url>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/x5/template/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@
* Updates: <A href="http://www.x5software.com/chunk/">Chunk Documentation</A><BR>
*
* @author Tom McClure
* @version 3.1.1
* @version 3.1.2
*/

public class Chunk implements Map<String,Object>
{
public static final int HASH_THRESH = 8;
public static final int DEPTH_LIMIT = 17;

public static final String VERSION = "3.1.1";
public static final String VERSION = "3.1.2";

private static final String TRUE = "TRUE";

Expand Down Expand Up @@ -1081,7 +1081,7 @@ protected Object _resolveTagValue(SnippetTag tag, int depth, boolean ignoreParen
tagValue = coercePrimitivesToStringAndBoxAliens(tagValue);
}

String filters = tag.getFilters();
Filter[] filters = tag.getFilters();

if (tagValue == null) {

Expand Down
52 changes: 40 additions & 12 deletions src/main/java/com/x5/template/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,47 @@ private static Map<String,ChunkFilter> registerStockFilters()
return filters;
}

private FilterArgs filterArgs;

public static Object applyFilter(Chunk context, String filter, Object input)
{
if (filter == null) return input;

// filters might be daisy-chained
int pipePos = findNextFilter(filter);
if (pipePos >= 0) {
String firstFilter = filter.substring(0,pipePos);
String nextFilters = filter.substring(pipePos+1);
Object output = applyFilter(context, firstFilter, input);
return applyFilter(context, nextFilters, output);
return applyFilter(context, parseFilterChain(filter), input);
}

public static Object applyFilter(Chunk context, Filter[] filters, Object input)
{
if (filters == null) return input;

Object filtered = input;
for (int i=0; i<filters.length; i++) {
filtered = filters[i].apply(context, filtered);
}

FilterArgs filterArgs = new FilterArgs(filter);
return filtered;
}

public static Filter[] parseFilterChain(String filter)
{
if (filter == null) return null;

String[] filters = splitFilters(filter);
Filter[] parsedFilters = new Filter[filters.length];
for (int i=0; i<filters.length; i++) {
parsedFilters[i] = new Filter(filters[i]);
}

return parsedFilters;
}

public Filter(String filter)
{
this.filterArgs = new FilterArgs(filter);
}

public Object apply(Chunk context, Object input)
{
String filterName = filterArgs.getFilterName();

// if custom filter is registered with this name, it takes precedence
Expand All @@ -67,7 +94,8 @@ public static Object applyFilter(Chunk context, String filter, Object input)
}
}

if (filter.equals("type")) {
String rawFilter = filterArgs.getUnparsedFilter();
if (rawFilter.equals("type")) {
return typeFilter(context, input);
}

Expand All @@ -80,15 +108,15 @@ public static Object applyFilter(Chunk context, String filter, Object input)

if (text != null) {
// provide a few core filters without making a whole class for each one.
if (filter.equals("trim")) {
if (rawFilter.equals("trim")) {
// trim leading and trailing whitespace
return text.trim(); //text.replaceAll("^\\s+","").replaceAll("\\s+$","");
} else if (filter.startsWith("join(")) {
} else if (rawFilter.startsWith("join(")) {
TableData array = InlineTable.parseTable(text);
if (array != null) {
return joinInlineTable(array, filterArgs);
}
} else if (filter.startsWith("get(")) {
} else if (rawFilter.startsWith("get(")) {
TableData array = InlineTable.parseTable(text);
if (array != null) {
return accessArrayIndex(array, filterArgs);
Expand Down
Loading

0 comments on commit aa87674

Please sign in to comment.