001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.deployer.filter; 020 021import lucee.commons.io.res.Resource; 022import lucee.runtime.exp.PageException; 023import lucee.runtime.type.util.ListUtil; 024 025/** 026 * Die Klasse CFMLFilter implementiert das Interface Filter, 027 * die Klasse prueft bei einem uebergebenen File Objekt, 028 * ob dessen Extension mit denen die dem Konstruktor mitgegeben wurden uebereinstimmen. 029 */ 030public final class CFMLFilter implements Filter { 031 032 private String[] extensions; 033 034 /** 035 * Konstruktor von CFMLFilter, dem Konstruktor wird ein String Array uebergeben mit Extensions die geprueft werden sollen, 036 * wie z.B. {"cfml","cfm"}. 037 * @param extensions Extensions die geprueft werden sollen. 038 */ 039 public CFMLFilter(String[] extensions) { 040 this.extensions=extensions; 041 for(int i=0;i<extensions.length;i++) { 042 extensions[i]=extensions[i].toLowerCase(); 043 } 044 } 045 046 public boolean isValid(Resource file) { 047 String[] arr; 048 try { 049 arr = ListUtil.toStringArray(ListUtil.listToArray(file.getName(), '.')); 050 } 051 catch (PageException e) { 052 return false; 053 } 054 String ext=arr[arr.length-1].toLowerCase(); 055 for(int i=0;i<extensions.length;i++) { 056 if(extensions[i].equals(ext)) 057 return true; 058 } 059 return false; 060 } 061}