| 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.ma.arrays.ArrayItem; |
| 13 |
import net.sf.saxon.om.Item; |
| 14 |
import net.sf.saxon.om.NodeName; |
| 15 |
import net.sf.saxon.trans.XPathException; |
| 16 |
import net.sf.saxon.type.SchemaType; |
| 17 |
import net.sf.saxon.value.AtomicValue; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public class SequenceNormalizerWithItemSeparator extends SequenceNormalizer { |
| 28 |
|
| 29 |
private String separator; |
| 30 |
private boolean first = true; |
| 31 |
|
| 32 |
public SequenceNormalizerWithItemSeparator(Receiver next, String separator) { |
| 33 |
super(next); |
| 34 |
this.separator = separator; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
@Override |
| 41 |
public void open() throws XPathException { |
| 42 |
first = true; |
| 43 |
super.open(); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
@Override |
| 50 |
public void startDocument(int properties) throws XPathException { |
| 51 |
sep(); |
| 52 |
super.startDocument(properties); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
@Override |
| 64 |
public void startElement(NodeName elemName, SchemaType typeCode, Location location, int properties) throws XPathException { |
| 65 |
sep(); |
| 66 |
super.startElement(elemName, typeCode, location, properties); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
@Override |
| 73 |
public void characters(CharSequence chars, Location locationId, int properties) throws XPathException { |
| 74 |
sep(); |
| 75 |
super.characters(chars, locationId, properties); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
@Override |
| 82 |
public void processingInstruction(String target, CharSequence data, Location locationId, int properties) throws XPathException { |
| 83 |
sep(); |
| 84 |
super.processingInstruction(target, data, locationId, properties); |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
@Override |
| 91 |
public void comment(CharSequence chars, Location locationId, int properties) throws XPathException { |
| 92 |
sep(); |
| 93 |
super.comment(chars, locationId, properties); |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
@Override |
| 107 |
public void append(Item item, Location locationId, int copyNamespaces) throws XPathException { |
| 108 |
if (item instanceof ArrayItem) { |
| 109 |
flatten((ArrayItem) item, locationId, copyNamespaces); |
| 110 |
} else { |
| 111 |
if (item instanceof AtomicValue) { |
| 112 |
sep(); |
| 113 |
nextReceiver.characters(item.getStringValueCS(), locationId, 0); |
| 114 |
} else { |
| 115 |
decompose(item, locationId, copyNamespaces); |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
@Override |
| 125 |
public void close() throws XPathException { |
| 126 |
|
| 127 |
super.close(); |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
public void sep() throws XPathException { |
| 135 |
if (level == 0 && !first) { |
| 136 |
super.characters(separator, ExplicitLocation.UNKNOWN_LOCATION, 0); |
| 137 |
} else { |
| 138 |
first = false; |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
|