1 16 package org.apache.cocoon.portal.layout.renderer.aspect.impl; 17 18 import javax.portlet.PortletMode; 19 import javax.portlet.WindowState; 20 import javax.servlet.ServletConfig ; 21 import javax.servlet.http.HttpServletRequest ; 22 23 import org.apache.avalon.framework.context.Context; 24 import org.apache.avalon.framework.context.ContextException; 25 import org.apache.avalon.framework.context.Contextualizable; 26 import org.apache.avalon.framework.parameters.ParameterException; 27 import org.apache.avalon.framework.parameters.Parameters; 28 import org.apache.cocoon.portal.PortalService; 29 import org.apache.cocoon.portal.coplet.CopletInstanceData; 30 import org.apache.cocoon.portal.coplet.adapter.impl.PortletAdapter; 31 import org.apache.cocoon.portal.layout.Layout; 32 import org.apache.cocoon.portal.layout.impl.CopletLayout; 33 import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext; 34 import org.apache.cocoon.portal.pluto.PortletURLProviderImpl; 35 import org.apache.cocoon.portal.pluto.om.PortletWindowImpl; 36 import org.apache.cocoon.servlet.CocoonServlet; 37 import org.apache.cocoon.xml.XMLUtils; 38 import org.apache.pluto.om.portlet.PortletDefinition; 39 import org.apache.pluto.om.window.PortletWindow; 40 import org.apache.pluto.services.PortletContainerEnvironment; 41 import org.apache.pluto.services.information.DynamicInformationProvider; 42 import org.apache.pluto.services.information.InformationProviderService; 43 import org.xml.sax.ContentHandler ; 44 import org.xml.sax.SAXException ; 45 46 80 public final class PortletWindowAspect 81 extends AbstractAspect 82 implements Contextualizable { 83 84 85 protected PortletContainerEnvironment environment; 86 87 90 public void contextualize(Context context) throws ContextException { 91 try { 92 ServletConfig servletConfig = (ServletConfig ) context.get(CocoonServlet.CONTEXT_SERVLET_CONFIG); 94 PortletAdapter portalManager = (PortletAdapter) servletConfig.getServletContext().getAttribute(PortletAdapter.class.getName()); 95 if ( portalManager != null ) { 96 this.environment = portalManager.getPortletContainerEnvironment(); 97 } 98 } catch (ContextException ignore) { 99 this.getLogger().warn("The JSR-168 support is disabled as the servlet context is not available.", ignore); 103 } 104 } 105 106 109 public void toSAX(RendererAspectContext context, 110 Layout layout, 111 PortalService service, 112 ContentHandler contenthandler) 113 throws SAXException { 114 final PreparedConfiguration config = (PreparedConfiguration)context.getAspectConfiguration(); 115 final CopletInstanceData copletInstanceData = ((CopletLayout)layout).getCopletInstanceData(); 116 117 if ( config.rootTag ) { 118 XMLUtils.startElement(contenthandler, config.tagName); 119 } 120 final PortletWindow window = (PortletWindow)copletInstanceData.getTemporaryAttribute("window"); 121 if ( window == null ) { 122 XMLUtils.createElement(contenthandler, "title", copletInstanceData.getTitle()); 124 } else { 125 if ( ((PortletWindowImpl)window).getLayout() == null ) { 126 ((PortletWindowImpl)window).setLayout((CopletLayout)layout); 127 } 128 129 String title = (String ) copletInstanceData.getTemporaryAttribute("dynamic-title"); 130 if ( title == null ) { 131 final PortletDefinition def = window.getPortletEntity().getPortletDefinition(); 132 try { 133 title = def.getDisplayName(def.getLanguageSet().getDefaultLocale()).getDisplayName(); 134 } catch (Exception ignore) { 135 title = copletInstanceData.getTitle(); 136 } 137 } 138 XMLUtils.createElement(contenthandler, "title", title); 139 140 141 if ( this.environment != null ) { 142 InformationProviderService ips = (InformationProviderService) this.environment.getContainerService(InformationProviderService.class); 143 DynamicInformationProvider dip = ips.getDynamicProvider((HttpServletRequest ) context.getObjectModel().get("portlet-request")); 144 145 WindowState ws = (WindowState)copletInstanceData.getTemporaryAttribute("window-state"); 147 if ( ws == null ) { 148 ws = WindowState.NORMAL; 149 } 150 151 if ( !ws.equals(WindowState.MINIMIZED) && !ws.equals(WindowState.MAXIMIZED)) { 152 PortletURLProviderImpl url = (PortletURLProviderImpl)dip.getPortletURLProvider(window); 153 url.clearParameters(); 154 url.setWindowState(WindowState.MINIMIZED); 155 156 XMLUtils.createElement(contenthandler, "minimize-uri", url.toString()); 157 } 158 159 if ( !ws.equals(WindowState.NORMAL)) { 160 PortletURLProviderImpl url = (PortletURLProviderImpl)dip.getPortletURLProvider(window); 161 url.clearParameters(); 162 url.setWindowState(WindowState.NORMAL); 163 XMLUtils.createElement(contenthandler, "maximize-uri", url.toString()); 164 } 165 166 if ( !ws.equals(WindowState.MAXIMIZED)) { 167 PortletURLProviderImpl url = (PortletURLProviderImpl)dip.getPortletURLProvider(window); 168 url.clearParameters(); 169 url.setWindowState(WindowState.MAXIMIZED); 170 XMLUtils.createElement(contenthandler, "fullscreen-uri", url.toString()); 171 } 172 173 PortletMode pm = (PortletMode)copletInstanceData.getTemporaryAttribute("portlet-mode"); 175 if ( pm == null ) { 176 pm = PortletMode.VIEW; 177 } 178 if ( !pm.equals(PortletMode.EDIT) ) { 179 PortletURLProviderImpl url = (PortletURLProviderImpl)dip.getPortletURLProvider(window); 180 url.clearParameters(); 181 url.setPortletMode(PortletMode.EDIT); 182 XMLUtils.createElement(contenthandler, "edit-uri", url.toString()); 183 } 184 if ( !pm.equals(PortletMode.HELP) ) { 185 PortletURLProviderImpl url = (PortletURLProviderImpl)dip.getPortletURLProvider(window); 186 url.clearParameters(); 187 url.setPortletMode(PortletMode.HELP); 188 XMLUtils.createElement(contenthandler, "help-uri", url.toString()); 189 } 190 if ( !pm.equals(PortletMode.VIEW) ) { 191 PortletURLProviderImpl url = (PortletURLProviderImpl)dip.getPortletURLProvider(window); 192 url.clearParameters(); 193 url.setPortletMode(PortletMode.VIEW); 194 XMLUtils.createElement(contenthandler, "view-uri", url.toString()); 195 } 196 } 197 } 198 199 context.invokeNext( layout, service, contenthandler ); 200 201 if ( config.rootTag ) { 202 XMLUtils.endElement(contenthandler, config.tagName); 203 } 204 } 205 206 protected static class PreparedConfiguration { 207 public String tagName; 208 public boolean rootTag; 209 210 public void takeValues(PreparedConfiguration from) { 211 this.tagName = from.tagName; 212 this.rootTag = from.rootTag; 213 } 214 } 215 216 219 public Object prepareConfiguration(Parameters configuration) 220 throws ParameterException { 221 PreparedConfiguration pc = new PreparedConfiguration(); 222 pc.tagName = configuration.getParameter("tag-name", "window"); 223 pc.rootTag = configuration.getParameterAsBoolean("root-tag", true); 224 return pc; 225 } 226 227 } 228 | Popular Tags |