KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > core > comp > helper > BTemplateGateway


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
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: BTemplateGateway.java,v 1.11 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.core.comp.helper;
21
22 import java.io.*;
23 import javax.servlet.*;
24 import javax.servlet.http.*;
25
26 import org.apache.log4j.*;
27 import org.w3c.dom.*;
28
29 import org.enhydra.barracuda.core.comp.*;
30 import org.enhydra.barracuda.core.util.dom.*;
31
32 /**
33  * <p>A custom implementation of the component gateway tailored for
34  * template components. All you have to do is instantiate the class
35  * with the name of the template and a reference to the model; it takes
36  * care of everything else.
37  */

38 public abstract class BTemplateGateway extends ComponentGateway {
39
40     //public vars...eventually, these should probably be final
41
protected static final Logger logger = Logger.getLogger(BTemplateGateway.class.getName());
42     
43
44     //-------------------- TemplateGateway -----------------------
45
/**
46      * Return an instance of the template model
47      */

48     public abstract TemplateModel getTemplateModel();
49     
50     /**
51      * Return an instance of the template class (must implement Document)
52      */

53     public abstract Class JavaDoc getTemplateClass();
54     
55     /**
56      * Handle the default HttpRequest.
57      */

58     public Document handleDefault (BComponent root, ViewContext vc, HttpServletRequest req, HttpServletResponse resp) throws IOException {
59         //load the localized DOM template
60
//csc_061702.1 Document page = DefaultDOMLoader.getGlobalInstance().getDOM(getTemplateClass());
61
Document page = DefaultDOMLoader.getGlobalInstance().getDOM(getTemplateClass(), vc.getViewCapabilities().getClientLocale()); //csc_061702.1
62

63         //create a template component and bind it to the views
64
// TemplateView tv = new DefaultTemplateView(page.getDocumentElement());
65
// BTemplate templateComp = new BTemplate(getTemplateModel(), tv);
66
BTemplate templateComp = new BTemplate(getTemplateModel());
67         templateComp.setView(new DefaultTemplateView(page.getDocumentElement()));
68         root.addChild(templateComp);
69
70         //return the page
71
return page;
72     }
73
74
75 }
76
Popular Tags