CQ5 aka AEM - 以编程方式查找复制页面的来源

CQ5 aka AEM - Finding the source of a copied page programmatically

我目前正在探索 AEM,想知道是否可以识别页面的 "source"。澄清我的意思:

如果您使用 CQ5 WCM 中的 "Copy" 和 "Paste" 选项复制页面(不是实时副本,只是页面的普通副本)是否可以通过编程方式确定哪个页面您的新页面基于,即您复制了哪个页面来创建新页面?

您可以查找具有相同名称 (startsWith(...)) 和相同 ResourceType 的页面。但据我所知,一旦页面被粘贴 - 就没有与 "source" 页面的连接。 此外,您可以比较页面内容资源(jcr:content 节点)的子项的名称

我宁愿从不同的角度来处理。当您复制页面时,它们之间没有任何关系或引用。但是,您可以自己准备这样的机制。这可以按如下方式工作:

首先,你需要实现过滤器,它会拦截每个请求。

负责在 WCM 中创建新页面的请求表单如下所示:

cmd:copyPage
_charset_:utf-8
srcPath:/content/src
destParentPath:/content/dest
before:

然后 Filter,将捕获复制请求应该是这样的:

@Component(immediate = true)
@Service
@Properties({ @Property(name = "filter.scope", value = "REQUEST") })
public class CopyPageFilter implements Filter {

    private static final String WCM_COMMAND_SERVLET = "/bin/wcmcommand";

    private static final String CMD = "cmd";

    private static final String COPY_PAGE = "copyPage";

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        if (isValid((SlingHttpServletRequest) request)) {
            // store the src-dst for a while
        } else {
            chain.doFilter(request, response);
        }
    }

    private boolean isValid(SlingHttpServletRequest request) {
        return WCM_COMMAND_SERVLET.equals(request.getPathInfo())
                && COPY_PAGE.equals(request.getParameter(CMD));
    }

    @Override
    public void init(FilterConfig config) throws ServletException {
        // nothing to initialize
    }

    @Override
    public void destroy() {
        // nothing to destroy
    }

}

它将允许您临时存储源和目标之间的关系。下一步是实施 SlingPostProcessor,它将在新创建的页面中存储有关源的信息。

@Component(immediate = true)
@Service
public class BootstrapGridPostProcessorService implements SlingPostProcessor {

    @Reference
    private CopyPageFilter copyPageFilter;

    @Override
    public void process(SlingHttpServletRequest request, List<Modification> modifications)
            throws RepositoryException {
        // 1. Check if this modification is a page creation
        // 2. Check if in CopyPageFilter we have info about source for our destination
        // 3. To the newly created page add a weak reference (uuid) or path to the source
    }

}

就是这样。我们添加了可以进一步使用的复制页面之间的关系。

重要 我很确定在 Touch UI 中还有另一个 servlet 负责创建页面。因此,您的 Filter 应该考虑到这一点。