javax.jcr.Node.setPrimaryType()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(102)

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

Node.setPrimaryType介绍

[英]Changes the primary node type of this node to nodeTypeName. Also immediately changes this node's jcr:primaryType property appropriately. Semantically, the new node type may take effect immediately or on dispatch but must take effect on persist. The behavior adopted must be the same as the behavior adopted for #addMixin and the behavior that occurs when a node is first created.

If the presence of an existing property or child node would cause an incompatibility with the new node type then a ConstraintViolationException is thrown either immediately, on dispatch or on persist.

If the new node type would cause this node to be incompatible with the node type of its parent then a ConstraintViolationException is thrown either immediately, on dispatch or on persist.

A ConstraintViolationException is also thrown either immediately, on dispatch or on persist if a conflict with an already assigned mixin occurs.

A ConstraintViolationException may also be thrown either immediately , on dispatch or on persist if the attempted change violates implementation-specific node type transition rules. A repository that disallows all primary node type changes would simple throw this exception in all cases.

If the specified node type is not recognized a NoSuchNodeTypeException is thrown either immediately, on dispatch or on persist.

A VersionException is thrown either immediately , on dispatch or on persist if this node is read-only dues to a check-in.

A LockException is thrown either immediately, on dispatch or on persist if a lock prevents the change of node type.
[中]将此节点的主节点类型更改为nodeTypeName。还将立即适当更改此节点的jcr:primaryType属性。从语义上讲,新节点类型可以立即生效,也可以在分派时生效,但必须在持久化时生效。所采用的行为必须与#addMixin所采用的行为以及首次创建节点时发生的行为相同。
如果现有属性或子节点的存在会导致与新节点类型不兼容,则在分派或持久化时立即抛出ConstraintViolationException
如果新的节点类型会导致此节点与其父节点的节点类型不兼容,则会在分派或持久化时立即抛出ConstraintViolationException
如果与已分配的mixin发生冲突,则ConstraintViolationException也会立即、在分派时或在持久化时抛出。
如果尝试的更改违反了特定于实现的节点类型转换规则,则ConstraintViolationException也可以在分派时立即抛出,也可以在持久化时抛出。不允许所有主节点类型更改的存储库在所有情况下都会引发此异常。
如果指定的节点类型无法识别,NoSuchNodeTypeException将在分派或持久化时立即抛出。
如果由于签入,该节点是只读的,则会立即、在分派时或在持久化时抛出VersionException
如果锁阻止了节点类型的更改,则LockException会在分派时立即抛出,或在持久化时抛出。

代码示例

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

public Object run() throws RepositoryException {
    Node n = getNode(nodeId, sInfo);
    n.setPrimaryType(getJcrName(primaryNodeTypeName));
    return null;
  }
});

代码示例来源:origin: info.magnolia/magnolia-core

@Override
protected void operateOnNode(InstallContext installContext, Node node) {
  try {
    node.setPrimaryType(NodeTypes.ContentNode.NAME);
  } catch (RepositoryException e) {
    log.error("Failed to change primary node type from {} to {} of {}", NodeTypes.Content.NAME, NodeTypes.ContentNode.NAME, node);
  }
}

代码示例来源:origin: org.modeshape/modeshape-sequencer-xml

@Override
public void startDocument() throws SAXException {
  try {
    currentNode.setPrimaryType(XmlLexicon.DOCUMENT);
  } catch (RepositoryException e) {
    throw new SAXException(e);
  }
}

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

@Override
public void startDocument() throws SAXException {
  try {
    currentNode.setPrimaryType(XmlLexicon.DOCUMENT);
  } catch (RepositoryException e) {
    throw new SAXException(e);
  }
}

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

/**
 * Passing the current primary type to {@link Node#setPrimaryType(String)}
 * to a new node must always succeed.
 *
 * @throws RepositoryException
 */
public void testSetCurrentTypeOnNew() throws RepositoryException {
  Session session = testRootNode.getSession();
  Node node = testRootNode.addNode(nodeName1, testNodeType);
  node.setPrimaryType(testNodeType);
  superuser.save();
}

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

/** {@inheritDoc} */
public void setPrimaryType(String nodeTypeName) 
    throws RepositoryException, RemoteException {
  try {
    node.setPrimaryType(nodeTypeName);
  } catch (RepositoryException ex) {
    throw getRepositoryException(ex);
  }
}

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

private Node getMetadataNode( Node outputNode ) throws RepositoryException {
  if (outputNode.isNew()) {
    outputNode.setPrimaryType(METADATA_NODE);
    return outputNode;
  }
  return outputNode.addNode(METADATA_NODE, METADATA_NODE);
}

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

private Node getImageMetadataNode( Node outputNode ) throws RepositoryException {
  if (outputNode.isNew()) {
    outputNode.setPrimaryType(ImageMetadataLexicon.METADATA_NODE);
    return outputNode;
  }
  return outputNode.addNode(ImageMetadataLexicon.METADATA_NODE, ImageMetadataLexicon.METADATA_NODE);
}

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

private Node getMetadataNode( Node outputNode ) throws RepositoryException {
  if (outputNode.isNew()) {
    outputNode.setPrimaryType(OdfMetadataLexicon.METADATA_NODE);
    return outputNode;
  }
  return outputNode.addNode(OdfMetadataLexicon.METADATA_NODE, OdfMetadataLexicon.METADATA_NODE);
}

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

private Node getPdfMetadataNode( Node outputNode ) throws RepositoryException {
  if (outputNode.isNew()) {
    outputNode.setPrimaryType(PdfMetadataLexicon.METADATA_NODE);
    return outputNode;
  }
  return outputNode.addNode(PdfMetadataLexicon.METADATA_NODE, PdfMetadataLexicon.METADATA_NODE);
}

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

private static void setPrimaryType(Node n, Value[] values) throws RepositoryException, DiffException {
  if (values.length == 1) {
    String ntName = values[0].getString();
    if (!ntName.equals(n.getPrimaryNodeType().getName())) {
      n.setPrimaryType(ntName);
    } // else: same primaryType as before -> nothing to do.
  } else {
    throw new DiffException("Invalid diff: jcr:primarytype cannot have multiple values, nor can it's value be removed.");
  }
}

代码示例来源:origin: org.apache.sling/org.apache.sling.servlets.post

public void setPrimaryNodeType(final Object node, final String type)
throws PersistenceException {
  try {
    ((Node)node).setPrimaryType(type);
  } catch ( final RepositoryException re) {
    throw new PersistenceException(re.getMessage(), re);
  }
}

代码示例来源:origin: info.magnolia/magnolia-core

@Override
  protected void doExecute(InstallContext ctx) throws RepositoryException, TaskExecutionException {

    final Session session = ctx.getJCRSession(workspace);
    try {
      final Node node = session.getNode(nodePath);
      node.setPrimaryType(newType);
    } catch (RepositoryException e) {
      ctx.error("Could not change node type: ", e);
    }
  }
}

代码示例来源:origin: org.onehippo.cms7/hippo-repository-api

protected void setPrimaryType(final Node node, final NodeInfo nodeInfo) throws RepositoryException {
  if (!nodeInfo.getNodeTypeName().equals(node.getPrimaryNodeType().getName())) {
    node.setPrimaryType(nodeInfo.getNodeTypeName());
  }
}

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

@Test
public void testSetPrimaryType() throws Exception {
  Node child = (Node) superuser.getItem(childNode.getPath());
  String ntName = child.getPrimaryNodeType().getName();
  String changedNtName = "oak:Unstructured";
  child.setPrimaryType(changedNtName);
  testSession.save();
  modify(childNode.getPath(), Privilege.JCR_NODE_TYPE_MANAGEMENT, true);
  childNode.setPrimaryType(ntName);
  testSession.save();
}

代码示例来源:origin: info.magnolia/magnolia-core

@Test
public void testCollectAllChildrenDefaultPredicateFilterType() throws RepositoryException {
  // GIVEN
  second.setPrimaryType("toto:data");
  // WHEN
  Iterable<Node> res = NodeUtil.collectAllChildren(root);
  // THEN
  List<Node> resAsList = NodeUtil.asList(res);
  assertEquals("Should have 2 nodes  ", 2, resAsList.size());
}

代码示例来源:origin: info.magnolia/magnolia-core

@Test
public void testUUIDToBinaryIsEncoded() throws Exception {
  session.getNode("/parent/sub").setPrimaryType(NodeTypes.Resource.NAME);
  session.getNode("/parent/sub").setProperty("fileName", "name with spaces");
  Link link = LinkUtil.parseUUIDLink(UUID_PATTERN_BINARY);
  assertEquals(HREF_BINARY_ENCODED, NOP_TRANSFORMER.transform(link));
}

代码示例来源:origin: info.magnolia/magnolia-core

@Test
public void testUUIDToBinary() throws Exception {
  session.getNode("/parent/sub").setPrimaryType(NodeTypes.Resource.NAME);
  session.getNode("/parent/sub").setProperty("fileName", "test");
  Link link = LinkUtil.parseUUIDLink(UUID_PATTERN_BINARY);
  assertEquals(HREF_BINARY, NOP_TRANSFORMER.transform(link));
}

代码示例来源:origin: info.magnolia/magnolia-core

@Test
  public void testUUIDToBinaryAfterRenaming() throws Exception {
    // now rename the the page
    session.getNode("/parent/sub").setPrimaryType(NodeTypes.Resource.NAME);
    session.getNode("/parent/sub").setProperty("fileName", "test");
    MockNode renameNode = (MockNode) session.getNode("/parent/sub");
    renameNode.setName("subRenamed");

    Link link = LinkUtil.parseUUIDLink(UUID_PATTERN_BINARY);
    assertEquals(StringUtils.replace(HREF_BINARY, "sub", "subRenamed"), NOP_TRANSFORMER.transform(link));
  }
}

代码示例来源:origin: info.magnolia/magnolia-core

@Test
public void copyToVersionWhenChangingPrimaryNodeType() throws RepositoryException {
  // GIVEN
  Node node = websiteSession.getRootNode().addNode("test", NodeTypes.Content.NAME);
  copyUtil.copyToVersion(node, new RuleBasedNodePredicate(new Rule()));
  assertEquals(NodeTypes.Content.NAME, versionSession.getNode("/" + CopyUtil.getSavePath(node) + "/" + node.getIdentifier()).getPrimaryNodeType().getName());
  node.setPrimaryType(NodeTypes.Page.NAME);
  // WHEN
  copyUtil.copyToVersion(node, new RuleBasedNodePredicate(new Rule()));
  // THEN
  assertThat(versionSession.getRootNode(), hasNode(CopyUtil.getSavePath(node) + "/" + node.getIdentifier(), NodeTypes.Page.NAME));
}

相关文章

微信公众号

最新文章

更多