Page 1 of 1

Replace URL in Chat Message

PostPosted: Mon Jan 30, 2012 8:37 pm
by MadEvil
Hi,

i tried to implement a Regexp function to catch URLs from the Chat Message in ChatService.java but i get only this result.

How can this be done ?

the DWR framework is confusing me :cry:

Re: Replace URL in Chat Message

PostPosted: Fri Feb 03, 2012 1:07 am
by MadEvil
I get it to work ! :)

Re: Replace URL in Chat Message

PostPosted: Fri Feb 03, 2012 2:53 am
by ytechie
Can you share the regexp mod? I would love to learn something new!

Re: Replace URL in Chat Message

PostPosted: Fri Feb 03, 2012 11:09 pm
by MadEvil
ytechie wrote:Can you share the regexp mod? I would love to learn something new!


Hi, sure!

But before i release the final mod i will fix some bugs in the interface.

about this Mod: I use this function with this simple Regexp in ChatService.java:

Code: Select all
   private String ReplaceUrl(String message) {

       Pattern patt = Pattern.compile("(?<!\\S)(((f|ht){1}tp[s]?:\\/\\/|(?<!\\S)www\\.)[-a-zA-Z0-9@:%_\\+.~#?&\\/\\/=]+)");
        Matcher matcher = patt.matcher(message);   
        if(matcher.find()){
            if (matcher.group(1).startsWith("http://")){
                return matcher.replaceAll("<a href=\"$1\" target=_blank>$1</a>");
            }else{
                return matcher.replaceAll("<a href=\"http://$1\" target=_blank>$1</a>");
              }   
        }else{
            return message;
        }
    }


I found out that you can use the dwr framework to escape the HTML Code

Code: Select all
dwr.util.setEscapeHtml(false);

or
Code: Select all
dwr.util.setValue('x', "<b>Hi</b>", { escapeHtml:false });


.. for my use the Regexp works fine.

best regards :D

Re: Replace URL in Chat Message

PostPosted: Sun Feb 05, 2012 5:25 am
by ytechie
Oh. You're working with the java. I thought you did this is javascript. Either way, cool mod! Keep modding!