1 23 package org.hammurapi.inspectors.techstack; 24 25 import java.util.ArrayList ; 26 import java.util.Collection ; 27 import java.util.Iterator ; 28 29 import javax.xml.transform.TransformerException ; 30 31 import org.apache.xpath.CachedXPathAPI; 32 import org.w3c.dom.Element ; 33 import org.w3c.dom.Node ; 34 import org.w3c.dom.traversal.NodeIterator; 35 36 import com.pavelvlasov.xml.dom.DomSerializable; 37 38 42 public class Publisher extends Licensor { 43 44 public Publisher(TechStack stack) { 45 super(stack); 46 } 47 48 public Publisher(TechStack stack, Element holder, CachedXPathAPI cxpa) throws TransformerException { 49 super(stack, holder, cxpa); 50 NodeIterator nit = cxpa.selectNodeIterator(holder, "product"); 51 Node n; 52 while ((n=nit.nextNode())!=null) { 53 new Product(stack, this, (Element ) n, cxpa); 54 } 55 } 56 57 private Collection products=new ArrayList (); 58 59 void addProduct(Product product) { 60 products.add(product); 61 62 } 63 64 public void toDom(Element holder) { 65 super.toDom(holder); 66 Iterator it=products.iterator(); 67 while (it.hasNext()) { 68 ((DomSerializable) it.next()).toDom(addElement(holder, "product")); 69 } 70 } 71 72 78 public boolean match(String packageName, Collection clients) { 79 Iterator it=products.iterator(); 80 while (it.hasNext()) { 81 Product product=(Product) it.next(); 82 if (product.match(packageName, clients)) { 83 return true; 84 } 85 } 86 return false; 87 } 88 89 94 public String [] match(String packageName) { 95 Iterator it=packages.iterator(); 96 while (it.hasNext()) { 97 String pn=(String ) it.next(); 98 if (pn.equals(packageName)) { 99 return new String [] {packageName, null}; 100 } else if (packageName.startsWith(pn+".")) { 101 int idx=packageName.indexOf('.', pn.length()+1); 102 if (idx==-1) { 103 return new String [] {pn, packageName.substring(pn.length()+1)}; 104 } else { 105 return new String [] {pn, packageName.substring(pn.length()+1, idx)}; 106 } 107 } 108 } 109 return null; 110 } 111 } 112 | Popular Tags |