Rev 7 | Rev 10 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7 | Rev 8 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | package org.hellomenta.action; |
1 | package org.hellomenta.action; |
2 | - | ||
3 | import java.util.regex.Matcher; |
- | |
4 | import java.util.regex.Pattern; |
- | |
5 | 2 | ||
6 | import org.mentawai.core.BaseAction; |
3 | import org.mentawai.core.BaseAction; |
7 | 4 | ||
8 | public class HelloAction extends BaseAction { |
5 | public class HelloAction extends BaseAction { |
9 | 6 | ||
10 | public String hi() { |
7 | public String hi() { |
11 | String msg = input.getString("msg"); |
8 | String msg = input.getString("msg"); |
12 | if (isEmpty(msg)) { |
9 | if (isEmpty(msg)) { |
13 | msg = "Why you did not type anything?"; |
10 | msg = "Why you did not type anything?"; |
14 | }
|
11 | }
|
15 | output.setValue("msg", |
12 | output.setValue("msg", msg); |
16 | return SUCCESS; |
13 | return SUCCESS; |
17 | }
|
- | |
18 | - | ||
19 | public static String[] REPLACES = { "a", "e", "i", "o", "u", "c", "A", "E", "I", "O", "U", "C" }; |
- | |
20 | - | ||
21 | public static Pattern[] PATTERNS = null; |
- | |
22 | - | ||
23 | static { |
- | |
24 | PATTERNS = new Pattern[REPLACES.length]; |
- | |
25 | PATTERNS[0] = Pattern.compile("[âãáàä]"); |
- | |
26 | PATTERNS[1] = Pattern.compile("[éèêë]"); |
- | |
27 | PATTERNS[2] = Pattern.compile("[íìîï]"); |
- | |
28 | PATTERNS[3] = Pattern.compile("[óòôõö]"); |
- | |
29 | PATTERNS[4] = Pattern.compile("[úùûü]"); |
- | |
30 | PATTERNS[5] = Pattern.compile("[ç]"); |
- | |
31 | PATTERNS[6] = Pattern.compile("[ÂÃÁÀÄ]"); |
- | |
32 | PATTERNS[7] = Pattern.compile("[ÉÈÊË]"); |
- | |
33 | PATTERNS[8] = Pattern.compile("[ÍÌÎÏ]"); |
- | |
34 | PATTERNS[9] = Pattern.compile("[ÓÒÔÕÖ]"); |
- | |
35 | PATTERNS[10] = Pattern.compile("[ÚÙÛÜ]"); |
- | |
36 | PATTERNS[11] = Pattern.compile("[Ç]"); |
- | |
37 | }
|
- | |
38 | - | ||
39 | public static String removeAccents(String text) { |
- | |
40 | String result = text; |
- | |
41 | for (int i = 0; i < PATTERNS.length; i++) { |
- | |
42 | Matcher matcher = PATTERNS[i].matcher(result); |
- | |
43 | result = matcher.replaceAll(REPLACES[i]); |
- | |
44 | }
|
- | |
45 | return result; |
- | |
46 | }
|
14 | }
|
47 | }
|
15 | }
|