1 48 49 50 package com.caucho.portal.generic; 51 52 import com.caucho.portal.generic.context.ConnectionContext; 53 54 import javax.portlet.PortletMode; 55 import javax.portlet.PortletModeException; 56 import javax.portlet.PortletSecurityException; 57 import javax.portlet.PortletURL; 58 import javax.portlet.WindowState; 59 import javax.portlet.WindowStateException; 60 import java.util.Map ; 61 62 public class PortalURL 63 implements PortletURL 64 { 65 private ConnectionContext _context; 66 private InvocationURL _invocationURL; 67 68 private String _url; 69 70 public PortalURL( ConnectionContext context, 71 InvocationURL invocationURL) 72 { 73 _context = context; 74 _invocationURL = invocationURL; 75 } 76 77 protected void checkWindowState(String namespace, WindowState windowState) 78 throws WindowStateException 79 { 80 if (!_context.isWindowStateAllowed(namespace, windowState)) 81 throw new WindowStateException( 82 "WindowState `" + windowState 83 + "' not allowed for namespace `" + namespace + "'", 84 windowState); 85 } 86 87 public void setWindowState(WindowState windowState) 88 throws WindowStateException 89 { 90 _url = null; 91 checkWindowState(_invocationURL.getNamespace(), windowState); 92 _invocationURL.setWindowState(windowState); 93 } 94 95 public void setWindowState(String namespace, WindowState windowState) 96 throws WindowStateException 97 { 98 _url = null; 99 checkWindowState(namespace, windowState); 100 _invocationURL.setWindowState(namespace, windowState); 101 } 102 103 protected void checkPortletMode(String namespace, PortletMode portletMode) 104 throws PortletModeException 105 { 106 if (!_context.isPortletModeAllowed(namespace, portletMode)) 107 throw new PortletModeException( 108 "PortletMode `" + portletMode 109 + "' not allowed for namespace `" + namespace + "'", 110 portletMode); 111 } 112 113 public void setPortletMode(PortletMode portletMode) 114 throws PortletModeException 115 { 116 _url = null; 117 checkPortletMode(_invocationURL.getNamespace(), portletMode); 118 _invocationURL.setPortletMode(portletMode); 119 } 120 121 public void setPortletMode(String namespace, PortletMode portletMode) 122 throws PortletModeException 123 { 124 _url = null; 125 checkPortletMode(namespace, portletMode); 126 _invocationURL.setPortletMode(namespace, portletMode); 127 } 128 129 public void setParameters(Map parameters) 130 { 131 _url = null; 132 _invocationURL.setParameters(parameters); 133 } 134 135 public void setParameter(String name, String value) 136 { 137 _url = null; 138 _invocationURL.setParameter(name, value); 139 } 140 141 public void setParameter(String name, String [] values) 142 { 143 _url = null; 144 _invocationURL.setParameter(name, values); 145 } 146 147 public void setParameter(String namespace, String name, String value) 148 { 149 _url = null; 150 _invocationURL.setParameter(namespace, name, value); 151 } 152 153 public void setParameter(String namespace, String name, String [] values) 154 { 155 _url = null; 156 _invocationURL.setParameter(namespace, name, values); 157 } 158 159 public void setParameters(String namespace, Map <String , String []> parameters) 160 { 161 _url = null; 162 _invocationURL.setParameters(namespace, parameters); 163 } 164 165 public void setSecure(boolean secure) 166 throws PortletSecurityException 167 { 168 _url = null; 169 170 _invocationURL.setSecure(secure); 171 172 if (secure == true) 173 getURL(); 174 } 175 176 180 protected boolean isSecureSpecified() 181 { 182 return _invocationURL.isSecureSpecified(); 183 } 184 185 protected boolean isSecure() 186 { 187 return _invocationURL.isSecure(); 188 } 189 190 protected String getURL() 191 throws PortletSecurityException 192 { 193 if (_url != null) 194 return _url; 195 196 String url = _invocationURL.getURL(); 197 198 199 if (isSecureSpecified()) 200 _url = _context.resolveURL(url, isSecure()); 201 else 202 _url = _context.resolveURL(url); 203 204 return _url; 205 } 206 207 public String toString() 208 { 209 try { 210 return getURL(); 211 } 212 catch (PortletSecurityException ex) { 213 throw new RuntimeException (ex); 214 } 215 } 216 } 217 | Popular Tags |