1 16 package org.apache.cocoon.xml.xlink; 17 18 import java.util.HashMap ; 19 import java.util.HashSet ; 20 import java.util.Map ; 21 import java.util.Set ; 22 23 import org.xml.sax.Attributes ; 24 import org.xml.sax.SAXException ; 25 import org.xml.sax.helpers.AttributesImpl ; 26 27 44 public abstract class ExtendedXLinkPipe extends XLinkPipe { 45 46 protected static Set arrayToSet(Object [] array) { 47 final Set set = new HashSet (array.length); 48 49 for (int i = 0; i < array.length; i++) 50 set.add(array[i]); 51 return set; 52 } 53 54 private final Map MAP = new HashMap () { 55 { 56 put( 57 "", 58 arrayToSet( 59 new String [] { 60 "about", 61 "action", 62 "background", 63 "data", 64 "discuri", 65 "href", 66 "longdesc", 67 "onenterforward", 68 "onenterbackward", 69 "ontimer", 70 "onpick", 71 "src" })); 72 put( 73 "http://www.w3.org/1999/xhtml", 74 arrayToSet( 75 new String [] { 76 "action", 77 "background", 78 "data", 79 "href", 80 "longdesc", 81 "src" })); 82 put( 83 "http://www.w3.org/2001/XInclude", 84 arrayToSet(new String [] { "href" })); 85 put( 86 "http://www.wapforum.org/2001/wml", 87 arrayToSet( 88 new String [] { 89 "onenterforward", 90 "onenterbackward", 91 "ontimer", 92 "href", 93 "onpick", 94 "src" })); 95 put( 96 "http://www.w3.org/2002/01/P3Pv1", 97 arrayToSet( 98 new String [] { "about", "discuri", "src", "service" })); 99 } 100 }; 101 102 private int attrIndex = -1; 103 104 public void startElement( 105 String uri, 106 final String name, 107 final String raw, 108 final Attributes attr) 109 throws SAXException { 110 final Set attrList = (Set ) MAP.get((uri == null) ? "" : uri); 111 112 if (attrList != null) { 113 for (int i = attrIndex + 1; i < attr.getLength(); i++) 114 if (attr.getURI(i).equals("") 115 && attrList.contains(attr.getLocalName(i))) { 116 117 final String att = attr.getValue(i); 118 119 if (att != null) { 120 final String str = 121 ": URI=" 122 + uri 123 + " NAME=" 124 + name 125 + " RAW=" 126 + raw 127 + " ATT=" 128 + attr.getLocalName(i) 129 + " NS=" 130 + uri 131 + " VALUE=" 132 + att; 133 134 if (getLogger().isDebugEnabled()) 135 getLogger().debug("Transforming to XLink" + str); 136 137 attrIndex = i; 138 139 simpleLink( 140 att, 141 null, 142 null, 143 null, 144 null, 145 null, 146 uri, 147 name, 148 raw, 149 attr); 150 151 return; 152 } 153 } 154 attrIndex = -1; 155 } 156 157 super.startElement(uri, name, raw, attr); 158 } 159 160 public void simpleLink( 161 final String href, 162 final String role, 163 final String arcrole, 164 final String title, 165 final String show, 166 final String actuate, 167 final String uri, 168 final String name, 169 final String raw, 170 final Attributes attr) 171 throws SAXException { 172 if (attrIndex != -1) { 173 final AttributesImpl newattr = new AttributesImpl (attr); 174 newattr.setValue(attrIndex, href); 175 startElement(uri, name, raw, newattr); 176 } else { 177 super.simpleLink( 178 href, 179 role, 180 arcrole, 181 title, 182 show, 183 actuate, 184 uri, 185 name, 186 raw, 187 attr); 188 } 189 } 190 } 191 | Popular Tags |