【问题标题】:Adobe AEM (Adobe Experience Manager) HTL2HTML for components用于组件的 Adob​​e AEM (Adobe Experience Manager) HTL2HTML
【发布时间】:2019-04-16 17:56:35
【问题描述】:

Adobe AEM (Adobe Experience Manager) HTL2HTML 编译和测试 (AEM 6.1 即将迁移到 6.3)

我想从 HTL 组件自动生成 HTML 作为构建过程的一部分(使用默认/自定义值) 所以我可以提供额外的自动化测试和质量保证。 即 HTML 验证和辅助功能 QA。

是否有 java 调用或其他命令行工具可以为每个组件生成 html sn-ps 或页面。 调用时可以将其合并到构建过程中 mvn clean install -PautoInstallPackage

我曾考虑使用 selenium 生成页面,但我怀疑这种方法速度慢且容易出错。

感谢您的帮助

迈克

【问题讨论】:

    标签: aem


    【解决方案1】:

    您可以使用SlingRequestProcessor 在服务器端获取呈现的 HTML。

    来自@nateyolles blog post

    在 Apache Sling 中获取资源的 HTML 标记。

    @SlingServlet(paths={"/bin/foo"})
    public class SlingResourceResolutionServlet extends SlingSafeMethodsServlet {
    
        /** Service to process requests through Sling */
        @Reference
        private SlingRequestProcessor requestProcessor;
    
        @Override
        protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
    
            /* The resource path to resolve. Use any selectors or extension. */
            String requestPath = "/content/myapp/us/en/index/jcr:content/myparsys/mycomponent_f93d.html";
    
            /* 
             * Create a fake request and fake response. The response adds a method to make the HTML accessible.
             * You need the following three files from Apache Sling:
             *
             * https://github.com/apache/sling/blob/trunk/testing/junit/scriptable/src/main/java/org/apache/sling/junit/scriptable/HttpRequest.java
             * https://github.com/apache/sling/blob/trunk/testing/junit/scriptable/src/main/java/org/apache/sling/junit/scriptable/HttpResponse.java
             * https://github.com/apache/sling/blob/trunk/testing/junit/scriptable/src/main/java/org/apache/sling/junit/scriptable/TestServletOutputStream.java
             */
            final HttpRequest req = new HttpRequest(requestPath);
            final HttpResponse resp = new HttpResponse();
    
            /* Process request through Sling */
            requestProcessor.processRequest(req, resp, request.getResourceResolver());
            String html = resp.getContent();
        }
    

    在 AEM 中获取资源的 HTML 标记。

    @SlingServlet(paths={"/bin/foo"})
    public class AemResourceResolutionServlet extends SlingSafeMethodsServlet {
    
        /** Service to create HTTP Servlet requests and responses */
        @Reference
        private RequestResponseFactory requestResponseFactory;
    
        /** Service to process requests through Sling */
        @Reference
        private SlingRequestProcessor requestProcessor;
    
        @Override
        protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
    
            /* The resource path to resolve. Use any selectors or extension. */
            String requestPath = "/content/myapp/us/en/index/jcr:content/myparsys/mycomponent_f93d.html";
    
            /* Setup request */
            HttpServletRequest req = requestResponseFactory.createRequest("GET", requestPath);
            WCMMode.DISABLED.toRequest(req);
    
            /* Setup response */
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            HttpServletResponse resp = requestResponseFactory.createResponse(out);
    
            /* Process request through Sling */
            requestProcessor.processRequest(req, resp, request.getResourceResolver());
            String html = out.toString();
        }
    }
    

    【讨论】:

    • 谢谢 - 我会试一试
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    相关资源
    最近更新 更多