| 1 19 20 package com.sslexplorer.webforwards.webforwardwizard.forms; 21 22 import java.net.MalformedURLException ; 23 import java.net.URL ; 24 import java.util.HashMap ; 25 import java.util.List ; 26 import java.util.Map ; 27 import java.util.StringTokenizer ; 28 29 import javax.servlet.http.HttpServletRequest ; 30 31 import org.apache.commons.logging.Log; 32 import org.apache.commons.logging.LogFactory; 33 import org.apache.struts.Globals; 34 import org.apache.struts.action.ActionErrors; 35 import org.apache.struts.action.ActionMapping; 36 import org.apache.struts.action.ActionMessage; 37 38 import com.sslexplorer.boot.PropertyList; 39 import com.sslexplorer.core.BundleActionMessage; 40 import com.sslexplorer.core.forms.AbstractResourceDetailsWizardForm; 41 import com.sslexplorer.vfs.webdav.DAVUtilities; 42 import com.sslexplorer.webforwards.WebForward; 43 import com.sslexplorer.webforwards.WebForwardPlugin; 44 import com.sslexplorer.webforwards.WebForwardTypes; 45 import com.sslexplorer.wizard.AbstractWizardSequence; 46 47 54 public class WebForwardSpecificDetailsForm extends AbstractResourceDetailsWizardForm { 55 56 final static Log log = LogFactory.getLog(WebForwardSpecificDetailsForm.class); 57 58 private int type = -1; 59 public final static String ATTR_DESTINATION_URL = "destinationURL"; 61 public final static String ATTR_CATEGORY = "category"; 62 63 private String destinationURL; 64 private String category; 65 66 public final static String ATTR_RESTRICT_TO_HOSTS = "restrictToHosts"; 68 public final static String ATTR_ENCODEING = "encoding"; 69 70 private String encoding; 71 private PropertyList restrictToHosts; 72 73 public final static String ATTR_PATHS = "paths"; 75 public final static String ATTR_ACTIVE_DNS = "activeDNS"; 76 public final static String ATTR_CUSTOM_HEADERS = "customHeaders"; 77 78 public static final String ATTR_HOST_HEADER = "hostHeader"; 79 80 private String hostHeader; 81 private String paths; 82 private boolean activeDNS; 83 private Map customHeaders; 84 85 88 public WebForwardSpecificDetailsForm() { 89 super(true, true, "/WEB-INF/jsp/content/webforward/webforwardwizard/webForwardSpecificDetails.jspf", "destinationURL", true, false, 90 "webForwardSpecificDetails", "webForwards", "webForwardWizard.webForwardSpecificDetails", 3, WebForwardPlugin.WEBFORWARD_RESOURCE_TYPE); 91 } 92 93 99 public void init(AbstractWizardSequence sequence, HttpServletRequest request) throws Exception { 100 super.init(sequence, request); 101 this.restrictToHosts = (PropertyList)sequence.getAttribute(ATTR_RESTRICT_TO_HOSTS, new PropertyList()); 102 this.destinationURL = (String ) sequence.getAttribute(ATTR_DESTINATION_URL, ""); 103 this.category = (String ) sequence.getAttribute(ATTR_CATEGORY, "General"); 104 type = ((Integer ) sequence.getAttribute(WebForwardTypeSelectionForm.ATTR_TYPE, new Integer (0))).intValue(); 105 this.encoding = (String ) sequence.getAttribute(ATTR_ENCODEING, WebForwardTypes.DEFAULT_ENCODING); 106 107 this.paths = (String ) sequence.getAttribute(ATTR_PATHS, ""); 108 this.hostHeader = (String ) sequence.getAttribute(ATTR_HOST_HEADER, ""); 109 this.activeDNS = ((Boolean ) sequence.getAttribute(ATTR_ACTIVE_DNS, Boolean.FALSE)).booleanValue(); 110 this.customHeaders = (Map ) sequence.getAttribute(ATTR_CUSTOM_HEADERS, new HashMap ()); 111 } 112 113 118 public void apply(AbstractWizardSequence sequence) throws Exception { 119 super.apply(sequence); 120 sequence.putAttribute(ATTR_DESTINATION_URL, this.destinationURL); 121 sequence.putAttribute(ATTR_CATEGORY, this.category); 122 sequence.putAttribute(ATTR_ENCODEING, this.encoding); 123 sequence.putAttribute(ATTR_PATHS, this.paths); 124 sequence.putAttribute(ATTR_ACTIVE_DNS, new Boolean (this.activeDNS)); 125 sequence.putAttribute(ATTR_HOST_HEADER, activeDNS ? "" : this.hostHeader); 126 sequence.putAttribute(ATTR_CUSTOM_HEADERS, this.customHeaders); 127 sequence.putAttribute(ATTR_RESTRICT_TO_HOSTS, restrictToHosts); 128 } 129 130 136 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { 137 if (getResourceName() != null && isCommiting()) { 138 ActionErrors errs = super.validate(mapping, request); 139 AbstractWizardSequence seq = getWizardSequence(request); 140 141 try { 142 if (this.getDestinationURL().indexOf("${") == -1){ 143 new URL (this.getDestinationURL()); 145 } 146 } catch (MalformedURLException e) { 147 errs.add(Globals.ERROR_KEY, new BundleActionMessage(seq.getCurrentPageForm().getResourceBundle(), seq 148 .getCurrentPageForm().getResourcePrefix() 149 + ".error.malformedURLException")); 150 } 151 152 153 if(getCategory().trim().equals("")) { 154 errs.add(Globals.ERROR_KEY, new BundleActionMessage(seq.getCurrentPageForm().getResourceBundle(), seq 155 .getCurrentPageForm().getResourcePrefix() 156 + ".error.noCategory")); 157 } 158 159 if (type == WebForward.TYPE_PATH_BASED_REVERSE_PROXY){ 160 if (this.paths != null && this.paths.length() == 0){ 161 errs.add(Globals.ERROR_KEY, new ActionMessage("webForwardWizard.webForwardSpecificDetails.error.needs.path")); 162 } 163 String validatedPaths = ""; 164 165 if (this.paths != null && this.paths.length() > 0){ 166 StringTokenizer t = new StringTokenizer (this.paths, "\n\r"); 167 while (t.hasMoreTokens()) { 168 String path = t.nextToken(); 169 path = path.trim(); 170 if(!path.startsWith("/")) 171 path = "/" + path; 172 if(path.endsWith("/")) 173 path = DAVUtilities.stripTrailingSlash(path); 174 175 validatedPaths += path + "\n"; 176 } 177 if(errs.size() == 0) 178 this.paths = validatedPaths; 179 } 180 } else if (type == WebForward.TYPE_HOST_BASED_REVERSE_PROXY){ 181 if (this.activeDNS && !this.hostHeader.equals("")){ 182 errs.add(Globals.ERROR_KEY, new ActionMessage("webForwardWizard.webForwardSpecificDetails.error.hostBased.bothSelected")); 183 } 184 if (!this.activeDNS && this.hostHeader.equals("")){ 185 errs.add(Globals.ERROR_KEY, new ActionMessage("webForwardWizard.webForwardSpecificDetails.error.hostBased.nonSelected")); 186 } 187 } 188 189 return errs; 190 } 191 return null; 192 } 193 194 197 public String getCategory() { 198 return category; 199 } 200 201 204 public void setCategory(String category) { 205 this.category = category; 206 } 207 208 211 public String getDestinationURL() { 212 return destinationURL; 213 } 214 215 218 public void setDestinationURL(String destinationURL) { 219 this.destinationURL = destinationURL; 220 } 221 222 public boolean isPathBased() { 223 return WebForward.TYPE_PATH_BASED_REVERSE_PROXY == type; 224 } 225 226 public boolean isHostBased() { 227 return WebForward.TYPE_HOST_BASED_REVERSE_PROXY == type; 228 } 229 230 public PropertyList getRestrictToHostsList() { 231 return restrictToHosts; 232 } 233 234 public String getRestrictToHosts() { 235 return restrictToHosts.getAsTextFieldText(); 236 } 237 238 public void setRestrictToHosts(String restrictToHosts) { 239 this.restrictToHosts.setAsTextFieldText(restrictToHosts); 240 } 241 242 public void reset(ActionMapping mapping, HttpServletRequest request) { 243 super.reset(mapping, request); 244 this.activeDNS = false; 245 } 246 247 public boolean isActiveDNS() { 248 return activeDNS; 249 } 250 251 public void setActiveDNS(boolean activeDNS) { 252 this.activeDNS = activeDNS; 253 } 254 255 public Map getCustomHeaders() { 256 return customHeaders; 257 } 258 259 public void setCustomHeaders(Map customHeaders) { 260 this.customHeaders = customHeaders; 261 } 262 263 public String getPaths() { 264 return paths; 265 } 266 267 public void setPaths(String paths) { 268 this.paths = paths; 269 } 270 public String getEncoding() { 271 return encoding; 272 } 273 274 public void setEncoding(String encoding) { 275 this.encoding = encoding; 276 } 277 278 public String getHostHeader() { 279 return hostHeader; 280 } 281 282 public void setHostHeader(String hostHeader) { 283 this.hostHeader = hostHeader; 284 } 285 286 public List getEncodeingTypeList() { 287 return WebForwardTypes.ENCODING_TYPES; 288 } 289 } | Popular Tags |