001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS <http://nuxeo.com> and others 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Jean-Marc Orliaguet, Chalmers 011 * 012 * $Id$ 013 */ 014 015package org.nuxeo.theme.protocol.nxtheme; 016 017import java.net.InetAddress; 018import java.net.URL; 019import java.net.URLConnection; 020import java.net.URLStreamHandler; 021 022public final class Handler extends URLStreamHandler { 023 024 @Override 025 protected URLConnection openConnection(URL url) { 026 return new Connection(url); 027 } 028 029 /** 030 * Theme URL do not reference any networked resource. This method is called by URL.equals and URL.hashCode so that 031 * we need override it to avoid DNS lookup for the theme host. 032 * 033 * @param u a URL object 034 * @return null for url with nxtheme protocol, URLStreamHandler.getHostAddress(u) otherwise 035 */ 036 @Override 037 protected synchronized InetAddress getHostAddress(URL u) { 038 if ("nxtheme".equals(u.getProtocol())) { 039 // do not do a DNS lookup for a theme resource 040 return null; 041 } 042 return super.getHostAddress(u); 043 } 044 045}