1 48 49 package com.caucho.portal.generic; 50 51 import javax.portlet.Portlet; 52 import javax.portlet.PortletContext; 53 import javax.portlet.PortletException; 54 import java.io.IOException ; 55 import java.util.logging.Level ; 56 import java.util.logging.Logger ; 57 58 61 public class GenericPortletWindow 62 extends GenericWindow 63 { 64 static protected final Logger log = 65 Logger.getLogger(GenericPortletWindow.class.getName()); 66 67 private Portlet _portlet; 68 private boolean _isPortletNameSet; 69 70 public GenericPortletWindow() 71 { 72 } 73 74 78 public void setPortlet(Portlet portlet) 79 { 80 if (_portlet != null) 81 throw new IllegalArgumentException ("`portlet' is already set"); 82 83 _portlet = portlet; 84 } 85 86 87 91 public void setPortletClass(String className) 92 { 93 setPortlet( (Portlet) newInstance(Portlet.class, className) ); 94 } 95 96 99 public void setPortletName(String portletName) 100 { 101 super.setPortletName(portletName); 102 _isPortletNameSet = true; 103 } 104 105 public void init(PortletContext portletContext) 106 throws PortletException 107 { 108 super.init(portletContext); 109 110 if (_portlet == null) 111 throw new PortletException("`portlet' is required"); 112 113 if (!_isPortletNameSet) 114 setPortletName(_portlet.getClass().getName()); 115 116 _portlet.init(this); 117 } 118 119 120 protected Portlet getPortlet() 121 { 122 if (_portlet == null) 123 throw new IllegalStateException ("missing init()?"); 124 125 return _portlet; 126 } 127 128 133 public void processAction(PortletConnection connection) 134 throws PortletException, IOException 135 { 136 Action action = connection.getAction(this, getNamespace()); 137 138 if (action != null) { 139 try { 140 if (action.isTarget()) 141 action.processAction(getPortlet()); 142 } 143 finally { 144 action.finish(); 145 } 146 } 147 } 148 149 154 public void render(PortletConnection connection) 155 throws PortletException, IOException 156 { 157 Render render = connection.getRender(this, getNamespace()); 158 159 if (render != null) { 160 try { 161 render.render(getPortlet()); 162 } 163 finally { 164 render.finish(); 165 } 166 } 167 } 168 169 public void destroy() 170 { 171 Portlet portlet = _portlet; 172 173 _portlet = null; 174 175 try { 176 if (portlet != null) 177 portlet.destroy(); 178 } 179 catch (Exception ex) { 180 log.log(Level.WARNING, ex.toString(), ex); 181 } 182 } 183 } 184 185 | Popular Tags |