1 package org.enhydra.server; 2 3 import java.util.ArrayList ; 4 import java.util.HashMap ; 5 6 import org.enhydra.server.util.WebAppXML; 7 8 16 17 public class FiltersEdit { 18 private EnhydraServer es = null; 19 private String appName = null; 20 private WebAppXML webXML = null; 21 private HashMap filters = null; 22 23 public FiltersEdit(String appName) { 24 es = EnhydraServer.getInstance(); 25 this.appName = appName; 26 AppInfo appInfo = es.getAppInfo(appName); 27 webXML = appInfo.getWebAppXML(); 28 reloadFilters(); 29 } 30 public void reloadFilters(){ 31 32 webXML.reloadDocument(); 34 refreshFilters(); 35 36 } 37 38 private void refreshFilters(){ 39 String [] filterNames = webXML.getFilterNames(); 40 filters = new HashMap (); 41 if(filterNames != null){ 42 for(int i=0 ;i<filterNames.length ; i++){ 43 FilterData filterData = createFilterData(filterNames[i]); 44 filters.put(filterNames[i], filterData); 45 } 46 } 47 } 48 49 public WebAppXML getWebAppXML(){ 50 return webXML; 51 } 52 53 54 55 public String [] getFilterNames(){ 56 return webXML.getFilterNames(); 57 } 58 59 public FilterData getFilterData(String filterName){ 60 return (FilterData) filters.get(filterName); 61 } 62 63 public void addFilter(FilterData filterData){ 64 HashMap params = new HashMap (); 65 if(webXML.getFilterParameters(filterData.getName()).containsKey("filter-class")){ 66 webXML.removeFilter(filterData.getName()); 69 } 70 71 72 String name, className, description, displayName, smallIcon, largeIcon,urlPattern, servletName; 74 ArrayList initParamsArray = filterData.getInitParams(); 75 76 name = filterData.getName().trim(); 77 className = filterData.getFilterClass().trim(); 78 79 description = filterData.getDescription(); 80 if(description!=null && description.trim().equalsIgnoreCase("")){ 82 description = null; 83 } 84 85 displayName = filterData.getDisplayName(); 86 if(displayName!=null && displayName.trim().equalsIgnoreCase("")){ 87 displayName = null; 88 } 89 90 smallIcon = filterData.getSmallIcon(); 91 if(smallIcon!=null && smallIcon.trim().equalsIgnoreCase("")){ 92 smallIcon = null; 93 } 94 95 largeIcon = filterData.getLargeIcon(); 96 if(largeIcon!=null && largeIcon.trim().equalsIgnoreCase("")){ 97 largeIcon = null; 98 } 99 100 urlPattern = filterData.getMappingURLPattern(); 101 if(urlPattern!=null && urlPattern.trim().equalsIgnoreCase("")){ 102 urlPattern = null; 103 } 104 105 servletName = filterData.getMappingServletName(); 106 107 if(urlPattern!=null){ 109 servletName = null; 110 }else if(servletName!=null && servletName.trim().equalsIgnoreCase("")){ 111 servletName = null; 112 } 113 114 String [] paramNames = null; 115 String [] paramValues = null; 116 String [] paramDescriptions = null; 117 118 if(initParamsArray!=null){ 120 paramNames = new String [initParamsArray.size()]; 121 paramValues = new String [initParamsArray.size()]; 122 paramDescriptions = new String [initParamsArray.size()]; 123 124 for(int i=0; i<initParamsArray.size(); i++){ 125 paramNames[i] = (String ) ((ArrayList )initParamsArray.get(i)).get(0); 126 paramValues[i] = (String ) ((ArrayList )initParamsArray.get(i)).get(1); 127 paramDescriptions[i] = (String ) ((ArrayList )initParamsArray.get(i)).get(2); 128 } 129 } 130 131 webXML.addFilter(name, className, smallIcon, largeIcon, displayName, description,paramNames, paramValues, paramDescriptions, urlPattern, servletName); 132 refreshFilters(); 133 } 134 135 public FilterData createFilterData(String filterName){ 136 137 FilterData filterData = new FilterData(filterName); 138 HashMap params = webXML.getFilterParameters(filterName); 139 if(params !=null){ 140 if(params.containsKey("description")){ 141 filterData.setDescription((String )params.get("description")); 142 } 143 if(params.containsKey("display-name")){ 144 filterData.setDisplayName((String )params.get("display-name")); 145 } 146 if(params.containsKey("filter-class")){ 147 filterData.setFilterClass((String )params.get("filter-class")); 148 } 149 if(params.containsKey("large-icon")){ 150 filterData.setLargeIcon((String )params.get("large-icon")); 151 } 152 if(params.containsKey("small-icon")){ 153 filterData.setSmallIcon((String )params.get("small-icon")); 154 } 155 if(params.containsKey("url-pattern")){ 156 filterData.setMappingURLPattern((String )params.get("url-pattern")); 157 } 158 159 if(params.containsKey("servlet-name")){ 160 filterData.setMappingServletName((String )params.get("servlet-name")); 161 } 162 if(params.containsKey("init-param")){ 164 filterData.setInitParams((ArrayList )params.get("init-param")); 165 } 166 } 167 168 return filterData; 169 } 170 public void removeFilter(String filterName){ 171 webXML.removeFilter(filterName); 172 refreshFilters(); 173 } 174 public void save(){ 175 webXML.saveDocument(); 176 } 177 } | Popular Tags |