uriToIndex.put(uri, idx);
}
}
private void load() throws RepositoryException {
FileSystemResource propFile =
new FileSystemResource(nsRegStore, NS_REG_RESOURCE);
FileSystemResource idxFile =
new FileSystemResource(nsRegStore, NS_IDX_RESOURCE);
try {
if (!propFile.exists()) {
// clear existing mappings
clear();
// default namespace (if no prefix is specified)
map(Name.NS_EMPTY_PREFIX, Name.NS_DEFAULT_URI);
// declare the predefined mappings
// rep:
map(Name.NS_REP_PREFIX, Name.NS_REP_URI);
// jcr:
map(Name.NS_JCR_PREFIX, Name.NS_JCR_URI);
// nt:
map(Name.NS_NT_PREFIX, Name.NS_NT_URI);
// mix:
map(Name.NS_MIX_PREFIX, Name.NS_MIX_URI);
// sv:
map(Name.NS_SV_PREFIX, Name.NS_SV_URI);
// xml:
map(Name.NS_XML_PREFIX, Name.NS_XML_URI);
// persist mappings
store();
return;
}
// check if index file exists
Properties indexes = new Properties();
if (idxFile.exists()) {
InputStream in = idxFile.getInputStream();
try {
indexes.load(in);
} finally {
in.close();
}
}
InputStream in = propFile.getInputStream();
try {
Properties props = new Properties();
props.load(in);
// clear existing mappings
clear();
// read mappings from properties
for (Object p : props.keySet()) {
String prefix = (String) p;
String uri = props.getProperty(prefix);
String idx = indexes.getProperty(escapePropertyKey(uri));
// JCR-888: Backwards compatibility check
if (idx == null && uri.equals("")) {
idx = indexes.getProperty(uri);
}
if (idx != null) {
map(unescapePropertyKey(prefix), uri, Integer.decode(idx));
} else {
map(unescapePropertyKey(prefix), uri);
}
}
} finally {
in.close();
}
if (!idxFile.exists()) {
store();
}
} catch (Exception e) {
String msg = "failed to load namespace registry";
log.debug(msg);