remm 01/01/12 21:17:05 Modified: catalina/src/share/org/apache/naming/resources DirContextURLConnection.java LocalStrings.properties Added: catalina/src/share/org/apache/naming/resources DirContextURLStreamHandlerFactory.java Log: - Added a factory for the stream handler. - The URL connection will auto connect. Revision Changes Path 1.2 +57 -16 jakarta-tomcat-4.1/catalina/src/share/org/apache/naming/resources/DirContextURLConnection.java Index: DirContextURLConnection.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/naming/resources/DirContextURLConnection.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DirContextURLConnection.java 2001/01/12 06:59:08 1.1 +++ DirContextURLConnection.java 2001/01/13 05:17:04 1.2 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/naming/resources/DirContextURLConnection.java,v 1.1 2001/01/12 06:59:08 remm Exp $ - * $Revision: 1.1 $ - * $Date: 2001/01/12 06:59:08 $ + * $Header: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/naming/resources/DirContextURLConnection.java,v 1.2 2001/01/13 05:17:04 remm Exp $ + * $Revision: 1.2 $ + * $Date: 2001/01/13 05:17:04 $ * * ==================================================================== * @@ -84,7 +84,7 @@ * content is directly returned. * * @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a> - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ */ public class DirContextURLConnection extends URLConnection { @@ -132,6 +132,12 @@ protected Attributes attributes; + /** + * Date. + */ + protected long date; + + // ------------------------------------------------------------- Properties @@ -145,19 +151,24 @@ public void connect() throws IOException { - try { - object = context.lookup(getURL().getFile()); - attributes = context.getAttributes(getURL().getFile()); - if (object instanceof Resource) - resource = (Resource) object; - if (object instanceof DirContext) - collection = (DirContext) object; - } catch (NamingException e) { - // Object not found + if (!connected) { + + try { + date = System.currentTimeMillis(); + object = context.lookup(getURL().getFile()); + attributes = context.getAttributes(getURL().getFile()); + if (object instanceof Resource) + resource = (Resource) object; + if (object instanceof DirContext) + collection = (DirContext) object; + } catch (NamingException e) { + // Object not found + } + + connected = true; + } - connected = true; - } @@ -180,6 +191,14 @@ /** * Return the last modified date. */ + public long getDate() { + return date; + } + + + /** + * Return the last modified date. + */ public long getLastModified() { return getHeaderFieldDate(ResourceAttributes.LAST_MODIFIED, 0); } @@ -189,6 +208,14 @@ * Returns the name of the specified header field. */ public String getHeaderField(String name) { + if (!connected) { + // Try to connect (silently) + try { + connect(); + } catch (IOException e) { + } + } + Attribute attribute = attributes.get(name); try { return attribute.get().toString(); @@ -196,6 +223,7 @@ // Shouldn't happen, unless the attribute has no value } return (null); + } @@ -205,8 +233,11 @@ public Object getContent() throws IOException { + if (!connected) + connect(); + if (resource != null) - return resource; + return getInputStream(); if (collection != null) return collection; if (object != null) @@ -241,8 +272,18 @@ public InputStream getInputStream() throws IOException { - if (resource == null) - throw new IOException(); + if (!connected) + connect(); + + if (resource == null) { + throw new FileNotFoundException(); + } else { + // Reopen resource + try { + resource = (Resource) context.lookup(getURL().getFile()); + } catch (NamingException e) { + } + } return (resource.streamContent()); 1.2 +0 -6 jakarta-tomcat-4.1/catalina/src/share/org/apache/naming/resources/LocalStrings.properties Index: LocalStrings.properties =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/naming/resources/LocalStrings.properties,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- LocalStrings.properties 2001/01/10 04:46:49 1.1 +++ LocalStrings.properties 2001/01/13 05:17:04 1.2 @@ -1,9 +1,3 @@ -directory.filename=Filename -directory.lastModified=Last Modified -directory.parent=Up To {0} -directory.size=Size -directory.title=Directory Listing For {0} -directory.version=Tomcat Catalina version 4.1 fileResources.base=Document base {0} does not exist or is not a readable directory jarResources.syntax=Document base {0} must start with 'jar:' and end with '!/' resources.alreadyStarted=Resources has already been started 1.1 jakarta-tomcat-4.1/catalina/src/share/org/apache/naming/resources/DirContextURLStreamHandlerFactory.java Index: DirContextURLStreamHandlerFactory.java =================================================================== /* * $Header: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/naming/resources/DirContextURLStreamHandlerFactory.java,v 1.1 2001/01/13 05:17:04 remm Exp $ * $Revision: 1.1 $ * $Date: 2001/01/13 05:17:04 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * [Additional notices, if required by prior licensing conditions] * */ package org.apache.naming.resources; import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; import java.io.IOException; import javax.naming.NamingException; import javax.naming.directory.DirContext; /** * Factory for Stream handlers to a JNDI directory context. * * @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a> * @version $Revision: 1.1 $ */ public class DirContextURLStreamHandlerFactory implements URLStreamHandlerFactory { // ----------------------------------------------------------- Constructors public DirContextURLStreamHandlerFactory(DirContext context) { this.context = context; } // ----------------------------------------------------- Instance Variables /** * Directory context. */ protected DirContext context; // ------------------------------------------------------------- Properties // ---------------------------------------- URLStreamHandlerFactory Methods /** * Creates a new URLStreamHandler instance with the specified protocol. * Will return null if the protocol is not <code>jndi</code>. * * @param protocol the protocol (must be "jndi" here) * @return a URLStreamHandler for the jndi protocol, or null if the * protocol is not JNDI */ public URLStreamHandler createURLStreamHandler(String protocol) { if (protocol.equals("jndi")) { return new DirContextURLStreamHandler(context); } else { return null; } } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]