KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > examples > xmlc > CompEx7


1 package org.enhydra.barracuda.examples.xmlc;
2
3 import java.io.*;
4 import java.util.*;
5 import javax.servlet.*;
6 import javax.servlet.http.*;
7
8 import org.w3c.dom.*;
9 import org.w3c.dom.html.*;
10 import org.enhydra.xml.xmlc.*;
11
12 import org.enhydra.barracuda.core.comp.*;
13 import org.enhydra.barracuda.core.comp.helper.*;
14 import org.enhydra.barracuda.core.util.dom.*;
15 import org.enhydra.barracuda.core.event.*;
16 import org.enhydra.barracuda.core.util.dom.*;
17 import org.enhydra.barracuda.core.view.*;
18 import org.enhydra.barracuda.examples.xmlc.data.*;
19
20 /**
21  * Test BText ability to return encoded text, as well as markup
22  * Created to test the implementation of csc_092701.1
23  */

24 public class CompEx7 extends ComponentGateway {
25
26     //-------------------- ComponentGateway ----------------------
27
/**
28      * Handle the default HttpRequest.
29      */

30     public Document handleDefault (BComponent root, ViewContext vc, HttpServletRequest req, HttpServletResponse resp) throws IOException {
31         //load the localized DOM template
32
Document page = DefaultDOMLoader.getGlobalInstance().getDOM(CompEx7HTML.class);
33
34         //create a template component and bind it to the views
35
BTemplate templateComp = new BTemplate(new LocalTemplateModel(req));
36         templateComp.setView(new DefaultTemplateView(page.getDocumentElement()));
37         root.addChild(templateComp);
38
39         //return the page
40
return page;
41     }
42
43     /**
44      * <p>Get a DOMWriter. By default, we use a DefaultDOMWriter. If
45      * you'd like to use something else, override this method.
46      *
47      * @return a DOMWriter to be used to render the DOM
48      */

49     public DOMWriter getDOMWriter() {
50         //return DefaultDOM writer
51
return new DefaultDOMWriter(true);
52     }
53
54     //--------------- TemplateModel --------------------------
55
/**
56      * LocalTemplateModel
57      */

58     class LocalTemplateModel extends AbstractTemplateModel {
59     
60         HttpServletRequest req = null;
61         
62         public LocalTemplateModel(HttpServletRequest ireq) {
63             req = ireq;
64         }
65         
66         //register the model by name
67
public String JavaDoc getName() {return "Test1";}
68         
69         //provide items by key
70
public Object JavaDoc getItem(String JavaDoc key) {
71             ViewContext vc = getViewContext();
72             ViewCapabilities vcap = vc.getViewCapabilities();
73             if (key.equals("NormalText1")) {
74                 return "Text1: <strong>bold</strong>";
75             } else if (key.equals("NormalText2")) {
76                 return new BLink("Link1: A link with <em>zing1</em>", "blah99.html");
77             } else if (key.equals("MarkupText1")) {
78                 BText btext = new BText("Text2: <strong>bold</strong>");
79                 btext.setAllowMarkupInText(true);
80                 return btext;
81             } else if (key.equals("MarkupText2")) {
82                 BLink blink = new BLink("Link2: A link with <em>zing2</em>", "blah99.html");
83                 blink.setAllowMarkupInText(true);
84                 return blink;
85             } else {
86                 return super.getItem(key);
87             }
88         }
89     }
90 }
91
Popular Tags