KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.invicta.handler;
2
3 import java.io.File JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.List JavaDoc;
6 import java.util.Map JavaDoc;
7
8 import net.sf.invicta.InvictaException;
9 import net.sf.invicta.api.Product;
10 import net.sf.invicta.api.ProductContainer;
11
12 /**
13  *
14  *
15  */

16 public class RelatedProductListHandler extends InvictaBasicHandler {
17     private final static String JavaDoc LIST_SEPARATOR = " ";
18     private final static boolean DEFAULT_INCLUDE_SELF = false;
19
20     /**
21      *
22      */

23     public String JavaDoc getName() {
24         return "relatedProductList";
25     }
26
27
28     /**
29      *
30      */

31     public String JavaDoc handle(List JavaDoc params) throws InvictaException {
32         return getProductsList(DEFAULT_INCLUDE_SELF);
33     }
34     
35     /**
36      *
37      */

38     public String JavaDoc handle(Map JavaDoc paramsMap) throws InvictaException {
39         boolean includeSelf = getBooleanParameter("includeSelf", DEFAULT_INCLUDE_SELF);
40         
41         return getProductsList(includeSelf);
42     }
43     
44     /**
45      *
46      */

47     protected String JavaDoc getProductsList(boolean includeSelf) {
48         ProductContainer products;
49         if (includeSelf)
50             products =getComponent().getRecursiveProducts();
51         else
52             products =getComponent().getRecursiveProductsWithoutSelf();
53         String JavaDoc productList = "";
54         for (Iterator JavaDoc iter = products.iterator(); iter.hasNext();) {
55             Product product = (Product) iter.next();
56             if (product.getType().equals("jar")) {
57             
58                 File JavaDoc file = new File JavaDoc(product.getFile());
59                 productList += file.getName();
60             
61                 if (iter.hasNext())
62                     productList += LIST_SEPARATOR;
63             }
64         }
65         return productList;
66     }
67
68 }
69
Popular Tags