javax.jcr.Session.getItem()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(161)

本文整理了Java中javax.jcr.Session.getItem()方法的一些代码示例,展示了Session.getItem()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Session.getItem()方法的具体详情如下:
包路径:javax.jcr.Session
类名称:Session
方法名:getItem

Session.getItem介绍

[英]Returns the node at the specified absolute path in the workspace. If no such node exists, then it returns the property at the specified path.

This method should only be used if the application does not know whether the item at the indicated path is property or node. In cases where the application has this information, either #getNode or #getProperty should be used, as appropriate. In many repository implementations the node and property-specific methods are likely to be more efficient than getItem.
[中]返回工作区中指定绝对路径处的节点。如果不存在这样的节点,则返回指定路径上的属性。
仅当应用程序不知道指定路径中的项是属性还是节点时,才应使用此方法。如果应用程序包含此信息,则应酌情使用#getNode或#getProperty。在许多存储库实现中,特定于节点和属性的方法可能比getItem更有效。

代码示例

代码示例来源:origin: apache/jackrabbit

/**
 * Tests if the primary node type is properly stored in jcr:primaryType
 */
public void testPrimaryType() throws Exception {
  // get default workspace test root node using superuser session
  Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
  Node testNode = defaultRootNode.addNode(nodeName1, testNodeType);
  assertEquals("The primary node type is not properly stored in jcr:primaryType",testNodeType,testNode.getProperty(jcrPrimaryType).getString());
}

代码示例来源:origin: apache/jackrabbit

/**
 * Test if Item.isNew() returns false after a NodeItem is added and
 * the node is saved (persistent).
 *
 * @see javax.jcr.Item#isNew()
 */
public void testPersistentNodeItemIsNew () throws RepositoryException {
  Node testNode = testRootNode.addNode(nodeName1, testNodeType);
  testRootNode.getSession().save();
  Item testNodeItem = superuser.getItem(testNode.getPath());
  // check testNodeItem is new after save
  assertFalse("Item.isNew() must return false after a new NodeItem is added and the parent Node is saved", testNodeItem.isNew());
}

代码示例来源:origin: ModeShape/modeshape

private List<RestItem> updateMultipleNodes( HttpServletRequest request,
                      Session session,
                      TreeMap<String, JSONObject> nodesByPath )
  throws RepositoryException, JSONException {
  List<RestItem> result = new ArrayList<RestItem>();
  for (String nodePath : nodesByPath.keySet()) {
    Item item = session.getItem(nodePath);
    item = updateItem(item, nodesByPath.get(nodePath));
    result.add(createRestItem(request, 0, session, item));
  }
  session.save();
  return result;
}

代码示例来源:origin: apache/jackrabbit

public void testMoveNode() throws Exception {
  Node n = (Node) readOnlySession.getItem(testNodePath);
  String destPath = testRootNode.getPath() + "/" + nodeName2;
  try {
    readOnlySession.move(n.getPath(), destPath);
    readOnlySession.save();
    fail("A read only session must not be allowed to move a node");
  } catch (AccessDeniedException e) {
    // expected
    log.debug(e.getMessage());
  }
}

代码示例来源:origin: apache/jackrabbit

public void testWorkspaceMoveNode() throws Exception {
  Node n = (Node) readOnlySession.getItem(testNodePath);
  String destPath = testRootNode.getPath() + "/" + nodeName2;
  try {
    readOnlySession.getWorkspace().move(n.getPath(), destPath);
    fail("A read only session must not be allowed to move a node");
  } catch (AccessDeniedException e) {
    // expected
    log.debug(e.getMessage());
  }
}

代码示例来源:origin: brix-cms/brix-cms

@Override
protected synchronized void setAttribute(String workspaceId, String attributeKey, String attributeValue)
    throws RepositoryException {
  if (!availableWorkspaceNames.contains(workspaceId)) {
    throw new IllegalStateException("Trying to set attribute of workspace " + workspaceId
        + " that doesn't exist or was removed.");
  }
  Session session = getSession(workspaceId);
  Node node = (Node) session.getItem(NODE_PATH);
  Node properties;
  if (!node.hasNode(PROPERTIES_NODE)) {
    properties = node.addNode(PROPERTIES_NODE, "nt:unstructured");
  } else {
    properties = node.getNode(PROPERTIES_NODE);
  }
  properties.setProperty(attributeKey, attributeValue);
  node.getSession().save();
  setCachedAttribute(workspaceId, attributeKey, attributeValue);
}

代码示例来源:origin: org.exoplatform.jcr/exo.jcr.framework.command

public boolean execute(Context context) throws Exception
{
 Session session = ((JCRAppContext)context).getSession();
 Node parentNode = (Node)session.getItem((String)context.get(currentNodeKey));
 String relPath = (String)context.get(pathKey);
 if (context.containsKey(nodeTypeKey))
   context.put(resultKey, parentNode.addNode(relPath, (String)context.get(nodeTypeKey)));
 else
   context.put(resultKey, parentNode.addNode(relPath));
 return true;
}

代码示例来源:origin: apache/jackrabbit

/**
 * Creates a new node using {@link Node#addNode(String, String)}, saves using
 * {@link javax.jcr.Session#save()}. Uses a second session to verify if the
 * node has been safed.
 */
public void testAddNodeSessionSave() throws RepositoryException {
  // get default workspace test root node using superuser session
  Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
  // add node
  Node testNode = defaultRootNode.addNode(nodeName1, testNodeType);
  // save new node
  superuser.save();
  // use a different session to verify if the node is there
  Session session = getHelper().getReadOnlySession();
  try {
    session.getItem(testNode.getPath());
  } finally {
    session.logout();
  }
}

代码示例来源:origin: apache/jackrabbit

/**
 * Tests if jcr:primaryType is protected
 */
public void testPrimaryTypeProtected() throws Exception {
  // get default workspace test root node using superuser session
  Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
  Node testNode = defaultRootNode.addNode(nodeName1, testNodeType);
  try {
    testNode.setProperty(jcrPrimaryType,ntBase);
    fail("Manually setting jcr:primaryType should throw a ConstraintViolationException");
  }
  catch (ConstraintViolationException success) {
    // ok
  }
}

代码示例来源:origin: apache/jackrabbit

public void testShallowHoldForOtherSession() throws RepositoryException, NotExecutableException {
  retentionMgr.addHold(testNodePath, getHoldName(), false);
  superuser.save();
  
  // check for other session
  assertNoEffect((Node) otherS.getItem(childN.getPath()), nodeName3, propertyName2);
  assertEffect((Node) otherS.getItem(testNodePath), childN.getName(), childP.getName(), nodeName3, propertyName2);
}

代码示例来源:origin: apache/jackrabbit

public void testCopyNode() throws Exception {
    Node n = (Node) readOnlySession.getItem(testNodePath);
    String destPath = testRootNode.getPath() + "/" + nodeName2;
    try {
      readOnlySession.getWorkspace().copy(n.getPath(), destPath);
      fail("A read only session must not be allowed to copy a node");
    } catch (AccessDeniedException e) {
      // expected
      log.debug(e.getMessage());
    }
  }
}

代码示例来源:origin: pentaho/pentaho-platform

public Node createAuthzFolderNode( final Session session, final PentahoJcrConstants pentahoJcrConstants,
  final ITenant tenant ) throws RepositoryException {
 Node tenantRootFolderNode = null;
 try {
  tenantRootFolderNode = (Node) session.getItem( ServerRepositoryPaths.getTenantRootFolderPath( tenant ) );
 } catch ( PathNotFoundException e ) {
  Assert.state( false, Messages.getInstance().getString(
    "JcrRoleAuthorizationPolicyRoleBindingDao.ERROR_0002_REPO_NOT_INITIALIZED" ) ); //$NON-NLS-1$
 }
 Node authzFolderNode =
   tenantRootFolderNode.addNode( FOLDER_NAME_AUTHZ, pentahoJcrConstants.getPHO_NT_INTERNALFOLDER() );
 session.save();
 return authzFolderNode;
}

代码示例来源:origin: apache/jackrabbit

public void testDeleteNode() throws Exception {
  Node n = (Node) readOnlySession.getItem(testNodePath);
  try {
    n.remove();
    readOnlySession.save();
    fail("A read only session must not be allowed to remove a node");
  } catch (AccessDeniedException e) {
    // success
  }
}

代码示例来源:origin: apache/jackrabbit

public void testIsSameProperty() throws RepositoryException {
  Node n = testRootNode.addNode(nodeName1, testNodeType);
  Property p = n.setProperty(propertyName1, "anyvalue");
  testRootNode.save();
  // access same property through different session
  Session otherSession = getHelper().getReadOnlySession();
  try {
    Property otherProperty = (Property) otherSession.getItem(p.getPath());
    assertTrue(p.isSame(otherProperty));
  } finally {
    otherSession.logout();
  }
}

代码示例来源:origin: apache/jackrabbit

/**
 * Creates a new node using {@link Node#addNode(String)} , saves using
 * {@link javax.jcr.Session#save()}. Uses a second session to verify if the
 * node has been saved.
 */
public void testAddNodeSessionSave() throws RepositoryException {
  // get default workspace test root node using superuser session
  Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
  // add a node
  Node testNode = defaultRootNode.addNode(nodeName1, testNodeType);
  // save new nodes
  superuser.save();
  // use a different session to verify if the node is there
  Session session = getHelper().getReadOnlySession();
  try {
    testNode = (Node) session.getItem(testNode.getPath());
  } finally {
    session.logout();
  }
}

代码示例来源:origin: apache/jackrabbit

/**
 * Adds a new node using {@link javax.jcr.Node#addNode(String)} with an
 * index for the new name.
 * <p>This should throw an {@link RepositoryException}.
 */
public void testAddNodeRepositoryExceptionRelPathIndex() throws RepositoryException {
  // get default workspace test root node using superuser session
  Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
  try {
    // use invalid relPath
    defaultRootNode.addNode(nodeName1 + "[1]", testNodeType);
    fail("Creating a node with index as postfix for new name should throw RepositoryException");
  } catch (RepositoryException e) {
    // ok, works as expected
  }
}

代码示例来源:origin: apache/jackrabbit

public void testRemoveLockedChild() throws RepositoryException {
    Session otherSession = getHelper().getReadWriteSession();
    try {
      Node child = (Node) otherSession.getItem(childNode.getPath());
      child.remove();
      otherSession.save();
      fail("A node below a deeply locked node cannot be removed by another Session.");
    } catch (LockException e) {
      // success
    } finally {
      otherSession.logout();
    }
  }
}

代码示例来源:origin: apache/jackrabbit

public void testTransientShallowHoldForOtherSession() throws RepositoryException, NotExecutableException {
  retentionMgr.addHold(testNodePath, getHoldName(), false);
  assertNoEffect((Node) otherS.getItem(testNodePath), nodeName3, propertyName2);
  assertNoEffect((Node) otherS.getItem(childN.getPath()), nodeName3, propertyName2);
  assertNoEffect((Property) otherS.getItem(childP.getPath()));
}

代码示例来源:origin: pentaho/pentaho-platform

protected Node getOrCreateLockTokensNode( final Session session, final PentahoJcrConstants pentahoJcrConstants,
  final Lock lock ) throws RepositoryException {
 String absPath =
   ServerRepositoryPaths.getUserHomeFolderPath( userNameUtils.getTenant( getLockOwner( session,
     pentahoJcrConstants, lock ) ), userNameUtils.getPrincipleName( getLockOwner( session, pentahoJcrConstants,
     lock ) ) );
 Node userHomeFolderNode = (Node) session.getItem( absPath );
 if ( userHomeFolderNode.hasNode( FOLDER_NAME_LOCK_TOKENS ) ) {
  return userHomeFolderNode.getNode( FOLDER_NAME_LOCK_TOKENS );
 } else {
  Node lockTokensNode =
    userHomeFolderNode.addNode( FOLDER_NAME_LOCK_TOKENS, pentahoJcrConstants.getPHO_NT_INTERNALFOLDER() );
  session.save();
  return lockTokensNode;
 }
}

代码示例来源:origin: apache/jackrabbit

public void testDeleteProperty() throws Exception {
  Property p = (Property) readOnlySession.getItem(testPropertyPath);
  try {
    p.remove();
    readOnlySession.save();
    fail("A read only session must not be allowed to remove a property.");
  } catch (AccessDeniedException e) {
    // success
  }
}

相关文章

微信公众号

最新文章

更多