1 20 package org.enhydra.barracuda.core.util.dom; 21 22 import java.io.InputStream ; 23 import java.io.IOException ; 24 import javax.servlet.ServletContext ; 25 import org.w3c.dom.Document ; 26 import org.apache.log4j.Logger; 27 import org.jivan.html.document.DocumentFactory; 28 29 30 34 public class JivanDOMFactory implements DOMFactory { 35 36 39 protected static final Logger logger = Logger.getLogger(JivanDOMFactory.class.getName()); 40 41 46 protected ServletContext servletContext; 47 48 51 protected final Object sync = new Object (); 52 53 57 protected boolean initialized = false; 58 59 63 protected DocumentFactory jivanFactory; 64 65 72 public Document getInstance(Class clazz) throws IOException { 73 throw new IOException ("Error: Unimplemented - Jivan DocumentFactory does not support creation of documents from a class. If you already have a DocumentManager instance, use it directly"); 74 } 75 76 87 public Document getInstance(String docPath) throws IOException { 88 initFactory(); 89 if (servletContext != null && docPath.startsWith("/")) { 90 InputStream in = servletContext.getResourceAsStream(docPath); 91 if (in == null) throw new IOException ("non-existent resource path: " + docPath); 92 return jivanFactory.docManFor(docPath, in).getDocument(); 93 } 94 return jivanFactory.docManFor(docPath).getDocument(); 95 } 96 97 106 public void setServletContext(ServletContext iservletContext) { 107 this.servletContext = iservletContext; 108 } 109 110 private void initFactory() { 111 if (initialized == false) { 112 synchronized (sync) { 113 logger.info("initializing a Jivan factory for returning HTML documents"); 114 jivanFactory = DocumentFactory.getInstance(); 115 initialized = true; 116 } 117 } 118 } 119 120 } 121 | Popular Tags |