Replace URL in Chat Message

Third-party modifications and add-ons, Apps and Clients

Moderator: moderators

Replace URL in Chat Message

Postby MadEvil » Mon Jan 30, 2012 8:37 pm

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:
Madsonic Developer
User avatar
MadEvil
 
Posts: 354
Joined: Wed Nov 09, 2011 8:35 pm
Location: Vienna

Re: Replace URL in Chat Message

Postby MadEvil » Fri Feb 03, 2012 1:07 am

I get it to work ! :)
Madsonic Developer
User avatar
MadEvil
 
Posts: 354
Joined: Wed Nov 09, 2011 8:35 pm
Location: Vienna

Re: Replace URL in Chat Message

Postby ytechie » Fri Feb 03, 2012 2:53 am

Can you share the regexp mod? I would love to learn something new!
User avatar
ytechie
 
Posts: 547
Joined: Sun Dec 12, 2010 5:05 am
Location: Manhattan, New York

Re: Replace URL in Chat Message

Postby MadEvil » Fri Feb 03, 2012 11:09 pm

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
Madsonic Developer
User avatar
MadEvil
 
Posts: 354
Joined: Wed Nov 09, 2011 8:35 pm
Location: Vienna

Re: Replace URL in Chat Message

Postby ytechie » Sun Feb 05, 2012 5:25 am

Oh. You're working with the java. I thought you did this is javascript. Either way, cool mod! Keep modding!
User avatar
ytechie
 
Posts: 547
Joined: Sun Dec 12, 2010 5:05 am
Location: Manhattan, New York


Return to Mods, Apps and Clients

Who is online

Users browsing this forum: No registered users and 1 guest