All Downloads are FREE. Search and download functionalities are using the official Maven repository.

bboss.org.apache.velocity.runtime.resource.loader.JarResourceLoader Maven / Gradle / Ivy

Go to download

bboss is a j2ee framework include aop/ioc,mvc,persistent,taglib,rpc,event ,bean-xml serializable and so on.http://www.bbossgroups.com

There is a newer version: 6.2.5
Show newest version
package bboss.org.apache.velocity.runtime.resource.loader;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.    
 */

import java.io.InputStream;

import java.util.Hashtable;
import java.util.Vector;
import java.util.Map;
import java.util.HashMap;

import bboss.org.apache.velocity.util.StringUtils;
import bboss.org.apache.velocity.runtime.resource.Resource;
import bboss.org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.commons.collections.ExtendedProperties;

/**
 * 

* ResourceLoader to load templates from multiple Jar files. *

*

* The configuration of the JarResourceLoader is straightforward - * You simply add the JarResourceLoader to the configuration via *

*

 *    resource.loader = jar
 *    jar.resource.loader.class = bboss.org.apache.velocity.runtime.resource.loader.JarResourceLoader
 *    jar.resource.loader.path = list of JAR <URL>s
 * 

* *

So for example, if you had a jar file on your local filesystem, you could simply do *

 *    jar.resource.loader.path = jar:file:/opt/myfiles/jar1.jar
 *    
*

*

Note that jar specification for the .path configuration property * conforms to the same rules for the java.net.JarUrlConnection class. *

* *

For a working example, see the unit test case, * bboss.org.apache.velocity.test.MultiLoaderTestCase class *

* * @author Aki Nieminen * @author Dave Bryson * @version $Id: JarResourceLoader.java 691884 2008-09-04 06:46:51Z nbubna $ */ public class JarResourceLoader extends ResourceLoader { /** * Maps entries to the parent JAR File * Key = the entry *excluding* plain directories * Value = the JAR URL */ private Map entryDirectory = new HashMap(559); /** * Maps JAR URLs to the actual JAR * Key = the JAR URL * Value = the JAR */ private Map jarfiles = new HashMap(89); /** * Called by Velocity to initialize the loader * @param configuration */ public void init( ExtendedProperties configuration) { log.trace("JarResourceLoader : initialization starting."); // rest of Velocity engine still use legacy Vector // and Hashtable classes. Classes are implicitly // synchronized even if we don't need it. Vector paths = configuration.getVector("path"); StringUtils.trimStrings(paths); /* * support the old version but deprecate with a log message */ if( paths == null || paths.size() == 0) { paths = configuration.getVector("resource.path"); StringUtils.trimStrings(paths); if (paths != null && paths.size() > 0) { log.debug("JarResourceLoader : you are using a deprecated configuration" + " property for the JarResourceLoader -> '.resource.loader.resource.path'." + " Please change to the conventional '.resource.loader.path'."); } } if (paths != null) { log.debug("JarResourceLoader # of paths : " + paths.size() ); for ( int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy