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.runtime.listener; 020 021import java.util.ArrayList; 022import java.util.List; 023 024import lucee.commons.io.res.Resource; 025import lucee.commons.io.res.util.ResourceUtil; 026import lucee.runtime.type.util.ArrayUtil; 027 028public class JavaSettingsImpl implements JavaSettings { 029 030 private final Resource[] resources; 031 private Resource[] resourcesTranslated; 032 private final boolean loadCFMLClassPath; 033 private final boolean reloadOnChange; 034 private final int watchInterval; 035 private final String[] watchedExtensions; 036 037 public JavaSettingsImpl(){ 038 this.resources=new Resource[0]; 039 this.loadCFMLClassPath=false; 040 this.reloadOnChange=false; 041 this.watchInterval=60; 042 this.watchedExtensions=new String[]{"jar","class"}; 043 } 044 045 public JavaSettingsImpl(Resource[] resources, Boolean loadCFMLClassPath,boolean reloadOnChange, int watchInterval, String[] watchedExtensions) { 046 047 this.resources=resources; 048 this.loadCFMLClassPath=loadCFMLClassPath; 049 this.reloadOnChange=reloadOnChange; 050 this.watchInterval=watchInterval; 051 this.watchedExtensions=watchedExtensions; 052 } 053 054 @Override 055 public Resource[] getResources() { 056 return resources; 057 } 058 059 // FUTURE add to interface 060 public Resource[] getResourcesTranslated() { 061 if(resourcesTranslated==null) { 062 List<Resource> list=new ArrayList<Resource>(); 063 _getResourcesTranslated(list,resources, true); 064 resourcesTranslated=list.toArray(new Resource[list.size()]); 065 } 066 return resourcesTranslated; 067 } 068 069 public static void _getResourcesTranslated(List<Resource> list, Resource[] resources, boolean deep) { 070 if(ArrayUtil.isEmpty(resources)) return; 071 for(int i=0;i<resources.length;i++){ 072 if(resources[i].isFile()) { 073 if(ResourceUtil.getExtension(resources[i], "").equalsIgnoreCase("jar")) 074 list.add(resources[i]); 075 } 076 else if(deep && resources[i].isDirectory()){ 077 list.add(resources[i]); // add as possible classes dir 078 _getResourcesTranslated(list,resources[i].listResources(),false); 079 080 } 081 } 082 } 083 084 @Override 085 public boolean loadCFMLClassPath() { 086 return loadCFMLClassPath; 087 } 088 089 @Override 090 public boolean reloadOnChange() { 091 return reloadOnChange; 092 } 093 094 @Override 095 public int watchInterval() { 096 return watchInterval; 097 } 098 099 @Override 100 public String[] watchedExtensions() { 101 return watchedExtensions; 102 } 103 104}