KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > wsrp > utils > WindowStates


1 /* ====================================================================
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  *
19  * 3. The end-user documentation included with the redistribution,
20  * if any, must include the following acknowledgment:
21  * "This product includes software developed by the
22  * Apache Software Foundation (http://www.apache.org/)."
23  * Alternately, this acknowledgment may appear in the software itself,
24  * if and wherever such third-party acknowledgments normally appear.
25  *
26  * 4. The names "WSRP4J", and "Apache Software
27  * Foundation" must not be used to endorse or promote products
28  * derived from this software without prior written permission. For
29  * written permission, please contact apache@apache.org.
30  *
31  * 5. Products derived from this software may not be called "Apache"
32  * or "WSRP4J", nor may "Apache" or "WSRP4J" appear in their name,
33  * without prior written permission of the Apache Software Foundation.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Apache Software Foundation. For more
51  * information on the Apache Software Foundation, please see
52  * <http://www.apache.org/>.
53  */

54
55 package org.exoplatform.services.wsrp.utils;
56
57 import javax.portlet.WindowState;
58
59 public class WindowStates implements java.io.Serializable JavaDoc {
60   private java.lang.String JavaDoc _value_;
61   private static java.util.HashMap JavaDoc _table_ = new java.util.HashMap JavaDoc();
62
63   // Constructor
64
protected WindowStates(java.lang.String JavaDoc value) {
65     _value_ = value;
66     _table_.put(_value_, this);
67   }
68
69   // define the window states we can currently handle
70
public static final java.lang.String JavaDoc _normal = "wsrp:normal";
71   public static final java.lang.String JavaDoc _minimized = "wsrp:minimized";
72   public static final java.lang.String JavaDoc _maximized = "wsrp:maximized";
73   public static final java.lang.String JavaDoc _solo = "wsrp:solo";
74   public static final WindowStates normal = new WindowStates(_normal);
75   public static final WindowStates minimized = new WindowStates(_minimized);
76   public static final WindowStates maximized = new WindowStates(_maximized);
77   public static final WindowStates solo = new WindowStates(_solo);
78
79   public java.lang.String JavaDoc getValue() {
80     return _value_;
81   }
82
83   /**
84    * Returns the WSRP window state build from a string representation
85    * If a not supported window state is requested, null is returned
86    *
87    * @param <code>String</string> representation of the WSRP window state
88    * @return The WSRP <code>WindowStates</code> represented by the passed string
89    */

90   public static WindowStates fromValue(java.lang.String JavaDoc value) {
91     return (WindowStates) _table_.get(value);
92   }
93
94   /**
95    * Returns the WSRP window state build from a string representation
96    * If a not supported window state is requested, null is returned
97    *
98    * @param <code>String</string> representation of the WSRP window state
99    * @return The WSRP <code>WindowStates</code> represented by the passed string
100    */

101   public static WindowStates fromString(java.lang.String JavaDoc value) {
102     return fromValue(value);
103   }
104
105   public boolean equals(java.lang.Object JavaDoc obj) {
106     return (obj == this);
107   }
108
109   public int hashCode() {
110     return toString().hashCode();
111   }
112
113   public java.lang.String JavaDoc toString() {
114     return _value_;
115   }
116
117   public java.lang.Object JavaDoc readResolve() throws java.io.ObjectStreamException JavaDoc {
118     return fromValue(_value_);
119   }
120
121   /**
122    * This helper method maps portlet window states defined in wsrp to portlet
123    * window states defined in the java portlet standard (JSR-168).
124    * If the passed wsrp window state is null or can not be mapped
125    * directly the normal state is returned.
126    *
127    * @return The <code>javax.portlet.WindowState</code> which corresponds to the given wsrp state.
128    */

129   public static WindowState getJsrPortletStateFromWsrpState(WindowStates wsrpState) {
130     if (wsrpState == null) {
131       return WindowState.NORMAL;
132     } else if (wsrpState.equals(WindowStates.maximized)) {
133       return WindowState.MAXIMIZED;
134     } else if (wsrpState.equals(WindowStates.minimized)) {
135       return WindowState.MINIMIZED;
136     } else if (wsrpState.equals(WindowStates.normal)) {
137       return WindowState.NORMAL;
138     }
139
140     return WindowState.NORMAL;
141   }
142
143   /**
144    * This helper method maps portlet window states defined in tha java portlet standard (JSR-168)
145    * to window states defined in wsrp. If the passed state can not be resolved wsrp:normal state
146    * is returned.
147    *
148    * @param portletMode The <code>javax.portlet.WindowState</code> which should be resolved as
149    * as portlet window state defined in wsrp.
150    * @return
151    */

152   public static WindowStates getWsrpStateFromJsrPortletState(WindowState portletState) {
153     if (portletState.equals(WindowState.MAXIMIZED)) {
154       return WindowStates.maximized;
155     } else if (portletState.equals(WindowState.MINIMIZED)) {
156       return WindowStates.minimized;
157     } else if (portletState.equals(WindowState.NORMAL)) {
158       return WindowStates.normal;
159     }
160
161     return WindowStates.normal;
162   }
163
164   public static String JavaDoc[] getWindowStatesAsStringArray() {
165     return (String JavaDoc[]) _table_.keySet().toArray();
166   }
167 }
168
Popular Tags