001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.components;
018:
019: import org.apache.avalon.framework.configuration.DefaultConfiguration;
020: import org.apache.avalon.framework.configuration.ConfigurationException;
021: import org.apache.avalon.framework.configuration.Configuration;
022: import org.apache.avalon.framework.logger.Logger;
023: import org.apache.cocoon.util.SettingsHelper;
024: import org.apache.cocoon.util.Settings;
025:
026: /**
027: * Property Aware Configuration.
028: * This component extends the {@link DefaultConfiguration}
029: * by suppporting configurations that can contain placeholders for System Properties.
030: *
031: * @version SVN $Id: $
032: */
033: public class PropertyAwareConfiguration extends DefaultConfiguration {
034: private Settings settings;
035: private Logger logger;
036:
037: /**
038: * Copy constructor, to create a clone of another configuration.
039: * To modify children, use <code>getChild()</code>,
040: * <code>removeChild()</code> and <code>addChild()</code>.
041: *
042: * @param config the <code>Configuration</code> to copy
043: * @param deepCopy true will cause clones of the children to be added,
044: * false will add the original instances and is thus
045: * faster.
046: * @param settings The Settings to use when resolving tokens
047: * @param logger A Logger to use
048: * @throws ConfigurationException if an error occurs when copying
049: */
050: public PropertyAwareConfiguration(Configuration config,
051: boolean deepCopy, Settings settings, Logger logger)
052: throws ConfigurationException {
053: super (config, deepCopy);
054: this .settings = settings;
055: this .logger = logger;
056: }
057:
058: /**
059: * Shallow copy constructor, suitable for craeting a writable clone of
060: * a read-only configuration. To modify children, use <code>getChild()</code>,
061: * <code>removeChild()</code> and <code>addChild()</code>.
062: *
063: * @param config the <code>Configuration</code> to copy
064: * @param settings The Settings to use when resolving tokens
065: * @param logger A Logger to use
066: * @throws ConfigurationException if an error occurs when copying
067: */
068: public PropertyAwareConfiguration(Configuration config,
069: Settings settings, Logger logger)
070: throws ConfigurationException {
071: super (config);
072: this .settings = settings;
073: this .logger = logger;
074: }
075:
076: /**
077: * Create a new <code>DefaultConfiguration</code> instance.
078: *
079: * @param name a <code>String</code> value
080: */
081: public PropertyAwareConfiguration(final String name,
082: Settings settings, Logger logger) {
083: super (name);
084: this .settings = settings;
085: this .logger = logger;
086: }
087:
088: /**
089: * Create a new <code>DefaultConfiguration</code> instance.
090: *
091: * @param name a <code>String</code> value
092: * @param location a <code>String</code> value
093: * @param settings The Settings to use when resolving tokens
094: * @param logger A Logger to use
095: */
096: public PropertyAwareConfiguration(final String name,
097: final String location, Settings settings, Logger logger) {
098: super (name, location);
099: this .settings = settings;
100: this .logger = logger;
101: }
102:
103: /**
104: * Create a new <code>DefaultConfiguration</code> instance.
105: *
106: * @param name config node name
107: * @param location Builder-specific locator string
108: * @param ns Namespace string (typically a URI). Should not be null; use ""
109: * if no namespace.
110: * @param prefix A short string prefixed to element names, associating
111: * elements with a longer namespace string. Should not be null; use "" if no
112: * namespace.
113: * @param settings The Settings to use when resolving tokens
114: * @param logger A Logger to use
115: */
116: public PropertyAwareConfiguration(final String name,
117: final String location, final String ns,
118: final String prefix, Settings settings, Logger logger) {
119: super (name, location, ns, prefix);
120: this .settings = settings;
121: this .logger = logger;
122: }
123:
124: /**
125: * Create a new <code>DefaultConfiguration</code> instance.
126: *
127: * @param config A DefaultConfiguration
128: * @param settings The Settings to use when resolving tokens
129: * @param logger A Logger to use
130: */
131: public PropertyAwareConfiguration(
132: final DefaultConfiguration config, Settings settings,
133: Logger logger) throws ConfigurationException {
134: super (config, false);
135: this .settings = settings;
136: this .logger = logger;
137: }
138:
139: /**
140: * Set the value of this <code>Configuration</code> object to the specified string.
141: *
142: * @param value a <code>String</code> value
143: */
144: public void setValue(final String value) {
145: super .setValue(SettingsHelper.replace(value, this .settings,
146: this .logger));
147: }
148:
149: /**
150: * Set the value of the specified attribute to the specified string.
151: *
152: * @param name name of the attribute to set
153: * @param value a <code>String</code> value
154: */
155: public void setAttribute(final String name, final String value) {
156: super.setAttribute(name, SettingsHelper.replace(value,
157: this.settings, this.logger));
158: }
159: }
|