1 5 6 package org.infohazard.maverick.view; 7 8 import org.infohazard.maverick.flow.*; 9 import java.io.IOException ; 10 import java.io.Reader ; 11 import javax.servlet.ServletException ; 12 import javax.servlet.ServletConfig ; 13 import javax.xml.transform.Source ; 14 import org.jdom.Element; 15 import org.w3c.dom.Node ; 16 17 18 37 public class TrivialViewFactory implements ViewFactory 38 { 39 41 public void init(Element factoryNode, ServletConfig servletCfg) throws ConfigException 42 { 43 } 45 46 48 public View createView(Element viewNode) throws ConfigException 49 { 50 return new TrivialView(); 51 } 52 53 55 protected static class TrivialView implements View 56 { 57 59 public void go(ViewContext vctx) throws IOException , ServletException 60 { 61 TransformStep next = vctx.getNextStep(); 62 63 if (vctx.getModel() == null) 64 { 65 } 67 else if (vctx.getModel() instanceof String ) 68 { 69 next.go((String )vctx.getModel()); 70 } 71 else if (vctx.getModel() instanceof Reader ) 72 { 73 next.go((Reader )vctx.getModel()); 74 } 75 else if (vctx.getModel() instanceof Source ) 76 { 77 next.go((Source )vctx.getModel()); 78 } 79 else if (vctx.getModel() instanceof Node ) 80 { 81 Source src = new javax.xml.transform.dom.DOMSource ((Node )vctx.getModel()); 82 next.go(src); 83 } 84 else 85 { 86 throw new ServletException ("TrivialView does not understand a model of type " 87 + vctx.getModel().getClass().getName() + ", only String, " 88 + "Reader, javax.xml.transform.Source, and org.w3c.dom.Node"); 89 } 90 } 91 } 92 } | Popular Tags |