| OLD | NEW | 
| (Empty) |  | 
 |   1 /* | 
 |   2  * This file is part of Adblock Plus <https://adblockplus.org/>, | 
 |   3  * Copyright (C) 2006-present eyeo GmbH | 
 |   4  * | 
 |   5  * Adblock Plus is free software: you can redistribute it and/or modify | 
 |   6  * it under the terms of the GNU General Public License version 3 as | 
 |   7  * published by the Free Software Foundation. | 
 |   8  * | 
 |   9  * Adblock Plus is distributed in the hope that it will be useful, | 
 |  10  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 |  11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 |  12  * GNU General Public License for more details. | 
 |  13  * | 
 |  14  * You should have received a copy of the GNU General Public License | 
 |  15  * along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. | 
 |  16  */ | 
 |  17  | 
 |  18 package org.adblockplus.browser; | 
 |  19  | 
 |  20 import java.net.MalformedURLException; | 
 |  21 import java.net.URL; | 
 |  22  | 
 |  23 public class UrlUtils | 
 |  24 { | 
 |  25  | 
 |  26   private static final String SCHEME_HTTP = "http"; | 
 |  27   private static final String SCHEME_SEPARATOR = "://"; | 
 |  28   private static final String WWW_HOST_PART = "www."; | 
 |  29  | 
 |  30   public static String formatUrl(String urlStr) | 
 |  31   { | 
 |  32     if (!urlStr.contains(SCHEME_SEPARATOR)) | 
 |  33     { | 
 |  34       urlStr = SCHEME_HTTP + SCHEME_SEPARATOR + urlStr; | 
 |  35     } | 
 |  36     return urlStr; | 
 |  37   } | 
 |  38  | 
 |  39   public static String getHostFromUrl(String urlStr) | 
 |  40   { | 
 |  41     try | 
 |  42     { | 
 |  43       final URL url = new URL(formatUrl(urlStr)); | 
 |  44       String host = url.getHost(); | 
 |  45       if (host != null) | 
 |  46       { | 
 |  47         if (host.startsWith(WWW_HOST_PART)) | 
 |  48         { | 
 |  49           host = host.substring(WWW_HOST_PART.length()); | 
 |  50         } | 
 |  51         return host; | 
 |  52       } | 
 |  53     } | 
 |  54     catch (MalformedURLException e) | 
 |  55     { | 
 |  56     } | 
 |  57     return null; | 
 |  58   } | 
 |  59  | 
 |  60   public static boolean isSchemeHttpOrHttps(String urlStr) | 
 |  61   { | 
 |  62     try | 
 |  63     { | 
 |  64       return new URL(urlStr).getProtocol().contains(SCHEME_HTTP); | 
 |  65     } | 
 |  66     catch (MalformedURLException e) | 
 |  67     { | 
 |  68     } | 
 |  69     return false; | 
 |  70   } | 
 |  71 } | 
| OLD | NEW |