1 11 package org.jboss.portal.junit.invocation; 12 13 import org.jboss.portal.server.invocation.Interceptor; 14 import org.jboss.portal.server.invocation.Invocation; 15 import org.jboss.portal.server.invocation.AttachmentKey; 16 import org.jboss.portal.server.PortalRequest; 17 import org.jboss.portal.server.PortalServer; 18 import org.jboss.portal.server.Portal; 19 import org.jboss.portal.server.Window; 20 import org.jboss.portal.junit.TestAttachmentKey; 21 import org.apache.log4j.Logger; 22 23 import java.util.List ; 24 import java.util.ArrayList ; 25 26 30 public class ViewInterceptor implements Interceptor 31 { 32 private static Logger log = Logger.getLogger(ViewInterceptor.class); 33 34 private List windows = new ArrayList (); 35 36 public Object invoke(Invocation invocation) 37 { 38 try 39 { 40 PortalRequest req = (PortalRequest)invocation.getAttachment(AttachmentKey.PORTAL_REQUEST); 42 PortalServer container = req.getServer(); 43 Portal portal = container.getDefaultPortal(); 44 45 String [] values = (String [])invocation.getAttachment(TestAttachmentKey.TEST_WINDOWS); 47 if (values != null) 48 { 49 windows.clear(); 51 52 StringBuffer tmp = new StringBuffer ("Window request list ["); 54 for (int i = 0; i < values.length; i++) 55 { 56 tmp.append(i == 0 ? "" : ",").append(values[i]); 57 } 58 tmp.append("]"); 59 log.info(tmp); 60 61 for (int i = 0; i < values.length; i++) 62 { 63 String windowName = values[i]; 64 Window window = portal.getWindow(windowName); 65 if (window != null) 66 { 67 windows.add(window); 68 } 69 else 70 { 71 log.error("Cannot find window " + windowName); 72 } 73 } 74 } 75 76 invocation.setAttachment(AttachmentKey.VIEW, new ArrayList (windows)); 78 invocation.setAttachment(AttachmentKey.PORTAL, portal); 79 return invocation.invokeNext(); 80 } 81 finally 82 { 83 invocation.removeAttachment(AttachmentKey.VIEW); 84 } 85 } 86 } 87 | Popular Tags |