1 16 package org.apache.cocoon.sitemap; 17 18 import org.apache.avalon.framework.parameters.Parameters; 19 import org.apache.cocoon.ProcessingException; 20 import org.apache.cocoon.Constants; 21 import org.apache.cocoon.caching.CacheableProcessingComponent; 22 import org.apache.cocoon.environment.SourceResolver; 23 import org.apache.cocoon.transformation.Transformer; 24 import org.apache.cocoon.xml.xlink.ExtendedXLinkPipe; 25 26 import org.apache.excalibur.source.SourceValidity; 27 28 import org.xml.sax.Attributes ; 29 import org.xml.sax.SAXException ; 30 31 import java.io.IOException ; 32 import java.util.List ; 33 import java.util.Map ; 34 35 39 public class LinkGatherer extends ExtendedXLinkPipe implements Transformer, CacheableProcessingComponent { 40 private List links; 41 42 43 47 public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, 48 SAXException , IOException { 49 this.links = (List )objectModel.get(Constants.LINK_COLLECTION_OBJECT); 50 } 51 52 58 public java.io.Serializable getKey() { 59 return "1"; 60 } 61 62 68 public SourceValidity getValidity() { 69 return null; 72 } 73 74 public void simpleLink(String href, String role, String arcrole, String title, String show, String actuate, String uri, 75 String name, String raw, Attributes attr) throws SAXException { 76 if (!this.links.contains(href)){ 77 this.addLink(href); 78 } 79 super.simpleLink(href, role, arcrole, title, show, actuate, uri, name, raw, attr); 80 } 81 82 public void startLocator(String href, String role, String title, String label, String uri, String name, String raw, 83 Attributes attr) throws SAXException { 84 if (!this.links.contains(href)){ 85 this.addLink(href); 86 } 87 super.startLocator(href, role, title, label, uri, name, raw, attr); 88 } 89 private void addLink(String href) { 90 if (href.length() == 0) return; 91 if (href.charAt(0) == '#') return; 92 if (href.indexOf("://") != -1) return; 93 if (href.startsWith("mailto:")) return; 94 if (href.startsWith("news:")) return; 95 if (href.startsWith("javascript:")) return; 96 97 int anchorPos = href.indexOf('#'); 98 if (anchorPos == -1) { 99 this.links.add(href); 100 } else { 101 this.links.add(href.substring(0, anchorPos)); 102 } 103 } 104 } 105 | Popular Tags |