How to handle the content with a Non-breaking hypen for example company name like V-John | Community
Skip to main content
airnavin30
Level 2
September 19, 2020
Solved

How to handle the content with a Non-breaking hypen for example company name like V-John

  • September 19, 2020
  • 1 reply
  • 944 views

I have a issue related to one name display in a content while authoring or rendering like for a company name like V-John,

In the rendered content every where the name should display as V-John and not like V John or V (new line)

John or V ‑  John So all such occurrences should be taken always same as V-John.

 

What could be more generic solution (Preferred any backend/java utility method ) here that can be applicable for all text like components like RTE etc  

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by raj_mandalapu

We can use sling transformers to rewrite V John to V-John, because we don't know in which component this text comes, it is difficult to go and modify every component and also when it comes to maintenance it is tough.

With this TransformerFactory you can rewrite URLs, modify HTML elements content, add attributes to HTML elements, etc. you can refer below the sample code, it is reading image src attribute and changing it is CDN based URL.

public void startElement(String uri, String loc, String raw, Attributes attributes) throws SAXException { AttributesImpl attrs = new AttributesImpl(attributes); for (int i = 0; i < attrs.getLength(); i++) { String name = attrs.getLocalName(i); if(name.equals("src")) { String url = attrs.getValue(i); url = "http://cdn.coderss.in" + url; attrs.setValue(i, url); } } super.startElement(uri, loc, raw, attrs); }

in your case, you need to read the text of the paragraph inside the startElement method and look for V John and change it to V-John wherever you find. 

For more information, you can refer to this 

http://www.coderss.in/apache-sling-rewriter-how-to-rewrite-urls-in-aemcq5/

https://www.cognifide.com/our-blogs/zen-garden/aem-transformers

You can also configure this to run only certain elements and only for specific paths.

<custom-pipeline jcr:primaryType="nt:unstructured" contentTypes="text/html" generatorType="htmlparser" order="1" paths="[/content/aemtookit]" serializerType="htmlwriter" transformerTypes="[linkchecker,preserve-wcmmode-transformer]"> <generator-htmlparser jcr:primaryType="nt:unstructured" includeTags="[A,/A,IMG,AREA,FORM,BASE,LINK,SCRIPT,BODY,/BODY,DIV,/DIV]" /> </custom-pipeline>

 

1 reply

raj_mandalapu
raj_mandalapuAccepted solution
Level 7
September 20, 2020

We can use sling transformers to rewrite V John to V-John, because we don't know in which component this text comes, it is difficult to go and modify every component and also when it comes to maintenance it is tough.

With this TransformerFactory you can rewrite URLs, modify HTML elements content, add attributes to HTML elements, etc. you can refer below the sample code, it is reading image src attribute and changing it is CDN based URL.

public void startElement(String uri, String loc, String raw, Attributes attributes) throws SAXException { AttributesImpl attrs = new AttributesImpl(attributes); for (int i = 0; i < attrs.getLength(); i++) { String name = attrs.getLocalName(i); if(name.equals("src")) { String url = attrs.getValue(i); url = "http://cdn.coderss.in" + url; attrs.setValue(i, url); } } super.startElement(uri, loc, raw, attrs); }

in your case, you need to read the text of the paragraph inside the startElement method and look for V John and change it to V-John wherever you find. 

For more information, you can refer to this 

http://www.coderss.in/apache-sling-rewriter-how-to-rewrite-urls-in-aemcq5/

https://www.cognifide.com/our-blogs/zen-garden/aem-transformers

You can also configure this to run only certain elements and only for specific paths.

<custom-pipeline jcr:primaryType="nt:unstructured" contentTypes="text/html" generatorType="htmlparser" order="1" paths="[/content/aemtookit]" serializerType="htmlwriter" transformerTypes="[linkchecker,preserve-wcmmode-transformer]"> <generator-htmlparser jcr:primaryType="nt:unstructured" includeTags="[A,/A,IMG,AREA,FORM,BASE,LINK,SCRIPT,BODY,/BODY,DIV,/DIV]" /> </custom-pipeline>