com.jrefinery.report.io.simple
Class ElementFactory

java.lang.Object
  extended bycom.jrefinery.report.io.simple.AbstractReportDefinitionHandler
      extended bycom.jrefinery.report.io.simple.ElementFactory
All Implemented Interfaces:
org.jfree.xml.ElementDefinitionHandler, ReportDefinitionTags

public class ElementFactory
extends AbstractReportDefinitionHandler
implements ReportDefinitionTags

The ElementFactory is responsible for creating ReportElements and is called by the ReportDefinitionContentHandler. For details on the format of the parser have a look at the DTD supplied in the distribution or on http://jfreereport.sourceforge.net/

This factory uses the deprecated element classes. These classes will get not extension for new features and as soon as the discrepancy between implemented and possible features gets too huge, this parser will be discontinued.

Author:
Thomas Morgner

Field Summary
 
Fields inherited from interface com.jrefinery.report.io.simple.ReportDefinitionTags
ALIGNMENT_ATT, BOTTOMMARGIN_ATT, COLOR_ATT, CONFIGURATION_TAG, DATAREF_TAG, DATE_FIELD_TAG, DATE_FUNCTION_TAG, DEPENCY_LEVEL_ATT, DRAWABLE_FIELD_TAG, EXPRESSION_TAG, FIELD_TAG, FIELDNAME_ATT, FIELDS_TAG, FONT_NAME_ATT, FONT_SIZE_ATT, FONT_STYLE_ATT, FORMAT_ATT, FS_BOLD, FS_EMBEDDED, FS_ENCODING, FS_ITALIC, FS_STRIKETHR, FS_UNDERLINE, FUNCTION_TAG, FUNCTIONNAME_ATT, FUNCTIONS_TAG, GENERAL_FIELD_TAG, GENERAL_FUNCTION_TAG, GROUP_FOOTER_TAG, GROUP_HEADER_TAG, GROUP_TAG, GROUPS_TAG, HEIGHT_ATT, IMAGEFIELD_TAG, IMAGEFUNCTION_TAG, IMAGEREF_TAG, IMAGEURLFIELD_TAG, IMAGEURLFUNCTION_TAG, ITEMS_TAG, LABEL_TAG, LEFTMARGIN_ATT, LINE_TAG, LINEHEIGHT, MULTILINE_FIELD_TAG, MULTILINE_FUNCTION_TAG, NAME_ATT, NULLSTRING_ATT, NUMBER_FIELD_TAG, NUMBER_FUNCTION_TAG, ORIENTATION_ATT, ORIENTATION_LANDSCAPE_VAL, ORIENTATION_PORTRAIT_VAL, ORIENTATION_REVERSE_LANDSCAPE_VAL, PAGE_FOOTER_TAG, PAGE_HEADER_TAG, PAGEFORMAT_ATT, PROPERTIES_TAG, PROPERTY_ENCODING_ATT, PROPERTY_ENCODING_TEXT, PROPERTY_REFERENCE_TAG, PROPERTY_TAG, RECTANGLE_TAG, REPEAT_HEADER, REPORT_FOOTER_TAG, REPORT_HEADER_TAG, REPORT_TAG, RESOURCEBASE_ATTR, RESOURCEFIELD_TAG, RESOURCELABEL_TAG, RIGHTMARGIN_ATT, SHAPE_FIELD_TAG, STRING_FIELD_TAG, STRING_FUNCTION_TAG, TOPMARGIN_ATT, VALIGNMENT_ATT, WIDTH_ATT
 
Constructor Summary
ElementFactory(org.jfree.xml.Parser parser, java.lang.String finishTag, Band band)
          Creates a new ElementFactory.
 
Method Summary
 void characters(char[] ch, int start, int length)
          Receives some (or all) of the text in the current element.
protected  void clearCurrentText()
          Removes all text from the textbuffer at the end of a CDATA section.
protected  void endDateField()
          Ends the date field and adds it to the current band.
protected  void endDateFunction()
          Ends the date function and adds it to the current band.
protected  void endDrawableField()
          Ends the drawable element.
 void endElement(java.lang.String qName)
          SAX handler function that is forwarded from the ReportDefinitionContentHandler.
protected  void endImageField()
          Ends the image element and adds it to the current band.
protected  void endImageFunction()
          Ends the image element and adds it to the current band.
protected  void endImageRef()
          Ends the image element and adds it to the current band.
protected  void endImageURLField()
          Ends the image element and adds it to the current band.
protected  void endImageURLFunction()
          Ends the image element and adds it to the current band.
protected  void endLabel()
          Ends a label tag, sets the static text for the label which was build during the parsing.
protected  void endLine()
          Ends the line element and adds it to the current band.
protected  void endMultilineField()
          Ends the multiline text element and adds it to the current band.
protected  void endNumberField()
          Ends the number field and adds it to the current band.
protected  void endNumberFunction()
          Ends the number function and adds it to the current band.
protected  void endRectangle()
          Ends the rectangle shape element and adds it to the current band.
protected  void endResourceField()
          Ends the resource field and adds it to the current band.
protected  void endResourceLabel()
          Ends a resource label tag, sets the static key for the resource label, which was build during the parsing.
protected  void endShapeField()
          Ends the shape element.
protected  void endStringField()
          Ends the String field and adds it to the current band.
protected  void endStringFunction()
          Ends the string function and adds it to the current band.
protected  Band getCurrentBand()
          Returns the current band, which receives the parsed elements.
protected  java.lang.String getCurrentText()
          Returns the current text of the textbuffer.
protected  void getDataElementAttributes(org.xml.sax.Attributes atts)
          Appends all data element relevant attributes to the data element parsed.
protected  void getFunctionElementAttributes(org.xml.sax.Attributes atts)
          Appends all function element relevant attributes to the data element parsed.
protected  void getTextElementAttributes(org.xml.sax.Attributes atts)
          Reads the attributes that are base for all band-elements, as name, x, y, width, height, font, fontstyle, fontsize and alignment.
protected  int parseTextAlignment(java.lang.String alignment, int defaultAlignment)
          Parses the text looking for a text alignment, which is one of "left", "center" or "right".
protected  int parseTextVerticalAlignment(java.lang.String alignment, int defaultAlignment)
          Parses the text looking for a text alignment, which is one of "top", "middle"/"center" or "bottom".
protected  void startDateField(org.xml.sax.Attributes atts)
          Creates a date element (a text element that displays a date value).
protected  void startDateFunction(org.xml.sax.Attributes atts)
          Begins processing a date function element (which is a text element).
protected  void startDrawableField(org.xml.sax.Attributes atts)
          Starts a drawable field.
 void startElement(java.lang.String qName, org.xml.sax.Attributes atts)
          SAX-Handler function that is forwarded from the ReportDefinitionContentHandler.
protected  void startImageField(org.xml.sax.Attributes atts)
          Create a ImageElement with an static ImageDataSource.
protected  void startImageFunction(org.xml.sax.Attributes atts)
          Create a ImageElement with an static ImageDataSource.
protected  void startImageRef(org.xml.sax.Attributes atts)
          Create a ImageElement with an static ImageDataSource.
protected  void startImageURLField(org.xml.sax.Attributes atts)
          Create a ImageElement with an static ImageDataSource.
protected  void startImageURLFunction(org.xml.sax.Attributes atts)
          Create a ImageElement with an static ImageDataSource.
protected  void startLabel(org.xml.sax.Attributes atts)
          Creates a label element, an text element with an static datasource attached.
protected  void startLine(org.xml.sax.Attributes atts)
          Creates a LineShapeElement.
protected  void startMultilineField(org.xml.sax.Attributes atts)
          Creates a text element.
protected  void startNumberField(org.xml.sax.Attributes atts)
          Creates a number element (a text element that displays a numerical value).
protected  void startNumberFunction(org.xml.sax.Attributes atts)
          Begins processing a number function element (which is a text element).
protected  void startRectangle(org.xml.sax.Attributes atts)
          Creates a RectangleShapeElement.
protected  void startResourceField(org.xml.sax.Attributes attrs)
          Creates a resource field element.
protected  void startResourceLabel(org.xml.sax.Attributes attrs)
          Creates a resource label element, an text element with an static datasource attached.
protected  void startShapeField(org.xml.sax.Attributes atts)
          Creates a RectangleShapeElement.
protected  void startStringField(org.xml.sax.Attributes atts)
          Creates a text element.
protected  void startStringFunction(org.xml.sax.Attributes atts)
          Begins processing a string function element (which is a text element).
 
Methods inherited from class com.jrefinery.report.io.simple.AbstractReportDefinitionHandler
getContentBase, getFinishTag, getLocator, getNameGenerator, getParser, getReport
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ElementFactory

public ElementFactory(org.jfree.xml.Parser parser,
                      java.lang.String finishTag,
                      Band band)
Creates a new ElementFactory. The factory queries the current Band of the ReportFactory and will add created element to this band. If unknown end-Tags are encountered, the parsing for elements will stop and the previous handler will be activated.

Parameters:
parser - the used parser to coordinate the parsing process.
finishTag - the finish tag, that should trigger the deactivation of this parser.
band - the band that should be defined.
Throws:
java.lang.NullPointerException - if the finishTag or the parser are null.
Method Detail

startElement

public void startElement(java.lang.String qName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
SAX-Handler function that is forwarded from the ReportDefinitionContentHandler. StartTag-occurences of element definitions get handled by this factory. If an unknown element is encountered, a SAXException is thrown.

The elements parsed in this factory denote base usecases. Element creation is delegated to the ItemFactory

Specified by:
startElement in interface org.jfree.xml.ElementDefinitionHandler
Parameters:
qName - the element name.
atts - the element attributes.
Throws:
org.xml.sax.SAXException - if an unknown tag is encountered.
See Also:
ItemFactory

getCurrentBand

protected Band getCurrentBand()
Returns the current band, which receives the parsed elements.

Returns:
the current band.

clearCurrentText

protected void clearCurrentText()
Removes all text from the textbuffer at the end of a CDATA section.


getCurrentText

protected java.lang.String getCurrentText()
Returns the current text of the textbuffer.

Returns:
the current text.

characters

public void characters(char[] ch,
                       int start,
                       int length)
Receives some (or all) of the text in the current element.

Specified by:
characters in interface org.jfree.xml.ElementDefinitionHandler
Overrides:
characters in class AbstractReportDefinitionHandler
Parameters:
ch - character buffer.
start - the start index.
length - the length of the valid character data.

endElement

public void endElement(java.lang.String qName)
                throws org.xml.sax.SAXException
SAX handler function that is forwarded from the ReportDefinitionContentHandler. If an unknown element is encountered, the previous handler gets activated.

Specified by:
endElement in interface org.jfree.xml.ElementDefinitionHandler
Parameters:
qName - the element name.
Throws:
org.xml.sax.SAXException - if an unknown tag is encountered.

startImageRef

protected void startImageRef(org.xml.sax.Attributes atts)
                      throws org.xml.sax.SAXException
Create a ImageElement with an static ImageDataSource. The ImageData is read from the supplied URL (attribute "src") in conjunction with the contentbase defined in the ReportDefinitionContentHandler.

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

startImageField

protected void startImageField(org.xml.sax.Attributes atts)
                        throws org.xml.sax.SAXException
Create a ImageElement with an static ImageDataSource. The ImageData is read from the supplied URL (attribute "src") in conjunction with the contentbase defined in the ReportDefintionContentHandler

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

startDrawableField

protected void startDrawableField(org.xml.sax.Attributes atts)
                           throws org.xml.sax.SAXException
Starts a drawable field.

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX error.

startImageURLField

protected void startImageURLField(org.xml.sax.Attributes atts)
                           throws org.xml.sax.SAXException
Create a ImageElement with an static ImageDataSource. The ImageData is read from the supplied URL (attribute "src") in conjunction with the contentbase defined in the ReportDefintionContentHandler

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

startImageFunction

protected void startImageFunction(org.xml.sax.Attributes atts)
                           throws org.xml.sax.SAXException
Create a ImageElement with an static ImageDataSource. The ImageData is read from the supplied URL (attribute "src") in conjunction with the contentbase defined in the ReportDefintionContentHandler

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

startImageURLFunction

protected void startImageURLFunction(org.xml.sax.Attributes atts)
                              throws org.xml.sax.SAXException
Create a ImageElement with an static ImageDataSource. The ImageData is read from the supplied URL (attribute "src") in conjunction with the contentbase defined in the ReportDefintionContentHandler

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

startLine

protected void startLine(org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
Creates a LineShapeElement.

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

startRectangle

protected void startRectangle(org.xml.sax.Attributes atts)
                       throws org.xml.sax.SAXException
Creates a RectangleShapeElement.

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

startShapeField

protected void startShapeField(org.xml.sax.Attributes atts)
                        throws org.xml.sax.SAXException
Creates a RectangleShapeElement.

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

startLabel

protected void startLabel(org.xml.sax.Attributes atts)
                   throws org.xml.sax.SAXException
Creates a label element, an text element with an static datasource attached.

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

startMultilineField

protected void startMultilineField(org.xml.sax.Attributes atts)
                            throws org.xml.sax.SAXException
Creates a text element. In ancient times there was a difference between string elements (single line) and multiline fields. This is resolved in the text element class which handles all cases of printing text in reports.

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

startStringField

protected void startStringField(org.xml.sax.Attributes atts)
                         throws org.xml.sax.SAXException
Creates a text element. In ancient times there was a difference between string elements (single line) and multiline fields. This is resolved in the text element class which handles all cases of printing text in reports.

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

startNumberField

protected void startNumberField(org.xml.sax.Attributes atts)
                         throws org.xml.sax.SAXException
Creates a number element (a text element that displays a numerical value).

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

startDateField

protected void startDateField(org.xml.sax.Attributes atts)
                       throws org.xml.sax.SAXException
Creates a date element (a text element that displays a date value).

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

startNumberFunction

protected void startNumberFunction(org.xml.sax.Attributes atts)
                            throws org.xml.sax.SAXException
Begins processing a number function element (which is a text element).

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

startDateFunction

protected void startDateFunction(org.xml.sax.Attributes atts)
                          throws org.xml.sax.SAXException
Begins processing a date function element (which is a text element).

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

startStringFunction

protected void startStringFunction(org.xml.sax.Attributes atts)
                            throws org.xml.sax.SAXException
Begins processing a string function element (which is a text element).

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

endLabel

protected void endLabel()
                 throws org.xml.sax.SAXException
Ends a label tag, sets the static text for the label which was build during the parsing. The label is added to the current band.

Throws:
org.xml.sax.SAXException - if there is a SAX problem.

endLine

protected void endLine()
                throws org.xml.sax.SAXException
Ends the line element and adds it to the current band.

Throws:
org.xml.sax.SAXException - if there is a SAX problem.

endShapeField

protected void endShapeField()
                      throws org.xml.sax.SAXException
Ends the shape element.

Throws:
org.xml.sax.SAXException - if there is a SAX problem.

endRectangle

protected void endRectangle()
                     throws org.xml.sax.SAXException
Ends the rectangle shape element and adds it to the current band.

Throws:
org.xml.sax.SAXException - if there is a SAX problem.

endImageField

protected void endImageField()
                      throws org.xml.sax.SAXException
Ends the image element and adds it to the current band.

Throws:
org.xml.sax.SAXException - if there is a SAX problem.

endImageFunction

protected void endImageFunction()
                         throws org.xml.sax.SAXException
Ends the image element and adds it to the current band.

Throws:
org.xml.sax.SAXException - if there is a SAX problem.

endImageURLField

protected void endImageURLField()
                         throws org.xml.sax.SAXException
Ends the image element and adds it to the current band.

Throws:
org.xml.sax.SAXException - if there is a SAX problem.

endImageURLFunction

protected void endImageURLFunction()
                            throws org.xml.sax.SAXException
Ends the image element and adds it to the current band.

Throws:
org.xml.sax.SAXException - if there is a SAX problem.

endImageRef

protected void endImageRef()
                    throws org.xml.sax.SAXException
Ends the image element and adds it to the current band.

Throws:
org.xml.sax.SAXException - if there is a SAX problem.

endDrawableField

protected void endDrawableField()
                         throws org.xml.sax.SAXException
Ends the drawable element.

Throws:
org.xml.sax.SAXException - if there is a SAX problem.

startResourceLabel

protected void startResourceLabel(org.xml.sax.Attributes attrs)
                           throws org.xml.sax.SAXException
Creates a resource label element, an text element with an static datasource attached.

Parameters:
attrs - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

startResourceField

protected void startResourceField(org.xml.sax.Attributes attrs)
                           throws org.xml.sax.SAXException
Creates a resource field element.

Parameters:
attrs - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

endResourceLabel

protected void endResourceLabel()
Ends a resource label tag, sets the static key for the resource label, which was build during the parsing. The label is added to the current band.


endResourceField

protected void endResourceField()
Ends the resource field and adds it to the current band.


endMultilineField

protected void endMultilineField()
                          throws org.xml.sax.SAXException
Ends the multiline text element and adds it to the current band.

Throws:
org.xml.sax.SAXException - if there is a SAX problem.

endStringField

protected void endStringField()
                       throws org.xml.sax.SAXException
Ends the String field and adds it to the current band.

Throws:
org.xml.sax.SAXException - if there is a SAX problem.

endNumberField

protected void endNumberField()
                       throws org.xml.sax.SAXException
Ends the number field and adds it to the current band.

Throws:
org.xml.sax.SAXException - if there is a SAX problem.

endDateField

protected void endDateField()
                     throws org.xml.sax.SAXException
Ends the date field and adds it to the current band.

Throws:
org.xml.sax.SAXException - if there is a SAX problem.

endNumberFunction

protected void endNumberFunction()
                          throws org.xml.sax.SAXException
Ends the number function and adds it to the current band.

Throws:
org.xml.sax.SAXException - if there is a SAX problem.

endStringFunction

protected void endStringFunction()
                          throws org.xml.sax.SAXException
Ends the string function and adds it to the current band.

Throws:
org.xml.sax.SAXException - if there is a SAX problem.

endDateFunction

protected void endDateFunction()
                        throws org.xml.sax.SAXException
Ends the date function and adds it to the current band.

Throws:
org.xml.sax.SAXException - if there is a SAX problem.

getTextElementAttributes

protected void getTextElementAttributes(org.xml.sax.Attributes atts)
                                 throws org.xml.sax.SAXException
Reads the attributes that are base for all band-elements, as name, x, y, width, height, font, fontstyle, fontsize and alignment.

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

parseTextAlignment

protected int parseTextAlignment(java.lang.String alignment,
                                 int defaultAlignment)
Parses the text looking for a text alignment, which is one of "left", "center" or "right".

The method returns one of the values: Element.LEFT, Element.CENTER and Element.RIGHT.

Parameters:
alignment - the alignment.
defaultAlignment - the default alignment.
Returns:
an alignment code.

parseTextVerticalAlignment

protected int parseTextVerticalAlignment(java.lang.String alignment,
                                         int defaultAlignment)
Parses the text looking for a text alignment, which is one of "top", "middle"/"center" or "bottom".

The method returns one of the values: Element.TOP, Element.BOTTOM and Element.MIDDLE.

Parameters:
alignment - the alignment.
defaultAlignment - the default alignment.
Returns:
an alignment code.

getDataElementAttributes

protected void getDataElementAttributes(org.xml.sax.Attributes atts)
                                 throws org.xml.sax.SAXException
Appends all data element relevant attributes to the data element parsed.

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.

getFunctionElementAttributes

protected void getFunctionElementAttributes(org.xml.sax.Attributes atts)
                                     throws org.xml.sax.SAXException
Appends all function element relevant attributes to the data element parsed.

Parameters:
atts - the attributes.
Throws:
org.xml.sax.SAXException - if there is a SAX problem.