class BrowseJasperReportTemplate
extends java.lang.Object
prepare(String)
function which loads
template into XML tree and performs preparation steps, and
generateReport(BrowseWidget)
function which transforms the XML tree into report
applicable to the specific browse and compiles the report.Modifier and Type | Field and Description |
---|---|
private int |
bottomMargin
The bottom margin of the page, as read from the template file.
|
private XmlAst |
columnDataTemplate
Sub-tree representing template for a column data area.
|
private XmlAst |
columnHeaderTemplate
Sub-tree representing template for a column header.
|
private static java.lang.String |
DEFAULT_COLUMN_LABEL_BGCOLOR
Default column label bgcolor.
|
private java.lang.String |
designTemplateFile
Name of the design template file.
|
private XmlAst |
detailsRootTemplate
Sub-tree representing template for a split table details.
|
private XmlAst |
headersRootTemplate
Sub-tree representing template for a split table header.
|
private int |
leftMargin
The left margin of the page, as read from the template file.
|
private int |
rightMargin
The right margin of the page, as read from the template file.
|
private int |
templatePageHeight
Page height specified in the report (assumed to be Portrait, width < height).
|
private int |
templatePageWidth
Page width specified in the report (assumed to be Portrait, width < height).
|
private XmlAst |
templateRoot
Root node of the prepared template.
|
private int |
topMargin
The top margin of the page, as read from the template file.
|
Constructor and Description |
---|
BrowseJasperReportTemplate() |
Modifier and Type | Method and Description |
---|---|
private void |
cleanUUID(XmlAst root)
Remove all "uuid" attributes in the given tree.
|
private XmlAst |
createFieldNode(java.lang.String name,
XmlAst parent,
XmlAst anchor)
Create FIELD node for Jasper report template.
|
private XmlAst |
createPropertyNode(java.lang.String name,
java.lang.String value,
XmlAst parent,
XmlAst anchor)
Create PROPERTY node for Jasper report template.
|
private XmlAst |
findChild(XmlAst parent,
int nodeType,
java.lang.String nodeText,
boolean noError)
Find the single available child with the specified node type and text under the given parent
node.
|
private XmlAst |
findChild(XmlAst parent,
java.lang.String tag)
Find the single available child with the specified XML tag under the given parent node.
|
private XmlAst |
findChild(XmlAst parent,
java.lang.String tag,
boolean noError)
Find the single available child with the specified XML tag under the given parent node.
|
private XmlAst |
findChildPath(XmlAst parent,
java.lang.String path)
Find the single available path under the given parent node, and return the last node in this
path.
|
private java.util.List<XmlAst> |
findChildren(XmlAst parent,
int nodeType,
java.lang.String nodeText)
Find the child nodes with the specified node type and text under the given parent node.
|
private java.util.List<XmlAst> |
findChildren(XmlAst parent,
int nodeType,
java.lang.String nodeText,
boolean noError)
Find the child nodes with the specified node type and text under the given parent node.
|
private java.util.List<XmlAst> |
findChildren(XmlAst parent,
java.lang.String tag)
Find the child nodes with the specified XML tag under the given parent node.
|
(package private) net.sf.jasperreports.engine.JasperReport |
generateReport(BrowseWidget browse)
Transform the XML tree representing prepared template (
templateRoot field) into the
report applicable to the specific browse and compile it. |
private java.lang.String |
getAttribute(XmlAst node,
java.lang.String name)
Get value of the specified attribute of the specified node.
|
private int |
getAttributeInt(XmlAst node,
java.lang.String name,
int defaultValue)
Get value of the specified integer attribute of the specified node.
|
(package private) void |
prepare(java.lang.String designTemplateFile)
Load given design template into XML tree and perform preparation steps, which in the future
allow to quickly transform this tree into a report suitable for the specific browse.
|
private void |
removeAttribute(XmlAst node,
java.lang.String name)
Delete the specified attribute of the specified node.
|
private void |
setAttribute(XmlAst node,
java.lang.String name,
java.lang.String value)
Set the value of the specified attribute.
|
private void |
setPositionAndWidth(XmlAst parent,
int xPos,
int columnWidth)
Set position and width of the single
reportElement element under the given
parent node. |
private void |
setTextAlignment(XmlAst parent,
BrowseTextAlignment alignment)
Set text alignment of the single
textElement element under the given
parent node. |
private static final java.lang.String DEFAULT_COLUMN_LABEL_BGCOLOR
private XmlAst templateRoot
private XmlAst columnHeaderTemplate
private XmlAst headersRootTemplate
private XmlAst detailsRootTemplate
private XmlAst columnDataTemplate
private java.lang.String designTemplateFile
private int templatePageWidth
private int templatePageHeight
private int leftMargin
private int rightMargin
private int topMargin
private int bottomMargin
void prepare(java.lang.String designTemplateFile) throws JasperReportException
designTemplateFile
- Name of the design template file.JasperReportException
- if design template file could not be read or parsed or has invalid structure.net.sf.jasperreports.engine.JasperReport generateReport(BrowseWidget browse) throws JasperReportException
templateRoot
field) into the
report applicable to the specific browse and compile it.
What to do when "Bands are larger than one page":
* use landscape page,
* https://community.jaspersoft.com/wiki/bands-larger-one-pagebrowse
- Browse for which the report is generated.JasperReportException
- if there was an error during creation of the browse report or the report could not
be compiled.private void setPositionAndWidth(XmlAst parent, int xPos, int columnWidth)
reportElement
element under the given
parent node.parent
- Parent node.xPos
- Element X position.columnWidth
- Element width.private void setTextAlignment(XmlAst parent, BrowseTextAlignment alignment)
textElement
element under the given
parent node.parent
- Parent node.alignment
- Text alignment.private XmlAst findChildPath(XmlAst parent, java.lang.String path)
parent
- Parent node.path
- "/"-separated down path, e.g. "jasperReport/columnHeader/band". Elements of the path
are XML tags.null
if there is no
path or there are multiple matching paths.private XmlAst findChild(XmlAst parent, java.lang.String tag)
parent
- Parent node.tag
- XML tag.JasperReportXmlSearchException
- if there is no available node, or there are multiple matching nodes.private XmlAst findChild(XmlAst parent, java.lang.String tag, boolean noError)
parent
- Parent node.tag
- XML tag.noError
is
true
: returns null
if there is no available node, or
there are multiple matching nodes.JasperReportXmlSearchException
- if noError
is false
: there is no available node, or
there are multiple matching nodes.private XmlAst findChild(XmlAst parent, int nodeType, java.lang.String nodeText, boolean noError)
parent
- Parent node.nodeType
- Node type (see constants in XmlTokenTypes
).nodeText
- Node text (e.g. XML tag or attribute name).noError
is true
: returns null
if there are no
available node, or there are multiple matching nodes.JasperReportXmlSearchException
- if noError
is false
: there are no available node, or
there are multiple matching nodes.private java.util.List<XmlAst> findChildren(XmlAst parent, java.lang.String tag)
parent
- Parent node.tag
- XML tag.JasperReportXmlSearchException
- there are no available node.private java.util.List<XmlAst> findChildren(XmlAst parent, int nodeType, java.lang.String nodeText)
parent
- Parent node.nodeType
- Type of the target nodes (see constants in XmlTokenTypes
).nodeText
- Node text (e.g. XML tag or attribute name).JasperReportXmlSearchException
- there are no available node.private java.util.List<XmlAst> findChildren(XmlAst parent, int nodeType, java.lang.String nodeText, boolean noError)
parent
- Parent node.nodeType
- Type of the target nodes (see constants in XmlTokenTypes
).nodeText
- Node text (e.g. XML tag or attribute name).noError
is true
: returns null
if there are no
available nodes.JasperReportXmlSearchException
- if noError
is false
: there are no available nodes.private void cleanUUID(XmlAst root)
root
- Root of the tree.private XmlAst createFieldNode(java.lang.String name, XmlAst parent, XmlAst anchor)
name
- Field name.parent
- Parent node.anchor
- Anchor node: created node will be positioned after the anchor node.private XmlAst createPropertyNode(java.lang.String name, java.lang.String value, XmlAst parent, XmlAst anchor)
name
- Property name.value
- Property value.parent
- Parent node.anchor
- Anchor node: created node will be positioned after the anchor node. Can be
null
.private int getAttributeInt(XmlAst node, java.lang.String name, int defaultValue)
node
- Parent node.name
- Attribute name.defaultValue
- Default value of the attribute.private java.lang.String getAttribute(XmlAst node, java.lang.String name)
node
- Parent node.name
- Attribute name.null
if there is no such attribute.private void removeAttribute(XmlAst node, java.lang.String name)
node
- Parent node.name
- Attribute name.private void setAttribute(XmlAst node, java.lang.String name, java.lang.String value)
node
- Parent node.name
- Attribute name.value
- Attribute value to set.