• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Escape HTML characters - what's the good practice?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a line of text that needs to be displayed on a web page, printed in PDF and also possibly output as xml. There are multiple places in my application where this property is displayed. Recently we encountered a situation where this text had a "Less Than" symbol, a well know html character. The text gets truncated in html but prints fine in PDF. If I use StringEscapeUtils.escapeHtml in JSP it prints the entire text without problems. But I have a lot of places in the application where this property is rendered in HTML. I can find all these places and use StringEscapeUtils... to escape the HTML character. But I felt it is bad design. What if I have future needs to display this character else where. It could be a potential ongoing problem.

So I thought why not wrap the escaping logic in the domain object that returns this text. But soon it started printing the lt; in the PDF reports. Not a good option either.

I thought of the visitor pattern. But somehow I need to provide a context e.g. html, pdf, xml etc. to get a well formatted text.

Any ideas on how I may proceed from here?

Thanks in advance,
Kalyan
 
Our first order of business must be this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic