01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.config.schema.dynamic;
05:
06: import org.apache.xmlbeans.XmlObject;
07:
08: import com.tc.config.schema.context.ConfigContext;
09:
10: import java.io.File;
11:
12: /**
13: * A {@link com.tc.config.schema.dynamic.FileXPathBasedConfigItem} that uses the
14: * {@link com.tc.config.schema.dynamic.ParameterSubstituter} to substitute values before processing.
15: */
16: public class SubstitutedFileXPathBasedConfigItem extends
17: FileXPathBasedConfigItem {
18:
19: public SubstitutedFileXPathBasedConfigItem(ConfigContext context,
20: String xpath, File relativeTo) {
21: super (context, xpath, relativeTo);
22: }
23:
24: public SubstitutedFileXPathBasedConfigItem(ConfigContext context,
25: String xpath) {
26: super (context, xpath);
27: }
28:
29: protected Object fetchDataFromXmlObject(XmlObject xmlObject) {
30: String theString = (String) super
31: .fetchDataFromXmlObjectByReflection(xmlObject,
32: "getStringValue");
33: if (theString == null || theString.trim().length() == 0)
34: return null;
35: String substituted = ParameterSubstituter.substitute(theString);
36:
37: File out = new File(substituted);
38: if (relativeTo() != null && !out.isAbsolute())
39: out = new File(relativeTo(), substituted);
40: return out;
41: }
42:
43: }
|