1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.talika.tarsis.util;
24
25 import javax.servlet.http.HttpServletRequest;
26
27 import org.talika.tarsis.Globals;
28
29 /**
30 * Utility class for command common task in servlets and filters.
31 *
32 * @author Jose M. Palomar
33 * @version $Revision: 122 $
34 */
35 public final class CommandHelper {
36
37
38
39
40 /**
41 * Singleton instance.
42 */
43 private static final CommandHelper INSTANCE = new CommandHelper();
44
45
46 /**
47 * Creates a new <code>CommandHelper</code> instance.
48 */
49 private CommandHelper() {
50 }
51
52
53 /**
54 * Obtains a <code>CommandHelper</code> instance.
55 *
56 * @return CommandHelper instance.
57 */
58 public static CommandHelper getInstance() {
59 return INSTANCE;
60 }
61
62 /**
63 * Obtains command name from request.
64 *
65 * @param request HttpServletRequest client request.
66 * @return String command name or <code>null</code> if none is found.
67 */
68 public String getCommand(HttpServletRequest request) {
69
70 String commandName = null;
71
72 String pathInfo = request.getPathInfo();
73 if (pathInfo != null && pathInfo.length() > 0) {
74
75 commandName = pathInfo.substring(1);
76
77 }
78 else {
79
80 String commandParameter = request.getParameter(Globals.COMMAND_NAME_PARAMETER);
81 if (commandParameter != null && commandParameter.length() > 0) {
82 commandName = commandParameter;
83 }
84
85 }
86
87 return commandName;
88
89 }
90
91 }