Package net.sf.jasperreports.engine.util
Class JRApiWriter
- java.lang.Object
-
- net.sf.jasperreports.engine.util.JRApiWriter
-
public class JRApiWriter extends Object
A writer that generates the Java code required to produce a given report template programmatically, using the JasperReports API.- Author:
- Teodor Danciu (teodord@users.sourceforge.net)
-
-
Field Summary
Fields Modifier and Type Field Description static String
EXCEPTION_MESSAGE_KEY_FILE_WRITE_ERROR
static String
EXCEPTION_MESSAGE_KEY_OUTPUT_STREAM_WRITE_ERROR
-
Constructor Summary
Constructors Constructor Description JRApiWriter(JasperReportsContext jasperReportsContext)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
close()
void
flush()
String
getBooleanText(Boolean key)
String
getIndent()
static void
main(String[] args)
protected boolean
toWriteConditionalStyles()
void
write(String text)
void
write(String pattern, boolean value, boolean defaultValue)
void
write(String pattern, byte value, byte defaultValue)
void
write(String pattern, int value)
void
write(String pattern, int value, int defaultValue)
void
write(String pattern, Color value)
void
write(String pattern, Color value, Color defaultValue)
void
write(String pattern, Double value)
void
write(String pattern, Double value, Double defaultValue)
void
write(String pattern, Enum<?> value)
void
write(String pattern, Enum<?> value, Enum<?> defaultValue)
void
write(String pattern, Float value)
void
write(String pattern, Float value, Float defaultValue)
void
write(String pattern, Object value)
void
write(String pattern, Object value, Object defaultValue)
String
write(JRReport report)
void
write(JRReport report, OutputStream outputStream)
void
write(JRReport report, String destFileName)
void
writeBox(JRLineBox box, String boxHolder)
void
writeBreak(JRBreak breakElement, String breakName)
protected void
writeBucket(JRCrosstabBucket bucket, String parentName)
protected void
writeCellContents(JRCellContents contents, String cellName)
void
writeChildElements(JRElementGroup elementContainer, String parentName)
Writes the contents (child elements) of an element container.void
writeComponentElement(JRComponentElement componentElement, String componentName)
protected void
writeConditionalStyle(JRConditionalStyle style, String styleName)
Writes a conditional style.void
writeCrosstab(JRCrosstab crosstab, String crosstabName)
protected void
writeCrosstabCell(JRCrosstabCell cell, String cellName)
protected void
writeCrosstabColumnGroup(JRCrosstabColumnGroup group, String groupName)
protected void
writeCrosstabMeasure(JRCrosstabMeasure measure, String measureName)
protected void
writeCrosstabParameter(JRCrosstabParameter parameter, String parameterName)
protected void
writeCrosstabRowGroup(JRCrosstabRowGroup group, String groupName)
protected void
writeCrosstabTitleCell(JRCrosstab crosstab, String crosstabName)
void
writeDataset(JRDataset dataset, String datasetName)
protected void
writeDatasetContents(JRDataset dataset, String datasetName)
void
writeDatasetRun(JRDatasetRun datasetRun, String parentName)
Outputs the XML representation of a subdataset run object.void
writeElementDataset(JRElementDataset dataset, boolean skipIfEmpty, String datasetName)
Writes the JRXML representation of anelement dataset
.void
writeElementDataset(JRElementDataset dataset, String datasetName)
Writes the JRXML representation of anelement dataset
.void
writeElementGroup(JRElementGroup elementGroup, String groupName)
void
writeEllipse(JREllipse ellipse, String ellipseName)
void
writeExpression(JRExpression expression, String parentName, String expressionSuffix)
void
writeExpression(JRExpression expression, String parentName, String expressionSuffix, String defaultClassName)
void
writeFont(JRFont font, String fontHolderName)
void
writeFrame(JRFrame frame, String frameName)
void
writeGenericElement(JRGenericElement element, String elementName)
protected XmlNamespace getNamespace() { return JASPERREPORTS_NAMESPACE; } /**void
writeHyperlink(JRHyperlink hyperlink, String parentName, String hyperlinkSuffix)
public void writeHyperlink( String tagName, JRHyperlink hyperlink, String hyperlinkName) { writeHyperlink( tagName, null, hyperlink, hyperlinkName); } /** public void writeHyperlink( String tagName, XmlNamespace namespace, JRHyperlink hyperlink, String hyperlinkName) { if (hyperlink !protected void
writeHyperlinkParameter(JRHyperlinkParameter parameter, String parameterName)
void
writeHyperlinkParameters(JRHyperlinkParameter[] parameters, String parentName)
void
writeImage(JRImage image, String imageName)
void
writeLine(JRLine line, String lineName)
protected void
writeParagraph(JRParagraph paragraph, String paragraphHolder)
protected void
writePattern(String pattern, Object... arguments)
protected void
writePropertyExpression(DatasetPropertyExpression propertyExpression, String propertyExpressionName)
protected void
writePropertyExpression(JRPropertyExpression propertyExpression, String propertyExpressionName)
protected void
writePropertyExpressions(DatasetPropertyExpression[] propertyExpressions, String propertyHolderName)
protected void
writePropertyExpressions(JRPropertyExpression[] propertyExpressions, String propertyHolderName)
void
writeRectangle(JRRectangle rectangle, String rectangleName)
static String
writeReport(JRReport report)
static void
writeReport(JRReport report, OutputStream outputStream)
protected void
writeReport(JRReport report, Writer aWriter)
static void
writeReport(JRReport report, String destFileName)
void
writeReportElement(JRElement element, String elementName)
protected void
writeSection(JRSection section, String sectionName, String sectionBandListGetterName)
void
writeStaticText(JRStaticText staticText, String staticTextName)
protected void
writeStyleReferenceAttr(JRStyleContainer styleContainer, String styleName)
void
writeSubreport(JRSubreport subreport, String subreportName)
protected void
writeTemplate(JRReportTemplate template, String templateName)
protected void
writeTemplates(JRReport report, String indent)
void
writeTextField(JRTextField textField, String textFieldName)
-
-
-
Field Detail
-
EXCEPTION_MESSAGE_KEY_OUTPUT_STREAM_WRITE_ERROR
public static final String EXCEPTION_MESSAGE_KEY_OUTPUT_STREAM_WRITE_ERROR
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_FILE_WRITE_ERROR
public static final String EXCEPTION_MESSAGE_KEY_FILE_WRITE_ERROR
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JRApiWriter
public JRApiWriter(JasperReportsContext jasperReportsContext)
-
-
Method Detail
-
getIndent
public String getIndent()
-
write
public void write(JRReport report, String destFileName) throws JRException
- Throws:
JRException
-
write
public void write(JRReport report, OutputStream outputStream) throws JRException
- Throws:
JRException
-
writeReport
public static String writeReport(JRReport report)
- See Also:
write(JRReport)
-
writeReport
public static void writeReport(JRReport report, String destFileName) throws JRException
- Throws:
JRException
- See Also:
write(JRReport, String)
-
writeReport
public static void writeReport(JRReport report, OutputStream outputStream) throws JRException
- Throws:
JRException
- See Also:
write(JRReport, OutputStream)
-
writeTemplate
protected void writeTemplate(JRReportTemplate template, String templateName)
-
writeSection
protected void writeSection(JRSection section, String sectionName, String sectionBandListGetterName)
-
writeChildElements
public void writeChildElements(JRElementGroup elementContainer, String parentName)
Writes the contents (child elements) of an element container.- Parameters:
elementContainer
- the element container
-
writeElementGroup
public void writeElementGroup(JRElementGroup elementGroup, String groupName)
-
writePropertyExpressions
protected void writePropertyExpressions(JRPropertyExpression[] propertyExpressions, String propertyHolderName)
-
writePropertyExpressions
protected void writePropertyExpressions(DatasetPropertyExpression[] propertyExpressions, String propertyHolderName)
-
writePropertyExpression
protected void writePropertyExpression(JRPropertyExpression propertyExpression, String propertyExpressionName)
-
writePropertyExpression
protected void writePropertyExpression(DatasetPropertyExpression propertyExpression, String propertyExpressionName)
-
writeRectangle
public void writeRectangle(JRRectangle rectangle, String rectangleName)
-
writeStaticText
public void writeStaticText(JRStaticText staticText, String staticTextName)
-
writeTextField
public void writeTextField(JRTextField textField, String textFieldName)
-
writeSubreport
public void writeSubreport(JRSubreport subreport, String subreportName)
-
writeElementDataset
public void writeElementDataset(JRElementDataset dataset, String datasetName)
Writes the JRXML representation of anelement dataset
.The method produces a
<dataset>
XML element.- Parameters:
dataset
- the element dataset
-
writeElementDataset
public void writeElementDataset(JRElementDataset dataset, boolean skipIfEmpty, String datasetName)
Writes the JRXML representation of anelement dataset
.The method produces a
<dataset>
XML element.- Parameters:
dataset
- the element datasetskipIfEmpty
- if set, no output will be produced if the element dataset only has default attribute values
-
writeCrosstab
public void writeCrosstab(JRCrosstab crosstab, String crosstabName)
-
writeCrosstabTitleCell
protected void writeCrosstabTitleCell(JRCrosstab crosstab, String crosstabName)
-
writeCrosstabRowGroup
protected void writeCrosstabRowGroup(JRCrosstabRowGroup group, String groupName)
-
writeCrosstabColumnGroup
protected void writeCrosstabColumnGroup(JRCrosstabColumnGroup group, String groupName)
-
writeBucket
protected void writeBucket(JRCrosstabBucket bucket, String parentName)
-
writeCrosstabMeasure
protected void writeCrosstabMeasure(JRCrosstabMeasure measure, String measureName)
-
writeCrosstabCell
protected void writeCrosstabCell(JRCrosstabCell cell, String cellName)
-
writeCellContents
protected void writeCellContents(JRCellContents contents, String cellName)
-
writeCrosstabParameter
protected void writeCrosstabParameter(JRCrosstabParameter parameter, String parameterName)
-
writeDatasetRun
public void writeDatasetRun(JRDatasetRun datasetRun, String parentName)
Outputs the XML representation of a subdataset run object.- Parameters:
datasetRun
- the subdataset run
-
writeHyperlinkParameters
public void writeHyperlinkParameters(JRHyperlinkParameter[] parameters, String parentName)
-
writeHyperlinkParameter
protected void writeHyperlinkParameter(JRHyperlinkParameter parameter, String parameterName)
-
writeHyperlink
public void writeHyperlink(JRHyperlink hyperlink, String parentName, String hyperlinkSuffix)
public void writeHyperlink( String tagName, JRHyperlink hyperlink, String hyperlinkName) { writeHyperlink( tagName, null, hyperlink, hyperlinkName); } /** public void writeHyperlink( String tagName, XmlNamespace namespace, JRHyperlink hyperlink, String hyperlinkName) { if (hyperlink != null) { writer.startElement(tagName, namespace); writer.addEncodedAttribute(JRApiConstants.ATTRIBUTE_hyperlinkType, hyperlink.getLinkType(), JRHyperlinkHelper.HYPERLINK_TYPE_NONE); writer.addEncodedAttribute(JRApiConstants.ATTRIBUTE_hyperlinkTarget, hyperlink.getLinkTarget(), JRHyperlinkHelper.HYPERLINK_TARGET_SELF); writer.writeExpression(JRApiConstants.ELEMENT_hyperlinkReferenceExpression, JASPERREPORTS_NAMESPACE, hyperlink.getHyperlinkReferenceExpression(), false); writer.writeExpression(JRApiConstants.ELEMENT_hyperlinkWhenExpression, JASPERREPORTS_NAMESPACE, hyperlink.getHyperlinkWhenExpression(), false); writer.writeExpression(JRApiConstants.ELEMENT_hyperlinkAnchorExpression, JASPERREPORTS_NAMESPACE, hyperlink.getHyperlinkAnchorExpression(), false); writer.writeExpression(JRApiConstants.ELEMENT_hyperlinkPageExpression, JASPERREPORTS_NAMESPACE, hyperlink.getHyperlinkPageExpression(), false); writer.writeExpression(JRApiConstants.ELEMENT_hyperlinkTooltipExpression, JASPERREPORTS_NAMESPACE, hyperlink.getHyperlinkTooltipExpression(), false); writeHyperlinkParameters(hyperlink.getHyperlinkParameters()); flush(); } } /**
-
toWriteConditionalStyles
protected boolean toWriteConditionalStyles()
-
writeConditionalStyle
protected void writeConditionalStyle(JRConditionalStyle style, String styleName)
Writes a conditional style.- Parameters:
style
- the conditional style
-
writeComponentElement
public void writeComponentElement(JRComponentElement componentElement, String componentName)
-
writeGenericElement
public void writeGenericElement(JRGenericElement element, String elementName)
protected XmlNamespace getNamespace() { return JASPERREPORTS_NAMESPACE; } /**
-
writeStyleReferenceAttr
protected void writeStyleReferenceAttr(JRStyleContainer styleContainer, String styleName)
-
writeParagraph
protected void writeParagraph(JRParagraph paragraph, String paragraphHolder)
-
writeExpression
public void writeExpression(JRExpression expression, String parentName, String expressionSuffix)
-
writeExpression
public void writeExpression(JRExpression expression, String parentName, String expressionSuffix, String defaultClassName)
-
write
public void write(String text)
-
write
public void write(String pattern, int value)
-
write
public void write(String pattern, int value, int defaultValue)
-
write
public void write(String pattern, boolean value, boolean defaultValue)
-
write
public void write(String pattern, byte value, byte defaultValue)
-
close
protected void close()
-
flush
public void flush()
-
main
public static void main(String[] args)
-
-