1 7 8 package org.jboss.portal.core.theme.strategy.impl; 9 10 import org.apache.log4j.Logger; 11 import org.jboss.portal.common.MediaType; 12 import org.jboss.portal.server.plugins.windowstate.WindowState; 13 import org.jboss.portal.server.theme.strategy.AbstractLayoutStrategy; 14 import org.jboss.portal.server.theme.strategy.LayoutStrategy; 15 import org.jboss.portal.server.theme.strategy.PortletContext; 16 import org.jboss.portal.server.theme.strategy.StrategyContext; 17 import org.jboss.portal.server.theme.strategy.StrategyException; 18 import org.jboss.portal.server.theme.strategy.StrategyResponse; 19 20 import java.util.ArrayList ; 21 import java.util.Iterator ; 22 23 34 public class DefaultStrategyImpl extends AbstractLayoutStrategy 35 { 36 private static final Logger log = Logger.getLogger(DefaultStrategyImpl.class); 37 38 41 public DefaultStrategyImpl() 42 { 43 setMediaType(MediaType.HTML); 44 } 45 46 53 public StrategyResponse evaluate(StrategyContext context) throws StrategyException 54 { 55 if (context == null) 56 { 57 throw new NullPointerException ("strategy context is null"); 58 } 59 60 log.debug("evaluating strategy for: " + context.getLayout()); 61 62 73 74 StrategyResponse response = context.createResponse(); 75 76 ArrayList maximizedPortlets = new ArrayList (); 77 78 for (Iterator i = context.getPortletList().iterator(); i.hasNext();) 81 { 82 PortletContext portlet = (PortletContext)i.next(); 83 log.debug("evaluating portlet: " + portlet.getPortletName()); 84 if (WindowState.MAXIMIZED.equals(portlet.getWindowState())) 85 { 86 log.debug("found maximized portlet: " + portlet); 87 maximizedPortlets.add(portlet); 88 } 89 else 90 { 91 response.addNoRender(portlet); 93 99 } 100 } 101 if (maximizedPortlets.size() > 0) 108 { 109 if (context.getTargetPortlet() != null && maximizedPortlets.size() > 1) 111 { 112 if (maximizedPortlets.contains(context.getTargetPortlet()) && 113 WindowState.MAXIMIZED.equals(context.getTargetPortlet().getWindowState())) 114 { 115 for (Iterator i = maximizedPortlets.iterator(); i.hasNext();) 116 { 117 PortletContext portlet = (PortletContext)i.next(); 118 if (!portlet.equals(context.getTargetPortlet())) 119 { 120 log.debug("resetting maximized portlet to normal (there can only be one): " + portlet + " " + 121 context.getTargetPortlet() + " will be maximized"); 122 response.addWindowStateChange(portlet, WindowState.NORMAL); 125 response.addNoRender(portlet); 126 } 127 } 128 } 129 } 130 131 response.setState(WindowState.MAXIMIZED.toString()); 133 maximizedPortlets.clear(); 134 } 135 else 136 { 137 response.reset(); 139 } 140 141 if (context.getLayout() != null) 142 { 143 response.setURI(context.getLayout().getURI()); 144 } 145 146 return response; 147 } 148 149 152 public String toString() 153 { 154 return this.getClass().getName(); 155 } 156 } 157 | Popular Tags |