001: /*
002: * Copyright 2002 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */
013:
014: package com.sun.portal.portletappengine;
015:
016: import javax.portlet.PortletMode;
017: import javax.portlet.WindowState;
018:
019: /*
020: * This class include utility methods for the Portlet Application Engine.
021: */
022: public class PortletAppEngineUtils {
023:
024: /**
025: * Converts the given <code>ChannelMode</code> to <code>PortletMode</code>.
026: * <P>
027: * @param <code>ChannelMode</code>
028: * @return <code>PortletMode</code>
029: */
030: static public PortletMode getPortletMode(
031: com.sun.portal.container.ChannelMode channelMode) {
032: PortletMode portletMode = null;
033:
034: if (channelMode != null) {
035:
036: String name = channelMode.toString().toLowerCase();
037: if (name.equals(PortletMode.VIEW.toString())) {
038: portletMode = PortletMode.VIEW;
039: } else if (name.equals(PortletMode.EDIT.toString())) {
040: portletMode = PortletMode.EDIT;
041: } else if (name.equals(PortletMode.HELP.toString())) {
042: portletMode = PortletMode.HELP;
043: } else {
044: portletMode = new PortletMode(name);
045: }
046: }
047:
048: return portletMode;
049: }
050:
051: /**
052: * Converts the given <code>PortletMode</code> to <code>ChannelMode</code>.
053: * <P>
054: * @param <code>PortletMode</code>
055: * @return <code>ChannelMode</code>
056: */
057: static public com.sun.portal.container.ChannelMode getChannelMode(
058: PortletMode portletMode) {
059: com.sun.portal.container.ChannelMode channelMode = null;
060:
061: if (portletMode != null) {
062: String name = portletMode.toString().toLowerCase();
063:
064: if (name.equals(com.sun.portal.container.ChannelMode.VIEW
065: .toString())) {
066: channelMode = com.sun.portal.container.ChannelMode.VIEW;
067: } else if (name
068: .equals(com.sun.portal.container.ChannelMode.HELP
069: .toString())) {
070: channelMode = com.sun.portal.container.ChannelMode.HELP;
071: } else if (name
072: .equals(com.sun.portal.container.ChannelMode.EDIT
073: .toString())) {
074: channelMode = com.sun.portal.container.ChannelMode.EDIT;
075: } else {
076: channelMode = new com.sun.portal.container.ChannelMode(
077: name);
078: }
079: }
080:
081: return channelMode;
082: }
083:
084: /**
085: * Converts the given <code>com.sun.portal.container.WindowState</code>
086: * to <code>WindowState</code>.
087: * <P>
088: * @param <code>com.sun.portal.container.WindowState</code>
089: * @return <code>WindowState</code>
090: */
091: static public WindowState getWindowState(
092: com.sun.portal.container.WindowState windowState) {
093: WindowState retState = null;
094:
095: if (windowState != null) {
096: String name = windowState.toString().toLowerCase();
097: if (name.equals(WindowState.NORMAL.toString())) {
098: retState = WindowState.NORMAL;
099: } else if (name.equals(WindowState.MAXIMIZED.toString())) {
100: retState = WindowState.MAXIMIZED;
101: } else if (name.equals(WindowState.MINIMIZED.toString())) {
102: retState = WindowState.MINIMIZED;
103: } else {
104: retState = new WindowState(name);
105: }
106: }
107:
108: return retState;
109: }
110:
111: /**
112: * Converts the given <code>javax.portlet.WindowState</code>
113: * to <code>com.sun.portal.container.WindowState</code>.
114: * <P>
115: * @param <code>com.sun.portal.container.WindowState</code>
116: * @return <code>WindowState</code>
117: */
118: static public com.sun.portal.container.WindowState getWindowState(
119: WindowState windowState) {
120: com.sun.portal.container.WindowState retState = null;
121:
122: if (windowState != null) {
123: String name = windowState.toString().toLowerCase();
124: if (name.equals(com.sun.portal.container.WindowState.NORMAL
125: .toString())) {
126: retState = com.sun.portal.container.WindowState.NORMAL;
127: } else if (name
128: .equals(com.sun.portal.container.WindowState.MAXIMIZED
129: .toString())) {
130: retState = com.sun.portal.container.WindowState.MAXIMIZED;
131: } else if (name
132: .equals(com.sun.portal.container.WindowState.MINIMIZED
133: .toString())) {
134: retState = com.sun.portal.container.WindowState.MINIMIZED;
135: } else {
136: retState = new com.sun.portal.container.WindowState(
137: name);
138: }
139: }
140:
141: return retState;
142: }
143:
144: }
|