private void copyPrivileges(NodeBuilder root) throws RepositoryException {
PrivilegeRegistry registry = source.getPrivilegeRegistry();
NodeBuilder privileges = root.child(JCR_SYSTEM).child(REP_PRIVILEGES);
privileges.setProperty(JCR_PRIMARYTYPE, NT_REP_PRIVILEGES, NAME);
PrivilegeBits next = PrivilegeBits.NEXT_AFTER_BUILT_INS;
logger.info("Copying registered privileges");
for (Privilege privilege : registry.getRegisteredPrivileges()) {
String name = privilege.getName();
NodeBuilder def = privileges.child(name);
def.setProperty(JCR_PRIMARYTYPE, NT_REP_PRIVILEGE, NAME);
if (privilege.isAbstract()) {
def.setProperty(REP_IS_ABSTRACT, true);
}
Privilege[] aggregate = privilege.getDeclaredAggregatePrivileges();
if (aggregate.length > 0) {
List<String> names = newArrayListWithCapacity(aggregate.length);
for (Privilege p : aggregate) {
names.add(p.getName());
}
def.setProperty(REP_AGGREGATES, names, NAMES);
}
PrivilegeBits bits = PrivilegeBits.BUILT_IN.get(name);
if (bits != null) {
def.setProperty(bits.asPropertyState(REP_BITS));
} else if (aggregate.length == 0) {
bits = next;
next = next.nextBits();
def.setProperty(bits.asPropertyState(REP_BITS));
}
}
privileges.setProperty(next.asPropertyState(REP_NEXT));