[FOray-commit] SF.net SVN: foray: [7706] 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 17:09:35
|
Revision: 7706 Author: victormote Date: 2006-06-19 10:09:24 -0700 (Mon, 19 Jun 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7706&view=rev Log Message: ----------- Move and rename the ClasspathHandler class to a location where the java property scheme can find it. Modified Paths: -------------- trunk/foray/foray-common/src/java/org/foray/common/AbstractURLStreamHandler.java Added Paths: ----------- trunk/foray/foray-common/src/java/org/foray/common/url/ trunk/foray/foray-common/src/java/org/foray/common/url/classpath/ trunk/foray/foray-common/src/java/org/foray/common/url/classpath/Handler.java Removed Paths: ------------- trunk/foray/foray-common/src/java/org/foray/common/ClasspathHandler.java Modified: trunk/foray/foray-common/src/java/org/foray/common/AbstractURLStreamHandler.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/AbstractURLStreamHandler.java 2006-06-19 17:02:20 UTC (rev 7705) +++ trunk/foray/foray-common/src/java/org/foray/common/AbstractURLStreamHandler.java 2006-06-19 17:09:24 UTC (rev 7706) @@ -92,7 +92,7 @@ classPath.length()); /* Validate the class name. */ - if (! className.equals("Handler")) { + if (! className.equals("Handler")) { return; } Deleted: 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 17:02:20 UTC (rev 7705) +++ trunk/foray/foray-common/src/java/org/foray/common/ClasspathHandler.java 2006-06-19 17:09:24 UTC (rev 7706) @@ -1,79 +0,0 @@ -/* - * 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.io.InputStream; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLStreamHandler; - -/** - * Stream handler for URLs with the <code>classpath</code> protocol. Such URLs - * are used to refer to resources in the CLASSPATH. The two following syntaxes - * are allowed, but the first one is preferred: - * <ul> - * <li><code>classpath:/path/to/the/resource</code></li> - * <li><code>classpath:path/to/the/resource</code></li> - * </ul> - */ -public class ClasspathHandler extends AbstractURLStreamHandler { - - private static final String PROTOCOL = "classpath"; - - protected URLConnection openConnection(URL u) { - return new URLConnection(u) { - public void connect() {} - - public InputStream getInputStream() throws IOException { - String path = url.getPath(); - String resourcePath = - (path.charAt(0) == '/')? path.substring(1): path; - InputStream inputStream = getClass().getClassLoader(). - getResourceAsStream(resourcePath); - if (inputStream == null) { - throw new IOException("Unable to open input stream for: " - + url.toString()); - } - return inputStream; - } - }; - } - - /** - * Register an instance of this class with the custom - * URLStreamHandlerFactory so that this handler will be used for URLs of - * protocol "classpath". - */ - public static void register() { - URLStreamHandler handler = new ClasspathHandler(); - AbstractURLStreamHandler.register(ClasspathHandler.PROTOCOL, handler); - } - -} Added: trunk/foray/foray-common/src/java/org/foray/common/url/classpath/Handler.java =================================================================== --- trunk/foray/foray-common/src/java/org/foray/common/url/classpath/Handler.java (rev 0) +++ trunk/foray/foray-common/src/java/org/foray/common/url/classpath/Handler.java 2006-06-19 17:09:24 UTC (rev 7706) @@ -0,0 +1,81 @@ +/* + * 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.url.classpath; + +import org.foray.common.AbstractURLStreamHandler; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLStreamHandler; + +/** + * Stream handler for URLs with the <code>classpath</code> protocol. Such URLs + * are used to refer to resources in the CLASSPATH. The two following syntaxes + * are allowed, but the first one is preferred: + * <ul> + * <li><code>classpath:/path/to/the/resource</code></li> + * <li><code>classpath:path/to/the/resource</code></li> + * </ul> + */ +public class Handler extends AbstractURLStreamHandler { + + private static final String PROTOCOL = "classpath"; + + protected URLConnection openConnection(URL u) { + return new URLConnection(u) { + public void connect() {} + + public InputStream getInputStream() throws IOException { + String path = url.getPath(); + String resourcePath = + (path.charAt(0) == '/')? path.substring(1): path; + InputStream inputStream = getClass().getClassLoader(). + getResourceAsStream(resourcePath); + if (inputStream == null) { + throw new IOException("Unable to open input stream for: " + + url.toString()); + } + return inputStream; + } + }; + } + + /** + * Register an instance of this class with the custom + * URLStreamHandlerFactory so that this handler will be used for URLs of + * protocol "classpath". + */ + public static void register() { + URLStreamHandler handler = new Handler(); + AbstractURLStreamHandler.register(Handler.PROTOCOL, handler); + } + +} Property changes on: trunk/foray/foray-common/src/java/org/foray/common/url/classpath/Handler.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. |