如何在吊索重写管道中配置变压器?

编程入门 行业动态 更新时间:2024-10-25 08:24:53
本文介绍了如何在吊索重写管道中配置变压器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想为我们网站上的每个 <a> 标签设置目标,但我没有编辑组件,而是编写了一个转换器.我该如何配置它?

I want to set targets to every <a>-tag on our site but instead of editing the components, I wrote a transformer. How can I configure it?

我们已经有了变压器和相应的工厂.该工厂属于管道类型 content-fragments 并根据 文档:

We already have a transformer and a corresponding factory. The factory is of pipeline type content-fragments and registered in a configuration file as per the documentation:

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp/jcr/1.0" xmlns:nt="http://www.jcp/jcr/nt/1.0"
          jcr:primaryType="nt:unstructured"
          contentTypes="text/html"
          enabled="{Boolean}true"
          generatorType="htmlparser"
          order="1000"
          paths="[/content]"
          serializerType="htmlwriter"
          transformerTypes="[link-transformer,content-fragments,linkchecker]">
    <generator-htmlparser
        jcr:primaryType="nt:unstructured"
        includeTags="[A]"/>
</jcr:root>

我都尝试为新转换器提供相同的管道类型和新的管道类型 linktransformer,并尝试了以下每种组合:

I both tried to give the new transformer the same pipeline type and a new pipeline type, linktransformer, and tried each of the following combinations:

transformerTypes="[link-transformer, content-fragments,linkchecker]"transformerTypes="[content-fragments,linkchecker]"

该配置在 Sling Rewriter Console 中处于活动状态:

The configuration is active in the Sling Rewriter Console:

Configuration content-fragments-rewrite

Name : content-fragments-rewrite
Content Types : [text/html]
Paths : [/content]
Order : 1000
Active : true
Valid : true
Process Error Response : true
Pipeline : 
    Generator : 
        htmlparser : {includeTags=[Ljava.lang.String;@23d079e2}
    Transformers : 
        link-transformer
        content-fragments
        linkchecker
    Serializer : 
        htmlwriter

但管道不会在发布者和作者实例上转换 HTML.

but neither does the pipeline transform the HTML on the publisher nor on the author instance.

这是旧变压器:

@Component(
    property = "pipeline.type=" + ContentFragmentLinkTransformerFactory.PIPELINE_TYPE,
    service = TransformerFactory.class
)
public class ContentFragmentLinkTransformerFactory implements TransformerFactory {

    public static final String PIPELINE_TYPE = "content-fragments";

    @Override
    public Transformer createTransformer() {
        return new ContentFragmentLinkTransformer();
    }

}

和新的:

@Component(
    property = "pipeline.type=" + LinkTransformerFactory.PIPELINE_TYPE,
    service = TransformerFactory.class
)
public class LinkTransformerFactory implements TransformerFactory {

    public static final String PIPELINE_TYPE = "link-transformer";

    @Override
    public Transformer createTransformer() {
        return new LinkTransformer();
    }

}

我在 createTransforemer() 方法和转换器的 startElement() 方法中都设置了断点,但是在这两个实例中,程序在调试时都不会停止.我还尝试添加一个 activate 方法,在该方法中我在程序确实按预期停止的地方放置了一个断点.

I put breakpoints into both of the createTransforemer() methods as well as the transformers' startElement() method but on neither of the instances does the program halt when debugging. I also tried to add an activate method into which I put a breakpoint where the program did indeed halt as expected.

我希望转换器转换发布者的 HTML.

I expect the transformer to transform the publisher HTML.

推荐答案

我们的问题是我们有另一个具有更高order的重写器配置:

Our problem was that we had another rewriter config with a higher order:

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp/jcr/1.0" xmlns:nt="http://www.jcp/jcr/nt/1.0"
    jcr:primaryType="nt:unstructured"
    contentTypes="[text/html]"
    enabled="{Boolean}true"
    generatorType="htmlparser"
    order="1001"
    serializerType="htmlwriter"
    transformerTypes="[linkchecker,versioned-clientlibs]">
    <transformer-mobile
        jcr:primaryType="nt:unstructured"
        component-optional="{Boolean}true"/>
    <transformer-mobiledebug
        jcr:primaryType="nt:unstructured"
        component-optional="{Boolean}true"/>
    <transformer-contentsync
        jcr:primaryType="nt:unstructured"
        component-optional="{Boolean}true"/>
</jcr:root>

快速解决方法是将这两个配置合并为一个:

The quick fix was to merge these two configs into one:

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp/jcr/1.0" xmlns:nt="http://www.jcp/jcr/nt/1.0"
          jcr:primaryType="nt:unstructured"
          contentTypes="text/html"
          enabled="{Boolean}true"
          generatorType="htmlparser"
          order="1010"
          paths="[/content]"
          serializerType="htmlwriter"
          transformerTypes="[linkchecker,link-transformer,versioned-clientlibs]">
    <transformer-mobile
        jcr:primaryType="nt:unstructured"
        component-optional="{Boolean}true"/>
    <transformer-mobiledebug
        jcr:primaryType="nt:unstructured"
        component-optional="{Boolean}true"/>
    <transformer-contentsync
        jcr:primaryType="nt:unstructured"
        component-optional="{Boolean}true"/>
    <generator-htmlparser
        jcr:primaryType="nt:unstructured"
        includeTags="[A,LINK,SCRIPT]"/>
</jcr:root>

此外,我在转换器中添加了一个检查以仅转换 -tags.

Furthermore, I added a check to the transformer to transform only <a>-tags.

这篇关于如何在吊索重写管道中配置变压器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 08:01:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1038466.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:吊索   重写   变压器   道中   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!