1 16 17 package org.apache.jetspeed.util.template; 18 19 import org.apache.turbine.util.RunData; 20 import org.apache.turbine.util.DynamicURI; 21 import org.apache.turbine.util.template.TemplateLink; 22 import org.apache.turbine.services.pull.ApplicationTool; 23 24 import org.apache.jetspeed.portal.Portlet; 25 import org.apache.jetspeed.portal.PortletSet; 26 import org.apache.jetspeed.portal.PortletController; 27 import org.apache.jetspeed.portal.PanedPortletController; 28 import org.apache.jetspeed.om.profile.Entry; 29 import org.apache.jetspeed.om.profile.Portlets; 30 31 import org.apache.jetspeed.services.rundata.JetspeedRunData; 32 import org.apache.jetspeed.services.resources.JetspeedResources; 33 34 49 public class JetspeedTemplateLink 50 extends TemplateLink implements ApplicationTool 51 { 52 53 public static final String PORTLET_KEY = "portlet"; 55 public static final String ACTION_KEY = "action"; 56 public static final String SCREEN_KEY = "screen"; 57 public static final String TEMPLATE_KEY = "template"; 58 public static final String PANEL_KEY = "select-panel"; 59 60 63 private String portletName = null; 64 65 68 private JetspeedRunData data = null; 69 70 73 protected Portlet activePortlet = null; 74 75 76 77 80 public JetspeedTemplateLink() 81 { 82 } 83 84 89 public JetspeedTemplateLink(RunData data) 90 { 91 super(data); 92 this.data = (JetspeedRunData)data; 93 94 String tmpl = this.data.getRequestedTemplate(); 95 if (tmpl!=null) 96 { 97 setPage(tmpl); 98 } 99 } 100 101 108 public void init(Object data) 109 { 110 super.init(data); 111 this.data = (JetspeedRunData)data; 112 113 String tmpl = this.data.getRequestedTemplate(); 114 if (tmpl!=null) 115 { 116 setPage(tmpl); 117 } 118 } 119 120 124 public void setPortlet(Portlet portlet) 125 { 126 this.activePortlet=portlet; 127 } 128 129 130 131 134 public void refresh() 135 { 136 super.refresh(); 137 138 String tmpl = this.data.getRequestedTemplate(); 139 if (tmpl!=null) 140 { 141 setPage(tmpl); 142 } 143 } 144 145 151 public DynamicURI forPortlet(String portlet) 152 { 153 this.portletName = portlet; 154 removePathInfo(getPortletKey()); 155 removeQueryData(getPortletKey()); 156 return addPathInfo(getPortletKey(), portlet); 157 } 158 159 166 public DynamicURI setPortlet(String portlet) 167 { 168 return this.forPortlet( portlet ); 169 } 170 171 174 public String getPortlet() 175 { 176 return this.portletName; 177 } 178 179 182 public String getPortletKey() 183 { 184 return PORTLET_KEY; 185 } 186 187 190 public String getActionKey() 191 { 192 return ACTION_KEY; 193 } 194 195 198 public String getScreenKey() 199 { 200 return SCREEN_KEY; 201 } 202 203 206 public String getPageKey() 207 { 208 return TEMPLATE_KEY; 209 } 210 211 217 public DynamicURI setPanel(String panel) 218 { 219 removePathInfo(JetspeedResources.PATH_PANEID_KEY); 220 removeQueryData(JetspeedResources.PATH_PANEID_KEY); 221 PortletController controller = activePortlet.getPortletConfig() 222 .getPortletSet() 223 .getController(); 224 225 String id = null; 226 227 if (controller instanceof PanedPortletController) 228 { 229 PortletSet set = controller.getPortlets(); 230 Portlet portlet = null; 231 if (null != set) 232 { 233 portlet = set.getPortletByName(panel); 234 } 235 if (portlet != null) 236 id = portlet.getID(); 237 } 238 else 239 { 240 Portlets entry = data.getProfile().getDocument().getPortlets(panel); 241 if (entry != null) 242 id = entry.getId(); 243 } 244 return addPathInfo(JetspeedResources.PATH_PANEID_KEY, id); 245 } 246 247 252 public String getPanelKey() 253 { 254 String panelName = PANEL_KEY; 255 try 256 { 257 PortletController controller = activePortlet.getPortletConfig() 258 .getPortletSet() 259 .getController(); 260 261 if (controller instanceof PanedPortletController) 262 { 263 panelName=((PanedPortletController)controller).getParameterName(); 264 } 265 266 } 267 catch (Exception e) 268 { 269 panelName = PANEL_KEY; 270 } 271 272 return panelName; 273 } 274 275 279 public String toString() 280 { 281 String tmpl = this.data.getRequestedTemplate(); 282 if (tmpl!=null) 283 { 284 setPage(tmpl); 285 } 286 287 String buf = super.toString(); 288 return buf; 289 } 290 291 public DynamicURI getPortletByName(String portletName) 292 { 293 String id = null; 294 Entry entry = data.getProfile().getDocument().getEntry(portletName); 295 if (entry != null) 297 { 298 id = entry.getId(); 299 } 300 System.out.println("js_peid:"+id); 301 return addPathInfo("js_peid", id); 302 303 } 304 305 public void clear() 306 { 307 removePathInfo(); 308 removeQueryData(); 309 } 310 } 311 | Popular Tags |