1 package net.sf.invicta.handler; 2 3 import java.io.File ; 4 import java.util.HashMap ; 5 import java.util.Iterator ; 6 import java.util.Map ; 7 8 import net.sf.invicta.InvictaException; 9 import net.sf.invicta.api.InvictaComponent; 10 import net.sf.invicta.api.Product; 11 12 23 public class DependFilesetHandler extends InvictaBasicHandler { 24 protected final static String DIR_ATTR = "dir"; 25 protected final static boolean DEFAULT_IGNORE = false; 26 protected String element; 27 protected String attribute; 28 protected String locationPropertyName; 29 protected String includePropertyName; 30 protected String excludeType; 31 32 35 public String handle(Map paramsMap) throws InvictaException { 36 this.element = getRequiredParameter("element"); 37 this.attribute = getRequiredParameter("attribute"); 38 39 this.locationPropertyName = getParameter("locationProperty"); 40 this.includePropertyName = getParameter("includeProperty"); 41 this.excludeType = getParameter("excludeType"); 42 43 if (getParameterPropertyBooleanValue("ignoreProperty", DEFAULT_IGNORE)) { 44 return ""; 45 } 46 return prepareDependFilesets(); 47 } 48 49 52 private String prepareDependFilesets() { 53 54 String filesetsStr = ""; 55 if (this.locationPropertyName != null) { 56 57 for (Iterator iter = getComponent().getDependComponents().iterator(); iter.hasNext();) { 59 InvictaComponent dependComponent = (InvictaComponent) iter.next(); 60 61 String propertyRefValue = dependComponent.getPropertyReferenceValue(locationPropertyName); 63 64 String includeRefValue = null; 66 if (includePropertyName != null) { 67 includeRefValue = dependComponent.getPropertyReferenceValue(includePropertyName); 68 if (includeRefValue == null) 70 continue; 71 } 72 73 if (propertyRefValue != null) 75 filesetsStr += prepareFileset(propertyRefValue, includeRefValue); 76 } 77 } else { 78 filesetsStr += prepareProductsFilesets(); 79 } 80 return filesetsStr; 81 } 82 83 86 private String prepareProductsFilesets() { 87 String filesetsStr = ""; 88 Map productKeys = new HashMap (); 89 90 for (Iterator iter = getComponent().getRecursiveProducts().iterator(); iter.hasNext();) { 92 Product product = (Product) iter.next(); 93 94 if ((product.getFile() != null) && 95 !((this.excludeType != null) && (product.getType() != null) && (product.getType().equals(this.excludeType))) && 96 (!productKeys.containsKey(product.getKey()))) { 97 98 filesetsStr += prepareFileset(product.getPath(), null); 99 productKeys.put(product.getKey(), new Object ()); 100 } 101 } 102 return filesetsStr; 103 } 104 105 108 private String prepareFileset(String attrValue, String includeValue) { 109 String fileset = "<" + this.element + " "; 110 111 String fileName = attrValue; 112 if (!this.attribute.equals(DIR_ATTR)) { 114 File file = new File (attrValue); 115 String dir = file.getParent(); 116 fileName = file.getName(); 117 if (dir == null) 118 dir = getProject().getProjectPropertyValue("home"); 119 fileset += DIR_ATTR + "=\"" + dir + "\" "; 120 } 121 122 fileset += this.attribute + "=\"" + fileName + "\">\n"; 123 124 if (includeValue != null) { 125 fileset += "<include name=\"" + includeValue + "\"/>\n"; 126 } 127 128 fileset += "</" + this.element + ">\n"; 129 130 return fileset; 131 } 132 133 136 public String getName() { 137 return "dependFileset"; 138 } 139 140 } 141 | Popular Tags |