1 package net.sf.invicta.handler; 2 3 import java.util.Map ; 4 5 import net.sf.invicta.InvictaConstants; 6 import net.sf.invicta.InvictaException; 7 import net.sf.invicta.api.InvictaComponent; 8 import net.sf.invicta.api.Product; 9 10 11 21 public class ProductHandler extends InvictaBasicHandler { 22 private final static boolean DEFAULT_ONLY_BASE_NAME = false; 23 private final static boolean DEFAULT_INCLUDE_SUFFIX = false; 24 25 28 public String getName() { 29 return "product"; 30 } 31 32 35 public String handle(Map paramsMap) throws InvictaException { 36 37 String componentReference = getParameter("component"); 38 String type = getParameter("type"); 39 String name = getParameter("name"); 40 String defaultProductFile = getParameter("defaultFile"); 41 boolean onlyBaseName = getBooleanParameter("onlyBaseName", DEFAULT_ONLY_BASE_NAME); 42 boolean includeSuffix = getBooleanParameter("includeSuffix", DEFAULT_INCLUDE_SUFFIX); 43 44 InvictaComponent component; 45 if (componentReference == null) { 46 component = getComponent(); 47 } else { 48 String componentName = getComponent().getPropertyValue(componentReference); 49 component = getProject().getComponent(componentName); 50 } 51 52 Product product = component.getSelfProduct(type, name); 53 54 if ((product == null) && (defaultProductFile != null)) 55 return defaultProductFile; 56 57 if (product == null) 58 throw new InvictaHandlerException(this, "No product defined for component '" + 59 component.getName() + 60 "' with type=" + type + ", name=" + name); 61 62 if (onlyBaseName) 63 return getBaseName(product.getFile(), includeSuffix); 64 else 65 return product.getPath(); 66 } 67 68 69 72 protected String getBaseName(String path, boolean includeSuffix) { 73 String base = path; 74 int index = base.lastIndexOf(InvictaConstants.FILE_SEPARATOR); 75 if (index != -1) 76 base = base.substring(index + 1); 77 78 if (!includeSuffix) { 79 index = base.lastIndexOf("."); 80 81 if (index != -1) 82 base = base.substring(0, index); 83 } 84 return base; 85 } 86 87 } 88 | Popular Tags |