use of org.apache.jackrabbit.oak.namepath.impl.GlobalNameMapper in project jackrabbit-oak by apache.
the class NodeObserver method contentChanged.
@Override
public void contentChanged(@Nonnull NodeState root, @Nonnull CommitInfo info) {
if (previousRoot != null) {
try {
long start = PERF_LOGGER.start();
NamePathMapper namePathMapper = new NamePathMapperImpl(new GlobalNameMapper(RootFactory.createReadOnlyRoot(root)));
Set<String> oakPropertyNames = Sets.newHashSet();
for (String name : propertyNames) {
String oakName = namePathMapper.getOakNameOrNull(name);
if (oakName == null) {
LOG.warn("Ignoring invalid property name: {}", name);
} else {
oakPropertyNames.add(oakName);
}
}
NodeState before = previousRoot;
NodeState after = root;
EventHandler handler = new FilteredHandler(VISIBLE_FILTER, new NodeEventHandler("/", info, namePathMapper, oakPropertyNames));
String oakPath = namePathMapper.getOakPath(path);
if (oakPath == null) {
LOG.warn("Cannot listen for changes on invalid path: {}", path);
return;
}
for (String oakName : PathUtils.elements(oakPath)) {
before = before.getChildNode(oakName);
after = after.getChildNode(oakName);
handler = handler.getChildHandler(oakName, before, after);
}
EventGenerator generator = new EventGenerator(before, after, handler);
while (!generator.isDone()) {
generator.generate();
}
PERF_LOGGER.end(start, 100, "Generated events (before: {}, after: {})", previousRoot, root);
} catch (Exception e) {
LOG.warn("Error while dispatching observation events", e);
}
}
previousRoot = root;
}
use of org.apache.jackrabbit.oak.namepath.impl.GlobalNameMapper in project jackrabbit-oak by apache.
the class NodeTypeRegistryTest method registerNodeType.
@Test
public void registerNodeType() throws Exception {
registerNodeType(root, "oak6440-1.cnd");
NodeTypeManager readOnlyNtMgr = new ReadOnlyNodeTypeManager() {
private Root r = session.getLatestRoot();
@Override
protected Tree getTypes() {
return r.getTree(NODE_TYPES_PATH);
}
};
NodeTypeManager ntMgr = new ReadWriteNodeTypeManager() {
@Override
protected Tree getTypes() {
return root.getTree(NODE_TYPES_PATH);
}
@Nonnull
@Override
protected Root getWriteRoot() {
return root;
}
};
ValueFactory valueFactory = new ValueFactoryImpl(root, new NamePathMapperImpl(new GlobalNameMapper(root)));
NamespaceRegistry nsRegistry = new ReadOnlyNamespaceRegistry(root);
DefinitionBuilderFactory<NodeTypeTemplate, NamespaceRegistry> factory = new TemplateBuilderFactory(ntMgr, valueFactory, nsRegistry);
InputStream in = NodeTypeRegistryTest.class.getResourceAsStream("oak6440-2.cnd");
List<NodeTypeTemplate> templates;
try {
CompactNodeTypeDefReader<NodeTypeTemplate, NamespaceRegistry> reader = new CompactNodeTypeDefReader<NodeTypeTemplate, NamespaceRegistry>(new InputStreamReader(in, UTF_8), "oak6440-2.cnd", factory);
templates = reader.getNodeTypeDefinitions();
} finally {
in.close();
}
for (NodeTypeTemplate t : templates) {
NodeTypeTemplateImpl template;
if (t instanceof NodeTypeTemplateImpl) {
template = (NodeTypeTemplateImpl) t;
} else {
template = new NodeTypeTemplateImpl(new GlobalNameMapper(root), t);
}
template.writeTo(root.getTree(NODE_TYPES_PATH), true);
}
NodeTypeDefinition beforeDef = readOnlyNtMgr.getNodeType("foo");
NodeTypeDefinition afterDef = ntMgr.getNodeType("foo");
NodeTypeDefDiff diff = NodeTypeDefDiff.create(beforeDef, afterDef);
assertFalse(diff.isMajor());
}
use of org.apache.jackrabbit.oak.namepath.impl.GlobalNameMapper in project jackrabbit-oak by apache.
the class PrivilegeManagerImplTest method testGetPrivilegeExpandedName.
@Test
public void testGetPrivilegeExpandedName() throws Exception {
Privilege p = create(root, new NamePathMapperImpl(new GlobalNameMapper(root))).getPrivilege(Privilege.JCR_VERSION_MANAGEMENT);
assertNotNull(p);
assertNotEquals(Privilege.JCR_VERSION_MANAGEMENT, p.getName());
assertEquals(PrivilegeConstants.JCR_VERSION_MANAGEMENT, p.getName());
}
use of org.apache.jackrabbit.oak.namepath.impl.GlobalNameMapper in project jackrabbit-oak by apache.
the class AccessControlManagerImplTest method before.
@Override
@Before
public void before() throws Exception {
super.before();
registerNamespace(TEST_PREFIX, TEST_URI);
NameMapper nameMapper = new GlobalNameMapper(root);
npMapper = new NamePathMapperImpl(nameMapper);
acMgr = new AccessControlManagerImpl(root, npMapper, getSecurityProvider());
NodeUtil rootNode = new NodeUtil(root.getTree("/"), getNamePathMapper());
rootNode.addChild(testName, JcrConstants.NT_UNSTRUCTURED);
root.commit();
valueFactory = new ValueFactoryImpl(root, npMapper);
testPrivileges = privilegesFromNames(PrivilegeConstants.JCR_ADD_CHILD_NODES, PrivilegeConstants.JCR_READ);
testPrincipal = getTestUser().getPrincipal();
}
use of org.apache.jackrabbit.oak.namepath.impl.GlobalNameMapper in project jackrabbit-oak by apache.
the class ACLTest method testGetPath.
@Test
public void testGetPath() {
NameMapper nameMapper = new GlobalNameMapper(Collections.singletonMap("jr", "http://jackrabbit.apache.org"));
NamePathMapper npMapper = new NamePathMapperImpl(nameMapper);
// map of jcr-path to standard jcr-path
Map<String, String> paths = new HashMap<String, String>();
paths.put(null, null);
paths.put(TEST_PATH, TEST_PATH);
paths.put("/", "/");
paths.put("/jr:testPath", "/jr:testPath");
paths.put("/{http://jackrabbit.apache.org}testPath", "/jr:testPath");
for (String path : paths.keySet()) {
AbstractAccessControlList acl = createACL(path, Collections.<ACE>emptyList(), npMapper);
assertEquals(paths.get(path), acl.getPath());
}
}
Aggregations