Frames | No Frames |
1: /* ======================================================================== 2: * JCommon : a free general purpose class library for the Java(tm) platform 3: * ======================================================================== 4: * 5: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. 6: * 7: * Project Info: http://www.jfree.org/jcommon/index.html 8: * 9: * This library is free software; you can redistribute it and/or modify it 10: * under the terms of the GNU Lesser General Public License as published by 11: * the Free Software Foundation; either version 2.1 of the License, or 12: * (at your option) any later version. 13: * 14: * This library is distributed in the hope that it will be useful, but 15: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17: * License for more details. 18: * 19: * You should have received a copy of the GNU Lesser General Public 20: * License along with this library; if not, write to the Free Software 21: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * ---------------------- 28: * StringReadHandler.java 29: * ---------------------- 30: * (C)opyright 2003, 2004, by Thomas Morgner and Contributors. 31: * 32: * Original Author: Thomas Morgner; 33: * Contributor(s): David Gilbert (for Object Refinery Limited); 34: * 35: * $Id: StringReadHandler.java,v 1.5 2005/10/18 13:33:32 mungady Exp $ 36: * 37: * Changes 38: * ------- 39: * 03-Dec-2003 : Initial version 40: * 11-Feb-2004 : Added missing Javadocs (DG); 41: * 42: */ 43: 44: package org.jfree.xml.parser.coretypes; 45: 46: import org.jfree.xml.parser.AbstractXmlReadHandler; 47: import org.jfree.xml.parser.XmlReaderException; 48: import org.xml.sax.Attributes; 49: import org.xml.sax.SAXException; 50: 51: /** 52: * Required for list contents ... 53: */ 54: public class StringReadHandler extends AbstractXmlReadHandler 55: { 56: 57: /** 58: * A string buffer. 59: */ 60: private StringBuffer buffer; 61: 62: /** 63: * The string under construction. 64: */ 65: private String result; 66: 67: /** 68: * Creates a new handler. 69: */ 70: public StringReadHandler () 71: { 72: super(); 73: } 74: 75: /** 76: * Starts parsing. 77: * 78: * @param attrs the attributes. 79: * @throws SAXException if there is a parsing error. 80: */ 81: protected void startParsing (final Attributes attrs) 82: throws SAXException 83: { 84: this.buffer = new StringBuffer(); 85: } 86: 87: /** 88: * This method is called to process the character data between element tags. 89: * 90: * @param ch the character buffer. 91: * @param start the start index. 92: * @param length the length. 93: * @throws SAXException if there is a parsing error. 94: */ 95: public void characters (final char[] ch, final int start, final int length) 96: throws SAXException 97: { 98: this.buffer.append(ch, start, length); 99: } 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: public String getResult () 115: { 116: return result; 117: } 118: 119: /** 120: * Returns the object for this element. 121: * 122: * @return the object. 123: */ 124: public Object getObject () 125: { 126: return this.result; 127: } 128: }