| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.event; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.parser.ExplicitLocation; |
| 11 |
import net.sf.saxon.expr.parser.Location; |
| 12 |
import net.sf.saxon.om.NodeName; |
| 13 |
import net.sf.saxon.trans.XPathException; |
| 14 |
import net.sf.saxon.tree.tiny.CompressedWhitespace; |
| 15 |
import net.sf.saxon.tree.util.FastStringBuffer; |
| 16 |
import net.sf.saxon.type.SchemaType; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class CommentStripper extends ProxyReceiver { |
| 29 |
|
| 30 |
private CompressedWhitespace savedWhitespace = null; |
| 31 |
private FastStringBuffer buffer = new FastStringBuffer(FastStringBuffer.C256); |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public CommentStripper(Receiver next) { |
| 40 |
super(next); |
| 41 |
} |
| 42 |
|
| 43 |
public void startElement(NodeName nameCode, SchemaType typeCode, Location location, int properties) |
| 44 |
throws XPathException { |
| 45 |
flush(); |
| 46 |
nextReceiver.startElement(nameCode, typeCode, location, properties); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public void endElement() throws XPathException { |
| 54 |
flush(); |
| 55 |
nextReceiver.endElement(); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public void characters(CharSequence chars, Location locationId, int properties) throws XPathException { |
| 67 |
if (chars instanceof CompressedWhitespace) { |
| 68 |
if (buffer.isEmpty() && savedWhitespace == null) { |
| 69 |
savedWhitespace = (CompressedWhitespace) chars; |
| 70 |
} else { |
| 71 |
((CompressedWhitespace) chars).uncompress(buffer); |
| 72 |
} |
| 73 |
} else { |
| 74 |
if (savedWhitespace != null) { |
| 75 |
savedWhitespace.uncompress(buffer); |
| 76 |
savedWhitespace = null; |
| 77 |
} |
| 78 |
buffer.append(chars); |
| 79 |
} |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public void comment(CharSequence chars, Location locationId, int properties) { |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
public void processingInstruction(String name, CharSequence data, Location locationId, int properties) { |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
private void flush() throws XPathException { |
| 105 |
if (!buffer.isEmpty()) { |
| 106 |
nextReceiver.characters(buffer, ExplicitLocation.UNKNOWN_LOCATION, 0); |
| 107 |
} else if (savedWhitespace != null) { |
| 108 |
nextReceiver.characters(savedWhitespace, ExplicitLocation.UNKNOWN_LOCATION, 0); |
| 109 |
} |
| 110 |
savedWhitespace = null; |
| 111 |
buffer.setLength(0); |
| 112 |
} |
| 113 |
|
| 114 |
} |
| 115 |
|