org.mortbay.resource.ResourceCollection Maven / Gradle / Ivy
//========================================================================
//Copyright 2007 Mort Bay Consulting Pty. Ltd.
//------------------------------------------------------------------------
//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.
//========================================================================
package org.mortbay.resource;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.StringTokenizer;
import org.mortbay.util.URIUtil;
/**
* A collection of resources (dirs).
* Allows webapps to have multiple (static) sources.
* The first resource in the collection is the main resource.
* If a resource is not found in the main resource, it looks it up in
* the order the resources were constructed.
*
* @author dyu
*
*/
public class ResourceCollection extends Resource
{
private Resource[] _resources;
public ResourceCollection()
{
}
/* ------------------------------------------------------------ */
public ResourceCollection(Resource[] resources)
{
setResources(resources);
}
/* ------------------------------------------------------------ */
public ResourceCollection(String[] resources)
{
setResources(resources);
}
/* ------------------------------------------------------------ */
public ResourceCollection(String csvResources)
{
setResources(csvResources);
}
/* ------------------------------------------------------------ */
/**
*
* @param resources Resource array
*/
public void setResources(Resource[] resources)
{
if(_resources!=null)
throw new IllegalStateException("*resources* already set.");
if(resources==null)
throw new IllegalArgumentException("*resources* must not be null.");
if(resources.length==0)
throw new IllegalArgumentException("arg *resources* must be one or more resources.");
_resources = resources;
for(int i=0; i<_resources.length; i++)
{
Resource r = _resources[i];
if(!r.exists() || !r.isDirectory())
throw new IllegalArgumentException(r + " is not an existing directory.");
}
}
/* ------------------------------------------------------------ */
/**
*
* @param resources String array
*/
public void setResources(String[] resources)
{
if(_resources!=null)
throw new IllegalStateException("*resources* already set.");
if(resources==null)
throw new IllegalArgumentException("*resources* must not be null.");
if(resources.length==0)
throw new IllegalArgumentException("arg *resources* must be one or more resources.");
_resources = new Resource[resources.length];
try
{
for(int i=0; i
© 2015 - 2024 Weber Informatics LLC | Privacy Policy