1 package net.sf.saxon.event; 2 3 import net.sf.saxon.om.NamePool; 4 import net.sf.saxon.om.NamespaceConstant; 5 import net.sf.saxon.trans.XPathException; 6 7 import java.util.HashSet ; 8 9 10 15 16 public class XHTMLURIEscaper extends HTMLURIEscaper { 17 18 21 22 private HashSet urlTable; 23 24 private synchronized void buildURIAttributeTable() { 25 NamePool pool = getPipelineConfiguration().getConfiguration().getNamePool(); 27 urlTable = (HashSet )pool.getClientData(this.getClass()); 28 if (urlTable == null) { 29 urlTable = new HashSet (40); 30 pool.setClientData(this.getClass(), urlTable); 31 } 32 setUrlAttribute(pool, "form", "action"); 33 setUrlAttribute(pool, "body", "background"); 34 setUrlAttribute(pool, "q", "cite"); 35 setUrlAttribute(pool, "blockquote", "cite"); 36 setUrlAttribute(pool, "del", "cite"); 37 setUrlAttribute(pool, "ins", "cite"); 38 setUrlAttribute(pool, "object", "classid"); 39 setUrlAttribute(pool, "object", "codebase"); 40 setUrlAttribute(pool, "applet", "codebase"); 41 setUrlAttribute(pool, "object", "data"); 42 setUrlAttribute(pool, "a", "href"); 43 setUrlAttribute(pool, "a", "name"); setUrlAttribute(pool, "area", "href"); 45 setUrlAttribute(pool, "link", "href"); 46 setUrlAttribute(pool, "base", "href"); 47 setUrlAttribute(pool, "img", "longdesc"); 48 setUrlAttribute(pool, "frame", "longdesc"); 49 setUrlAttribute(pool, "iframe", "longdesc"); 50 setUrlAttribute(pool, "head", "profile"); 51 setUrlAttribute(pool, "script", "src"); 52 setUrlAttribute(pool, "input", "src"); 53 setUrlAttribute(pool, "frame", "src"); 54 setUrlAttribute(pool, "iframe", "src"); 55 setUrlAttribute(pool, "img", "src"); 56 setUrlAttribute(pool, "img", "usemap"); 57 setUrlAttribute(pool, "input", "usemap"); 58 setUrlAttribute(pool, "object", "usemap"); 59 } 60 61 private void setUrlAttribute(NamePool pool, String element, String attribute) { 62 int elcode = pool.allocate("", NamespaceConstant.XHTML, element) & NamePool.FP_MASK; 63 int atcode = pool.allocate("", "", attribute) & NamePool.FP_MASK; 64 Long key = new Long (((long)elcode)<<32 | (long)atcode); 65 urlTable.add(key); 66 } 67 68 71 72 private boolean isURLAttribute(int elcode, int atcode) { 73 elcode = elcode & NamePool.FP_MASK; 74 atcode = atcode & NamePool.FP_MASK; 75 Long key = new Long (((long)elcode)<<32 | (long)atcode); 76 return urlTable.contains(key); 77 } 78 79 86 87 public void open() throws XPathException { 88 super.open(); 89 if (escapeURIAttributes) { 90 buildURIAttributeTable(); 91 } 92 } 93 94 106 107 public void attribute(int nameCode, int typeCode, CharSequence value, int locationId, int properties) throws XPathException { 108 if (escapeURIAttributes && 109 isURLAttribute(currentElement, nameCode) && 110 (properties & ReceiverOptions.DISABLE_ESCAPING) == 0) { 111 getUnderlyingReceiver().attribute( 112 nameCode, typeCode, HTMLEmitter.escapeURL(value), locationId, 113 properties | ReceiverOptions.DISABLE_CHARACTER_MAPS); 114 } else { 115 getUnderlyingReceiver().attribute( 116 nameCode, typeCode, value, locationId, properties); 117 } 118 } 119 120 } 121 122 | Popular Tags |