in core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/components/modules/input/XPathXMLFileModule.java [274:450]
private Object getAttribute(String name, Configuration modeConf, Map objectModel, boolean getValues)
throws ConfigurationException {
if (modeConf != null) {
name = modeConf.getChild("parameter").getValue(this.parameter != null ? this.parameter : name);
}
boolean hasDynamicConf = false; // whether we have a <file src="..."> dynamic configuration
Configuration fileConf = null; // the nested <file>, if any
if (modeConf != null && modeConf.getChildren().length > 0) {
fileConf = modeConf.getChild("file", false);
if (fileConf == null) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Missing 'file' child element at " + modeConf.getLocation());
}
} else {
hasDynamicConf = true;
}
}
String src = this.src;
Boolean cacheSource = this.cacheSource;
Boolean reloadSource = this.cacheSource;
boolean needsResolve = this.needsResolve;
String cacheParm = this.cacheParm;
String reloadParm = this.reloadParm;
if (hasDynamicConf) {
src = fileConf.getAttribute("src");
cacheParm = fileConf.getAttribute("cacheable", this.cacheParm);
reloadParm = fileConf.getAttribute("reloadable", this.reloadParm);
if (cacheParm == null) {
cacheSource = this.cacheSource;
} else if (VariableResolverFactory.needsResolve(cacheParm)) {
cacheSource = null;
if (cacheSource == null) {
try {
VariableResolver varResolver = VariableResolverFactory.getResolver(cacheParm, this.manager);
cacheSource = Boolean.valueOf(varResolver.resolve(objectModel));
} catch (PatternException pe) {
throw new ConfigurationException("Unable to resolve " + cacheParm, pe);
}
}
} else {
cacheSource = Boolean.valueOf(cacheParm);
}
if (reloadParm == null) {
reloadSource = this.reloadSource;
} else if (VariableResolverFactory.needsResolve(reloadParm)) {
reloadSource = null;
} else {
reloadSource = Boolean.valueOf(reloadParm);
}
needsResolve = true;
}
if (cacheSource == null) {
try {
VariableResolver varResolver = VariableResolverFactory.getResolver(cacheParm, this.manager);
cacheSource = Boolean.valueOf(varResolver.resolve(objectModel));
} catch (PatternException pe) {
throw new ConfigurationException("Unable to resolve " + cacheParm, pe);
}
}
if (reloadSource == null) {
try {
VariableResolver varResolver =
VariableResolverFactory.getResolver(reloadParm, this.manager);
reloadSource = Boolean.valueOf(varResolver.resolve(objectModel));
} catch (PatternException pe) {
throw new ConfigurationException("Unable to resolve " + reloadParm, pe);
}
}
if (src == null) {
throw new ConfigurationException(
"No source specified"
+ (modeConf != null ? ", either dynamically in " + modeConf.getLocation() + ", or " : "")
+ " statically in "
+ staticConfLocation);
}
if (needsResolve) {
try {
VariableResolver varResolver = VariableResolverFactory.getResolver(src, this.manager);
src = varResolver.resolve(objectModel);
} catch (PatternException pe) {
throw new ConfigurationException("Error resolving variables for " + src, pe);
}
}
Object result;
if (cacheSource.booleanValue()) {
DocumentInfo info = (DocumentInfo) this.cache.get(src);
if (info == null || (reloadSource.booleanValue() && !info.isValid())) {
Source docSource = null;
try {
docSource = resolver.resolveURI(src);
DocumentInfo newInfo = new DocumentInfo(src, SourceUtil.toDOM(this.manager, docSource),
docSource.getValidity(), this.cacheExpressions, this.resolver);
synchronized(this.cache) {
DocumentInfo cachedInfo = (DocumentInfo)this.cache.get(src);
if (cachedInfo == null || cachedInfo == info) {
this.cache.store(src, newInfo);
info = newInfo;
} else {
info = cachedInfo;
}
}
} catch (MalformedURLException mue) {
throw new ConfigurationException("Unable to resolve " + src, mue);
} catch (IOException ioe) {
throw new ConfigurationException("Unable to access" + src, ioe);
} catch (ProcessingException pe) {
throw new ConfigurationException("Unable to process " + src, pe);
} catch (SAXException se) {
throw new ConfigurationException("Error processing XML document " + src, se);
} finally {
if (docSource != null) {
resolver.release(docSource);
}
}
}
if (info.cacheExpressions) {
Map cache = getValues ? info.expressionValuesCache : info.expressionCache;
synchronized (cache) {
if (cache.containsKey(name)) {
result = cache.get(name);
if (getLogger().isDebugEnabled()) {
getLogger().debug("for " + name + " using cached result " + result);
}
} else {
result = getResult(name, info.document, modeConf, getValues);
if (result != null) {
cache.put(name, result);
if (getLogger().isDebugEnabled()) {
getLogger().debug("for " + name + " newly caching result " + result);
}
} else {
if (getLogger().isDebugEnabled()) {
getLogger().debug("for " + name + " result is null");
}
}
}
}
} else {
result = getResult(name, info.document, modeConf, getValues);
if (getLogger().isDebugEnabled()) {
getLogger().debug("for " + name + " result is " + result);
}
}
} else {
Source docSource = null;
try {
docSource = resolver.resolveURI(src);
result = getResult(name, SourceUtil.toDOM(this.manager, docSource), modeConf, getValues);
if (getLogger().isDebugEnabled()) {
getLogger().debug("for " + name + " result is " + result);
}
} catch (MalformedURLException mue) {
throw new ConfigurationException("Unable to resolve " + src, mue);
} catch (IOException ioe) {
throw new ConfigurationException("Unable to access" + src, ioe);
} catch (ProcessingException pe) {
throw new ConfigurationException("Unable to process " + src, pe);
} catch (SAXException se) {
throw new ConfigurationException("Error processing XML document " + src, se);
} finally {
if (docSource != null) {
resolver.release(docSource);
}
}
}
return result;
}