Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Encoding Special case characters

 
Mike Miller
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Sorry if this is posted elsewhere, i've had a look and can't find it.

I'm creating a PDF via FOP, from user data so I need to include provisions for < > & etc...

I know i need to encode the characters into &#xxxx; format, and I can write a class to do this.

However is there a built in method somewhere, like the URLEncode.Encode? or should i use this and a regular expression to replace %84 with the format i need?

I'm using the bog standard UTF-8 encoding.

Any Help / comments would be appreciated.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used a whole lot of java.util.regex Pattern objects - precompiled as static variables.

with code like this....

I have no idea whether this is a fast way, but it worked for me.
Bill
 
Mike Miller
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help there... But I found a more elegant way to catch the issue.

Instead of translating the needed characters in code I've left it up to the processor by wrapping the text data in cdata tags.

<CustomerName>
<![CDATA[MR & MRS SMITH]]>
</CustomerName>

This means I don't have to write code for each special case character and hasn't impacted the speed of which the PDF is created.

Mike.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic