Author: gangolli
Date: Sun Sep 15 15:43:36 2013
New Revision: 1523445
URL: http://svn.apache.org/r1523445
Log:
More fixes to UIAction.
Modified:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIAction.java
roller/trunk/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/UIActionTest.java
Modified:
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIAction.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIAction.java?rev=1523445&r1=1523444&r2=1523445&view=diff
==============================================================================
---
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIAction.java
(original)
+++
roller/trunk/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIAction.java
Sun Sep 15 15:43:36 2013
@@ -176,53 +176,53 @@ public abstract class UIAction extends A
@Override
public String getText(String aTextName) {
- return super.getText(cleanText(aTextName));
+ return super.getText(cleanTextKey(aTextName));
}
@Override
public String getText(String aTextName, String defaultValue) {
- return super.getText(cleanText(aTextName), cleanText(defaultValue));
+ return super.getText(cleanTextKey(aTextName),
cleanTextKey(defaultValue));
}
@Override
public String getText(String aTextName, String defaultValue, String obj) {
- return super.getText(cleanText(aTextName), cleanText(defaultValue),
cleanText(obj));
+ return super.getText(cleanTextKey(aTextName),
cleanTextKey(defaultValue), cleanTextArg(obj));
}
@Override
public String getText(String aTextName, List<?> args) {
List<Object> cleanedArgs = new ArrayList<Object>(args.size());
for (Object el : args) {
- cleanedArgs.add(el instanceof String ? cleanText((String) el) :
el);
+ cleanedArgs.add(el instanceof String ? cleanTextArg((String) el) :
el);
}
- return super.getText(cleanText(aTextName), cleanedArgs);
+ return super.getText(cleanTextKey(aTextName), cleanedArgs);
}
@Override
public String getText(String key, String[] args) {
String[] cleanedArgs = new String[args.length];
for (int i = 0; i < args.length; ++i) {
- cleanedArgs[i] = cleanText(args[i]);
+ cleanedArgs[i] = cleanTextArg(args[i]);
}
- return super.getText(cleanText(key), cleanedArgs);
+ return super.getText(cleanTextKey(key), cleanedArgs);
}
@Override
public String getText(String aTextName, String defaultValue, List<?> args)
{
List<Object> cleanedArgs = new ArrayList<Object>(args.size());
for (Object el : args) {
- cleanedArgs.add(el instanceof String ? cleanText((String) el) :
el);
+ cleanedArgs.add(el instanceof String ? cleanTextArg((String) el) :
el);
}
- return super.getText(cleanText(aTextName), cleanText(defaultValue),
cleanedArgs);
+ return super.getText(cleanTextKey(aTextName),
cleanTextKey(defaultValue), cleanedArgs);
}
@Override
public String getText(String key, String defaultValue, String[] args) {
String[] cleanedArgs = new String[args.length];
for (int i = 0; i < args.length; ++i) {
- cleanedArgs[i] = cleanText(args[i]);
+ cleanedArgs[i] = cleanTextArg(args[i]);
}
- return super.getText(cleanText(key), cleanText(defaultValue),
cleanedArgs);
+ return super.getText(cleanTextKey(key), cleanTextKey(defaultValue),
cleanedArgs);
}
public void addError(String errorKey) {
@@ -374,69 +374,36 @@ public abstract class UIAction extends A
List opts = new ArrayList();
- opts.add(new KeyValueObject(0,
getText("weblogEdit.unlimitedCommentDays")));
- opts.add(new KeyValueObject(1, getText("weblogEdit.days1")));
- opts.add(new KeyValueObject(2, getText("weblogEdit.days2")));
- opts.add(new KeyValueObject(3, getText("weblogEdit.days3")));
- opts.add(new KeyValueObject(4, getText("weblogEdit.days4")));
- opts.add(new KeyValueObject(5, getText("weblogEdit.days5")));
- opts.add(new KeyValueObject(7, getText("weblogEdit.days7")));
- opts.add(new KeyValueObject(10, getText("weblogEdit.days10")));
- opts.add(new KeyValueObject(20, getText("weblogEdit.days20")));
- opts.add(new KeyValueObject(30, getText("weblogEdit.days30")));
- opts.add(new KeyValueObject(60, getText("weblogEdit.days60")));
- opts.add(new KeyValueObject(90, getText("weblogEdit.days90")));
+ opts.add(new KeyValueObject(new Integer(0),
getText("weblogEdit.unlimitedCommentDays")));
+ opts.add(new KeyValueObject(new Integer(1),
getText("weblogEdit.days1")));
+ opts.add(new KeyValueObject(new Integer(2),
getText("weblogEdit.days2")));
+ opts.add(new KeyValueObject(new Integer(3),
getText("weblogEdit.days3")));
+ opts.add(new KeyValueObject(new Integer(4),
getText("weblogEdit.days4")));
+ opts.add(new KeyValueObject(new Integer(5),
getText("weblogEdit.days5")));
+ opts.add(new KeyValueObject(new Integer(7),
getText("weblogEdit.days7")));
+ opts.add(new KeyValueObject(new Integer(10),
getText("weblogEdit.days10")));
+ opts.add(new KeyValueObject(new Integer(20),
getText("weblogEdit.days20")));
+ opts.add(new KeyValueObject(new Integer(30),
getText("weblogEdit.days30")));
+ opts.add(new KeyValueObject(new Integer(60),
getText("weblogEdit.days60")));
+ opts.add(new KeyValueObject(new Integer(90),
getText("weblogEdit.days90")));
return opts;
}
- private static final Set OPEN_CHARS = new HashSet(Arrays.asList('$', '%'));
+ private static Set OPEN_CHARS = new HashSet(Arrays.asList('$', '%'));
private static String cleanExpressions(String s) {
- StringBuilder cleaned = new StringBuilder(s.length());
- boolean skipping = false;
- int braceDepth = 0;
- int p = 0;
- Character prior = ' ';
- while (p < s.length()) {
- boolean priorIsOpenChar = OPEN_CHARS.contains(prior);
- char c = s.charAt(p);
- switch (c) {
- case '{':
- ++braceDepth;
- skipping = skipping || priorIsOpenChar;
- break;
- case '}':
- if (braceDepth > 0) {
- --braceDepth;
- }
- break;
- default:
- }
- if (!skipping) {
- if (priorIsOpenChar) {
- cleaned.append(prior);
- }
- if (!OPEN_CHARS.contains(c)) {
- cleaned.append(c);
- }
- }
- skipping = skipping && (braceDepth > 0);
- prior = c;
- ++p;
- }
- if (OPEN_CHARS.contains(prior)) {
- // string had final open character held in prior
- cleaned.append(prior);
- }
- return cleaned.toString();
+ return (s == null || s.contains("${") || s.contains("%{")) ? "" : s;
}
- public static String cleanText(String s) {
- if (s == null || s.isEmpty()) {
- return s;
- }
+ public static String cleanTextKey(String s) {
+ if (s == null || s.isEmpty()) return s;
// escape HTML
return StringEscapeUtils.escapeHtml(cleanExpressions(s));
}
+
+ public static String cleanTextArg(String s) {
+ if (s == null || s.isEmpty()) return s;
+ return StringEscapeUtils.escapeHtml(s);
+ }
}
Modified:
roller/trunk/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/UIActionTest.java
URL:
http://svn.apache.org/viewvc/roller/trunk/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/UIActionTest.java?rev=1523445&r1=1523444&r2=1523445&view=diff
==============================================================================
---
roller/trunk/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/UIActionTest.java
(original)
+++
roller/trunk/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/UIActionTest.java
Sun Sep 15 15:43:36 2013
@@ -34,38 +34,33 @@ public class UIActionTest extends TestCa
}
public void testCleanTextEmpty() {
- assertEquals(null,UIAction.cleanText(null));
- assertEquals("",UIAction.cleanText(""));
+ assertEquals(null,UIAction.cleanTextKey(null));
+ assertEquals("",UIAction.cleanTextKey(""));
+ assertEquals(null,UIAction.cleanTextArg(null));
+ assertEquals("",UIAction.cleanTextArg(""));
}
- public void testCleanExpressions() {
- assertEquals(null,UIAction.cleanText(null));
- assertEquals("",UIAction.cleanText(""));
- assertEquals("a",UIAction.cleanText("a"));
- assertEquals("$",UIAction.cleanText("$"));
- assertEquals("%",UIAction.cleanText("%"));
- assertEquals("%$",UIAction.cleanText("%$"));
- assertEquals("{",UIAction.cleanText("{"));
- assertEquals("}",UIAction.cleanText("}"));
- assertEquals("",UIAction.cleanText("${"));
- assertEquals("",UIAction.cleanText("%{"));
- assertEquals("text$",UIAction.cleanText("text$"));
- assertEquals("text%",UIAction.cleanText("text%"));
- assertEquals("text something more", UIAction.cleanText("text
something ${ more } ${ and more } more"));
- assertEquals("text something more", UIAction.cleanText("text
something %{ more } %{ and more } more"));
- assertEquals("text more", UIAction.cleanText("text %{ something ${
more } ${ and more } } more"));
- assertEquals("text {1} text {2} more", UIAction.cleanText("text {1}
text${2} {2} more"));
- assertEquals("text text {2} more", UIAction.cleanText("text %{1}
text${2} {2} more"));
- assertEquals("already { clean }", UIAction.cleanText("already { clean
}"));
- assertEquals("$signs but not immediately followed by { braces }",
UIAction.cleanText("$signs but not immediately followed by { braces }"));
- assertEquals("%signs but not immediately followed by { braces }",
UIAction.cleanText("%signs but not immediately followed by { braces }"));
- assertEquals("clean", UIAction.cleanText("${part %{ }
}clean${%anything}"));
- assertEquals("clean", UIAction.cleanText("%{part ${}
}clean${%anything}"));
+ public void testCleanTextKey() {
+ assertEquals(null,UIAction.cleanTextKey(null));
+ assertEquals("",UIAction.cleanTextKey(""));
+ assertEquals("a",UIAction.cleanTextKey("a"));
+ assertEquals("$",UIAction.cleanTextKey("$"));
+ assertEquals("%",UIAction.cleanTextKey("%"));
+ assertEquals("%$",UIAction.cleanTextKey("%$"));
+ assertEquals("{",UIAction.cleanTextKey("{"));
+ assertEquals("}",UIAction.cleanTextKey("}"));
+ assertEquals("",UIAction.cleanTextKey("${"));
+ assertEquals("",UIAction.cleanTextKey("%{"));
+ assertEquals("text$",UIAction.cleanTextKey("text$"));
+ assertEquals("text%",UIAction.cleanTextKey("text%"));
+ assertEquals("", UIAction.cleanTextKey("something ${foo} more"));
+ assertEquals("", UIAction.cleanTextKey("something %{foo} more"));
+ assertEquals("", UIAction.cleanTextKey("something %{foo} more"));
}
- public void testCleanTextHtml() {
- assertEquals("<i>some
text</i>",UIAction.cleanText("<i>some text</i>"));
- assertEquals("<i>some </i>",UIAction.cleanText("<i>some
${text}</i>")); // combined
+ public void testCleanTextArg() {
+ assertEquals("<i>some
text</i>",UIAction.cleanTextArg("<i>some text</i>"));
+ assertEquals("<i>some
${text}</i>",UIAction.cleanTextArg("<i>some ${text}</i>"));
}
}