    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.6 2008/09/10 09:19:23 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      /**
    058       * A string buffer.
    059       */
    060      private StringBuffer buffer;
    061
    062      /**
    063       * The string under construction.
    064       */
    065      private String result;
    066
    067      /**
    068       * Creates a new handler.
    069       */
    070      public StringReadHandler ()
    071      {
    072        super();
    073      }
    074
    075      /**
    076       * Starts parsing.
    077       *
    078       * @param attrs the attributes.
    079       * @throws SAXException if there is a parsing error.
    080       */
    081      protected void startParsing (final Attributes attrs)
    082              throws SAXException
    083      {
    084        this.buffer = new StringBuffer();
    085      }
    086
    087      /**
    088       * This method is called to process the character data between element tags.
    089       *
    090       * @param ch     the character buffer.
    091       * @param start  the start index.
    092       * @param length the length.
    093       * @throws SAXException if there is a parsing error.
    094       */
    095      public void characters (final char[] ch, final int start, final int length)
    096              throws SAXException
    097      {
    098        this.buffer.append(ch, start, length);
    099      }
    100
    101      /**
    102       * Done parsing.
    103       *
    104       * @throws SAXException       if there is a parsing error.
    105       * @throws XmlReaderException if there is a reader error.
    106       */
    107      protected void doneParsing ()
    108              throws SAXException, XmlReaderException
    109      {
    110        this.result = this.buffer.toString();
    111        this.buffer = null;
    112      }
    113
    114      /**
    115       * Returns the result.
    116       *
    117       * @return The result.
    118       */
    119      public String getResult ()
    120      {
    121        return this.result;
    122      }
    123
    124      /**
    125       * Returns the object for this element.
    126       *
    127       * @return the object.
    128       */
    129      public Object getObject ()
    130      {
    131        return this.result;
    132      }
    133    }