1
22
23
41
42 package com.liferay.portal.portletcontainer;
43
44 import com.liferay.portlet.PortletURLImpl;
45
46 import com.sun.portal.container.ChannelURLType;
47
48 import javax.portlet.PortletMode;
49 import javax.portlet.PortletModeException;
50 import javax.portlet.PortletRequest;
51 import javax.portlet.WindowState;
52 import javax.portlet.WindowStateException;
53
54 import javax.servlet.http.HttpServletRequest;
55
56 import org.apache.commons.logging.Log;
57 import org.apache.commons.logging.LogFactory;
58
59
65 public class LiferayPortletURLImpl extends PortletURLImpl {
66
67 public LiferayPortletURLImpl(
68 HttpServletRequest request, String portletId, WindowState windowState,
69 PortletMode portletMode, long plid, String lifecycle) {
70
71 super(request, portletId, plid, lifecycle);
72
73 setLifecycle(getLifecyclePhase(lifecycle));
74 setURLType(getChannelURlType(lifecycle));
75
76 try {
77 setWindowState(windowState);
78 }
79 catch (WindowStateException wse1) {
80 if (_log.isWarnEnabled()) {
81 _log.warn(
82 "Exception while setting window state for " + portletId,
83 wse1);
84 }
85 try {
86 setWindowState(WindowState.NORMAL);
87 }
88 catch (WindowStateException wse2) {
89 }
90 }
91
92 try {
93 setPortletMode(portletMode);
94 }
95 catch (PortletModeException pme1) {
96 if (_log.isWarnEnabled()) {
97 _log.warn(
98 "Exception while setting portlet mode for " + portletId,
99 pme1);
100 }
101 try {
102 setPortletMode(PortletMode.VIEW);
103 }
104 catch (PortletModeException pme2) {
105 }
106 }
107 }
108
109 protected ChannelURLType getChannelURlType(String lifecycle) {
110 if (PortletRequest.ACTION_PHASE.equals(lifecycle)) {
111 return ChannelURLType.ACTION;
112 }
113 else if (PortletRequest.RENDER_PHASE.equals(lifecycle)) {
114 return ChannelURLType.RENDER;
115 }
116 else if (PortletRequest.RESOURCE_PHASE.equals(lifecycle)) {
117 return ChannelURLType.RESOURCE;
118 }
119 else {
120 return ChannelURLType.RENDER;
121 }
122 }
123
124 protected String getLifecyclePhase(String lifecycle) {
125 if (PortletRequest.RENDER_PHASE.equals(lifecycle)) {
126
127
129 return PortletRequest.ACTION_PHASE;
130 }
131
132 return lifecycle;
133 }
134
135 private static Log _log = LogFactory.getLog(LiferayPortletURLImpl.class);
136
137 }