1 28 29 30 package com.caucho.widget; 31 32 import com.caucho.util.L10N; 33 34 import javax.portlet.*; 35 import java.util.LinkedHashMap ; 36 import java.util.Map ; 37 import java.util.logging.Logger ; 38 39 public class PortletWidgetURL 40 extends WidgetURL 41 { 42 private static L10N L = new L10N( PortletWidgetURL.class ); 43 44 static protected final Logger log = 45 Logger.getLogger( PortletWidgetURL.class.getName() ); 46 47 private PortletWidgetConnection _connection; 48 49 private Map <String ,String []> _parameterMap; 50 private PortletMode _portletMode; 51 private WindowState _windowState; 52 private Boolean _isSecure; 53 private boolean _isAction; 54 55 private PortletURL _portletURL; 56 private String _url; 57 58 public PortletWidgetURL( PortletWidgetConnection connection ) 59 { 60 _connection = connection; 61 62 } 63 64 public void setParameter( String name, String value ) 65 { 66 String [] values = new String [] { value }; 67 68 setParameter( name, values ); 69 } 70 71 public void setParameter( String name, String [] values ) 72 { 73 if ( _parameterMap == null ) 74 _parameterMap = new LinkedHashMap <String ,String []>(); 75 76 _parameterMap.put( name, values ); 77 78 _url = null; 79 80 if ( _portletURL != null ) 81 _portletURL.setParameter( name, values ); 82 } 83 84 public void setParameters( Map <String ,String []> parameters ) 85 { 86 if ( _parameterMap == null ) 87 _parameterMap = new LinkedHashMap <String , String []>(); 88 else 89 _parameterMap.clear(); 90 91 _url = null; 92 93 _parameterMap.putAll( parameters ); 94 95 if ( _portletURL != null ) 96 _portletURL.setParameters( parameters ); 97 } 98 99 public void setPortletMode( PortletMode portletMode ) 100 throws PortletModeException 101 { 102 if ( portletMode.equals( _portletMode ) ) 103 return; 104 105 _portletMode = portletMode; 106 107 _url = null; 108 109 if ( _portletURL != null ) 110 _portletURL.setPortletMode( portletMode ); 111 } 112 113 public void setWindowState( WindowState windowState ) 114 throws WindowStateException 115 { 116 if ( windowState.equals( _windowState ) ) 117 return; 118 119 _windowState = windowState; 120 121 _url = null; 122 123 if ( _portletURL != null ) 124 _portletURL.setWindowState( windowState ); 125 } 126 127 public void setSecure( boolean secure ) 128 { 129 if ( _isSecure != null && _isSecure.booleanValue() == secure ) 130 return; 131 132 _isSecure = secure ? Boolean.TRUE : Boolean.FALSE; 133 134 _url = null; 135 136 if ( _portletURL != null ) { 137 try { 138 _portletURL.setSecure( secure ); 139 } 140 catch ( PortletException ex ) { 141 throw new RuntimeException ( ex ); 142 } 143 } 144 } 145 146 public void setAction( boolean isAction ) 147 { 148 if ( isAction != _isAction) { 149 _url = null; 150 _portletURL = null; 151 152 _isAction = isAction; 153 } 154 } 155 156 public String toString() 157 { 158 if ( _url != null ) 159 return _url; 160 161 if ( _portletURL != null ) 162 return _portletURL.toString(); 163 164 try { 165 RenderResponse response = _connection.getRenderResponse(); 166 167 _portletURL = _isAction ? response.createActionURL() 168 : response.createRenderURL(); 169 170 if ( _windowState != null ) 171 _portletURL.setWindowState( _windowState ); 172 if ( _portletMode != null ) 173 _portletURL.setPortletMode( _portletMode ); 174 175 if ( _isSecure != null ) 176 _portletURL.setSecure( _isSecure.booleanValue() ); 177 178 if ( _parameterMap != null ) { 179 for ( Map.Entry <String ,String []> entry : _parameterMap.entrySet() ) { 180 _portletURL.setParameter( entry.getKey(), entry.getValue() ); 181 } 182 } 183 } 184 catch ( PortletException ex ) { 185 throw new RuntimeException ( ex ); 186 } 187 188 _url = _portletURL.toString(); 189 190 return _url; 191 } 192 } 193 | Popular Tags |