geirm 01/11/24 16:33:10 Added: whiteboard/geir URLResourceLoader.java velocity.properties Log: to play with... Revision Changes Path 1.1 jakarta-velocity/whiteboard/geir/URLResourceLoader.java Index: URLResourceLoader.java =================================================================== package org.apache.velocity.runtime.resource.loader; /* * The Apache Software License, Version 1.1 * * Copyright (c) 2001 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/>. */ import java.net.URL; import java.net.URLConnection; import java.io.InputStream; import java.util.Vector; import org.apache.velocity.runtime.resource.Resource; import org.apache.velocity.exception.ResourceNotFoundException; import org.apache.commons.collections.ExtendedProperties; /** * This is a simple URL-based loader. * * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a> * @version $Id: URLResourceLoader.java,v 1.1 2001/11/25 00:33:10 geirm Exp $ */ public class URLResourceLoader extends ResourceLoader { private Vector urlroots = new Vector(); public void init( ExtendedProperties configuration) { rsvc.info("URLResourceLoader : initialization starting."); urlroots = configuration.getVector("root"); for( int i=0; i < urlroots.size(); i++) { rsvc.info("URLResourceLoader : adding root '" + (String) urlroots.get(i) + "'"); } rsvc.info("URLResourceLoader : initialization complete."); } /** * Get an InputStream so that the Runtime can build a * template with it. * * @param url url of template to fetch bytestream of * @return InputStream containing the template * @throws ResourceNotFoundException if template not found * in the file template path. */ public synchronized InputStream getResourceStream( String url ) throws ResourceNotFoundException { for( int i=0; i < urlroots.size(); i++) { try { String full = (String) urlroots.get( i ); URL u = new URL( full + url ); URLConnection conn = u.openConnection(); InputStream inputStream = conn.getInputStream(); if (inputStream != null) { return inputStream; } } catch( Exception e ) { /* * for now, just ignore. we can prollie do * something better here.. */ } } String msg = "URLResourceLoader : Error: cannot find resource " + url; rsvc.error( "URLResourceLoader : " + msg ); throw new ResourceNotFoundException( msg ); } /** * How to keep track of all the modified times * across the paths. */ public boolean isSourceModified(Resource resource) { return true; } public long getLastModified(Resource resource) { return 0; } } 1.1 jakarta-velocity/whiteboard/geir/velocity.properties Index: velocity.properties =================================================================== resource.loader = url url.resource.loader.class = org.apache.velocity.runtime.resource.loader.URLResourceLoader url.resource.loader.root = http://localhost:8080/veltest/, file:///opt/
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
