[FOray-commit] SF.net SVN: foray: [7704] trunk/foray/foray-common/src/java/org/foray/common
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2006-06-19 16:07:16
|
Revision: 7704 Author: victormote Date: 2006-06-19 09:07:09 -0700 (Mon, 19 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7704&view=rev Log Message: ----------- Add abstract superclass to handle the details that it can handle. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/ClasspathHandler.java Added Paths: ----------- trunk/foray/foray-common/src/java/org/foray/common/AbstractURLStreamHandler.java Added: trunk/foray/foray-common/src/java/org/foray/common/AbstractURLStreamHandler.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/AbstractURLStreamHandler.java (rev 0) +++ trunk/foray/foray-common/src/java/org/foray/common/AbstractURLStreamHandler.java 2006-06-19 16:07:09 UTC (rev 7704) @@ -0,0 +1,80 @@ +/* + * Copyright 2006 The FOray Project. + * http://www.foray.org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This work is in part derived from the following work(s), used with the + * permission of the licensor: + * Apache FOP, licensed by the Apache Software Foundation + * + */ + +/* $Id$ */ + +/* Known contributors: + * Vincent Hennebert (original author) + */ + +package org.foray.common; + +import java.io.IOException; +import java.net.URLStreamHandler; + +/** + * Abstract superclass for all URLStreamHandlers using the FOray scheme for + * custom URLStreamHandler registration. + */ +public abstract class AbstractURLStreamHandler extends URLStreamHandler { + + /** + * Register an instance of this class with the custom + * URLStreamHandlerFactory so that this handler will be used for URLs of + * protocol "classpath". + */ + protected static void register(String protocol, URLStreamHandler handler) { + /* Validate the input. */ + if (protocol == null) { + return; + } + if (handler == null) { + return; + } + + /* Get the Factory instance. */ + FOrayURLStreamHandlerFactory factory = + FOrayURLStreamHandlerFactory.getURLStreamHandlerFactory(); + + /* See if this protocol is already registered with the factory. */ + URLStreamHandler registeredHandler = factory.createURLStreamHandler( + protocol); + if (registeredHandler != null) { + /* If already registed, that one is the one being used, and there + * is no way to change it. */ + return; + } + + /* Register the protocol with the Factory. */ + try { + factory.registerProtocol(protocol, handler); + } catch (IOException e) { + /* This should never happen. We have already checked whether the + * protocol is previously registered, and we know that neither the + * protocol or handler are null. The only thing we could do is + * pass the exception upstream, but there is nothing they can do + * about it either. */ + return; + } + } + +} Property changes on: trunk/foray/foray-common/src/java/org/foray/common/AbstractURLStreamHandler.java ___________________________________________________________________ Name: svn:keywords + "Author Id Rev Date URL" Name: svn:eol-style + native Modified: trunk/foray/foray-common/src/java/org/foray/common/ClasspathHandler.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/ClasspathHandler.java 2006-06-19 15:38:32 UTC (rev 7703) +++ trunk/foray/foray-common/src/java/org/foray/common/ClasspathHandler.java 2006-06-19 16:07:09 UTC (rev 7704) @@ -43,7 +43,7 @@ * <li><code>classpath:path/to/the/resource</code></li> * </ul> */ -public class ClasspathHandler extends URLStreamHandler { +public class ClasspathHandler extends AbstractURLStreamHandler { private static final String PROTOCOL = "classpath"; @@ -72,29 +72,8 @@ * protocol "classpath". */ public static void register() { - FOrayURLStreamHandlerFactory factory = - FOrayURLStreamHandlerFactory.getURLStreamHandlerFactory(); - URLStreamHandler handler = factory.createURLStreamHandler( - ClasspathHandler.PROTOCOL); - if (handler != null) { - /* If already registed, that one is the one being used, and there - * is no way to change it. */ - return; - } - handler = new ClasspathHandler(); - if (handler == null) { - return; - } - try { - factory.registerProtocol(ClasspathHandler.PROTOCOL, handler); - } catch (IOException e) { - /* This should never happen. We have already checked whether the - * protocol is previously registered, and we know that neither the - * protocol or handler are null. The only thing we could do is - * pass the exception upstream, but there is nothing they can do - * about it either. */ - return; - } + URLStreamHandler handler = new ClasspathHandler(); + AbstractURLStreamHandler.register(ClasspathHandler.PROTOCOL, handler); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |