    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.net.URI;
    006    import java.net.URISyntaxException;
    007    import java.util.logging.Level;
    008    import java.util.logging.Logger;
    009    import java.util.regex.Matcher;
    010    import java.util.regex.Pattern;
    011
    012    @SideOnly(Side.CLIENT)
    013    public class ChatClickData
    014    {
    015        public static final Pattern pattern = Pattern.compile("^(?:(https?)://)?([-\\w_\\.]{2,}\\.[a-z]{2,3})(/\\S*)?$");
    016        private final FontRenderer fontR;
    017        private final ChatLine line;
    018        private final int field_78312_d;
    019        private final int field_78313_e;
    020        private final String field_78310_f;
    021
    022        /** The URL which was clicked on. */
    023        private final String clickedUrl;
    024
    025        public ChatClickData(FontRenderer par1FontRenderer, ChatLine par2ChatLine, int par3, int par4)
    026        {
    027            this.fontR = par1FontRenderer;
    028            this.line = par2ChatLine;
    029            this.field_78312_d = par3;
    030            this.field_78313_e = par4;
    031            this.field_78310_f = par1FontRenderer.trimStringToWidth(par2ChatLine.getChatLineString(), par3);
    032            this.clickedUrl = this.findClickedUrl();
    033        }
    034
    035        /**
    036         * Gets the URL which was clicked on.
    037         */
    038        public String getClickedUrl()
    039        {
    040            return this.clickedUrl;
    041        }
    042
    043        /**
    044         * computes the URI from the clicked chat data object
    045         */
    046        public URI getURI()
    047        {
    048            String var1 = this.getClickedUrl();
    049
    050            if (var1 == null)
    051            {
    052                return null;
    053            }
    054            else
    055            {
    056                Matcher var2 = pattern.matcher(var1);
    057
    058                if (var2.matches())
    059                {
    060                    try
    061                    {
    062                        String var3 = var2.group(0);
    063
    064                        if (var2.group(1) == null)
    065                        {
    066                            var3 = "http://" + var3;
    067                        }
    068
    069                        return new URI(var3);
    070                    }
    071                    catch (URISyntaxException var4)
    072                    {
    073                        Logger.getLogger("Minecraft").log(Level.SEVERE, "Couldn\'t create URI from chat", var4);
    074                    }
    075                }
    076
    077                return null;
    078            }
    079        }
    080
    081        private String findClickedUrl()
    082        {
    083            int var1 = this.field_78310_f.lastIndexOf(" ", this.field_78310_f.length()) + 1;
    084
    085            if (var1 < 0)
    086            {
    087                var1 = 0;
    088            }
    089
    090            int var2 = this.line.getChatLineString().indexOf(" ", var1);
    091
    092            if (var2 < 0)
    093            {
    094                var2 = this.line.getChatLineString().length();
    095            }
    096
    097            return StringUtils.stripControlCodes(this.line.getChatLineString().substring(var1, var2));
    098        }
    099    }