info.magnolia.cms.core.Path.getUniqueLabel()方法的使用及代码示例

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

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

Path.getUniqueLabel介绍

暂无

代码示例

代码示例来源:origin: net.sourceforge.openutils/openutils-mgnlutils

@SuppressWarnings("deprecation")
public static String getUniqueLabel(Node parent, String label)
{
  return Path.getUniqueLabel(info.magnolia.cms.util.ContentUtil.asContent(parent), label);
}

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

/**
 * Create a new Node Unique NodeName.
 */
private String generateUniqueNodeNameForContact(final Node node) throws RepositoryException {
  String newNodeName = defineNodeName(node);
  return Path.getUniqueLabel(node.getSession(), node.getParent().getPath(), newNodeName);
}

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

/**
 * Create a new Node Unique NodeName.
 */
public static String generateUniqueNodeNameForAsset(final Node node, String newNodeName) throws RepositoryException {
  return Path.getUniqueLabel(node.getSession(), node.getParent().getPath(), Path.getValidatedLabel(newNodeName));
}

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

protected String makeNameUnique(Content parent, String name) {
  return Path.getUniqueLabel(parent.getJCRNode(), cleanup(name));
}

代码示例来源:origin: info.magnolia/magnolia-module-inplace-templating

@Override
protected void setNodeName(Node node, JcrNodeAdapter item) throws RepositoryException {
  if (item.isNew()) {
    NodeUtil.renameNode(node, Path.getUniqueLabel(node.getSession(), node.getParent().getPath(), Path.getValidatedLabel(UNTITLED_TEMPLATE)));
  }
}

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

@Test
  public void getUniqueLabelWithExtension() throws Exception {
    Session session = new MockSession(RepositoryConstants.CONFIG);
    Node parent = session.getRootNode();
    parent.addNode("a.txt");
    parent.addNode("b.txt");
    parent.addNode("b0.txt");

    assertThat(Path.getUniqueLabel(session, parent.getPath(), "a.txt", "txt"), equalTo("a0.txt"));
    assertThat(Path.getUniqueLabel(session, parent.getPath(), "b.txt", "txt"), equalTo("b1.txt"));
    assertThat(Path.getUniqueLabel(session, parent.getPath(), "b0.txt", "txt"), equalTo("b1.txt"));
    assertThat(Path.getUniqueLabel(session, parent.getPath(), "c.txt", "txt"), equalTo("c.txt"));
    assertThat(Path.getUniqueLabel(session, parent.getPath(), "a.foo", "txt"), equalTo("a.foo"));
    assertThat(Path.getUniqueLabel(session, parent.getPath(), "a.txt", "bar"), equalTo("a.txt0"));
  }
}

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

@Test
public void getUniqueLabel() throws Exception {
  Session session = new MockSession(RepositoryConstants.CONFIG);
  Node parent = session.getRootNode();
  parent.addNode("a");
  parent.addNode("b");
  parent.addNode("b0");
  // from node
  assertThat(Path.getUniqueLabel(parent, "a"), equalTo("a0"));
  assertThat(Path.getUniqueLabel(parent, "b"), equalTo("b1"));
  assertThat(Path.getUniqueLabel(parent, "b0"), equalTo("b1"));
  assertThat(Path.getUniqueLabel(parent, "c"), equalTo("c"));
  // from session
  assertThat(Path.getUniqueLabel(session, parent.getPath(), "a"), equalTo("a0"));
  assertThat(Path.getUniqueLabel(session, parent.getPath(), "b"), equalTo("b1"));
  assertThat(Path.getUniqueLabel(session, parent.getPath(), "b0"), equalTo("b1"));
  assertThat(Path.getUniqueLabel(session, parent.getPath(), "c"), equalTo("c"));
}

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

/**
 *
 * @param label
 * @return unique label
 */
protected String getUniqueLabel(String label) {
  String slash = "/"; //$NON-NLS-1$
  boolean isRoot = false;
  if ("/".equals(getPath())) { //$NON-NLS-1$
    isRoot = true;
    slash = StringUtils.EMPTY;
  }
  if (getHierarchyManager().isExist(this.getPath() + slash + label)) {
    // todo: bugfix getUniqueLabel???
    if (isRoot) {
      label = Path.getUniqueLabel(getHierarchyManager(), StringUtils.EMPTY, label);
    } else {
      label = Path.getUniqueLabel(getHierarchyManager(), this.getPath(), label);
    }
  }
  return label;
}

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

/**
   * Insert unique increment before the extension in case of asset; primarily deduce reference name from the fileName property.
   */
  @Override
  protected String getUniqueNewItemName(Item referenceItem, Node destination) throws RepositoryException {
    if (referenceItem.isNode() && ((Node) referenceItem).isNodeType(Asset.NAME)) {
      Node resourceNode = AssetResource.getResourceNodeFromAsset(((Node) referenceItem));
      if (resourceNode != null) {
        String extension = PropertyUtil.getString(resourceNode, AssetResource.EXTENSION, EMPTY);
        String fileName = PropertyUtil.getString(resourceNode, AssetResource.FILENAME);
        String referenceName = (fileName != null && fileName.endsWith(extension)) ? fileName : fileName + "." + extension;
        return Path.getUniqueLabel(destination.getSession(), destination.getPath(), Path.getValidatedLabel(referenceName), extension);
      }
    }
    return super.getUniqueNewItemName(referenceItem, destination);
  }
}

代码示例来源:origin: net.sourceforge.openutils/openutils-mgnlutils

Path.getUniqueLabel(acls.getSession(), NodeUtil.getPathIfPossible(acls), "0"),
  MgnlNodeType.NT_CONTENTNODE);
setPermission(acl, path, newpermissions);

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

final String label = Path.getUniqueLabel(parentFolder.getSession(), parentFolder.getPath(), assetNode.getName(), extension);

代码示例来源:origin: net.sourceforge.openutils/openutils-mgnlmedia

label = Path.getUniqueLabel(session, parentPath, label);
goTo = parentPath + "/" + label; //$NON-NLS-1$

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

@Override
  public void execute(InstallContext ctx) throws TaskExecutionException {
    HierarchyManager hm = ctx.getConfigHierarchyManager();
    try {
      String nodePath = "/modules/cache/config/configurations/default/flushPolicy/policies/flushAll/repositories";
      if (!ctx.getModulesNode().hasContent("cache") || !hm.isExist(nodePath)) {
        // cache is not installed or other then default flush policy is used - ignore
        return;
      }
      Content c = hm.getContent(nodePath);
      // check if the workspace is not already registered manually by user. If so, just bail out, no need to punish users who registered workspaces previously themselves with the error message.
      Iterator iter = c.getNodeDataCollection().iterator();
      boolean found = false;
      while (iter.hasNext()) {
        if (this.workspaceName.equals(((NodeData) iter.next()).getString())) {
          found = true;
          break;
        }
      }
      if (!found) {
        c.createNodeData(Path.getUniqueLabel(c, "0"), this.workspaceName);
      }
    } catch (RepositoryException e) {
      throw new TaskExecutionException(e.getMessage(), e);
    }
  }
}

代码示例来源:origin: net.sourceforge.openutils/openutils-mgnlmedia

/**
 * {@inheritDoc}
 */
@Override
protected boolean onPreSave(SaveHandler control)
{
  try
  {
    Session hm = MgnlContext.getJCRSession(PlaylistConstants.REPO);
    Node c = hm.getNode(control.getPath());
    control.setNodeName(Path.getUniqueLabel(ContentUtil.asContent(c), "entry"));
  }
  catch (RepositoryException e)
  {
    log.error("error getting {}", control.getPath(), e);
    return false;
  }
  return super.onPreSave(control);
}

代码示例来源:origin: net.sourceforge.openutils/openutils-mgnlmedia

return false;
control.setNodeName(Path.getUniqueLabel(
  c,
  Path.getValidatedLabel(Components

代码示例来源:origin: net.sourceforge.openutils/openutils-mgnlmedia

String uniqueLabel = Path.getUniqueLabel(c, validatedlabel);

代码示例来源:origin: net.sourceforge.openutils/openutils-mgnlmedia

Content paramNode = node.createContent(Path.getUniqueLabel(node, "0"), ItemType.CONTENTNODE);
paramNode.setNodeData("name", StringUtils.removeStart(paramName, name + "."));
Value[] jcrValues = new Value[paramValues.length];

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

/**
 * Adds multi value type.
 * @param node Parent node.
 * @param name Name of the value node.
 * @param value Value.
 * @param itemType Item type of newly created node.
 * @return Newly created multi value node.
 * @throws RepositoryException When node can't be created or saved.
 * @see MULTI_VALUE_ITEM_TYPE
 */
public static Content addMultiValue(Content node, String name, Value value, ItemType itemType)
  throws RepositoryException {
  Content multiNode = ContentUtil.getOrCreateContent(node, name, new ItemType(
    DataConsts.MODULE_DATA_CONTENT_NODE_TYPE));
  String valueNodeName = StringUtils.left(
    Path.getValidatedLabel(NodeDataUtil.getValueString(value, "YYYYmmDD")),
    20);
  valueNodeName = Path.getUniqueLabel(node, valueNodeName);
  Content valueNode = multiNode.createContent(valueNodeName, itemType);
  NodeDataUtil.getOrCreate(valueNode, name).setValue(value);
  return valueNode;
}

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

@Override
public Content createForum(String name, String title, boolean withMessageNesting) throws RepositoryException {
  final HierarchyManager hm = getHierarchyManager();
  final String cleanName = Path.getUniqueLabel(hm.getWorkspace().getSession(), "/", cleanup(name));
  final Content repoRoot = hm.getRoot();
  final Content newForum = repoRoot.createContent(cleanName, FORUM_NODETYPE);
  newForum.createNodeData("title", title);
  newForum.setNodeData(ALLOWS_NESTING_MESSAGES, withMessageNesting);
  repoRoot.save();
  if (config.isCreateRolesForNewForums()) {
    createForumRoles(newForum);
  }
  return newForum;
}

相关文章

微信公众号

最新文章

更多