MentaTutorials

Compare Revisions

Ignore whitespace Rev 7 → Rev 8

/HelloMenta/trunk/src/main/java/org/hellomenta/action/HelloAction.java
1,8 → 1,5
package org.hellomenta.action;
 
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
import org.mentawai.core.BaseAction;
 
public class HelloAction extends BaseAction {
12,36 → 9,7
if (isEmpty(msg)) {
msg = "Why you did not type anything?";
}
output.setValue("msg", removeAccents(msg));
output.setValue("msg", msg);
return SUCCESS;
}
public static String[] REPLACES = { "a", "e", "i", "o", "u", "c", "A", "E", "I", "O", "U", "C" };
 
public static Pattern[] PATTERNS = null;
 
static {
PATTERNS = new Pattern[REPLACES.length];
PATTERNS[0] = Pattern.compile("[âãáàä]");
PATTERNS[1] = Pattern.compile("[éèêë]");
PATTERNS[2] = Pattern.compile("[íìîï]");
PATTERNS[3] = Pattern.compile("[óòôõö]");
PATTERNS[4] = Pattern.compile("[úùûü]");
PATTERNS[5] = Pattern.compile("[ç]");
PATTERNS[6] = Pattern.compile("[ÂÃÁÀÄ]");
PATTERNS[7] = Pattern.compile("[ÉÈÊË]");
PATTERNS[8] = Pattern.compile("[ÍÌÎÏ]");
PATTERNS[9] = Pattern.compile("[ÓÒÔÕÖ]");
PATTERNS[10] = Pattern.compile("[ÚÙÛÜ]");
PATTERNS[11] = Pattern.compile("[Ç]");
}
 
public static String removeAccents(String text) {
String result = text;
for (int i = 0; i < PATTERNS.length; i++) {
Matcher matcher = PATTERNS[i].matcher(result);
result = matcher.replaceAll(REPLACES[i]);
}
return result;
}
}