001: // Copyright (c) 2000, 2001 Per M.A. Bothner and Brainfood Inc.
002: // This is free software; for terms and warranty disclaimer see ./COPYING.
003:
004: package gnu.lists;
005:
006: /** A Consumer that wraps some other Consumer. */
007:
008: public class FilterConsumer implements Consumer {
009: protected Consumer base;
010: protected boolean skipping;
011: /** We seen a startAttribute but not the closing endAttribute. */
012: protected boolean inAttribute;
013: /** The 'attribute type' from the most recent startAttribute. */
014: protected Object attributeType;
015:
016: public FilterConsumer(Consumer base) {
017: this .base = base;
018: }
019:
020: protected void beforeContent() {
021: }
022:
023: public void write(int v) {
024: beforeContent();
025: if (!skipping)
026: base.write(v);
027: }
028:
029: public void writeBoolean(boolean v) {
030: beforeContent();
031: if (!skipping)
032: base.writeBoolean(v);
033: }
034:
035: public void writeFloat(float v) {
036: beforeContent();
037: if (!skipping)
038: base.writeFloat(v);
039: }
040:
041: public void writeDouble(double v) {
042: beforeContent();
043: if (!skipping)
044: base.writeDouble(v);
045: }
046:
047: public void writeInt(int v) {
048: beforeContent();
049: if (!skipping)
050: base.writeInt(v);
051: }
052:
053: public void writeLong(long v) {
054: beforeContent();
055: if (!skipping)
056: base.writeLong(v);
057: }
058:
059: public void startDocument() {
060: if (!skipping)
061: base.startDocument();
062: }
063:
064: public void endDocument() {
065: if (!skipping)
066: base.endDocument();
067: }
068:
069: public void startElement(Object type) {
070: if (!skipping)
071: base.startElement(type);
072: }
073:
074: public void endElement() {
075: if (!skipping)
076: base.endElement();
077: }
078:
079: public void startAttribute(Object attrType) {
080: attributeType = attrType;
081: inAttribute = true;
082: if (!skipping)
083: base.startAttribute(attrType);
084: }
085:
086: public void endAttribute() {
087: if (!skipping)
088: base.endAttribute();
089: inAttribute = false;
090: }
091:
092: public void writeObject(Object v) {
093: beforeContent();
094: if (!skipping)
095: base.writeObject(v);
096: }
097:
098: public boolean ignoring() {
099: return base.ignoring();
100: }
101:
102: public void write(char[] buf, int off, int len) {
103: beforeContent();
104: if (!skipping)
105: base.write(buf, off, len);
106: }
107:
108: public void write(String str) {
109: write(str, 0, str.length());
110: }
111:
112: /* #ifdef use:java.lang.CharSequence */
113: public void write(CharSequence str, int start, int length)
114: /* #else */
115: // public void write (String str, int start, int length)
116: /* #endif */
117: {
118: beforeContent();
119: if (!skipping)
120: base.write(str, start, length);
121: }
122:
123: /* #ifdef JAVA5 */
124: // public Consumer append (char c)
125: // {
126: // write(c);
127: // return this;
128: // }
129: // public Consumer append (CharSequence csq)
130: // {
131: // if (csq == null)
132: // csq = "null";
133: // append(csq, 0, csq.length());
134: // return this;
135: // }
136: // public Consumer append (CharSequence csq, int start, int end)
137: // {
138: // beforeContent();
139: // if (! skipping)
140: // {
141: // if (csq == null)
142: // csq = "null";
143: // base.append(csq, start, end);
144: // }
145: // return this;
146: // }
147: /* #endif */
148: }
|