1 package net.sf.invicta.handler; 2 3 import java.util.Iterator ; 4 import java.util.Map ; 5 6 import net.sf.invicta.InvictaException; 7 import net.sf.invicta.api.Product; 8 import net.sf.invicta.project.InvictaProjectException; 9 import net.sf.invicta.api.ProductContainer; 10 11 12 22 public class PathElementsHandler extends InvictaBasicHandler { 23 private final static boolean DEFAULT_IGNORE_EXPORT = false; 24 private final static boolean DEFAULT_FILESET_FORMAT = true; 25 private final static String DEFAULT_SEPARATOR = " "; 26 27 30 public String getName() { 31 return "pathElements"; 32 } 33 34 37 public String handle(Map paramsMap) throws InvictaException { 38 39 boolean ignoreExport = getParameterPropertyBooleanValue("ignoreExport", DEFAULT_IGNORE_EXPORT); 40 String componentName = getParameterPropertyValue("componentName"); 41 String productName = getParameterPropertyValue("productName"); 42 boolean fileSetFormat = getBooleanParameter("fileSetFormat", DEFAULT_FILESET_FORMAT); 43 String separator = getParameter("separator", DEFAULT_SEPARATOR); 44 45 if ((productName != null) && (productName.length() == 0)) { 46 productName = null; 47 } 48 49 return preparePathElements( 50 ignoreExport, 51 componentName, 52 productName, 53 fileSetFormat, 54 separator); 55 } 56 57 60 protected String preparePathElements( 61 boolean ignoreExport, 62 String componentName, 63 String productName, 64 boolean fileSetFormat, 65 String separator) throws InvictaProjectException { 66 ProductContainer productsList; 67 68 if (componentName == null) { 69 if (ignoreExport) 70 productsList = getComponent().getRecursiveProductsWithoutSelf(); 71 else 72 productsList = getComponent().getProductsWithoutSelf(); 73 74 } else if ((componentName.length() > 0) && 75 ((productName == null) || (productName.length() == 0))) { 76 if (ignoreExport) 77 productsList = getProject().getComponent(componentName).getRecursiveProducts(); 78 else 79 productsList = getProject().getComponent(componentName).getProducts(); 80 81 } else if (componentName.length() == 0) { 82 return ""; 83 } else { 84 productsList = 85 getProject().getComponent(componentName).getRecursiveSelfProducts(productName); 86 } 87 88 return 89 getActualPathElements(fileSetFormat, separator, productsList); 90 91 } 92 93 96 protected String getActualPathElements( 97 boolean fileSetFormat, 98 String separator, 99 ProductContainer productsList) { 100 String pathElements = ""; 101 102 for (Iterator iter = productsList.findByType("jar").iterator(); iter.hasNext();) { 103 Product product = (Product) iter.next(); 104 105 if (fileSetFormat) { 106 String pathElement = 107 "<pathelement path=\"" + product.getPath() + "\"/>"; 108 pathElements += pathElement; 109 if (iter.hasNext()) 110 pathElements += "\n"; 111 } else { 112 pathElements += product.getPath(); 113 if (iter.hasNext()) 114 pathElements += separator; 115 } 116 117 } 118 return pathElements; 119 } 120 121 } 122 | Popular Tags |