001: /* ========================================================================
002: * JCommon : a free general purpose class library for the Java(tm) platform
003: * ========================================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jcommon/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * ----------------------
028: * StringReadHandler.java
029: * ----------------------
030: * (C)opyright 2003, 2004, by Thomas Morgner and Contributors.
031: *
032: * Original Author: Thomas Morgner;
033: * Contributor(s): David Gilbert (for Object Refinery Limited);
034: *
035: * $Id: StringReadHandler.java,v 1.5 2005/10/18 13:33:32 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 03-Dec-2003 : Initial version
040: * 11-Feb-2004 : Added missing Javadocs (DG);
041: *
042: */
043:
044: package org.jfree.xml.parser.coretypes;
045:
046: import org.jfree.xml.parser.AbstractXmlReadHandler;
047: import org.jfree.xml.parser.XmlReaderException;
048: import org.xml.sax.Attributes;
049: import org.xml.sax.SAXException;
050:
051: /**
052: * Required for list contents ...
053: */
054: public class StringReadHandler extends AbstractXmlReadHandler {
055:
056: /**
057: * A string buffer.
058: */
059: private StringBuffer buffer;
060:
061: /**
062: * The string under construction.
063: */
064: private String result;
065:
066: /**
067: * Creates a new handler.
068: */
069: public StringReadHandler() {
070: super ();
071: }
072:
073: /**
074: * Starts parsing.
075: *
076: * @param attrs the attributes.
077: * @throws SAXException if there is a parsing error.
078: */
079: protected void startParsing(final Attributes attrs)
080: throws SAXException {
081: this .buffer = new StringBuffer();
082: }
083:
084: /**
085: * This method is called to process the character data between element tags.
086: *
087: * @param ch the character buffer.
088: * @param start the start index.
089: * @param length the length.
090: * @throws SAXException if there is a parsing error.
091: */
092: public void characters(final char[] ch, final int start,
093: final int length) throws SAXException {
094: this .buffer.append(ch, start, length);
095: }
096:
097: /**
098: * Done parsing.
099: *
100: * @throws SAXException if there is a parsing error.
101: * @throws XmlReaderException if there is a reader error.
102: */
103: protected void doneParsing() throws SAXException,
104: XmlReaderException {
105: this .result = this .buffer.toString();
106: this .buffer = null;
107: }
108:
109: public String getResult() {
110: return result;
111: }
112:
113: /**
114: * Returns the object for this element.
115: *
116: * @return the object.
117: */
118: public Object getObject() {
119: return this.result;
120: }
121: }
|