KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > contrib > dbroggisch > examples > view > pages > ExampleBasePage


1 /*
2  * Copyright (C) 2003 Diez B. Roggisch [deets@web.de]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: ExampleBasePage.java,v 1.3 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.contrib.dbroggisch.examples.view.pages;
21
22 import java.io.IOException JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Locale JavaDoc;
26 import javax.servlet.ServletException JavaDoc;
27 import org.w3c.dom.Document JavaDoc;
28 import org.enhydra.xml.io.OutputOptions;
29 //import org.enhydra.xml.xmlc.XMLCStdFactory;
30
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 JavaDoc 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 JavaDoc _menupoints;
65
66     public void setMenuPoints(List JavaDoc 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 JavaDoc dEvents = new ArrayList JavaDoc();
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 JavaDoc pDoc)
89             throws EventException, ServletException JavaDoc, IOException JavaDoc {
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 JavaDoc getItem(String JavaDoc 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         //add doctype - need to do here because XMLC can't yet add the one embedded in the html to the DOM
113
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         //now render the DOM
118
return new DefaultDOMWriter(oo);
119     }
120
121     public Document JavaDoc getDocument(Locale JavaDoc iLocale) {
122         //return new XMLCStdFactory(null, null).create(NavigationHTML.class);
123

124         Document JavaDoc doc = null;
125         //load the localized DOM template
126
try {doc = DefaultDOMLoader.getGlobalInstance().getDOM(NavigationHTML.class, iLocale);}
127         catch (IOException JavaDoc ioe) {logger.fatal ("Fatal Error loading DOM template:", ioe);}
128         return doc;
129     }
130
131 }
132
Popular Tags