1 20 package org.enhydra.barracuda.contrib.dbroggisch.examples.view.pages; 21 22 import java.io.IOException ; 23 import java.util.ArrayList ; 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.xml.io.OutputOptions; 29 import org.enhydra.barracuda.core.comp.BComponent; 31 import org.enhydra.barracuda.core.comp.BTemplate; 32 import org.enhydra.barracuda.core.comp.DefaultTemplateView; 33 import org.enhydra.barracuda.core.comp.ViewContext; 34 import org.enhydra.barracuda.core.event.ControlEventContext; 35 import org.enhydra.barracuda.core.event.EventException; 36 import org.enhydra.barracuda.core.util.dom.DefaultDOMLoader; 37 import org.enhydra.barracuda.core.util.dom.DefaultDOMWriter; 38 import org.enhydra.barracuda.core.util.dom.DOMWriter; 39 import org.enhydra.barracuda.contrib.dbroggisch.display.IterativeListModel; 40 import org.enhydra.barracuda.contrib.dbroggisch.page.AbstractPage; 41 import org.enhydra.barracuda.contrib.dbroggisch.page.Page; 42 import org.enhydra.barracuda.contrib.dbroggisch.page.SessionPage; 43 import org.apache.log4j.Logger; 44 45 import org.enhydra.barracuda.contrib.dbroggisch.examples.controller.events.*; 46 import org.enhydra.barracuda.contrib.dbroggisch.examples.view.xmlc.*; 47 48 49 public class ExampleBasePage extends AbstractPage implements SessionPage { 50 51 private static final Logger logger = Logger.getLogger(ExampleBasePage.class.getName()); 52 53 public static class State { 54 private State() {} 55 } 56 57 public static final String NAVIGATION_MODEL_NAME = "NavigationModel"; 58 59 public static final State REPOPULATION = new State(); 60 public static final State PREFIXMAPPING = new State(); 61 public static final State FILEUPLOAD = new State(); 62 private State _state = REPOPULATION; 63 64 List _menupoints; 65 66 public void setMenuPoints(List menupoints) { 67 _menupoints = menupoints; 68 } 69 70 public void setState(State state) { 71 _state = state; 72 } 73 74 public State getState() { 75 return _state; 76 } 77 78 public ExampleBasePage() { 79 List dEvents = new ArrayList (); 80 dEvents.add(new NavigationBar()); 81 setDefaultEvents(dEvents); 82 } 83 84 public void handOver(ControlEventContext ctx, Page p){ 85 createDefaultModels(ctx); 86 } 87 88 public void render(BComponent root, ViewContext vec, Document pDoc) 89 throws EventException, ServletException , IOException { 90 NavigationHTML doc = (NavigationHTML)pDoc; 91 BTemplate navComp = new BTemplate(); 92 93 navComp.setView(new DefaultTemplateView(doc.getElementNavigationHook())); 94 95 if(_menupoints == null) return; 96 97 navComp.addModel(new IterativeListModel(NAVIGATION_MODEL_NAME, _menupoints) { 98 public Object getItem(String key) { 99 if("MENUPOINT".equals(key)) { 100 return _current; 101 } 102 return "UNDEFINED"; 103 } 104 }); 105 106 root.addChild(navComp); 107 } 108 109 public DOMWriter getDOMWriter() { 110 OutputOptions oo = DefaultDOMWriter.getDefaultOutputOptions(getDocument(getViewContext().getViewCapabilities().getClientLocale())); 111 112 oo.setOmitDocType(false); 114 oo.setPublicId("-//W3C//DTD HTML 4.01 Transitional//EN"); 115 oo.setSystemId("http://www.w3.org/TR/html401/loose.dtd"); 116 117 return new DefaultDOMWriter(oo); 119 } 120 121 public Document getDocument(Locale iLocale) { 122 124 Document doc = null; 125 try {doc = DefaultDOMLoader.getGlobalInstance().getDOM(NavigationHTML.class, iLocale);} 127 catch (IOException ioe) {logger.fatal ("Fatal Error loading DOM template:", ioe);} 128 return doc; 129 } 130 131 } 132 | Popular Tags |