1 /* 2 URLUtils.java 3 Creation date : 6/07/2010 4 Copyright © Benjamin Croizet (graffity2199@yahoo.fr) 5 6 This program is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License 8 or GNU Lesser General Public License as published by the 9 Free Software Foundation; either version 3 of the License, 10 or (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received copies of the GNU General Public License 18 and GNU Lesser General Public License along with this program; 19 if not, write to the Free Software Foundation, Inc., 20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 http://www.fsf.org/licensing/licenses/gpl.html 22 http://www.gnu.org/licenses/lgpl.html 23 */ 24 25 package net.sourceforge.plantumldependency.common.utils.url; 26 27 import static java.util.logging.Level.SEVERE; 28 import static java.util.logging.Logger.getLogger; 29 import static net.sourceforge.plantumldependency.common.constants.log.ErrorConstants.MALFORMED_URL_ERROR; 30 import static net.sourceforge.plantumldependency.common.utils.log.LogUtils.buildLogString; 31 32 import java.net.MalformedURLException; 33 import java.net.URL; 34 import java.util.logging.Logger; 35 36 /** 37 * The utility class to manage URL without taking care of the {@link MalformedURLException}. 38 * 39 * @author Benjamin Croizet (<a href="mailto:graffity2199@yahoo.fr>graffity2199@yahoo.fr</a>) 40 * @since 1.3.0 41 * @version 1.3.0 42 */ 43 public abstract class URLUtils { 44 45 /** The class logger. */ 46 private static final transient Logger LOGGER = getLogger(URLUtils.class.getName()); 47 48 /** 49 * Creates an URL instance from a {@link String}. Don't throw {@link MalformedURLException}. 50 * 51 * @param urlStr 52 * the URL string to get the {@link URL} instance from, mustn't be <code>null</code>. 53 * @return the {@link URL} instance if it has been correctly parsed, <code>null</code> 54 * otherwise. 55 * @since 1.3.0 56 */ 57 public static URL createURL(final String urlStr) { 58 URL url = null; 59 try { 60 url = new URL(urlStr); 61 } catch (final MalformedURLException e) { 62 LOGGER.log(SEVERE, buildLogString(MALFORMED_URL_ERROR, urlStr)); 63 } 64 65 return url; 66 } 67 68 /** 69 * Private constructor to prevent from instantiation. 70 * 71 * @since 1.3.0 72 */ 73 private URLUtils() { 74 super(); 75 } 76 }