001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.config.core;
031:
032: import com.caucho.config.Config;
033: import com.caucho.config.ConfigException;
034: import com.caucho.config.SchemaBean;
035: import com.caucho.config.types.*;
036: import com.caucho.log.Log;
037: import com.caucho.util.L10N;
038: import com.caucho.vfs.Path;
039: import com.caucho.vfs.Vfs;
040: import com.caucho.xml.LooseXml;
041:
042: import org.w3c.dom.Document;
043:
044: import javax.annotation.PostConstruct;
045: import java.util.logging.Logger;
046:
047: /**
048: * Imports values from a separate file.
049: */
050: public class ResinInclude extends ResinControl {
051: private static final L10N L = new L10N(ResinInclude.class);
052: private static final Logger log = Log.open(ResinInclude.class);
053:
054: private Path _path;
055: private boolean _isOptional = true;
056: private String _systemId;
057:
058: /**
059: * Sets the current location.
060: */
061: public void setConfigSystemId(String systemId) {
062: _systemId = systemId;
063: }
064:
065: /**
066: * Sets the resin:import path.
067: */
068: public void setHref(String path) {
069: _path = Vfs.lookup().lookup(FileVar.__FILE__.toString())
070: .getParent().lookup(path);
071: }
072:
073: /**
074: * Sets the resin:import path.
075: */
076: public void setPath(String path) {
077: setHref(path);
078: }
079:
080: /**
081: * Sets true if the path is optional.
082: */
083: public void setOptional(boolean optional) {
084: _isOptional = optional;
085: }
086:
087: @PostConstruct
088: public void init() throws Exception {
089: if (_path == null)
090: throw new ConfigException(L
091: .l("'href' attribute missing from resin:include."));
092:
093: if (_path.canRead() && !_path.isDirectory()) {
094: } else {
095: throw new ConfigException(
096: L
097: .l(
098: "Required file '{0}' can not be read for resin:include.",
099: _path.getNativePath()));
100: }
101:
102: Object object = getObject();
103:
104: String schema = null;
105:
106: // Use the relax schema for beans with schema.
107: if (object instanceof SchemaBean) {
108: schema = ((SchemaBean) object).getSchema();
109: }
110:
111: log
112: .config(L
113: .l(
114: "resin:include '{0}'.\nresin:include is deprecated. Please use resin:import instead.",
115: _path.getNativePath()));
116:
117: LooseXml xml = new LooseXml();
118:
119: Document doc = xml.parseDocument(_path);
120:
121: new Config().configure(object, doc); // , schema);
122: }
123: }
|