001: package net.sf.saxon.event;
002:
003: import net.sf.saxon.Configuration;
004: import net.sf.saxon.om.NamePool;
005: import net.sf.saxon.trans.XPathException;
006:
007: /**
008: * A ProxyReceiver is an Receiver that filters data before passing it to another
009: * underlying Receiver.
010: */
011:
012: public abstract class ProxyReceiver extends SequenceReceiver {
013: protected Receiver nextReceiver;
014: protected String systemId;
015:
016: public void setSystemId(String systemId) {
017: if (systemId != this .systemId) {
018: this .systemId = systemId;
019: if (nextReceiver != null) {
020: nextReceiver.setSystemId(systemId);
021: }
022: }
023: }
024:
025: public String getSystemId() {
026: return systemId;
027: }
028:
029: /**
030: * Set the underlying receiver. This call is mandatory before using the Receiver.
031: */
032:
033: public void setUnderlyingReceiver(Receiver receiver) {
034: if (receiver != nextReceiver) {
035: nextReceiver = receiver;
036: if (pipelineConfiguration != null) {
037: nextReceiver
038: .setPipelineConfiguration(pipelineConfiguration);
039: }
040: }
041: }
042:
043: /**
044: * Get the underlying Receiver (that is, the next one in the pipeline)
045: */
046:
047: public Receiver getUnderlyingReceiver() {
048: return nextReceiver;
049: }
050:
051: public void setPipelineConfiguration(PipelineConfiguration config) {
052: if (this .pipelineConfiguration != config) {
053: this .pipelineConfiguration = config;
054: if (nextReceiver != null) {
055: nextReceiver.setPipelineConfiguration(config);
056: }
057: }
058: }
059:
060: public Configuration getConfiguration() {
061: return pipelineConfiguration.getConfiguration();
062: }
063:
064: /**
065: * Get the namepool for this configuration
066: */
067:
068: public NamePool getNamePool() {
069: return getConfiguration().getNamePool();
070: }
071:
072: /**
073: * Start of event stream
074: */
075:
076: public void open() throws XPathException {
077: if (nextReceiver == null) {
078: throw new IllegalStateException(
079: "ProxyReceiver.open(): no underlying emitter provided");
080: }
081: nextReceiver.open();
082: }
083:
084: /**
085: * End of document
086: */
087:
088: public void close() throws XPathException {
089: nextReceiver.close();
090: }
091:
092: /**
093: * Start of a document node.
094: */
095:
096: public void startDocument(int properties) throws XPathException {
097: nextReceiver.startDocument(properties);
098: }
099:
100: /**
101: * Notify the end of a document node
102: */
103:
104: public void endDocument() throws XPathException {
105: nextReceiver.endDocument();
106: }
107:
108: /**
109: * Notify the start of an element
110: *
111: * @param nameCode integer code identifying the name of the element within the name pool.
112: * @param typeCode integer code identifying the element's type within the name pool.
113: * @param properties properties of the element node
114: */
115:
116: public void startElement(int nameCode, int typeCode,
117: int locationId, int properties) throws XPathException {
118: nextReceiver.startElement(nameCode, typeCode, locationId,
119: properties);
120: }
121:
122: /**
123: * Notify a namespace. Namespaces are notified <b>after</b> the startElement event, and before
124: * any children for the element. The namespaces that are reported are only required
125: * to include those that are different from the parent element; however, duplicates may be reported.
126: * A namespace must not conflict with any namespaces already used for element or attribute names.
127: *
128: * @param namespaceCode an integer: the top half is a prefix code, the bottom half a URI code.
129: * These may be translated into an actual prefix and URI using the name pool. A prefix code of
130: * zero represents the empty prefix (that is, the default namespace). A URI code of zero represents
131: * a URI of "", that is, a namespace undeclaration.
132: * @throws IllegalStateException: attempt to output a namespace when there is no open element
133: * start tag
134: */
135:
136: public void namespace(int namespaceCode, int properties)
137: throws XPathException {
138: nextReceiver.namespace(namespaceCode, properties);
139: }
140:
141: /**
142: * Notify an attribute. Attributes are notified after the startElement event, and before any
143: * children. Namespaces and attributes may be intermingled.
144: *
145: * @param nameCode The name of the attribute, as held in the name pool
146: * @param typeCode The type of the attribute, as held in the name pool
147: * @param properties Bit significant value. The following bits are defined:
148: * <dd>DISABLE_ESCAPING</dd> <dt>Disable escaping for this attribute</dt>
149: * <dd>NO_SPECIAL_CHARACTERS</dd> <dt>Attribute value contains no special characters</dt>
150: * @throws IllegalStateException: attempt to output an attribute when there is no open element
151: * start tag
152: */
153:
154: public void attribute(int nameCode, int typeCode,
155: CharSequence value, int locationId, int properties)
156: throws XPathException {
157: nextReceiver.attribute(nameCode, typeCode, value, locationId,
158: properties);
159: }
160:
161: /**
162: * Notify the start of the content, that is, the completion of all attributes and namespaces.
163: * Note that the initial receiver of output from XSLT instructions will not receive this event,
164: * it has to detect it itself. Note that this event is reported for every element even if it has
165: * no attributes, no namespaces, and no content.
166: */
167:
168: public void startContent() throws XPathException {
169: nextReceiver.startContent();
170: }
171:
172: /**
173: * End of element
174: */
175:
176: public void endElement() throws XPathException {
177: nextReceiver.endElement();
178: }
179:
180: /**
181: * Character data
182: */
183:
184: public void characters(CharSequence chars, int locationId,
185: int properties) throws XPathException {
186: nextReceiver.characters(chars, locationId, properties);
187: }
188:
189: /**
190: * Processing Instruction
191: */
192:
193: public void processingInstruction(String target, CharSequence data,
194: int locationId, int properties) throws XPathException {
195: nextReceiver.processingInstruction(target, data, locationId,
196: properties);
197: }
198:
199: /**
200: * Output a comment
201: */
202:
203: public void comment(CharSequence chars, int locationId,
204: int properties) throws XPathException {
205: nextReceiver.comment(chars, locationId, properties);
206: }
207:
208: /**
209: * Set the URI for an unparsed entity in the document.
210: */
211:
212: public void setUnparsedEntity(String name, String uri,
213: String publicId) throws XPathException {
214: nextReceiver.setUnparsedEntity(name, uri, publicId);
215: }
216:
217: /**
218: * Get the Document Locator
219: */
220:
221: public LocationProvider getDocumentLocator() {
222: return pipelineConfiguration.getLocationProvider();
223: }
224: }
225:
226: //
227: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
228: // you may not use this file except in compliance with the License. You may obtain a copy of the
229: // License at http://www.mozilla.org/MPL/
230: //
231: // Software distributed under the License is distributed on an "AS IS" basis,
232: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
233: // See the License for the specific language governing rights and limitations under the License.
234: //
235: // The Original Code is: all this file.
236: //
237: // The Initial Developer of the Original Code is Michael H. Kay
238: //
239: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
240: //
241: // Contributor(s): none.
242: //
|