001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.wsrp.util;
022:
023: import com.liferay.portal.util.PortalUtil;
024: import com.liferay.portal.util.WebKeys;
025: import com.liferay.portal.wsrp.util.comparator.PortletDescriptionComparator;
026:
027: import java.util.Comparator;
028:
029: import javax.portlet.PortletMode;
030: import javax.portlet.WindowState;
031:
032: import javax.servlet.ServletContext;
033: import javax.servlet.http.HttpServletRequest;
034:
035: import org.apache.wsrp4j.producer.util.ServletAccess;
036: import org.apache.wsrp4j.util.Modes;
037: import org.apache.wsrp4j.util.WindowStates;
038:
039: /**
040: * <a href="WSRPUtil.java.html"><b><i>View Source</i></b></a>
041: *
042: * @author Michael Young
043: *
044: */
045: public class WSRPUtil {
046:
047: public static long getCompanyId() {
048: HttpServletRequest req = WSRPUtil.getHttpServletRequest();
049:
050: long companyId = PortalUtil.getCompanyId(req);
051:
052: return companyId;
053: }
054:
055: public static HttpServletRequest getHttpServletRequest() {
056: return ServletAccess.getServletRequest();
057: }
058:
059: public static ServletContext getServletContext() {
060: return (ServletContext) getHttpServletRequest().getAttribute(
061: WebKeys.CTX);
062: }
063:
064: public static PortletMode fromWsrpMode(String wsrpMode) {
065: PortletMode mode = PortletMode.VIEW;
066:
067: if (wsrpMode.equals(Modes._edit)) {
068: mode = PortletMode.EDIT;
069: } else if (wsrpMode.equals(Modes._view)) {
070: mode = PortletMode.VIEW;
071: } else if (wsrpMode.equals(Modes._help)) {
072: mode = PortletMode.HELP;
073: }
074:
075: return mode;
076: }
077:
078: public static WindowState fromWsrpWindowState(String wsrpWindowState) {
079: WindowState windowState = WindowState.NORMAL;
080:
081: if (wsrpWindowState.equals(WindowStates._maximized)) {
082: windowState = WindowState.MAXIMIZED;
083: } else if (wsrpWindowState.equals(WindowStates._minimized)) {
084: windowState = WindowState.MINIMIZED;
085: } else if (wsrpWindowState.equals(WindowStates._normal)) {
086: windowState = WindowState.NORMAL;
087: }
088:
089: return windowState;
090: }
091:
092: public static String toWsrpMode(String mode) {
093: String wsrpMode = Modes._view;
094:
095: if (mode.equals(PortletMode.EDIT.toString())) {
096: wsrpMode = Modes._edit;
097: } else if (mode.equals(PortletMode.VIEW.toString())) {
098: wsrpMode = Modes._view;
099: } else if (mode.equals(PortletMode.HELP.toString())) {
100: wsrpMode = Modes._help;
101: }
102:
103: return wsrpMode;
104: }
105:
106: public static String toWsrpWindowState(String windowState) {
107: String wsrpWindowState = WindowState.NORMAL.toString();
108:
109: if (windowState.equals(WindowState.MAXIMIZED.toString())) {
110: wsrpWindowState = WindowStates._maximized;
111: } else if (windowState.equals(WindowState.MINIMIZED.toString())) {
112: wsrpWindowState = WindowStates._minimized;
113: } else if (windowState.equals(WindowState.NORMAL.toString())) {
114: windowState = WindowStates._normal;
115: }
116:
117: return wsrpWindowState;
118: }
119:
120: public static Comparator getPortletDescriptionComparator() {
121: return _portletDescriptionComparator;
122: }
123:
124: private static final Comparator _portletDescriptionComparator = new PortletDescriptionComparator();
125:
126: }
|