首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >组件的Adobe () HTL2HTML

组件的Adobe () HTL2HTML
EN

Stack Overflow用户
提问于 2018-11-13 20:15:30
回答 1查看 463关注 0票数 0

Adobe () HTL2HTML编译和测试(AEM6.1很快将移至6.3)

我希望从HTL组件中自动生成HTML,作为构建过程的一部分(使用默认值/自定义值),这样我就可以提供额外的自动化测试和质量保证。即HTML验证和可访问性QA。

是否有一个java调用或其他命令行工具可以为每个组件生成html片段或页面。当调用mvn干净安装-PautoInstallPackage时,可以将其合并到构建过程中。

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

谢谢你的帮忙

麦克

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-14 05:56:10

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

来自@nateyolles 博客帖子

为Apache .中的资源获取HTML

代码语言:javascript
复制
@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

代码语言:javascript
复制
@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();
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53288821

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档