KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > invicta > handler > PathElementsHandler


1 package net.sf.invicta.handler;
2
3 import java.util.Iterator JavaDoc;
4 import java.util.Map JavaDoc;
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 /**
13  * Map:
14  * ignoreExport - Optional, boolean, default=false - Name of a property that specifies whether to
15  * include also products that are not exported.
16  * componentName - Optional, String - Name of a property that specifies the name of the component to include its products.
17  * productName - Optional, String - Name of a property that specifies the name of the product to include.
18  * fileSetFormat - Optional, boolean, default=true - Whether to return the result as a fileset definition.
19  * separator - Optional, String, default=" " - Specified the separator between products, when the format is not a fileSet format.
20  *
21  */

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 JavaDoc DEFAULT_SEPARATOR = " ";
26
27     /**
28      *
29      */

30     public String JavaDoc getName() {
31         return "pathElements";
32     }
33
34     /**
35      *
36      */

37     public String JavaDoc handle(Map JavaDoc paramsMap) throws InvictaException {
38
39             boolean ignoreExport = getParameterPropertyBooleanValue("ignoreExport", DEFAULT_IGNORE_EXPORT);
40             String JavaDoc componentName = getParameterPropertyValue("componentName");
41             String JavaDoc productName = getParameterPropertyValue("productName");
42             boolean fileSetFormat = getBooleanParameter("fileSetFormat", DEFAULT_FILESET_FORMAT);
43             String JavaDoc 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     /**
58      *
59      */

60     protected String JavaDoc preparePathElements(
61         boolean ignoreExport,
62         String JavaDoc componentName,
63         String JavaDoc productName,
64         boolean fileSetFormat,
65         String JavaDoc 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     /**
94      *
95      */

96     protected String JavaDoc getActualPathElements(
97         boolean fileSetFormat,
98         String JavaDoc separator,
99         ProductContainer productsList) {
100         String JavaDoc pathElements = "";
101         
102         for (Iterator JavaDoc iter = productsList.findByType("jar").iterator(); iter.hasNext();) {
103             Product product = (Product) iter.next();
104         
105             if (fileSetFormat) {
106                 String JavaDoc 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