aem - CQ API 中是否有任何内容允许您从 cq :component? 创建节点

标签 aem

我很好奇 CQ API 中是否有允许我基于 cq:component 创建节点的内容。 ,就像作者将组件添加到 parsys 时会发生的情况一样。

因为我需要完成这件作品,所以我继续手动完成。我已经包含了这个解决方案,看看是否有人可以去“哦,伙计,你可以用这个 .* 方法来做到这一点”。

这就是我正在做的:

public static Node createFromComponent(Node dstParent, Node srcComponent, String targetName) {
    Node newNode = null;

    try {
        //if there is a template use it
        if (srcComponent.hasNode("cq:template")) {
            newNode = JcrUtil.copy(srcComponent.getNode("cq:template"), dstParent, targetName);
        }
        else {
            newNode = dstParent.addNode(targetName);
        }

        //set the resourceType to the path of the component sent over
        newNode.setProperty("sling:resourceType", srcComponent.getPath());

        newNode.getSession().save();
    }
    catch(Exception e) {
        LOGGER.error("Error creating node from component: ", e);
    }

    return newNode;
}

这很直接。我在看 JcrUtil Class ,但我认为它没有我要找的东西。

最佳答案

不幸的是,没有一个内置方法:

  • 复制 cq:template 的内容节点或
  • 创建一个新节点,
  • 设置一个 sling:resourceType节点的属性。

  • 当您将组件从 sidekick 拖到 parsys 时,您的浏览器会向 Sling 发送 HTTP POST 请求。如果目标组件包含 cq:template子节点,此 HTTP 请求将包含一个附加属性:
    ./@CopyFrom:/apps/my/component/cq:template
    

    它负责设置默认值。因为您想通过 API 而不是 HTTP 请求来做同样的事情,所以您需要一个自定义方法。

    关于aem - CQ API 中是否有任何内容允许您从 cq :component? 创建节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23482515/

    相关文章:

    aem - 视力/HTL/AEM : using "tel:" on an href parameter (a tag) doesn't work

    java - 用户在 aem 中调用 API 时需要输入密码

    css - CQ5 parsys 即使在预览模式下也会留下一些空间?

    internationalization - 我可以得到特定词典的整个 i18n 标签吗

    osgi - 如何添加cq :listener to a component

    java - OSGI组件初始化顺序可选贪婪

    osgi - 哪个版本的 AEM 支持 .cfg.json 配置文件?

    aem - 如何在 Excel 中导出 AEM 报告?

    osgi - Day CQ 邮件服务配置不起作用

    java - 如何在aem6.2中以编程方式创建具有ACL权限的用户和组?