/*
*
* Perforce/Java Integration Layer
* Copyright (C) 2001-2002 David Freels
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.dafreels.vcs.util;
//Java
import java.util.List;
import java.util.ArrayList;
/**
*
* @author David Freels
* @version 1.0
*/
public final class ExtensionRegistry
{
private static List m_extensions = null;
private static ExtensionRegistry m_reg = null;
/** Creates new ExtensionRegistry */
private ExtensionRegistry()
{
// Don't re-initialize the m_extensions ArrayList if it's already
// been setup. (Matt Wolinski - 6/4/03)
if (m_extensions == null)
{
m_extensions = new ArrayList(10);
m_extensions.add("java");
m_extensions.add("jsp");
m_extensions.add("html");
m_extensions.add("htm");
m_extensions.add("gif");
m_extensions.add("jpg");
m_extensions.add("js");
m_extensions.add("css");
m_extensions.add("xml");
m_extensions.add("jsi");
}
}
/**
* Creates a new instance of the ExtensionRegistry
* class
* @param extensions A list of file extensions that the toll will recognize minus the "."
* @return An instance of the ExtensionRegistry class
*/
public static ExtensionRegistry newInstance(List extensions)
{
// Set the m_extensions ArrayList and overwrite it when it already exists.
// The list we passed in is the one we want to use. (MJW - 6/4/03)
ExtensionRegistry.m_extensions = extensions;
return getInstance();
}
/**
* Gets the singleton instance of this class.
* @return An instance of the ExtensioRegistry class
*/
public static ExtensionRegistry getInstance()
{
if(m_reg == null)
{
m_reg = new ExtensionRegistry();
}
return m_reg;
}
/**
* Validates the filename against the list of
* valid extensions.
* @param fileName The filename to validate
* @return True if the file has a valid extension.
*/
public boolean validateFile(String fileName)
{
if(m_extensions == null) return false;
return m_extensions.contains(fileName.substring(fileName.lastIndexOf(".") + 1));
}
}