001: /**
002: * Copyright 2003 IBM Corporation and Sun Microsystems, Inc.
003: * All rights reserved.
004: * Use is subject to license terms.
005: */package javax.portlet;
006:
007: /**
008: * The <CODE>PortletMode</CODE> class represents
009: * the possible modes that a portlet can assume.
010: * <P>
011: * A portlet mode indicates the function a portlet is performing.
012: * Normally, portlets perform different tasks and create different
013: * content depending on the function they are currently performing.
014: * When invoking a portlet, the portlet container provides the
015: * current portlet mode to the portlet.
016: * <p>
017: * Portlets can programmatically change their portlet
018: * mode when processing an action request.
019: * <P>
020: * This class defines the default portlet modes <code>EDIT, HELP, VIEW</code>.
021: * Additional portlet modes may be defined by calling the constructor
022: * of this class. If a portal/portlet-container does not support a
023: * custom portlet mode defined in the portlet application deployment descriptor,
024: * the custom portlet mode will be ignored by the portal/portlet container.
025: */
026: public class PortletMode {
027:
028: /**
029: * The expected functionality for a portlet in <code>VIEW</code> portlet mode
030: * is to generate markup reflecting the current state of the portlet.
031: * For example, the <code>VIEW</code> portlet mode of a portlet may
032: * include one or more screens that the user can navigate and interact
033: * with, or it may consist of static content that does not require any
034: * user interaction.
035: * <P>
036: * This mode must be supported by the portlet.
037: * <p>
038: * The string value for this mode is <code>"view"</code>.
039: */
040: public final static PortletMode VIEW = new PortletMode("view");
041:
042: /**
043: * Within the <code>EDIT</code> portlet mode, a portlet should provide
044: * content and logic that lets a user customize the behavior of the portlet.
045: * The EDIT portlet mode may include one or more screens among which
046: * users can navigate to enter their customization data.
047: * <p>
048: * Typically, portlets in <code>EDIT</code> portlet mode will
049: * set or update portlet preferences.
050: * <P>
051: * This mode is optional.
052: * <p>
053: * The string value for this mode is <code>"edit"</code>.
054: */
055: public final static PortletMode EDIT = new PortletMode("edit");
056:
057: /**
058: * When in <code>HELP</code> portlet mode, a portlet should provide help
059: * information about the portlet. This help information could be
060: * a simple help screen explaining the entire portlet in
061: * coherent text or it could be context-sensitive help.
062: * <P>
063: * This mode is optional.
064: * <p>
065: * The string value for this mode is <code>"help"</code>.
066: */
067: public final static PortletMode HELP = new PortletMode("help");
068:
069: private String _name;
070:
071: /**
072: * Creates a new portlet mode with the given name.
073: * <p>
074: * Upper case letters in the name are converted to
075: * lower case letters.
076: *
077: * @param name The name of the portlet mode
078: */
079: public PortletMode(String name) {
080: if (name == null) {
081: throw new IllegalArgumentException(
082: "PortletMode name can not be NULL");
083: }
084: _name = name.toLowerCase();
085: }
086:
087: /**
088: * Returns a String representation of this portlet mode.
089: * Portlet mode names are always lower case names.
090: *
091: * @return String representation of this portlet mode
092: */
093:
094: public String toString() {
095: return _name;
096: }
097:
098: /**
099: * Returns the hash code value for this portlet mode.
100: * The hash code is constructed by producing the
101: * hash value of the String value of this mode.
102: *
103: * @return hash code value for this portlet mode
104: */
105:
106: public int hashCode() {
107: return _name.hashCode();
108: }
109:
110: /**
111: * Compares the specified object with this portlet mode
112: * for equality. Returns <code>true</code> if the
113: * Strings <code>equals</code> method for the String
114: * representing the two portlet modes returns <code>true</code>.
115: *
116: * @param the portlet mode to compare this portlet mode with
117: *
118: * @return true, if the specified object is equal with this portlet mode
119: */
120:
121: public boolean equals(Object object) {
122: if (object instanceof PortletMode)
123: return _name.equals(((PortletMode) object)._name);
124: else
125: return false;
126: }
127: }
|