1 29 30 package com.caucho.config.core; 31 32 import com.caucho.config.Config; 33 import com.caucho.config.ConfigException; 34 import com.caucho.config.SchemaBean; 35 import com.caucho.log.Log; 36 import com.caucho.util.L10N; 37 import com.caucho.vfs.Path; 38 import com.caucho.vfs.Vfs; 39 import com.caucho.xml.LooseXml; 40 41 import org.w3c.dom.Document ; 42 43 import javax.annotation.PostConstruct; 44 import java.util.logging.Logger ; 45 46 49 public class ResinInclude extends ResinControl { 50 private static final L10N L = new L10N(ResinInclude.class); 51 private static final Logger log = Log.open(ResinInclude.class); 52 53 private Path _path; 54 private boolean _isOptional = true; 55 private String _systemId; 56 57 60 public void setConfigSystemId(String systemId) 61 { 62 _systemId = systemId; 63 } 64 65 68 public void setHref(String path) 69 { 70 if (_systemId != null) 71 _path = Vfs.lookup().lookup(_systemId).getParent().lookup(path); 72 else 73 _path = Vfs.lookup().lookup(path); 74 } 75 76 79 public void setPath(String path) 80 { 81 setHref(path); 82 } 83 84 87 public void setOptional(boolean optional) 88 { 89 _isOptional = optional; 90 } 91 92 @PostConstruct 93 public void init() 94 throws Exception 95 { 96 if (_path == null) 97 throw new ConfigException(L.l("'href' attribute missing from resin:include.")); 98 99 if (_path.canRead() && ! _path.isDirectory()) { 100 } 101 else { 102 throw new ConfigException(L.l("Required file '{0}' can not be read for resin:include.", 103 _path.getNativePath())); 104 } 105 106 Object object = getObject(); 107 108 String schema = null; 109 110 if (object instanceof SchemaBean) { 112 schema = ((SchemaBean) object).getSchema(); 113 } 114 115 log.config(L.l("resin:include '{0}'.\nresin:include is deprecated. Please use resin:import instead.", _path.getNativePath())); 116 117 118 LooseXml xml = new LooseXml(); 119 120 Document doc = xml.parseDocument(_path); 121 122 new Config().configure(object, doc); } 124 } 125 126 | Popular Tags |