// but the Source is unusable
if (!source.exists()) {
if (this.ignoreMissingTables) {
return Collections.EMPTY_MAP;
} else {
throw new PatternException("Mount table does not exist: '" + uri + "'");
}
}
// Source exists
Object[] values = (Object[]) this.mountTables.get(uri);
if (values != null) {
// Check validity
SourceValidity oldValidity = (SourceValidity) values[1];
int valid = oldValidity != null ? oldValidity.isValid() : SourceValidity.INVALID;
if (valid == SourceValidity.VALID) {
// Valid without needing the new validity
return (Map) values[0];
}
if (valid == SourceValidity.UNKNOWN &&
oldValidity.isValid(source.getValidity()) == SourceValidity.VALID) {
// Valid after comparing with the new validity
return (Map) values[0];
}
// Invalid: fallback below to read the mount table
} else {
values = new Object[2];
}
// Read the mount table
Map mounts = new HashMap();
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
Configuration config = builder.build(SourceUtil.getInputSource(source));
Configuration[] children = config.getChildren();
for (int i = 0; i < children.length; i++) {
Configuration child = children[i];
if ("mount".equals(child.getName())) {
String prefix = children[i].getAttribute("uri-prefix");
// Append a '/' at the end of a not-empty prefix
// this avoids flat uri matching which would cause
// exceptions in the sub sitemap!
if (!prefix.endsWith("/") && prefix.length() != 0) {
prefix = prefix + '/';
}
mounts.put(prefix, children[i].getAttribute("src"));
} else {
throw new PatternException(
"Unexpected element '" + child.getName() + "' (awaiting 'mount'), at " + child.getLocation());
}
}
values[0] = mounts;
values[1] = source.getValidity();
// Cache it with the source validity
this.mountTables.put(uri, values);
return mounts;
} catch (SecurityException e) {
if (this.ignoreMissingTables) {
return Collections.EMPTY_MAP;
} else {
throw new PatternException("Mount table is not accessible: '" + src + "' (" + e + ")");
}
} finally {
if (source != null) {
this.resolver.release(source);