Skip to content

Commit

Permalink
Removed dependency of commons-io
Browse files Browse the repository at this point in the history
  • Loading branch information
mbosecke committed Jan 19, 2014
1 parent b497649 commit 64e847b
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 15 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@
<version>1.3.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.mitchellbosecke.pebble.PebbleEngine;
import com.mitchellbosecke.pebble.node.expression.binary.NodeExpressionBinaryAdd;
import com.mitchellbosecke.pebble.node.expression.binary.NodeExpressionBinaryAnd;
Expand Down Expand Up @@ -61,6 +59,7 @@
import com.mitchellbosecke.pebble.tokenParser.SetTokenParser;
import com.mitchellbosecke.pebble.tokenParser.TokenParser;
import com.mitchellbosecke.pebble.utils.OperatorUtils;
import com.mitchellbosecke.pebble.utils.StringUtils;

public class CoreExtension extends AbstractExtension {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringEscapeUtils;

import com.mitchellbosecke.pebble.PebbleEngine;

public class EscaperExtension extends AbstractExtension {
Expand All @@ -28,7 +26,7 @@ public List<Filter> getFilters() {
filters.add(escapeFilter);
return filters;
}

private Filter escapeFilter = new Filter() {
public String getName() {
return "escape";
Expand Down Expand Up @@ -57,7 +55,38 @@ public Object apply(Object inputObject, List<Object> args) {
};

private String htmlEscape(String input) {
return StringEscapeUtils.escapeHtml4(input);
if (input == null) {
return input;
}
StringBuilder result = new StringBuilder();
char[] chars = input.toCharArray();
for (int i = 0; i < chars.length; i++) {
char charac = chars[i];

switch (charac) {
case '&':
result.append("&amp;");
break;
case '<':
result.append("&lt;");
break;
case '>':
result.append("&gt;");
break;
case '"':
result.append("&quot;");
break;
case '\'':
result.append("&#x27;");
break;
case '/':
result.append("&#x2F;");
default:
result.append(charac);
break;
}
}
return result.toString();
}

}
6 changes: 3 additions & 3 deletions src/main/java/com/mitchellbosecke/pebble/lexer/LexerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

import com.mitchellbosecke.pebble.PebbleEngine;
import com.mitchellbosecke.pebble.error.SyntaxException;
import com.mitchellbosecke.pebble.lexer.Token.Type;
import com.mitchellbosecke.pebble.operator.BinaryOperator;
import com.mitchellbosecke.pebble.operator.UnaryOperator;
import com.mitchellbosecke.pebble.utils.Pair;
import com.mitchellbosecke.pebble.utils.StringLengthComparator;
import com.mitchellbosecke.pebble.utils.StringUtils;

public class LexerImpl implements Lexer {

Expand Down Expand Up @@ -416,8 +415,9 @@ private void pushToken(Token.Type type) {
*/
private void pushToken(Token.Type type, String value) {
// ignore empty text tokens
if (type.equals(Token.Type.TEXT) && StringUtils.isEmpty(value))
if (type.equals(Token.Type.TEXT) && StringUtils.isEmpty(value)){
return;
}
this.tokens.add(new Token(type, value, this.lineNumber));
}

Expand Down
56 changes: 56 additions & 0 deletions src/main/java/com/mitchellbosecke/pebble/utils/StringUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.mitchellbosecke.pebble.utils;

public class StringUtils {

public static boolean isEmpty(String value) {
boolean blank = false;

if (value == null) {
blank = true;
} else if ("".equals(value)) {
blank = true;
}
return blank;
}

public static boolean isBlank(String value) {
boolean blank = false;

if (value == null) {
blank = true;
} else if ("".equals(value.trim())) {
blank = true;
}
return blank;
}

public static String capitalize(String value) {
if (value == null || (value.length() == 0)) {
return value;
}

char firstCharacter = value.charAt(0);
if (Character.isTitleCase(firstCharacter)) {
return value;
}
return new StringBuilder(value.length()).append(Character.toTitleCase(firstCharacter))
.append(value.substring(1)).toString();
}

public static String abbreviate(String value, int maxWidth) {
if(value == null){
return null;
}
String ellipsis = "...";
int length = value.length();

if(length < maxWidth){
return value;
}
if(length <= 3){
return value;
}
return value.substring(0, maxWidth - 3) + ellipsis;
}

}

0 comments on commit 64e847b

Please sign in to comment.