Workspace wsp = session.getWorkspace();
if (!(wsp instanceof JackrabbitWorkspace)) {
throw new RepositoryException("Unable to register privileges. No JackrabbitWorkspace.");
}
PrivilegeManager mgr = ((JackrabbitWorkspace) wsp).getPrivilegeManager();
ProgressTrackerListener.Mode mode = null;
if (tracker != null) {
mode = tracker.setMode(ProgressTrackerListener.Mode.TEXT);
}
// register namespaces
Map<String, String> pfxToURI = defs.getNamespaceMapping().getPrefixToURIMapping();
if (!pfxToURI.isEmpty()) {
for (Object o : pfxToURI.keySet()) {
String prefix = (String) o;
String uri = pfxToURI.get(prefix);
try {
session.getNamespacePrefix(uri);
track(tracker, "-", prefix + " -> " + uri);
} catch (RepositoryException e) {
session.getWorkspace().getNamespaceRegistry().registerNamespace(prefix, uri);
track(tracker, "A", prefix + " -> " + uri);
}
}
}
// register node types
List<Privilege> registeredPrivs = new LinkedList<Privilege>();
for (PrivilegeDefinition def: defs.getDefinitions()) {
String name = getJCRName(def.getName());
Privilege priv = null;
try {
priv = mgr.getPrivilege(name);
} catch (RepositoryException e) {
// ignore, already registered
}
if (priv == null) {
String[] aggregateNames = new String[def.getDeclaredAggregateNames().size()];
int i=0;
for (Name n: def.getDeclaredAggregateNames()) {
aggregateNames[i++] = getJCRName(n);
}
registeredPrivs.add(mgr.registerPrivilege(name, def.isAbstract(), aggregateNames));
track(tracker, "A", name);
} else {
track(tracker, "-", name);
}
}