1 package org.apache.jetspeed.portal.portlets; 2 3 18 19 import org.apache.jetspeed.portal.Portlet; 21 import org.apache.jetspeed.services.PortletFactory; 22 import org.apache.jetspeed.portal.PortletControl; 23 import org.apache.jetspeed.services.PortalToolkit; 24 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 25 import org.apache.jetspeed.services.logging.JetspeedLogger; 26 import org.apache.jetspeed.services.rundata.JetspeedRunData; 27 import org.apache.jetspeed.util.template.JetspeedLink; 28 import org.apache.jetspeed.util.template.JetspeedLinkFactory; 29 30 import org.apache.jetspeed.util.JetspeedClearElement; 32 import org.apache.ecs.ConcreteElement; 33 34 import org.apache.turbine.util.RunData; 36 import org.apache.turbine.services.velocity.TurbineVelocity; 37 import org.apache.velocity.context.Context; 38 39 47 public class PreviewPortlet extends AbstractPortlet 48 { 49 50 53 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(PreviewPortlet.class.getName()); 54 55 58 public ConcreteElement getContent(RunData rundata) 59 { 60 61 Context context = TurbineVelocity.getContext(rundata); 62 context.put( "data", rundata); 63 TurbineVelocity.getContext(rundata).put("jetspeed", new org.apache.jetspeed.util.template.JetspeedTool(rundata)); 64 65 ConcreteElement result = null; 66 String controlName = rundata.getParameters().getString("previewedControlName"); 67 String portletName = rundata.getParameters().getString("previewedPortletName"); 68 if ( portletName == null ) 69 { 70 JetspeedLink jsLink = null; 71 72 try 73 { 74 jsLink = JetspeedLinkFactory.getInstance(rundata); 75 rundata.setRedirectURI( 76 jsLink.setUser( 77 rundata.getUser().getUserName(), "default.psml") 78 .addPathInfo("template", "Customize") 79 .addPathInfo("media-type", "html") 80 .toString() 81 ); 82 JetspeedLinkFactory.putInstance(jsLink); 83 jsLink = null; 84 return new JetspeedClearElement(""); 85 } catch (Exception e) 86 { 87 logger.error("Exception", e); 88 rundata.setScreenTemplate("Home"); 89 return new JetspeedClearElement(""); 90 } 91 } 93 Portlet portlet = null; 94 95 try 96 { 97 portlet = PortletFactory.getPortlet(portletName, "PreviewPortlet"); 98 PortletControl control = controlName == null ? PortalToolkit.getControl((String )null) : 99 PortalToolkit.getControl(controlName); 100 control = null; 101 if ( control != null ) 102 { 103 JetspeedRunData jdata = (JetspeedRunData)rundata; 104 control.setPortlet(portlet); 107 control.init(); 108 result = control.getContent(rundata); 109 } 110 else if ( portlet != null ) 111 { 112 result = portlet.getContent(rundata); 113 } 114 115 if ( result != null && !result.toString().equals("") ) 116 { 117 122 } 123 else 124 { 125 result = new JetspeedClearElement(""); 127 } 128 129 } 130 catch ( Exception e ) 131 { 132 logger.error("Exception", e); 133 result = new JetspeedClearElement("This resource is temporarily unavailable"); 134 } 135 136 rundata.setLayout("preview"); 137 return result; 138 } 139 140 } 141 | Popular Tags |