1 7 package com.inversoft.verge.mvc.controller.form.config; 8 9 10 import org.jdom.Element; 11 12 import com.inversoft.config.ConfigurationException; 13 import com.inversoft.error.ErrorList; 14 import com.inversoft.util.StringTools; 15 import com.inversoft.verge.mvc.config.BaseConfig; 16 import com.inversoft.verge.mvc.config.BaseConfigBuilder; 17 18 19 25 public class MappingConfigBuilder extends BaseConfigBuilder { 26 27 28 31 public MappingConfigBuilder() { 32 } 33 34 35 41 public BaseConfig build(Element element) throws ConfigurationException { 42 43 ErrorList errors = new ErrorList(); 44 String name = element.getAttributeValue(Constants.NAME_ATTRIBUTE); 45 String url = element.getAttributeValue(Constants.URL_ATTRIBUTE); 46 String forward = element.getAttributeValue(Constants.FORWARD_ATTRIBUTE); 47 String category = element.getAttributeValue(Constants.CATEGORY_ATTRIBUTE); 48 49 if (name == null) { 50 errors.addError("Mappings must have a name"); 51 } 52 53 if (url == null) { 54 errors.addError("Mapping named: " + name + " must have a url"); 55 } 56 57 boolean forwardBool = true; 60 if (forward != null && !StringTools.isValidBoolean(forward)) { 61 errors.addError("Mapping named: " + name + 62 " has an invalid value for the forward attribute"); 63 } else if (forward != null) { 64 forwardBool = Boolean.valueOf(forward).booleanValue(); 65 } 66 67 if (!errors.isEmpty()) { 68 throw new ConfigurationException(errors); 69 } 70 71 if (forwardBool) { 73 category = null; 74 } 75 76 return new MappingConfig(name, url, forwardBool, category); 77 } 78 } 79 80 | Popular Tags |