本文整理汇总了Java中javax.jcr.Session.getRootNode方法的典型用法代码示例。如果您正苦于以下问题:Java Session.getRootNode方法的具体用法?Java Session.getRootNode怎么用?Java Session.getRootNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jcr.Session
的用法示例。
在下文中一共展示了Session.getRootNode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import javax.jcr.Session; //导入方法依赖的package包/类
@Override
public void execute(final InstallContext installContext) throws TaskExecutionException {
try {
final Session session = MgnlContext.getJCRSession(NewsRepositoryConstants.COLLABORATION);
final Node rootNode = session.getRootNode();
final int numberOfMovedNodes = processNewsItems(installContext, rootNode, 0);
if (numberOfMovedNodes > 0) {
installContext.info("Nested news items were found and have been un-nested.");
installContext.info("Note: If present, duplicate news items now have a name that ends with '-duplicate'.");
installContext.info("Please check all news items and re-publish if needed.");
}
} catch (RepositoryException e) {
throw new TaskExecutionException("Error while un-nesting event nodes", e);
}
}
示例2: getJcrFromFixture
import javax.jcr.Session; //导入方法依赖的package包/类
public Session getJcrFromFixture(InputStream fixture) {
Repository repository = null;
Session session = null;
try {
repository = MockJcr.newRepository();
session = repository.login();
Node rootNode = session.getRootNode();
Yaml parser = new Yaml();
List<Map<String, Object>> nodes = (ArrayList<Map<String, Object>>) parser.load(fixture);
for (Map object: nodes) {
NodeYaml node = new NodeYaml(
(String) object.get("path"),
(String) object.get("primaryType"),
(Map<String, Object>) object.getOrDefault("properties", emptyMap())
);
Node n = rootNode.addNode(node.path, node.primaryType);
for (Map.Entry<String, Object> entry : node.properties.entrySet()) {
if (entry.getValue() instanceof Boolean) {
n.setProperty(entry.getKey(), (Boolean) entry.getValue());
} else {
n.setProperty(entry.getKey(), entry.getValue().toString());
}
}
}
session.save();
} catch (RepositoryException e) {
throw new RuntimeException("Failed to set property on JCR node", e);
}
return session;
}
示例3: initialise
import javax.jcr.Session; //导入方法依赖的package包/类
public void initialise(Session session) throws LoginException, RepositoryException {
final NamespaceRegistry registry = session.getWorkspace().getNamespaceRegistry();
if (!Arrays.asList(registry.getPrefixes()).contains("ocm")) {
session.getWorkspace().getNamespaceRegistry().registerNamespace("ocm", "http://jackrabbit.apache.org/ocm");
}
Node rootNode = session.getRootNode();
for( String nodeName : this.mainNodes){
if(!rootNode.hasNode(nodeName)){
rootNode.addNode(nodeName);
}
}
session.save();
}
示例4: testJcrConsumer
import javax.jcr.Session; //导入方法依赖的package包/类
@Test
public void testJcrConsumer() throws Exception {
// start consumer thread first
JcrConsumerThread consumerThread = new JcrConsumerThread();
consumerThread.start();
// wait until the consumer thread has tried to receive event at least once
while (consumerThread.getReceiveTrialTimes() < 1) {
Thread.sleep(10L);
}
// now create a node under the specified event node path
Session session = openSession();
try {
Node folderNode = session.getRootNode();
for (String folderNodeName : absPath.split("\\/")) {
if (!"".equals(folderNodeName)) {
if (folderNode.hasNode(folderNodeName)) {
folderNode.getNode(folderNodeName).remove();
}
folderNode = folderNode.addNode(folderNodeName, "nt:unstructured");
}
}
folderNode.addNode("node", "nt:unstructured");
session.save();
} finally {
if (session != null && session.isLive()) {
session.logout();
}
}
// wait until the consumer thread captures an event
consumerThread.join();
Exchange exchange = consumerThread.getExchange();
assertNotNull(exchange);
Message message = exchange.getIn();
assertNotNull(message);
assertTrue(message instanceof JcrMessage);
EventIterator eventIterator = ((JcrMessage)message).getEventIterator();
assertNotNull(eventIterator);
assertEquals(1, eventIterator.getSize());
List<?> eventList = message.getBody(List.class);
assertEquals(1, eventList.size());
Event event = (Event) eventList.get(0);
assertEquals(Event.NODE_ADDED, event.getType());
assertNotNull(event.getPath());
assertTrue(event.getPath().startsWith(absPath));
}