How to turn this Java into something I can use in CF?

Hi - Following on from a recent post about how to strip our special characters from a string before insertion to the db I have found this Java code - my question is, how can I turn this into something I can use with CF? I think I need to use the cfscipt tag but that's right on the boundaries of my knowledge base.. If anyone could please help I'd be ever so grateful - thank you!
package net.htmlescape;
* HtmlEscape in Java, which is compatible with utf-8
* @author Ulrich Jensen, http://www.htmlescape.net
* Feel free to get inspired, use or steal this code and use it in your
* own projects.
* License:
* You have the right to use this code in your own project or publish it
* on your own website.
* If you are going to use this code, please include the author lines.
* Use this code at your own risk. The author does not warrent or assume any
* legal liability or responsibility for the accuracy, completeness or usefullness of
* this program code.
public class HtmlEscape {
  private static char[] hex={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
   * Method for html escaping a String, for use in a textarea
   * @param original The String to escape
   * @return The escaped String
  public static String escapeTextArea(String original)
    return escapeSpecial(escapeTags(original));    
   * Normal escape function, for Html escaping Strings
   * @param original The original String
   * @return The escape String
  public static String escape(String original)
    return escapeSpecial(escapeBr(escapeTags(original)));
  public static String escapeTags(String original)
    if(original==null) return "";
    StringBuffer out=new StringBuffer("");
    char[] chars=original.toCharArray();
    for(int i=0;i<chars.length;i++)
      boolean found=true;
      switch(chars[i])
        case 60:out.append("&lt;"); break; //<
        case 62:out.append("&gt;"); break; //>
        case 34:out.append("&quot;"); break; //"
        default:found=false;break;
      if(!found) out.append(chars[i]);
    return out.toString();
  public static String escapeBr(String original)
    if(original==null) return "";
    StringBuffer out=new StringBuffer("");
    char[] chars=original.toCharArray();
    for(int i=0;i<chars.length;i++)
      boolean found=true;
      switch(chars[i])
        case '\n': out.append("<br/>"); break; //newline
        case '\r': break;
        default:found=false;break;
      if(!found) out.append(chars[i]);
    return out.toString();
  public static String escapeSpecial(String original)
    if(original==null) return "";
    StringBuffer out=new StringBuffer("");
    char[] chars=original.toCharArray();
    for(int i=0;i<chars.length;i++)
        boolean found=true;
      switch(chars[i]) {
        case 38:out.append("&amp;"); break; //&
        case 198:out.append("&AElig;"); break; //Æ
        case 193:out.append("&Aacute;"); break; //Á
        case 194:out.append("&Acirc;"); break; //Â
        case 192:out.append("&Agrave;"); break; //À
        case 197:out.append("&Aring;"); break; //Å
        case 195:out.append("&Atilde;"); break; //Ã
        case 196:out.append("&Auml;"); break; //Ä
        case 199:out.append("&Ccedil;"); break; //Ç
        case 208:out.append("&ETH;"); break; //Ð
        case 201:out.append("&Eacute;"); break; //É
        case 202:out.append("&Ecirc;"); break; //Ê
        case 200:out.append("&Egrave;"); break; //È
        case 203:out.append("&Euml;"); break; //Ë
        case 205:out.append("&Iacute;"); break; //Í
        case 206:out.append("&Icirc;"); break; //Î
        case 204:out.append("&Igrave;"); break; //Ì
        case 207:out.append("&Iuml;"); break; //Ï
        case 209:out.append("&Ntilde;"); break; //Ñ
        case 211:out.append("&Oacute;"); break; //Ó
        case 212:out.append("&Ocirc;"); break; //Ô
        case 210:out.append("&Ograve;"); break; //Ò
        case 216:out.append("&Oslash;"); break; //Ø
        case 213:out.append("&Otilde;"); break; //Õ
        case 214:out.append("&Ouml;"); break; //Ö
        case 222:out.append("&THORN;"); break; //Þ
        case 218:out.append("&Uacute;"); break; //Ú
        case 219:out.append("&Ucirc;"); break; //Û
        case 217:out.append("&Ugrave;"); break; //Ù
        case 220:out.append("&Uuml;"); break; //Ü
        case 221:out.append("&Yacute;"); break; //Ý
        case 225:out.append("&aacute;"); break; //á
        case 226:out.append("&acirc;"); break; //â
        case 230:out.append("&aelig;"); break; //æ
        case 224:out.append("&agrave;"); break; //à
        case 229:out.append("&aring;"); break; //å
        case 227:out.append("&atilde;"); break; //ã
        case 228:out.append("&auml;"); break; //ä
        case 231:out.append("&ccedil;"); break; //ç
        case 233:out.append("&eacute;"); break; //é
        case 234:out.append("&ecirc;"); break; //ê
        case 232:out.append("&egrave;"); break; //è
        case 240:out.append("&eth;"); break; //ð
        case 235:out.append("&euml;"); break; //ë
        case 237:out.append("&iacute;"); break; //í
        case 238:out.append("&icirc;"); break; //î
        case 236:out.append("&igrave;"); break; //ì
        case 239:out.append("&iuml;"); break; //ï
        case 241:out.append("&ntilde;"); break; //ñ
        case 243:out.append("&oacute;"); break; //ó
        case 244:out.append("&ocirc;"); break; //ô
        case 242:out.append("&ograve;"); break; //ò
        case 248:out.append("&oslash;"); break; //ø
        case 245:out.append("&otilde;"); break; //õ
        case 246:out.append("&ouml;"); break; //ö
        case 223:out.append("&szlig;"); break; //ß
        case 254:out.append("&thorn;"); break; //þ
        case 250:out.append("&uacute;"); break; //ú
        case 251:out.append("&ucirc;"); break; //û
        case 249:out.append("&ugrave;"); break; //ù
        case 252:out.append("&uuml;"); break; //ü
        case 253:out.append("&yacute;"); break; //ý
        case 255:out.append("&yuml;"); break; //ÿ
        case 162:out.append("&cent;"); break; //¢
        default:
          found=false;
          break;
      if(!found)
        if(chars[i]>127) {
          char c=chars[i];
          int a4=c%16;
          c=(char) (c/16);
          int a3=c%16;
          c=(char) (c/16);
          int a2=c%16;
          c=(char) (c/16);
          int a1=c%16;
          out.append("&#x"+hex[a1]+hex[a2]+hex[a3]+hex[a4]+";");    
        else
          out.append(chars[i]);
    return out.toString();

hi Dan, thanks for asking
I did this in the end..
<cfscript>
  // function cleantext(string) {
  //   string = "<p>" & string;
  //   string = Replace(string, chr(13) & chr(10) & chr(13) & chr(10), "</p><p>", "all");
  //   string = Replace(string, chr(13) & chr(10), "<br />", "all");
  //   string = string & "</p>";
  //   return string;
* HtmlEscape in Java, which is compatible with utf-8
* @author Ulrich Jensen, http://www.htmlescape.net
* Feel free to get inspired, use or steal this code and use it in your
* own projects.
* License:
* You have the right to use this code in your own project or publish it
* on your own website.
* If you are going to use this code, please include the author lines.
* Use this code at your own risk. The author does not warrent or assume any
* legal liability or responsibility for the accuracy, completeness or usefullness of
* this program code.
function cleantext(string)  {
  private static char[] hex={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
   * Method for html escaping a String, for use in a textarea
   * @param original The String to escape
   * @return The escaped String
  public static String escapeTextArea(String original)
    return escapeSpecial(escapeTags(original));   
   * Normal escape function, for Html escaping Strings
   * @param original The original String
   * @return The escape String
  public static String escape(String original)
    return escapeSpecial(escapeBr(escapeTags(original)));
  public static String escapeTags(String original)
    if(original==null) return "";
    StringBuffer out=new StringBuffer("");
    char[] chars=original.toCharArray();
    for(int i=0;i<chars.length;i++)
      boolean found=true;
      switch(chars[i])
        case 60:out.append("&lt;"); break; //<
        case 62:out.append("&gt;"); break; //>
        case 34:out.append("&quot;"); break; //"
        default:found=false;break;
      if(!found) out.append(chars[i]);
    return out.toString();
  public static String escapeBr(String original)
    if(original==null) return "";
    StringBuffer out=new StringBuffer("");
    char[] chars=original.toCharArray();
    for(int i=0;i<chars.length;i++)
      boolean found=true;
      switch(chars[i])
        case '\n': out.append("<br/>"); break; //newline
        case '\r': break;
        default:found=false;break;
      if(!found) out.append(chars[i]);
    return out.toString();
  public static String escapeSpecial(String original)
    if(original==null) return "";
    StringBuffer out=new StringBuffer("");
    char[] chars=original.toCharArray();
    for(int i=0;i<chars.length;i++)
        boolean found=true;
      switch(chars[i]) {
        case 38:out.append("&amp;"); break; //&
        case 198:out.append("&AElig;"); break; //Æ
        case 193:out.append("&Aacute;"); break; //Á
        case 194:out.append("&Acirc;"); break; //Â
        case 192:out.append("&Agrave;"); break; //À
        case 197:out.append("&Aring;"); break; //Å
        case 195:out.append("&Atilde;"); break; //Ã
        case 196:out.append("&Auml;"); break; //Ä
        case 199:out.append("&Ccedil;"); break; //Ç
        case 208:out.append("&ETH;"); break; //Ð
        case 201:out.append("&Eacute;"); break; //É
        case 202:out.append("&Ecirc;"); break; //Ê
        case 200:out.append("&Egrave;"); break; //È
        case 203:out.append("&Euml;"); break; //Ë
        case 205:out.append("&Iacute;"); break; //Í
        case 206:out.append("&Icirc;"); break; //Î
        case 204:out.append("&Igrave;"); break; //Ì
        case 207:out.append("&Iuml;"); break; //Ï
        case 209:out.append("&Ntilde;"); break; //Ñ
        case 211:out.append("&Oacute;"); break; //Ó
        case 212:out.append("&Ocirc;"); break; //Ô
        case 210:out.append("&Ograve;"); break; //Ò
        case 216:out.append("&Oslash;"); break; //Ø
        case 213:out.append("&Otilde;"); break; //Õ
        case 214:out.append("&Ouml;"); break; //Ö
        case 222:out.append("&THORN;"); break; //Þ
        case 218:out.append("&Uacute;"); break; //Ú
        case 219:out.append("&Ucirc;"); break; //Û
        case 217:out.append("&Ugrave;"); break; //Ù
        case 220:out.append("&Uuml;"); break; //Ü
        case 221:out.append("&Yacute;"); break; //Ý
        case 225:out.append("&aacute;"); break; //á
        case 226:out.append("&acirc;"); break; //â
        case 230:out.append("&aelig;"); break; //æ
        case 224:out.append("&agrave;"); break; //à
        case 229:out.append("&aring;"); break; //å
        case 227:out.append("&atilde;"); break; //ã
        case 228:out.append("&auml;"); break; //ä
        case 231:out.append("&ccedil;"); break; //ç
        case 233:out.append("&eacute;"); break; //é
        case 234:out.append("&ecirc;"); break; //ê
        case 232:out.append("&egrave;"); break; //è
        case 240:out.append("&eth;"); break; //ð
        case 235:out.append("&euml;"); break; //ë
        case 237:out.append("&iacute;"); break; //í
        case 238:out.append("&icirc;"); break; //î
        case 236:out.append("&igrave;"); break; //ì
        case 239:out.append("&iuml;"); break; //ï
        case 241:out.append("&ntilde;"); break; //ñ
        case 243:out.append("&oacute;"); break; //ó
        case 244:out.append("&ocirc;"); break; //ô
        case 242:out.append("&ograve;"); break; //ò
        case 248:out.append("&oslash;"); break; //ø
        case 245:out.append("&otilde;"); break; //õ
        case 246:out.append("&ouml;"); break; //ö
        case 223:out.append("&szlig;"); break; //ß
        case 254:out.append("&thorn;"); break; //þ
        case 250:out.append("&uacute;"); break; //ú
        case 251:out.append("&ucirc;"); break; //û
        case 249:out.append("&ugrave;"); break; //ù
        case 252:out.append("&uuml;"); break; //ü
        case 253:out.append("&yacute;"); break; //ý
        case 255:out.append("&yuml;"); break; //ÿ
        case 162:out.append("&cent;"); break; //¢
        default:
          found=false;
          break;
      if(!found)
        if(chars[i]>127) {
          char c=chars[i];
          int a4=c%16;
          c=(char) (c/16);
          int a3=c%16;
          c=(char) (c/16);
          int a2=c%16;
          c=(char) (c/16);
          int a1=c%16;
          out.append("&#x"+hex[a1]+hex[a2]+hex[a3]+hex[a4]+";");   
        else
          out.append(chars[i]);
    return out.toString();
</cfscript>  
<cfset cleanedtext = cleantext(dirtytext)>
Although actually I also ended up changing my charset of my tables to utf8 (it was latin_swedish) and that seems to have solved the head issue (with special characters (bullet points i think it was) throwing an error when inserting them in the db)

Similar Messages

  • I have two rotating arrows at the top of my screen next to the 3G symbol. Does anyone know how to turn this off b/c it is using all of my battery life? This started after the iOS 5 update.

    I have two rotating arrows at the top of my screen next to the 3G symbol. This happened after the iOS 5 update. Does anyone know what it is and how I get it off, it is draining my battery?

    At first read, I also thought it sounded a bit snide.  Who here has read the entire manual before going to the web for a quick search? (Not me, and in fact, I found my answer - to this very question, by reading this post WAY faster than if I had read the manual.  What is so wrong with that?) 
    That is the beauty of having support forums.  If it is a bother to answer, without being snide, one is not obligated to do so.  And my apologies if he was not being snide... but there maybe a better way to point out the manual, such as "I have included a link to the searchable manual which may be of assistance to you next time you are puzzled by your iPhone's behaviour". 
    Just my 2¢.

  • Need to turn this PLSQL into a procedure

    Hi All,
    I have the following PLSQL which declares a cursor, then loops using the cursor variable. I'm new to creating procedures and packages and i'm having trouble turning this PLSQL into one of those. When i put my PLSQL code in a procedure it doesn't like the DECLARE statement or the CURSOR section. I'm not sure how to tweak it to get the syntax correct for a procedure. Can someone point me in the right direction?
    Here is the PLSQL:
    DECLARE
    /* Output variables to hold the result of the query: */
    groupid assignment_group.id%TYPE;
    /* Cursor declaration: */
    CURSOR Asset_Rank_HistoryCursor IS
    select distinct id from assignment_group;
    BEGIN
    OPEN Asset_Rank_HistoryCursor;
    LOOP
    /* Retrieve each row of the result of the above query into PL/SQL variables: */
    FETCH Asset_Rank_HistoryCursor INTO groupid;
    /* If there are no more rows to fetch, exit the loop: */
    EXIT WHEN Asset_Rank_HistoryCursor%NOTFOUND;
    /* Insert the the new rows */
    insert into ASSET_RANK_GROUPED (asset_id , dt, rank, score, ASSIGNMENT_GROUP_ID)
    select asset_id, max_dt, rownum, score, groupid from (
    SELECT <big nasty select statement>
    END LOOP;
    /* Free cursor used by the query. */
    CLOSE Asset_Rank_HistoryCursor;
    END;
    How do i change my DECLARE and CURSOR statement so the procedure will create. Do i need to break it out into a function?

    I figured it out... just had to play w/ the syntax. Had to make sure the BEGIN statement was AFTER the CURSOR declaration and had to make sure any variables are declared up top, didn't need a DECLARE section in procedure. I just put the groupid variable right after IS at the top of procedure creation statement.

  • How do I turn a photo into a pencil sketch using Photoshop Elements 12?

    How do I turn a photo into a pencil sketch using photoshop elements 12?

    Filter> Sketch> Pen & Ink.
    Cheers,
    Neale
    Insanity is hereditary, you get it from your children
    If this post or another user's post resolves the original issue, please mark the posts as correct and/or helpful accordingly. This helps other users with similar trouble get answers to their questions quicker. Thanks.

  • How to turn a silhouette into an outline?

    I need to create a line drawing of the outline of a chair. I tried following the various Illustrator tutorials to take the image of a chair and create a silhouette. However, I can't figure out how to take this silhouette and get just the outline of it. The Illustrator Image Trace tool doesn't seem to have an option to just save the outline.
    Is there an easy way in Illustrator or Photoshop to turn this silhouette into an outline image that I can save as a file? I will print the outline in a very light opacity so that the lines are barely visible for hand rendering. I don't want to use the pen tool to outline the silhouette because my hand is too shaky to do a good job.
    THank you for any advice...

    Thank you Monika and Steve for suggesting to ungroup and then use the direct selection to edit it, and to change the fill to zero and the stroke to a very thin line.
    It turned out that the outline was very wavy/crooked, since image trace outlined the pixels somewhat haphazardly. So the final solution was complicated because I had to learn how to use direct select and edit anchor points to straighten out the lines.
    I guess it would have been easier to use a light box and just trace the image by hand. oh well. I learned alot about Illustrator.
    Thank you again for your helpfulness!

  • When I open iTunes it will automatically go to full screen mode. I can't work out how to turn this off. Only iTunes opens to full screen mode.

    When I open iTunes it will automatically go to full screen mode. I can't work out how to turn this off. Only iTunes opens to full screen mode.

    Go to System Preferences (under the Apple logo in the menu bar).  Choose "General".  Click "Always close windows when quitting an application".
    That should fix it.

  • I just purchased Wittenberger Fraktur how do install this font into my photoshop cs6 for mac ?

    I just purchased Wittenberger Fraktur how do install this font into my photoshop cs6 for mac ?

    You just install it in the OS.
    Photoshop gets the fonts from the OS.

  • My new kitten jumped on my keyboard and now every command i perform on my computer is heard audibly. does anyone know how to turn this function off?

    my new kitten jumped on my keyboard and now every command i perform on my computer is heard audibly. does anyone know how to turn this function off?

    Chateaux Bleu wrote:
    my new kitten jumped on my keyboard and now every command i perform on my computer is heard audibly. does anyone know how to turn this function off?
    I don't know how to turn off a kitten (I would probably get the Nobel prize if I did!) but Pierre is correct, although his target is wrong:
    System Preferences/Universal Access/Seeing - turn off VoiceOver.

  • Can I turn .wma files into mp3 (or something I can use in itunes)?

    ....

    Cov99 wrote:
    Can I turn .wma files into mp3 (or something I can use in itunes)?
    iTunes for Mac can't handle WMA files, iTunes for winsloth can.
    if you have access to a PC, use iTunes there to convert the files. alternatively, you can get EasyWMA and use that app.
    the files need to be unprotected in both cases.
    JGG

  • How to Turn your iPad into a WiFi router for your laptop?

    how to Turn my iPad into a WiFi router for your laptop?

    Chris CA wrote:
    iPads have no tethering abilities either.
    I know, but I still don't know what the OP was asking.

  • How to turn this off in my macosx

    Hi All, how to turn this off in my macosx
    http://postimg.org/image/4sq33zqn3/

    Go step by step and test.
      Quit Safari.
      Hold the shift key down and relaunch Safari.
    Reset Safari.
    Click Safari in the menu bar.
    From the drop down select "Reset Safari".
    Uncheck the box next to  " Remove saved names and passwords".
    Click "Reset".
    Empty Caches
    Safari > Preference > Advanced
    Checkmark the box for "Show Develop menu in menu bar".
    Develop menu will appear in the Safari menu bar.
    Click Develop and select "Empty Caches" from the dropdown.
    Turn off Extensions if any, and launch Safari.
    Safari > Preferences > Extensions

  • How do I turn on the notification for pop-up blocker? I accidentally clicked the option saying "do not show this notification again." I want the notification so I have the option of seeing the pop-up or not, but don't know how to turn this back on.

    How do I turn on the notification for pop-up blocker? I accidentally clicked the option saying "do not show this notification again." I want the notification so I have the option of seeing the pop-up or not, but don't know how to turn this back on.

    Type "about:config" in the location bar.
    Filter for "privacy.popups.showBrowserMessage"
    Change this to true by double clicking the preference (or right click and choose Reset)

  • How to turn of Java in Yosemite

    I Have read that it is more secure to turn off Java. However I can't find it in Yosemite. In Mavricks it was under security in Safari preferences. Where is it?

    It is encapsulated in the Plug-ins section of Security. Java is just a plug-in on a web browser.
    If you don't have Java installed in the first place, it won't be listed in the plug-ins.

  • How to turn OFF trackpad on MacBook Air when using Magic Trackpad

    How to turn OFF trackpad on MacBook Air when using Magic Trackpad. Anyone have a clue on how to do this?

    Do you get more than one trackpad in system preferences? If not, which trackpad does it show in the "movie" in Preferences?

  • How to upload a video into Asset Library programmatically using server side code in sharepoint 2013

    How to upload a video into Asset Library programmatically using server side code in sharepoint 2013

    First you need to configure your asset library with video content type and then you can use SharePoint object model to upload the video files in it...
    check this link for setting up Asset library
    http://www.c-sharpcorner.com/UploadFile/54db21/asset-library-in-sharepoint-2010/ 
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/1d64a5f7-c7db-4ae0-8b0d-d0722cacf5f2/assets-library-video-files-and-c?forum=sharepointdevelopmentprevious
    Mark ANSWER if this reply resolves your query, If helpful then VOTE HELPFUL
    INSQLSERVER.COM
    Mohammad Nizamuddin

Maybe you are looking for

  • Error while invoking web service from BPEL 11g

    Hello All, I am creating a webservice using java. I created service using java and deployed it on the SOA server 11g. I am able to test it from the weblogic console. When i am trying to invoke it from BPEL, i am getting the remote fault: Error Messag

  • How do I find the menuID for the Photoshop Transform menu

    I am new to using ExtendScript and want to create a script that starts by selecting Transform >> Skew. The JavaScript script reference mentions the method 'runMenuItem' but I don't know how to find the menuID to use it.

  • Does Not Sync, Stuck

    When I went to go sync my iPod, it shows up on the screen and the iPod seems like it is starting to sync. But then it doesn't and the screen on the iPod goes back the cord picture where it says "Connected_Eject before disconnecting." When I click syn

  • CANNOT CONNECT iPhone/iPod touch to WIRELESS INTERNET wi-fi - (TTLS vs WEP)

    Hi. I bought the iPod touch on the day it came out; took it home, it all worked fine. At home i have a wireless router, and it supports the WEP format. so my iPod connects to the internet perfectly. the day i took it to school was the day I got very

  • Why we go for SAP ?what are the benifits to implement SAP inanyorganizat?

    Hi, Why we go for SAP ?what are the benifits to implement SAP in  any organization? Early reply is highely appruciable. Regards, Chow.