1 25 package org.ofbiz.base.config; 26 27 import java.io.InputStream ; 28 import java.net.URL ; 29 30 import org.ofbiz.base.util.UtilXml; 31 import org.ofbiz.base.util.Debug; 32 33 import org.w3c.dom.Document ; 34 import org.w3c.dom.Element ; 35 36 43 public class MainResourceHandler implements ResourceHandler { 44 45 public static final String module = MainResourceHandler.class.getName(); 46 protected String xmlFilename; 47 protected String loaderName; 48 protected String location; 49 50 public MainResourceHandler(String xmlFilename, Element element) { 51 this.xmlFilename = xmlFilename; 52 this.loaderName = element.getAttribute("loader"); 53 this.location = element.getAttribute("location"); 54 if (Debug.verboseOn()) Debug.logVerbose("Created " + this.toString(), module); 55 } 56 57 public MainResourceHandler(String xmlFilename, String loaderName, String location) { 58 this.xmlFilename = xmlFilename; 59 this.loaderName = loaderName; 60 this.location = location; 61 } 62 63 public String getLoaderName() { 64 return this.loaderName; 65 } 66 67 public String getLocation() { 68 return this.location; 69 } 70 71 public Document getDocument() throws GenericConfigException { 72 try { 73 return UtilXml.readXmlDocument(this.getStream(), this.xmlFilename); 74 } catch (org.xml.sax.SAXException e) { 75 throw new GenericConfigException("Error reading " + this.toString(), e); 76 } catch (javax.xml.parsers.ParserConfigurationException e) { 77 throw new GenericConfigException("Error reading " + this.toString(), e); 78 } catch (java.io.IOException e) { 79 throw new GenericConfigException("Error reading " + this.toString(), e); 80 } 81 } 82 83 public InputStream getStream() throws GenericConfigException { 84 return ResourceLoader.loadResource(this.xmlFilename, this.location, this.loaderName); 85 } 86 87 public URL getURL() throws GenericConfigException { 88 return ResourceLoader.getURL(this.xmlFilename, this.location, this.loaderName); 89 } 90 91 public boolean isFileResource() throws GenericConfigException { 92 ResourceLoader loader = ResourceLoader.getLoader(this.xmlFilename, this.loaderName); 93 94 if (loader instanceof FileLoader) { 95 return true; 96 } else { 97 return false; 98 } 99 } 100 101 public String getFullLocation() throws GenericConfigException { 102 ResourceLoader loader = ResourceLoader.getLoader(this.xmlFilename, this.loaderName); 103 104 return loader.fullLocation(location); 105 } 106 107 public boolean equals(Object obj) { 108 if (obj instanceof MainResourceHandler) { 109 MainResourceHandler other = (MainResourceHandler) obj; 110 111 if (this.loaderName.equals(other.loaderName) && 112 this.xmlFilename.equals(other.xmlFilename) && 113 this.location.equals(other.location)) { 114 return true; 115 } 116 } 117 return false; 118 } 119 120 public int hashCode() { 121 return (this.xmlFilename.hashCode() + ((this.loaderName.hashCode() + this.location.hashCode()) >> 1)) >> 1; 123 } 124 125 public String toString() { 126 return "ResourceHandler from XML file [" + this.xmlFilename + "] with loaderName [" + loaderName + "] and location [" + location + "]"; 127 } 128 } 129 | Popular Tags |