[FOray-commit] SF.net SVN: foray: [7673] 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-17 16:53:44
|
Revision: 7673 Author: victormote Date: 2006-06-17 09:53:33 -0700 (Sat, 17 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7673&view=rev Log Message: ----------- Create and use new singleton class FOrayURLStreamHandlerFactory to handle custom URLStreamHandler creation. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/ClasspathHandler.java Added Paths: ----------- trunk/foray/foray-common/src/java/org/foray/common/FOrayURLStreamHandlerFactory.java 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-17 15:38:21 UTC (rev 7672) +++ trunk/foray/foray-common/src/java/org/foray/common/ClasspathHandler.java 2006-06-17 16:53:33 UTC (rev 7673) @@ -53,4 +53,9 @@ } }; } + + public static void register() { + FOrayURLStreamHandlerFactory.getURLStreamHandlerFactory(); + } + } Added: trunk/foray/foray-common/src/java/org/foray/common/FOrayURLStreamHandlerFactory.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/FOrayURLStreamHandlerFactory.java (rev 0) +++ trunk/foray/foray-common/src/java/org/foray/common/FOrayURLStreamHandlerFactory.java 2006-06-17 16:53:33 UTC (rev 7673) @@ -0,0 +1,71 @@ +/* + * Copyright 2006 The aXSL Project. + * http://www.axsl.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. + * + */ + +/* $Id$ */ + +/* Known contributors: + * Vincent Hennebert (original author) + */ + +package org.foray.common; + +import java.net.URL; +import java.net.URLStreamHandler; +import java.net.URLStreamHandlerFactory; + +/** + * URLStreamHandlerFactory implementation that allows custom protocols to be + * registered and accessed. + */ +public class FOrayURLStreamHandlerFactory implements URLStreamHandlerFactory { + + /** The singleton instance of this class. */ + private static FOrayURLStreamHandlerFactory urlSHFactory; + + /** + * Private constructor. + * This is a singleton, and there should only be one instance per session. + * To get that instance, use + * {@link FOrayURLStreamHandlerFactory#getURLStreamHandlerFactory()}. + */ + private FOrayURLStreamHandlerFactory() { + } + + public URLStreamHandler createURLStreamHandler(String protocol) { + if (protocol.equals("classpath")) { + return new ClasspathHandler(); + } + return null; + } + + /** + * Provides access to a custom URLStreamHandlerFactory instance, creating + * it and registering it with Java if needed. + * @return The custom URLStreamHandlerFactory instance for this session. + */ + public static FOrayURLStreamHandlerFactory getURLStreamHandlerFactory() { + if (FOrayURLStreamHandlerFactory.urlSHFactory == null) { + FOrayURLStreamHandlerFactory.urlSHFactory + = new FOrayURLStreamHandlerFactory(); + URL.setURLStreamHandlerFactory( + FOrayURLStreamHandlerFactory.urlSHFactory); + } + return FOrayURLStreamHandlerFactory.urlSHFactory; + } + +} Property changes on: trunk/foray/foray-common/src/java/org/foray/common/FOrayURLStreamHandlerFactory.java ___________________________________________________________________ Name: svn:keywords + "Author Id Rev Date URL" Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |