| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.event; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.parser.Location; |
| 11 |
import net.sf.saxon.om.NodeName; |
| 12 |
import net.sf.saxon.trans.XPathException; |
| 13 |
import net.sf.saxon.type.ComplexType; |
| 14 |
import net.sf.saxon.type.SchemaType; |
| 15 |
import net.sf.saxon.type.Untyped; |
| 16 |
import net.sf.saxon.value.Whitespace; |
| 17 |
|
| 18 |
import java.util.Arrays; |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public class IgnorableWhitespaceStripper extends ProxyReceiver { |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
private boolean[] stripStack = new boolean[100]; |
| 31 |
private int top = 0; |
| 32 |
|
| 33 |
public IgnorableWhitespaceStripper(Receiver next) { |
| 34 |
super(next); |
| 35 |
} |
| 36 |
|
| 37 |
public void startElement(NodeName nameCode, SchemaType type, Location location, int properties) throws XPathException { |
| 38 |
|
| 39 |
nextReceiver.startElement(nameCode, type, location, properties); |
| 40 |
|
| 41 |
boolean strip = false; |
| 42 |
if (type != Untyped.getInstance()) { |
| 43 |
|
| 44 |
if (type.isComplexType() && |
| 45 |
!((ComplexType) type).isSimpleContent() && |
| 46 |
!((ComplexType) type).isMixedContent()) { |
| 47 |
strip = true; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
top++; |
| 55 |
if (top >= stripStack.length) { |
| 56 |
stripStack = Arrays.copyOf(stripStack, top*2); |
| 57 |
} |
| 58 |
stripStack[top] = strip; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public void endElement() throws XPathException { |
| 66 |
nextReceiver.endElement(); |
| 67 |
top--; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public void characters(CharSequence chars, Location locationId, int properties) throws XPathException { |
| 75 |
if (chars.length() > 0 && (!stripStack[top] || !Whitespace.isWhite(chars))) { |
| 76 |
nextReceiver.characters(chars, locationId, properties); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
public boolean usesTypeAnnotations() { |
| 89 |
return true; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
|