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.view.*; 15 import org.enhydra.barracuda.core.util.dom.*; 16 import org.enhydra.barracuda.plankton.http.*; 17 import org.enhydra.barracuda.examples.xmlc.data.*; 18 19 22 public class RedirectEx1 extends ComponentGateway { 23 24 public static boolean DEFAULT_NOBACK = true; 26 30 public Document handleDefault (BComponent root, ViewContext vc, HttpServletRequest req, HttpServletResponse resp) throws IOException { 31 Document page = DefaultDOMLoader.getGlobalInstance().getDOM(RedirectEx1HTML.class); 33 34 BTemplate templateComp = new BTemplate(new SimpleTemplateModel(req, resp)); 36 templateComp.setView(new DefaultTemplateView(page.getElementById("TemplateID"))); 37 root.addChild(templateComp); 38 39 return page; 41 } 42 43 49 public DOMWriter getDOMWriter() { 50 return new DefaultDOMWriter(true); 52 } 53 54 58 class SimpleTemplateModel extends AbstractTemplateModel { 59 HttpServletRequest req = null; 60 HttpServletResponse resp = null; 61 Integer cntr = null; 62 Boolean noBack = null; 63 String targetURL = "RedirectEx1"; 64 65 public SimpleTemplateModel(HttpServletRequest ireq, HttpServletResponse iresp) { 66 req = ireq; 67 resp = iresp; 68 69 HttpSession session = req.getSession(true); 71 cntr = (Integer ) session.getAttribute("cntr"); 72 if (cntr==null || req.getParameter("clear")!=null) cntr = new Integer (0); 73 else cntr = new Integer (cntr.intValue()+1); 74 session.setAttribute("cntr", cntr); 75 76 noBack = (Boolean ) session.getAttribute("noback"); 78 if (noBack==null) noBack = new Boolean (DEFAULT_NOBACK); 79 if (req.getParameter("noback")!=null) noBack = new Boolean (true); 80 else if (req.getParameter("okback")!=null) noBack = new Boolean (false); 81 session.setAttribute("noback", noBack); 82 } 83 84 public String getName() { 86 return "Rewrite"; 87 } 88 89 public Object getItem(String key) { 91 ViewContext vc = getViewContext(); 92 93 if (key.equals("RewritingVal")) { 95 return new Boolean (URLRewriter.REWRITE_URLS); 96 97 } else if (key.equals("BackButtonVal")) { 99 return noBack.booleanValue() ? "disabling" : "enabling"; 100 101 } else if (key.equals("ServletEncode")) { 103 String text = "Target URL = "+resp.encodeURL(targetURL); 107 BLink blink = new BLink(text, targetURL, vc); 108 blink.setDisableBackButton(noBack.booleanValue()); 109 return blink; 110 111 } else if (key.equals("BarracudaEncode")) { 113 String text = "Target URL = "+URLRewriter.encodeURL(req, resp, targetURL);; 117 BLink blink = new BLink(text, targetURL, vc); 118 blink.setDisableBackButton(noBack.booleanValue()); 119 return blink; 120 121 } else if (key.equals("EncodeForm1")) { 123 BAction baction = new BAction(targetURL); 126 baction.setParam("foo","bar?bar/bar=bar~bar^bar,bar;bar"); 127 baction.setDisableBackButton(noBack.booleanValue()); 128 return baction; 129 130 } else if (key.equals("EncodeForm2")) { 132 BAction baction = new BAction(targetURL); 135 baction.setDisableBackButton(noBack.booleanValue()); 136 return baction; 137 138 } else if (key.equals("EncodeForm3")) { 140 BAction baction = new BAction(targetURL); 143 baction.setDisableBackButton(noBack.booleanValue()); 144 return baction; 145 149 } else if (key.equals("EncodeForm4")) { 151 BAction baction = new BAction(targetURL); 154 baction.setDisableBackButton(noBack.booleanValue()); 155 return baction; 156 157 } else if (key.equals("Cntr")) { 159 return cntr; 160 161 } else if (key.equals("ResetLink")) { 163 String text = "Reset Cntr"; 164 String url = targetURL+"?clear=true"; 166 BLink blink = new BLink(text, url, vc); 167 blink.setDisableBackButton(noBack.booleanValue()); 168 return blink; 169 170 } else if (key.equals("ToggleLink")) { 172 String text = (noBack.booleanValue() ? "Enable back button" : "Disable back button"); 173 String url = targetURL+(noBack.booleanValue() ? "?okback=true" : "?noback=true"); 175 BLink blink = new BLink(text, url, vc); 176 blink.setDisableBackButton(noBack.booleanValue()); 177 return blink; 178 179 } else return super.getItem(key); 181 } 182 } 183 184 185 186 189 193 234 235 } 236 | Popular Tags |