Source for org.jfree.report.modules.factories.report.flow.ContentElementReadHandler

   1: /**
   2:  * ========================================
   3:  * JFreeReport : a free Java report library
   4:  * ========================================
   5:  *
   6:  * Project Info:  http://reporting.pentaho.org/
   7:  *
   8:  * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors.
   9:  *
  10:  * This library is free software; you can redistribute it and/or modify it under the terms
  11:  * of the GNU Lesser General Public License as published by the Free Software Foundation;
  12:  * either version 2.1 of the License, or (at your option) any later version.
  13:  *
  14:  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  15:  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16:  * See the GNU Lesser General Public License for more details.
  17:  *
  18:  * You should have received a copy of the GNU Lesser General Public License along with this
  19:  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  20:  * Boston, MA 02111-1307, USA.
  21:  *
  22:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  23:  * in the United States and other countries.]
  24:  *
  25:  * ------------
  26:  * $Id: ContentElementReadHandler.java 3525 2007-10-16 11:43:48Z tmorgner $
  27:  * ------------
  28:  * (C) Copyright 2000-2005, by Object Refinery Limited.
  29:  * (C) Copyright 2005-2007, by Pentaho Corporation.
  30:  */
  31: package org.jfree.report.modules.factories.report.flow;
  32: 
  33: import org.jfree.report.structure.ContentElement;
  34: import org.jfree.report.structure.Element;
  35: import org.jfree.xmlns.parser.XmlReadHandler;
  36: import org.jfree.xmlns.parser.ParseException;
  37: import org.xml.sax.Attributes;
  38: import org.xml.sax.SAXException;
  39: 
  40: /**
  41:  * Creation-Date: 09.04.2006, 14:38:32
  42:  *
  43:  * @author Thomas Morgner
  44:  */
  45: public class ContentElementReadHandler extends AbstractElementReadHandler
  46: {
  47:   private ValueExpressionReadHandler valueExpressionReadHandler;
  48:   private ContentElement ce;
  49: 
  50:   public ContentElementReadHandler()
  51:   {
  52:     ce = new ContentElement();
  53:   }
  54: 
  55:   /**
  56:    * Starts parsing.
  57:    *
  58:    * @param attrs the attributes.
  59:    * @throws org.xml.sax.SAXException if there is a parsing error.
  60:    */
  61:   protected void startParsing(final Attributes attrs) throws SAXException
  62:   {
  63:     super.startParsing(attrs);
  64:     final String format = attrs.getValue(FlowReportFactoryModule.NAMESPACE, "format");
  65:     ce.setAttribute(FlowReportFactoryModule.NAMESPACE, "format", format);
  66:   }
  67: 
  68:   /**
  69:    * Returns the handler for a child element.
  70:    *
  71:    * @param tagName the tag name.
  72:    * @param atts    the attributes.
  73:    * @return the handler or null, if the tagname is invalid.
  74:    * @throws SAXException       if there is a parsing error.
  75:    */
  76:   protected XmlReadHandler getHandlerForChild(final String uri,
  77:                                               final String tagName,
  78:                                               final Attributes atts)
  79:           throws SAXException
  80:   {
  81:     if (isSameNamespace(uri) == false)
  82:     {
  83:       return null;
  84:     }
  85:     if ("value-expression".equals(tagName))
  86:     {
  87:       valueExpressionReadHandler = new ValueExpressionReadHandler();
  88:       return valueExpressionReadHandler;
  89:     }
  90:     return super.getHandlerForChild(uri, tagName, atts);
  91:   }
  92: 
  93:   /**
  94:    * Done parsing.
  95:    *
  96:    * @throws SAXException       if there is a parsing error.
  97:    */
  98:   protected void doneParsing() throws SAXException
  99:   {
 100:     if (valueExpressionReadHandler == null)
 101:     {
 102:       throw new ParseException("No valid value expression.", getLocator());
 103:     }
 104: 
 105:     super.doneParsing();
 106:     configureElement(ce);
 107:     ce.setValueExpression(valueExpressionReadHandler.getExpression());
 108:   }
 109: 
 110:   /**
 111:    * Returns the object for this element or null, if this element does not
 112:    * create an object.
 113:    *
 114:    * @return the object.
 115:    * @throws SAXException if there's a parsing error
 116:    */
 117:   public Object getObject() throws SAXException
 118:   {
 119:     return ce;
 120:   }
 121: 
 122:   protected Element getElement()
 123:   {
 124:     return ce;
 125:   }
 126: }