本文整理了Java中javax.jcr.Node.getPrimaryItem()
方法的一些代码示例,展示了Node.getPrimaryItem()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.getPrimaryItem()
方法的具体详情如下:
包路径:javax.jcr.Node
类名称:Node
方法名:getPrimaryItem
[英]Returns the primary child item of this node. The primary node type of this node may specify one child item (child node or property) of this node as the primary child item. This method returns that item.
In cases where the primary child item specifies the name of a set same-name sibling child nodes, the node returned will be the one among the same-name siblings with index [1].
The same reacquisition semantics apply as with #getNode(String)
.
[中]返回此节点的主子项。此节点的主节点类型可以将此节点的一个子项(子节点或属性)指定为主子项。此方法返回该项。
如果主子项指定了一组同名同级子节点的名称,则返回的节点将是索引为[1]的同名同级节点中的节点。
与#getNode(String)
相同的重新获取语义也适用。
代码示例来源:origin: org.apache.sling/org.apache.sling.scripting.javascript
public Object jsFunction_getPrimaryItem() {
try {
return ScriptRuntime.toObject(this, node.getPrimaryItem());
} catch (RepositoryException re) {
return Undefined.instance;
}
}
代码示例来源:origin: org.onehippo.cms7/hippo-repository-connector
/**
* @inheritDoc
*/
public Item getPrimaryItem() throws ItemNotFoundException, RepositoryException {
return factory.getItemDecorator(session, node.getPrimaryItem());
}
代码示例来源:origin: info.magnolia/magnolia-core
@Override
public Item getPrimaryItem() throws ItemNotFoundException, RepositoryException {
return getWrappedNode().getPrimaryItem();
}
代码示例来源:origin: net.adamcin.oakpal/oakpal-core
@Override
public Item getPrimaryItem() throws RepositoryException {
return ensureBestWrapper(delegate.getPrimaryItem(), session);
}
代码示例来源:origin: nl.vpro/jcr-criteria
@Override
public Item getPrimaryItem() throws RepositoryException {
return getNode().getPrimaryItem();
}
代码示例来源:origin: apache/jackrabbit
/**
* Returns the first descendant of <code>node</code> without a primary item
*
* @param node
* @return first node without primary item
*/
private Node locateNodeWithoutPrimaryItem(Node node)
throws RepositoryException {
try {
node.getPrimaryItem();
} catch (ItemNotFoundException e) {
return node;
}
NodeIterator nodes = node.getNodes();
while (nodes.hasNext()) {
Node returnedNode = this.locateNodeWithoutPrimaryItem(nodes.nextNode());
if (returnedNode != null) {
return returnedNode;
}
}
return null;
}
代码示例来源:origin: apache/jackrabbit
/** {@inheritDoc} */
public RemoteItem getPrimaryItem()
throws RepositoryException, RemoteException {
try {
return getRemoteItem(node.getPrimaryItem());
} catch (RepositoryException ex) {
throw getRepositoryException(ex);
}
}
代码示例来源:origin: org.onehippo.cms7/hippo-repository-engine
@Override
public InputStream getResourceInputStream(final Source source, final String resourcePath) throws IOException {
try {
final String pathFromBase = makeBaseRelativePath(source, resourcePath);
Node resourceNode = baseNode.getNode(pathFromBase);
Property primary = (Property) resourceNode.getPrimaryItem();
// JCR API Spec defines conversion of String to binary using UTF-8, which is what we want here
return primary.getBinary().getStream();
}
catch (RepositoryException e) {
throw new RuntimeException("Problem loading stream for resource in baseline", e);
}
}
代码示例来源:origin: net.adamcin.commons/net.adamcin.commons.jcr
public Item getPrimaryItem() throws RepositoryException {
Item primaryItem = this.item.getPrimaryItem();
if (primaryItem.isNode()) {
return new NodeProxy((Node) primaryItem, this);
} else {
return new PropertyProxy((Property) primaryItem, this);
}
}
代码示例来源:origin: brix-cms/brix-cms
public JcrItem execute() throws Exception {
return JcrItem.Wrapper.wrap(getDelegate().getPrimaryItem(), getJcrSession());
}
});
代码示例来源:origin: brix-cms/brix-cms
public Item getPrimaryItem() throws RepositoryException {
return ItemWrapper.wrap(getDelegate().getPrimaryItem(), getSessionWrapper());
}
代码示例来源:origin: apache/jackrabbit
/**
* Test if getPrimaryItem does throw an ItemNotFoundException if the primary
* node type does not define a primary item. Therefor a node without a
* primary item is located recursively in the entire repository. A
* NotExecutableException is thrown when no such node is found.
*/
public void testGetPrimaryItemItemNotFoundException()
throws NotExecutableException, RepositoryException {
Node node = locateNodeWithoutPrimaryItem(testRootNode);
if (node == null) {
throw new NotExecutableException("Workspace does not contain a node without primary item defined");
}
try {
node.getPrimaryItem();
fail("getPrimaryItem() must throw a ItemNotFoundException " +
"if the primary node type does not define one");
} catch (ItemNotFoundException e) {
// success
}
}
代码示例来源:origin: org.exoplatform.jcr/exo.jcr.framework.command
/**
* traverses incoming node trying to find primary nt:resource node
*
* @param node
* @return nt:resource node
* @throws ItemNotFoundException
* if no such node found
* @throws RepositoryException
*/
public static Node getNtResourceRecursively(Node node) throws ItemNotFoundException, RepositoryException
{
if (node.isNodeType("nt:resource"))
return node;
Item pi = node.getPrimaryItem();
if (pi.isNode())
{
return getNtResourceRecursively((Node)pi);
}
throw new ItemNotFoundException("No nt:resource node found for " + node.getPath());
}
}
代码示例来源:origin: apache/jackrabbit
/**
* Test if getPrimaryItem returns the primary item as defined in the primary
* node type. Therefor a node with a primary item is located recursively in
* the entire repository. A NotExecutableException is thrown when no such
* node is found.
*/
public void testGetPrimaryItem()
throws NotExecutableException, RepositoryException {
Node node = locateNodeWithPrimaryItem(testRootNode);
if (node == null) {
throw new NotExecutableException("Workspace does not contain a node with primary item defined");
}
String primaryItemName = node.getPrimaryNodeType().getPrimaryItemName();
Item primaryItem = node.getPrimaryItem();
if (primaryItem.isNode()) {
assertTrue("Node returned by getPrimaryItem() is not the same as " +
"the one aquired by getNode(String)",
node.getNode(primaryItemName).isSame(primaryItem));
} else {
assertTrue("Property returned by getPrimaryItem() is not the same as " +
"the one aquired by getProperty(String)",
node.getProperty(primaryItemName).isSame(primaryItem));
}
}
代码示例来源:origin: ModeShape/modeshape
@FixFor( "MODE-1696" )
public void testShouldVerifyNtResourceNodesHavePrimaryItem() throws Exception {
Session session1 = getHelper().getSuperuserSession();
// Create node structure
Node root1 = getTestRoot(session1);
Node resource = root1.addNode("resource", "nt:resource");
Binary binary = session1.getValueFactory().createBinary(getClass().getResourceAsStream("/data/simple.json"));
resource.setProperty("jcr:data", binary);
session1.save();
// Find the primary item ...
resource = root1.getNode("resource");
Item primary = resource.getPrimaryItem();
assertNotNull(primary);
assertThat(resource.getProperty("jcr:data"), is(sameInstance(primary)));
}
代码示例来源:origin: apache/jackrabbit
/**
* Test if node.getPrimaryItemName() returns the same name as
* node.getPrimaryItem().getName()
*/
public void testGetPrimaryItemName()
throws NotExecutableException, RepositoryException {
Node node = locateNodeWithPrimaryItem(rootNode);
if (node == null) {
throw new NotExecutableException("Workspace does not contain a node with primary item defined");
}
String name = node.getPrimaryItem().getName();
NodeType type = node.getPrimaryNodeType();
assertEquals("node.getPrimaryNodeType().getPrimaryItemName() " +
"must return the same name as " +
"node.getPrimaryItem().getName()",
name, type.getPrimaryItemName());
}
代码示例来源:origin: ModeShape/modeshape
@Test
public void shouldFindMasterBranchAsPrimaryItemUnderTreeNode() throws Exception {
Node git = gitRemoteNode();
Node tree = git.getNode("tree");
Item primaryItem = tree.getPrimaryItem();
assertThat(primaryItem, is(notNullValue()));
assertThat(primaryItem, is(instanceOf(Node.class)));
Node primaryNode = (Node)primaryItem;
assertThat(primaryNode.getName(), is("master"));
assertThat(primaryNode.getParent(), is(sameInstance(tree)));
assertThat(primaryNode, is(sameInstance(tree.getNode("master"))));
}
代码示例来源:origin: ModeShape/modeshape
@Test
public void shouldFindMasterBranchAsPrimaryItemUnderBranchNode() throws Exception {
Node git = gitRemoteNode();
Node branches = git.getNode("branches");
Item primaryItem = branches.getPrimaryItem();
assertThat(primaryItem, is(notNullValue()));
assertThat(primaryItem, is(instanceOf(Node.class)));
Node primaryNode = (Node)primaryItem;
assertThat(primaryNode.getName(), is("master"));
assertThat(primaryNode.getParent(), is(sameInstance(branches)));
assertThat(primaryNode, is(sameInstance(branches.getNode("master"))));
}
代码示例来源:origin: ModeShape/modeshape
public void testShouldVerifyNtFileNodesHavePrimaryItem() throws Exception {
Session session1 = getHelper().getSuperuserSession();
// Create node structure
Node root1 = getTestRoot(session1);
Node folder1 = root1.addNode("folder1", "nt:folder");
String fileName = "simple.json";
String filePath = folder1.getPath() + "/" + fileName;
new JcrTools().uploadFile(session1, filePath, getClass().getResourceAsStream("/data/" + fileName));
session1.save();
// Find the primary item ...
Node file1 = folder1.getNode(fileName);
Node content = file1.getNode("jcr:content");
assertNotNull(file1);
Item primary = file1.getPrimaryItem();
assertThat(primary, is(sameInstance((Item)content)));
// Change the primary type of the "jcr:content" node to "nt:unstructured" ...
content.setPrimaryType("nt:unstructured");
session1.save();
// Find the primary item (again) ...
Node content2 = file1.getNode("jcr:content");
assertNotNull(file1);
Item primary2 = file1.getPrimaryItem();
assertThat(primary2, is(sameInstance((Item)content2)));
}
代码示例来源:origin: ModeShape/modeshape
@Test
public void shouldFindTreeBranchAsPrimaryItemUnderGitRoot() throws Exception {
Node git = gitRemoteNode();
Node tree = git.getNode("tree");
assertThat(tree, is(notNullValue()));
Item primaryItem = git.getPrimaryItem();
assertThat(primaryItem, is(notNullValue()));
assertThat(primaryItem, is(instanceOf(Node.class)));
Node primaryNode = (Node)primaryItem;
assertThat(primaryNode.getName(), is(tree.getName()));
assertThat(primaryNode.getParent(), is(sameInstance(git)));
assertThat(primaryNode, is(sameInstance(tree)));
}
内容来源于网络,如有侵权,请联系作者删除!