/******************************************************************************
 * ExternalLogicImpl.java - created by Sakai App Builder -AZ
 * 
 * Copyright (c) 2006 Sakai Project/Sakai Foundation
 * Licensed under the Educational Community License version 1.0
 * 
 * A copy of the Educational Community License has been included in this 
 * distribution and is available at: http://www.opensource.org/licenses/ecl1.php
 * 
 *****************************************************************************/

package org.sakaiproject.wontovlab.logic.impl;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sakaiproject.wontovlab.logic.UtilLogic;
import org.springframework.util.FileCopyUtils;

/**
 * This is the implementation for logic which is external to our app logic
 * @author Sakai App Builder -AZ
 */
public class UtilLogicImpl implements UtilLogic {

	private static Log log = LogFactory.getLog(UtilLogicImpl.class);

	
    /**
     * List files inside a specific directory
     * @param dir
     * @param prefix
     * @return
     */
    public List<File> listServerDirectoryFiles(File dir, final String prefix)
    {
    	log.debug("Listing directory files on dir: " + dir.getAbsolutePath()); 
    	if (!dir.exists())
    	{
    		return null;
    	}
    	
    	File[] files = dir.listFiles(new FilenameFilter()
    	{
    		public boolean accept(File dir, String name)
    		{
    			if (name.startsWith(prefix))
    			{
    				return true;
    			}
    			return false;
    		}
    	});
    	
    	if (files != null)
    	{
    		return Arrays.asList(files);
    	}
    	
    	return null;    	
    }
       



}
