001: /*
002: * Copyright 2000-2001,2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.wsrp4j.util;
018:
019: import java.util.HashMap;
020:
021: import javax.portlet.WindowState;
022:
023: public class WindowStates implements java.io.Serializable {
024: private String _value_;
025:
026: private static HashMap _table_ = new HashMap();
027:
028: // Constructor
029: protected WindowStates(String value) {
030: _value_ = value;
031: _table_.put(_value_, this );
032: }
033:
034: // define the window states we can currently handle
035: public static final String _normal = "wsrp:normal";
036:
037: public static final String _minimized = "wsrp:minimized";
038:
039: public static final String _maximized = "wsrp:maximized";
040:
041: public static final String _solo = "wsrp:solo";
042:
043: public static final WindowStates normal = new WindowStates(_normal);
044:
045: public static final WindowStates minimized = new WindowStates(
046: _minimized);
047:
048: public static final WindowStates maximized = new WindowStates(
049: _maximized);
050:
051: public static final WindowStates solo = new WindowStates(_solo);
052:
053: public String getValue() {
054: return _value_;
055: }
056:
057: /**
058: * Returns the WSRP window state build from a string representation
059: * If a not supported window state is requested, null is returned
060: * @param value <code>String</string> representation of the WSRP window state
061: * @return The WSRP <code>WindowStates</code> represented by the passed string
062: */
063: public static WindowStates fromValue(String value) {
064: return (WindowStates) _table_.get(value);
065: }
066:
067: /**
068: * Returns the WSRP window state build from a string representation
069: * If a not supported window state is requested, null is returned
070: * @param value <code>String</string> representation of the WSRP window state
071: * @return The WSRP <code>WindowStates</code> represented by the passed string
072: */
073: public static WindowStates fromString(String value) {
074: return fromValue(value);
075: }
076:
077: public boolean equals(java.lang.Object obj) {
078: return (obj == this );
079: }
080:
081: public int hashCode() {
082: return toString().hashCode();
083: }
084:
085: public String toString() {
086: return _value_;
087: }
088:
089: public java.lang.Object readResolve()
090: throws java.io.ObjectStreamException {
091: return fromValue(_value_);
092: }
093:
094: /**
095: * This helper method maps portlet window states defined in wsrp to portlet
096: * window states defined in the java portlet standard (JSR-168).
097: * If the passed wsrp window state is null or can not be mapped
098: * directly the normal state is returned.
099: *
100: * @return The <code>javax.portlet.WindowState</code> which corresponds to the given wsrp state.
101: **/
102: public static WindowState getJsrPortletStateFromWsrpState(
103: WindowStates wsrpState) {
104: if (wsrpState == null) {
105: return WindowState.NORMAL;
106: } else if (wsrpState.equals(WindowStates.maximized)) {
107: return WindowState.MAXIMIZED;
108: } else if (wsrpState.equals(WindowStates.minimized)) {
109: return WindowState.MINIMIZED;
110: } else if (wsrpState.equals(WindowStates.normal)) {
111: return WindowState.NORMAL;
112: }
113:
114: return WindowState.NORMAL;
115: }
116:
117: /**
118: * This helper method maps portlet window states defined in tha java portlet standard (JSR-168)
119: * to window states defined in wsrp. If the passed state can not be resolved wsrp:normal state
120: * is returned.
121: *
122: * @param portletState The <code>javax.portlet.WindowState</code> which should be resolved as
123: * as portlet window state defined in wsrp.
124: * @return
125: **/
126: public static WindowStates getWsrpStateFromJsrPortletState(
127: WindowState portletState) {
128: if (portletState.equals(WindowState.MAXIMIZED)) {
129: return WindowStates.maximized;
130: } else if (portletState.equals(WindowState.MINIMIZED)) {
131: return WindowStates.minimized;
132: } else if (portletState.equals(WindowState.NORMAL)) {
133: return WindowStates.normal;
134: }
135:
136: return WindowStates.normal;
137: }
138:
139: public static String[] getWindowStatesAsStringArray() {
140: return (String[]) _table_.keySet().toArray();
141: }
142: }
|