1 20 package org.enhydra.barracuda.contrib.dbroggisch.page; 21 22 import java.io.IOException ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import java.util.Locale ; 26 import javax.servlet.ServletException ; 27 import org.w3c.dom.Document ; 28 import org.enhydra.barracuda.core.comp.BComponent; 29 import org.enhydra.barracuda.core.comp.ViewContext; 30 import org.enhydra.barracuda.core.event.BaseEvent; 31 import org.enhydra.barracuda.core.event.ControlEventContext; 32 import org.enhydra.barracuda.core.event.DispatchQueue; 33 import org.enhydra.barracuda.core.event.EventException; 34 import org.enhydra.barracuda.core.event.ViewEventContext; 35 import org.enhydra.barracuda.core.event.helper.DefaultViewHandler; 36 import org.apache.log4j.Logger; 37 38 39 43 public abstract class AbstractPage extends DefaultViewHandler implements Page { 44 45 private static final Logger logger = Logger.getLogger(AbstractPage.class.getName()); 46 private List dEvents; 47 48 53 public void setDefaultEvents(List events) { 54 dEvents = events; 55 } 56 57 62 public void createDefaultModels(ControlEventContext ctx) { 63 filterEvents(ctx, dEvents); 64 } 65 66 73 public abstract Document getDocument(Locale iLocale); 74 75 87 public Document handleViewEvent(BComponent root) 88 throws EventException, ServletException , IOException { 89 ViewContext ctx = getViewContext(); 90 Locale iLocale = ctx.getViewCapabilities().getClientLocale(); 91 if (logger.isDebugEnabled()) logger.debug("Locale sent by the client is: " + iLocale); 92 Document doc = getDocument(iLocale); 93 if (logger.isInfoEnabled()) logger.info("Created document " + doc.getClass().getName()); 94 render(root, ctx, doc); 95 return doc; 96 } 97 98 106 public void render(ViewEventContext vec) 107 throws EventException, ServletException , IOException { 108 handleViewEvent(vec); 109 } 110 111 122 public abstract void render(BComponent root, ViewContext vec, Document doc) 123 throws EventException, ServletException , IOException ; 124 125 131 public static void filterEvents(ControlEventContext ctx, List defaultEvents) { 132 if (defaultEvents != null) { 133 BaseEvent event = ctx.getEvent(); 134 135 for (Iterator it = defaultEvents.iterator(); it.hasNext();) { 136 if (((BaseEvent)it.next()).equals(event)) { 137 if (logger.isDebugEnabled()) logger.debug("Removing event " + event.getClass().getName() + " from the queue"); 138 it.remove(); 139 } 140 } 141 142 DispatchQueue queue = ctx.getQueue(); 143 144 for (Iterator it = defaultEvents.iterator(); it.hasNext();) { 145 queue.addEvent((BaseEvent)it.next()); 147 } 148 } 149 } 150 151 } 152 | Popular Tags |