001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "Xerces" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 1999, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package org.apache.xerces.readers;
059:
060: import org.apache.xerces.framework.XMLErrorReporter;
061:
062: /**
063: * This is the class used by the scanner to process the XML data.
064: *
065: * @see org.apache.xerces.framework.XMLParser
066: * @version $Id: XMLEntityReader.java,v 1.3 2001/08/08 17:46:58 neilg Exp $
067: */
068: abstract class XMLEntityReader implements XMLEntityHandler.EntityReader {
069: /*
070: * Instance variables.
071: */
072: protected XMLEntityHandler fEntityHandler = null;
073: protected XMLErrorReporter fErrorReporter = null;
074: protected boolean fSendCharDataAsCharArray;
075: protected XMLEntityHandler.CharDataHandler fCharDataHandler = null;
076: protected boolean fInCDSect = false;
077: private boolean fStillActive = true;
078: /*
079: * These are updated directly by the subclass implementation.
080: */
081: protected int fCarriageReturnCounter = 1;
082: protected int fLinefeedCounter = 1;
083: protected int fCharacterCounter = 1;
084: protected int fCurrentOffset = 0;
085:
086: /**
087: * Constructor
088: */
089: protected XMLEntityReader(XMLEntityHandler entityHandler,
090: XMLErrorReporter errorReporter,
091: boolean sendCharDataAsCharArray) {
092: fEntityHandler = entityHandler;
093: fErrorReporter = errorReporter;
094: fSendCharDataAsCharArray = sendCharDataAsCharArray;
095: fCharDataHandler = fEntityHandler.getCharDataHandler();
096: }
097:
098: /**
099: * Constructor
100: */
101: protected XMLEntityReader(XMLEntityHandler entityHandler,
102: XMLErrorReporter errorReporter,
103: boolean sendCharDataAsCharArray, int lineNumber,
104: int columnNumber) {
105: fEntityHandler = entityHandler;
106: fErrorReporter = errorReporter;
107: fSendCharDataAsCharArray = sendCharDataAsCharArray;
108: fCharDataHandler = fEntityHandler.getCharDataHandler();
109: fLinefeedCounter = lineNumber;
110: fCharacterCounter = columnNumber;
111: }
112:
113: protected void init(XMLEntityHandler entityHandler,
114: XMLErrorReporter errorReporter,
115: boolean sendCharDataAsCharArray, int lineNumber,
116: int columnNumber) {
117: fEntityHandler = entityHandler;
118: fErrorReporter = errorReporter;
119: fSendCharDataAsCharArray = sendCharDataAsCharArray;
120: fCharDataHandler = fEntityHandler.getCharDataHandler();
121: fLinefeedCounter = lineNumber;
122: fCharacterCounter = columnNumber;
123: fStillActive = true;
124: fInCDSect = false;
125: fCarriageReturnCounter = 1;
126: fCurrentOffset = 0;
127: }
128:
129: /**
130: * Return the current offset within this reader.
131: *
132: * @return The offset.
133: */
134: public int currentOffset() {
135: return fCurrentOffset;
136: }
137:
138: /**
139: * Return the line number of the current position within the document that we are processing.
140: *
141: * @return The current line number.
142: */
143: public int getLineNumber() {
144: if (fLinefeedCounter > 1)
145: return fLinefeedCounter;
146: else
147: return fCarriageReturnCounter;
148: }
149:
150: /**
151: * Return the column number of the current position within the document that we are processing.
152: *
153: * @return The current column number.
154: */
155: public int getColumnNumber() {
156: return fCharacterCounter;
157: }
158:
159: /**
160: * This method is provided for scanner implementations.
161: */
162: public void setInCDSect(boolean inCDSect) {
163: fInCDSect = inCDSect;
164: }
165:
166: /**
167: * This method is provided for scanner implementations.
168: */
169: public boolean getInCDSect() {
170: return fInCDSect;
171: }
172:
173: /**
174: * This method is called by the reader subclasses at the end of input.
175: */
176: protected XMLEntityHandler.EntityReader changeReaders()
177: throws Exception {
178: XMLEntityHandler.EntityReader nextReader = null;
179: if (fStillActive) {
180: nextReader = fEntityHandler.changeReaders();
181: fStillActive = false;
182: // Allow these following three fields to be GC-ed.
183: fEntityHandler = null;
184: fErrorReporter = null;
185: fCharDataHandler = null;
186: }
187: return nextReader;
188: }
189: }
|