Expand my Community achievements bar.

SOLVED

Is there a way to skip the pipelines in sling rewriter?

Avatar

Level 9

I have five custom pipelines configured for html generator based on  Apache Sling - Output Rewriting Pipelines (org.apache.sling.rewriter) . Is there a way for any running pipeline to remove events programmatically so that does not pass on the events for rest of remaining pipelines?

cc: justinediener  justinpJorg

1 Accepted Solution

Avatar

Correct answer by
Employee

I don't think you are using the terminology correctly. For a single request, only a single pipeline will be used, so there are no 'remaining' pipelines.

I suspect what you mean to ask if whether a component within a pipeline can remove events so that they are not passed to subsequent components within the pipeline. If so, the answer is yes. Just don't call the corresponding SAX method on the next component. acs-aem-commons/StylesheetInlinerTransformerFactory.java at master · Adobe-Consulting-Services/acs-a...  is an example of such selective execution. When a <link> element is found inside the <head> element, it is effectively skipped until the the </head> element has been hit, at which point the stylesheet is inlined (before outputting </head>).

View solution in original post

4 Replies

Avatar

Correct answer by
Employee

I don't think you are using the terminology correctly. For a single request, only a single pipeline will be used, so there are no 'remaining' pipelines.

I suspect what you mean to ask if whether a component within a pipeline can remove events so that they are not passed to subsequent components within the pipeline. If so, the answer is yes. Just don't call the corresponding SAX method on the next component. acs-aem-commons/StylesheetInlinerTransformerFactory.java at master · Adobe-Consulting-Services/acs-a...  is an example of such selective execution. When a <link> element is found inside the <head> element, it is effectively skipped until the the </head> element has been hit, at which point the stylesheet is inlined (before outputting </head>).

Avatar

Level 9

Thanks for feedback justin_at_adobe & attempt to suspect the requirement. Also sorry the terminology was not correct.   Thanks for StylesheetInliner sample, Sounds not meet my requirement & will look into it.  Let me repharse with example for more clarity & is the solution proposed earlier will still work?

We have few transformer configured [1] like

  1. linkchecker :-  to validate  the href in anchor is valid
  2. externalnofollow:-   to retain seo on some of external link adding the attribute rel=nofollow
  3. external-tab:-  We have few business rules to open some of link in new tab.
  4. link-rewrite:-  to shortcut url & to remove .html .  (Not using jcr resolver for this)
  5. ......

The update is all links happening in the above order.  I was looking on some business rule at 3(external-tab) not to proceed with other transformer like link-rewrite....   

[1]

<?xml version="1.0" encoding="UTF-8"?>

<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"

    jcr:primaryType="nt:unstructured"

    contentTypes="[text/html]"

    enabled="{Boolean}true"

    generatorType="htmlparser"

    order="5"

    serializerType="htmlwriter"

    transformerTypes="[linkchecker,externalnofollow,external-tab,link-rewrite,mobile,mobiledebug]">

    <transformer-mobile

        jcr:primaryType="nt:unstructured"

        component-optional="{Boolean}true"/>

    <transformer-mobiledebug

        jcr:primaryType="nt:unstructured"

        component-optional="{Boolean}true"/>

</jcr:root>

Avatar

Employee

Ah, I see what you mean now. No, there's no standard approach to do this. If the transformers are all involved are under your control, however, you could accomplish this by sharing some state between the transformers, e.g. set some request attribute in external-tab and then have link-rewrite look at that request attribute to decide whether or not to do any rewriting.

Avatar

Level 9

Thanks justin_at_adobe​ .    Unfortunately all transformer are not under my control & developed by different vendor making more challenge. But you gave me a great clue & should help us.  Once again thanks a lot for timely help.