KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > portlet > PortletMode


1 /**
2   * Copyright 2003 IBM Corporation and Sun Microsystems, Inc.
3   * All rights reserved.
4   * Use is subject to license terms.
5   */

6
7 package javax.portlet;
8
9
10 /**
11  * The <CODE>PortletMode</CODE> class represents
12  * the possible modes that a portlet can assume.
13  * <P>
14  * A portlet mode indicates the function a portlet is performing.
15  * Normally, portlets perform different tasks and create different
16  * content depending on the function they are currently performing.
17  * When invoking a portlet, the portlet container provides the
18  * current portlet mode to the portlet.
19  * <p>
20  * Portlets can programmatically change their portlet
21  * mode when processing an action request.
22  * <P>
23  * This class defines the default portlet modes <code>EDIT, HELP, VIEW</code>.
24  * Additional portlet modes may be defined by calling the constructor
25  * of this class. If a portal/portlet-container does not support a
26  * custom portlet mode defined in the portlet application deployment descriptor,
27  * the custom portlet mode will be ignored by the portal/portlet container.
28  */

29 public class PortletMode
30 {
31
32   /**
33    * The expected functionality for a portlet in <code>VIEW</code> portlet mode
34    * is to generate markup reflecting the current state of the portlet.
35    * For example, the <code>VIEW</code> portlet mode of a portlet may
36    * include one or more screens that the user can navigate and interact
37    * with, or it may consist of static content that does not require any
38    * user interaction.
39    * <P>
40    * This mode must be supported by the portlet.
41    * <p>
42    * The string value for this mode is <code>"view"</code>.
43    */

44   public final static PortletMode VIEW = new PortletMode ("view");
45
46   /**
47    * Within the <code>EDIT</code> portlet mode, a portlet should provide
48    * content and logic that lets a user customize the behavior of the portlet.
49    * The EDIT portlet mode may include one or more screens among which
50    * users can navigate to enter their customization data.
51    * <p>
52    * Typically, portlets in <code>EDIT</code> portlet mode will
53    * set or update portlet preferences.
54    * <P>
55    * This mode is optional.
56    * <p>
57    * The string value for this mode is <code>"edit"</code>.
58    */

59   public final static PortletMode EDIT = new PortletMode ("edit");
60
61   /**
62    * When in <code>HELP</code> portlet mode, a portlet should provide help
63    * information about the portlet. This help information could be
64    * a simple help screen explaining the entire portlet in
65    * coherent text or it could be context-sensitive help.
66    * <P>
67    * This mode is optional.
68    * <p>
69    * The string value for this mode is <code>"help"</code>.
70    */

71   public final static PortletMode HELP = new PortletMode ("help");
72
73
74
75
76   private String JavaDoc _name;
77
78
79   /**
80    * Creates a new portlet mode with the given name.
81    * <p>
82    * Upper case letters in the name are converted to
83    * lower case letters.
84    *
85    * @param name The name of the portlet mode
86    */

87   public PortletMode(String JavaDoc name) {
88     if (name==null) {
89       throw new IllegalArgumentException JavaDoc("PortletMode name can not be NULL");
90     }
91     _name = name.toLowerCase();
92   }
93
94
95   /**
96    * Returns a String representation of this portlet mode.
97    * Portlet mode names are always lower case names.
98    *
99    * @return String representation of this portlet mode
100    */

101
102   public String JavaDoc toString() {
103     return _name;
104   }
105
106   /**
107    * Returns the hash code value for this portlet mode.
108    * The hash code is constructed by producing the
109    * hash value of the String value of this mode.
110    *
111    * @return hash code value for this portlet mode
112    */

113
114   public int hashCode() {
115     return _name.hashCode();
116   }
117
118   /**
119    * Compares the specified object with this portlet mode
120    * for equality. Returns <code>true</code> if the
121    * Strings <code>equals</code> method for the String
122    * representing the two portlet modes returns <code>true</code>.
123    *
124    * @param the portlet mode to compare this portlet mode with
125    *
126    * @return true, if the specified object is equal with this portlet mode
127    */

128      
129   public boolean equals(Object JavaDoc object) {
130     if ( object instanceof PortletMode )
131       return _name.equals(((PortletMode) object)._name);
132     else
133       return false;
134   }
135 }
136
137
Popular Tags