001: package com.nwalsh.saxon;
002:
003: import java.util.Stack;
004: import java.util.StringTokenizer;
005: import org.xml.sax.*;
006: import org.w3c.dom.*;
007: import javax.xml.transform.TransformerException;
008: import com.icl.saxon.Context;
009: import com.icl.saxon.expr.*;
010: import com.icl.saxon.expr.FragmentValue;
011: import com.icl.saxon.Controller;
012: import com.icl.saxon.functions.Extensions;
013: import com.icl.saxon.om.*;
014: import com.icl.saxon.output.*;
015: import com.icl.saxon.pattern.*;
016: import com.icl.saxon.tree.*;
017:
018: /**
019: * <p>A Saxon 6.0 Emitter that clones its input.</p>
020: *
021: * <p>$Id: CopyEmitter.java,v 1.1 2006/05/31 17:21:20 mbatchelor Exp $</p>
022: *
023: * <p>Copyright (C) 2000 Norman Walsh.</p>
024: *
025: * <p>This class provides a
026: * <a href="http://users.iclway.co.uk/mhkay/saxon/">Saxon 6.*</a>
027: * implementation of an emitter that manufactures a cloned result
028: * tree fragment.</p>
029: *
030: * <p>The purpose of this emitter is to provide something for
031: * CalloutEmitter and NumberLinesEmitter to extend.
032: * This emitter simply copies all input to a new result tree fragment.</p>
033: *
034: * <p><b>Change Log:</b></p>
035: * <dl>
036: * <dt>1.0</dt>
037: * <dd><p>Initial release.</p></dd>
038: * </dl>
039: *
040: * @see CalloutEmitter
041: * @see NumberLinesEmitter
042: *
043: * @author Norman Walsh
044: * <a href="mailto:ndw@nwalsh.com">ndw@nwalsh.com</a>
045: *
046: * @version $Id: CopyEmitter.java,v 1.1 2006/05/31 17:21:20 mbatchelor Exp $
047: *
048: */
049: public class CopyEmitter extends com.icl.saxon.output.Emitter {
050: /** The result tree fragment containing the copied fragment. */
051: protected FragmentValue rtf = null;
052: protected Emitter rtfEmitter = null;
053:
054: /** <p>The namePool.</p>
055: *
056: * <p>Copied from the caller, it should be the runtime name pool.</p>
057: */
058: protected NamePool namePool = null;
059:
060: /** <p>Constructor for the CopyEmitter.</p>
061: *
062: * @param namePool The name pool to use for constructing elements and attributes.
063: */
064: public CopyEmitter(Controller controller, NamePool namePool) {
065: rtf = new FragmentValue(controller);
066: rtfEmitter = rtf.getEmitter();
067: this .namePool = namePool;
068: }
069:
070: /**
071: * <p>Return the result tree fragment constructed by replaying events
072: * through this emitter.</p>
073: */
074: public FragmentValue getResultTreeFragment() {
075: return rtf;
076: }
077:
078: /** Copy characters. */
079: public void characters(char[] chars, int start, int len)
080: throws TransformerException {
081: rtfEmitter.characters(chars, start, len);
082: }
083:
084: /** Copy comments. */
085: public void comment(char[] chars, int start, int length)
086: throws TransformerException {
087: rtfEmitter.comment(chars, start, length);
088: }
089:
090: /** Copy end document events. */
091: public void endDocument() throws TransformerException {
092: rtfEmitter.endDocument();
093: }
094:
095: /** Copy end element events. */
096: public void endElement(int nameCode) throws TransformerException {
097: rtfEmitter.endElement(nameCode);
098: }
099:
100: /** Copy processing instructions. */
101: public void processingInstruction(java.lang.String name,
102: java.lang.String data) throws TransformerException {
103: rtfEmitter.processingInstruction(name, data);
104: }
105:
106: /** Copy set document locator events. */
107: public void setDocumentLocator(org.xml.sax.Locator locator) {
108: rtfEmitter.setDocumentLocator(locator);
109: }
110:
111: /** Copy set escaping events. */
112: public void setEscaping(boolean escaping)
113: throws TransformerException {
114: rtfEmitter.setEscaping(escaping);
115: }
116:
117: /** Copy set name pool events. */
118: public void setNamePool(NamePool namePool) {
119: rtfEmitter.setNamePool(namePool);
120: }
121:
122: /** Copy set unparsed entity events. */
123: public void setUnparsedEntity(java.lang.String name,
124: java.lang.String uri) throws TransformerException {
125: rtfEmitter.setUnparsedEntity(name, uri);
126: }
127:
128: /** Copy set writer events. */
129: public void setWriter(java.io.Writer writer) {
130: rtfEmitter.setWriter(writer);
131: }
132:
133: /** Copy start document events. */
134: public void startDocument() throws TransformerException {
135: rtfEmitter.startDocument();
136: }
137:
138: /** Copy start element events. */
139: public void startElement(int nameCode,
140: org.xml.sax.Attributes attributes, int[] namespaces,
141: int nscount) throws TransformerException {
142: rtfEmitter.startElement(nameCode, attributes, namespaces,
143: nscount);
144: }
145: }
|