📄 functionfactory.java
字号:
/**
* ========================================
* JFreeReport : a free Java report library
* ========================================
*
* Project Info: http://www.jfree.org/jfreereport/index.html
* Project Lead: Thomas Morgner;
*
* (C) Copyright 2000-2002, by Simba Management Limited and Contributors.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* --------------------
* FunctionFactory.java
* --------------------
* (C)opyright 2002, by Thomas Morgner and Contributors.
*
* Original Author: Thomas Morgner;
* Contributor(s): David Gilbert (for Simba Management Limited);
*
* $Id: FunctionFactory.java,v 1.15.2.1 2003/08/24 14:18:10 taqua Exp $
*
* Changes
* -------
* 10-May-2002 : Initial version
* 23-May-2002 : Rewrite and better structured, divided into several start* & end* methods
* 08-Jun-2002 : Documentation
* 19-Aug-2002 : Added support for expressions
* 10-Dec-2002 : Fixed issues reported by Checkstyle (DG);
*
*/
package com.jrefinery.report.io.simple;
import java.util.Properties;
import com.jrefinery.report.function.Expression;
import com.jrefinery.report.function.Function;
import com.jrefinery.report.function.FunctionInitializeException;
import com.jrefinery.report.util.CharacterEntityParser;
import com.jrefinery.report.util.Log;
import org.jfree.xml.ParseException;
import org.jfree.xml.Parser;
import org.jfree.xml.ParserUtil;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* The functionFactory creates functions and adds these functions to the FunctionCollection
* of the current report.
*
* @author Thomas Morgner
*/
public class FunctionFactory extends AbstractReportDefinitionHandler implements ReportDefinitionTags
{
/** The current function/expression. */
private Expression currentFunction;
/** The report properties. */
private Properties currentProperties;
/** The current text. */
private StringBuffer currentText;
/** The current property. */
private String currentProperty;
/** The current encoding. */
private String currentEncoding;
/** A character entity parser. */
private CharacterEntityParser entityParser;
/**
* Creates a new function handler.
*
* @param parser the used parser to coordinate the parsing process.
* @param finishTag the finish tag, that should trigger the deactivation of this parser.
* @throws NullPointerException if the finishTag or the parser are null.
*/
public FunctionFactory(final Parser parser, final String finishTag)
{
super(parser, finishTag);
entityParser = CharacterEntityParser.createXMLEntityParser();
}
/**
* SAX-Handler function that is forwarded from the ReportDefinitionContentHandler.
* StartTag-occurences of function definitions get handled by this factory. If an unknown
* tag is encountered, a SAXException is thrown.
*
* @param qName the element name.
* @param atts the attributes.
*
* @throws SAXException if an unknown tag is encountered.
*/
public void startElement(final String qName,
final Attributes atts) throws SAXException
{
final String elementName = qName.toLowerCase().trim();
if (elementName.equals(FUNCTION_TAG))
{
startFunction(atts);
}
else if (elementName.equals(FUNCTIONS_TAG))
{
startFunctions(atts);
}
else if (elementName.equals(PROPERTIES_TAG))
{
startProperties(atts);
}
else if (elementName.equals(PROPERTY_TAG))
{
startProperty(atts);
}
else if (elementName.equals(DATAREF_TAG))
{
// data ref is ignored, was specified some times ago, but never
// implemented and is now obsolete
}
else if (elementName.equals(EXPRESSION_TAG))
{
startExpression(atts);
}
else if (elementName.equals(PROPERTY_REFERENCE_TAG))
{
startPropertyRef(atts);
}
else
{
throw new SAXException("Expected one of 'function', 'functions', 'data-ref', 'properties', "
+ "'property' tag");
}
}
/**
* Returns the current properties bundle for the function that is currently created.
*
* @return the function/expression properties.
*/
protected Properties getProperties()
{
return currentProperties;
}
/**
* Sets the properties for the current function.
*
* @param p the properties.
*/
protected void setProperties(final Properties p)
{
this.currentProperties = p;
}
/**
* Returns the function under construction.
*
* @return the function just built (or under construction).
*/
protected Function getCurrentFunction()
{
return (Function) currentFunction;
}
/**
* Defines the current function. This function gets properties set and is then added
* to the report's function collection.
*
* @param function the function.
*/
protected void setCurrentFunction(final Function function)
{
this.currentFunction = function;
}
/**
* Returns the current expression.
*
* @return the expression just built (or under construction).
*/
protected Expression getCurrentExpression()
{
return currentFunction;
}
/**
* Sets the current expression. This expression gets properties set and is then added
* to the reports expression collection.
*
* @param function the expression.
*/
protected void setCurrentExpression(final Expression function)
{
this.currentFunction = function;
}
/**
* Starts the Properties tag to create a new property bundle for a function.
*
* @param atts the element attributes.
*
* @throws SAXException if there is an error parsing the XML.
*/
protected void startProperties(final Attributes atts)
throws SAXException
{
setProperties(new Properties());
}
/**
* Starts a new property entry for the current function.
*
* @param atts the element attributes.
*
* @throws SAXException if there is an error parsing the XML.
*/
protected void startProperty(final Attributes atts)
throws SAXException
{
currentProperty = atts.getValue(NAME_ATT);
currentEncoding = atts.getValue(PROPERTY_ENCODING_ATT);
if (currentEncoding == null)
{
currentEncoding = PROPERTY_ENCODING_TEXT;
}
currentText = new StringBuffer();
}
/**
* Starts a new function collection. Function collections are already contained in
* the report, so this function does nothing.
*
* @param atts the element attributes.
*
* @throws SAXException if there is an error parsing the XML.
*/
protected void startFunctions(final Attributes atts)
throws SAXException
{
}
/**
* Starts processing an expression element.
*
* @param attr the element attributes.
*
* @throws SAXException if there is an error parsing the XML.
*/
protected void startExpression(final Attributes attr)
throws SAXException
{
final String name = getNameGenerator().generateName(attr.getValue("name"));
final String className = attr.getValue("class");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -