Source code: com/nwalsh/saxon/CopyEmitter.java
1 package com.nwalsh.saxon;
2
3 import java.util.Stack;
4 import java.util.StringTokenizer;
5 import org.xml.sax.*;
6 import org.w3c.dom.*;
7 import javax.xml.transform.TransformerException;
8 import com.icl.saxon.Context;
9 import com.icl.saxon.expr.*;
10 import com.icl.saxon.expr.FragmentValue;
11 import com.icl.saxon.Controller;
12 import com.icl.saxon.functions.Extensions;
13 import com.icl.saxon.om.*;
14 import com.icl.saxon.output.*;
15 import com.icl.saxon.pattern.*;
16 import com.icl.saxon.tree.*;
17
18 /**
19 * <p>A Saxon 6.0 Emitter that clones its input.</p>
20 *
21 *
22 * <p>Copyright (C) 2000 Norman Walsh.</p>
23 *
24 * <p>This class provides a
25 * <a href="http://users.iclway.co.uk/mhkay/saxon/">Saxon 6.*</a>
26 * implementation of an emitter that manufactures a cloned result
27 * tree fragment.</p>
28 *
29 * <p>The purpose of this emitter is to provide something for
30 * CalloutEmitter and NumberLinesEmitter to extend.
31 * This emitter simply copies all input to a new result tree fragment.</p>
32 *
33 * <p><b>Change Log:</b></p>
34 * <dl>
35 * <dt>1.0</dt>
36 * <dd><p>Initial release.</p></dd>
37 * </dl>
38 *
39 * @see CalloutEmitter
40 * @see NumberLinesEmitter
41 *
42 * @author Norman Walsh
43 * <a href="mailto:ndw@nwalsh.com">ndw@nwalsh.com</a>
44 *
45 *
46 */
47 public class CopyEmitter extends com.icl.saxon.output.Emitter {
48 /** The result tree fragment containing the copied fragment. */
49 protected FragmentValue rtf = null;
50 protected Emitter rtfEmitter = null;
51
52 /** <p>The namePool.</p>
53 *
54 * <p>Copied from the caller, it should be the runtime name pool.</p>
55 */
56 protected NamePool namePool = null;
57
58 /** <p>Constructor for the CopyEmitter.</p>
59 *
60 * @param namePool The name pool to use for constructing elements and attributes.
61 */
62 public CopyEmitter(Controller controller, NamePool namePool) {
63 rtf = new FragmentValue(controller);
64 rtfEmitter = rtf.getEmitter();
65 this.namePool = namePool;
66 }
67
68 /**
69 * <p>Return the result tree fragment constructed by replaying events
70 * through this emitter.</p>
71 */
72 public FragmentValue getResultTreeFragment() {
73 return rtf;
74 }
75
76 /** Copy characters. */
77 public void characters(char[] chars, int start, int len)
78 throws TransformerException {
79 rtfEmitter.characters(chars, start, len);
80 }
81
82 /** Copy comments. */
83 public void comment(char[] chars, int start, int length)
84 throws TransformerException {
85 rtfEmitter.comment(chars, start, length);
86 }
87
88 /** Copy end document events. */
89 public void endDocument()
90 throws TransformerException {
91 rtfEmitter.endDocument();
92 }
93
94 /** Copy end element events. */
95 public void endElement(int nameCode)
96 throws TransformerException {
97 rtfEmitter.endElement(nameCode);
98 }
99
100 /** Copy processing instructions. */
101 public void processingInstruction(java.lang.String name,
102 java.lang.String data)
103 throws TransformerException {
104 rtfEmitter.processingInstruction(name, data);
105 }
106
107 /** Copy set document locator events. */
108 public void setDocumentLocator(org.xml.sax.Locator locator) {
109 rtfEmitter.setDocumentLocator(locator);
110 }
111
112 /** Copy set escaping events. */
113 public void setEscaping(boolean escaping)
114 throws TransformerException {
115 rtfEmitter.setEscaping(escaping);
116 }
117
118 /** Copy set name pool events. */
119 public void setNamePool(NamePool namePool) {
120 rtfEmitter.setNamePool(namePool);
121 }
122
123 /** Copy set unparsed entity events. */
124 public void setUnparsedEntity(java.lang.String name, java.lang.String uri)
125 throws TransformerException {
126 rtfEmitter.setUnparsedEntity(name, uri);
127 }
128
129 /** Copy set writer events. */
130 public void setWriter(java.io.Writer writer) {
131 rtfEmitter.setWriter(writer);
132 }
133
134 /** Copy start document events. */
135 public void startDocument()
136 throws TransformerException {
137 rtfEmitter.startDocument();
138 }
139
140 /** Copy start element events. */
141 public void startElement(int nameCode,
142 org.xml.sax.Attributes attributes,
143 int[] namespaces,
144 int nscount)
145 throws TransformerException {
146 rtfEmitter.startElement(nameCode, attributes, namespaces, nscount);
147 }
148 }