1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package javax.portlet;
22
23
24 /***
25 * The <CODE>PortletMode</CODE> class represents
26 * the possible modes that a portlet can assume.
27 * <P>
28 * A portlet mode indicates the function a portlet is performing.
29 * Normally, portlets perform different tasks and create different
30 * content depending on the function they are currently performing.
31 * When invoking a portlet, the portlet container provides the
32 * current portlet mode to the portlet.
33 * <p>
34 * Portlets can programmatically change their portlet
35 * mode when processing an action request.
36 * <P>
37 * This class defines the default portlet modes <code>EDIT, HELP, VIEW</code>.
38 * Additional portlet modes may be defined by calling the constructor
39 * of this class. If a portal/portlet-container does not support a
40 * custom portlet mode defined in the portlet application deployment descriptor,
41 * the custom portlet mode will be ignored by the portal/portlet container.
42 */
43 public class PortletMode
44 {
45
46
47 /***
48 * The expected functionality for a portlet in <code>VIEW</code> portlet mode
49 * is to generate markup reflecting the current state of the portlet.
50 * For example, the <code>VIEW</code> portlet mode of a portlet may
51 * include one or more screens that the user can navigate and interact
52 * with, or it may consist of static content that does not require any
53 * user interaction.
54 * <P>
55 * This mode must be supported by the portlet.
56 * <p>
57 * The string value for this mode is <code>"view"</code>.
58 */
59 public final static PortletMode VIEW = new PortletMode ("view");
60
61 /***
62 * Within the <code>EDIT</code> portlet mode, a portlet should provide
63 * content and logic that lets a user customize the behavior of the portlet.
64 * The EDIT portlet mode may include one or more screens among which
65 * users can navigate to enter their customization data.
66 * <p>
67 * Typically, portlets in <code>EDIT</code> portlet mode will
68 * set or update portlet preferences.
69 * <P>
70 * This mode is optional.
71 * <p>
72 * The string value for this mode is <code>"edit"</code>.
73 */
74 public final static PortletMode EDIT = new PortletMode ("edit");
75
76 /***
77 * When in <code>HELP</code> portlet mode, a portlet should provide help
78 * information about the portlet. This help information could be
79 * a simple help screen explaining the entire portlet in
80 * coherent text or it could be context-sensitive help.
81 * <P>
82 * This mode is optional.
83 * <p>
84 * The string value for this mode is <code>"help"</code>.
85 */
86 public final static PortletMode HELP = new PortletMode ("help");
87
88
89
90
91 private String _name;
92
93
94 /***
95 * Creates a new portlet mode with the given name.
96 * <p>
97 * Upper case letters in the name are converted to
98 * lower case letters.
99 *
100 * @param name The name of the portlet mode
101 */
102 public PortletMode(String name) {
103 if (name==null) {
104 throw new IllegalArgumentException("PortletMode name can not be NULL");
105 }
106 _name = name.toLowerCase();
107 }
108
109
110 /***
111 * Returns a String representation of this portlet mode.
112 * Portlet mode names are always lower case names.
113 *
114 * @return String representation of this portlet mode
115 */
116
117 public String toString() {
118 return _name;
119 }
120
121 /***
122 * Returns the hash code value for this portlet mode.
123 * The hash code is constructed by producing the
124 * hash value of the String value of this mode.
125 *
126 * @return hash code value for this portlet mode
127 */
128
129 public int hashCode() {
130 return _name.hashCode();
131 }
132
133 /***
134 * Compares the specified object with this portlet mode
135 * for equality. Returns <code>true</code> if the
136 * Strings <code>equals</code> method for the String
137 * representing the two portlet modes returns <code>true</code>.
138 *
139 * @param the portlet mode to compare this portlet mode with
140 *
141 * @return true, if the specified object is equal with this portlet mode
142 */
143
144 public boolean equals(Object object) {
145 if ( object instanceof PortletMode )
146 return _name.equals(((PortletMode) object)._name);
147 else
148 return false;
149 }
150 }
151