com.aspose.words
Class ReportingEngine

java.lang.Object
    extended by com.aspose.words.ReportingEngine

public class ReportingEngine 
extends java.lang.Object

Provides routines to populate template documents with data and a set of settings to control these routines.

To learn more, visit the LINQ Reporting Engine documentation article.


Constructor Summary
ReportingEngine()
           Initializes a new instance of this class.
 
Property Getters/Setters Summary
KnownTypeSetgetKnownTypes()
           Gets an unordered set (i.e. a collection of unique items) containing java.lang.Class objects which fully or partially qualified names can be used within report templates processed by this engine instance to invoke the corresponding types' static members, perform type casts, etc.
java.lang.StringgetMissingMemberMessage()
voidsetMissingMemberMessage(java.lang.String value)
           Gets or sets a string value printed instead of a template expression that represents a plain reference to a missing member of an object. The default value is an empty string.
intgetOptions()
voidsetOptions(int value)
           Gets or sets a set of flags controlling behavior of this ReportingEngine instance while building a report. The value of the property is ReportBuildOptions integer constant.
static booleangetUseReflectionOptimization()
static voidsetUseReflectionOptimization(boolean value)
           Gets or sets a value indicating whether invocations of custom type members performed via reflection API are optimized using dynamic class generation or not. The default value is true.
 
Method Summary
booleanbuildReport(Document document, java.lang.Object dataSource)
           Populates the specified template document with data from the specified source making it a ready report.
booleanbuildReport(Document document, java.lang.Object dataSource, java.lang.String dataSourceName)
           Populates the specified template document with data from the specified source making it a ready report.
booleanbuildReport(Document document, java.lang.Object[] dataSources, java.lang.String[] dataSourceNames)
           Populates the specified template document with data from the specified sources making it a ready report.
booleanequals(java.lang.Object obj)
           Determines whether the specified object is equal in value to the current object.
static java.lang.Class[]getRestrictedTypes()
           Returns types, which members as well as which derived types' members should be inaccessible by the engine through template syntax.
static voidsetRestrictedTypes(java.lang.Class[] types)
           Specifies types, which members as well as which derived types' members should be inaccessible by the engine through template syntax.
 

Constructor Detail

ReportingEngine

public ReportingEngine()
Initializes a new instance of this class.

Property Getters/Setters Detail

getKnownTypes

public KnownTypeSet getKnownTypes()
Gets an unordered set (i.e. a collection of unique items) containing java.lang.Class objects which fully or partially qualified names can be used within report templates processed by this engine instance to invoke the corresponding types' static members, perform type casts, etc.

getMissingMemberMessage/setMissingMemberMessage

public java.lang.String getMissingMemberMessage() / public void setMissingMemberMessage(java.lang.String value)
Gets or sets a string value printed instead of a template expression that represents a plain reference to a missing member of an object. The default value is an empty string.

The property should be used in conjunction with the ReportBuildOptions.ALLOW_MISSING_MEMBERS option. Otherwise, an exception is thrown when a missing member of an object is encountered.

The property affects only printing of a template expression representing a plain reference to a missing object member. For example, printing of a binary operator, one of which operands references a missing object member, is not affected.

The value of this property cannot be set to null.

Example:

Shows how to allow missinng members.
DocumentBuilder builder = new DocumentBuilder();
builder.writeln("<<[missingObject.First().id]>>");
builder.writeln("<<foreach [in missingObject]>><<[id]>><</foreach>>");

ReportingEngine engine = new ReportingEngine(); { engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS); }
engine.setMissingMemberMessage("Missed");
engine.buildReport(builder.getDocument(), new DataSet(), "");

getOptions/setOptions

public int getOptions() / public void setOptions(int value)
Gets or sets a set of flags controlling behavior of this ReportingEngine instance while building a report. The value of the property is ReportBuildOptions integer constant.

Example:

Shows how to allow missinng members.
DocumentBuilder builder = new DocumentBuilder();
builder.writeln("<<[missingObject.First().id]>>");
builder.writeln("<<foreach [in missingObject]>><<[id]>><</foreach>>");

ReportingEngine engine = new ReportingEngine(); { engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS); }
engine.setMissingMemberMessage("Missed");
engine.buildReport(builder.getDocument(), new DataSet(), "");

Example:

Shows how to set options for Reporting Engine
Document doc = new Document(getMyDir() + "Reporting engine template - Fields (Java).docx");

// Note that enabling of the option makes the engine to update fields while building a report,
// so there is no need to update fields separately after that.
ReportingEngine engine = new ReportingEngine();
engine.setOptions(ReportBuildOptions.UPDATE_FIELDS_SYNTAX_AWARE);
engine.buildReport(doc, new String[] { "First topic", "Second topic", "Third topic" }, "topics");

doc.save(getArtifactsDir() + "ReportingEngine.UpdateFieldsSyntaxAware.docx");

getUseReflectionOptimization/setUseReflectionOptimization

public static boolean getUseReflectionOptimization() / public static void setUseReflectionOptimization(boolean value)
Gets or sets a value indicating whether invocations of custom type members performed via reflection API are optimized using dynamic class generation or not. The default value is true. There are some scenarios where it is preferrable to disable this optimization. For example, if you are dealing with small collections of data items all the time, then an overhead of dynamic class generation can be more noticeable than an overhead of direct reflection API calls. The option does not have effect when run on iOS and reflection optimization is not used.

Method Detail

buildReport

public boolean buildReport(Document document, java.lang.Object dataSource)
                   throws java.lang.Exception
Populates the specified template document with data from the specified source making it a ready report.

Using this overload you can reference the data source's members in the template document, but you cannot reference the data source object itself. You should use the buildReport(com.aspose.words.Document,java.lang.Object,java.lang.String) overload to achieve this.

A data source object can be of one of the following types:

  • XmlDataSource
  • JsonDataSource
  • CsvDataSource
  • com.aspose.words.net.System.Data.DataSet
  • com.aspose.words.net.System.Data.DataTable
  • com.aspose.words.net.System.Data.DataRow
  • com.aspose.words.net.System.Data.IDataReader
  • com.aspose.words.net.System.Data.IDataRecord
  • com.aspose.words.net.System.Data.DataView
  • com.aspose.words.net.System.Data.DataRowView
  • Any other arbitrary Java type

For information on how to work with data sources of different types in template documents, see template syntax reference (https://docs.aspose.com/display/wordsjava/Template+Syntax).

Parameters:
document - A template document to be populated with data.
dataSource - A data source object.
Returns:
A flag indicating whether parsing of the template document was successful. The returned flag makes sense only if a value of the Options property includes the ReportBuildOptions.INLINE_ERROR_MESSAGES option.

buildReport

public boolean buildReport(Document document, java.lang.Object dataSource, java.lang.String dataSourceName)
                   throws java.lang.Exception
Populates the specified template document with data from the specified source making it a ready report.

Using this overload you can reference the data source's members and the data source object itself in the template. If you are not going to reference the data source object itself, you can omit dataSourceName passing null or use the buildReport(com.aspose.words.Document,java.lang.Object) overload.

A data source object can be of one of the following types:

  • XmlDataSource
  • JsonDataSource
  • CsvDataSource
  • com.aspose.words.net.System.Data.DataSet
  • com.aspose.words.net.System.Data.DataTable
  • com.aspose.words.net.System.Data.DataRow
  • com.aspose.words.net.System.Data.IDataReader
  • com.aspose.words.net.System.Data.IDataRecord
  • com.aspose.words.net.System.Data.DataView
  • com.aspose.words.net.System.Data.DataRowView
  • Any other arbitrary Java type

For information on how to work with data sources of different types in template documents, see template syntax reference (https://docs.aspose.com/display/wordsjava/Template+Syntax).

Parameters:
document - A template document to be populated with data.
dataSource - A data source object.
dataSourceName - A name to reference the data source object in the template.
Returns:
A flag indicating whether parsing of the template document was successful. The returned flag makes sense only if a value of the Options property includes the ReportBuildOptions.INLINE_ERROR_MESSAGES option.

Example:

Shows how to display values as dollar text.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.writeln("<<[ds.getValue1()]:dollarText>>\r<<[ds.getValue2()]:dollarText>>");

NumericTestClass testData = new NumericTestBuilder().withValues(1234, 5621718.589).build();

ReportingEngine report = new ReportingEngine();
report.getKnownTypes().add(NumericTestClass.class);
report.buildReport(doc, testData, "ds");

doc.save(getArtifactsDir() + "ReportingEngine.DollarTextFormat.docx");

Example:

Shows how to allow missinng members.
DocumentBuilder builder = new DocumentBuilder();
builder.writeln("<<[missingObject.First().id]>>");
builder.writeln("<<foreach [in missingObject]>><<[id]>><</foreach>>");

ReportingEngine engine = new ReportingEngine(); { engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS); }
engine.setMissingMemberMessage("Missed");
engine.buildReport(builder.getDocument(), new DataSet(), "");

Example:

Shows how to remove paragraphs selectively.
// Template contains tags with an exclamation mark. For such tags, empty paragraphs will be removed.
Document doc = new Document(getMyDir() + "Reporting engine template - Selective remove paragraphs.docx");

ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, false, "value");

doc.save(getArtifactsDir() + "ReportingEngine.SelectiveDeletionOfParagraphs.docx");

buildReport

public boolean buildReport(Document document, java.lang.Object[] dataSources, java.lang.String[] dataSourceNames)
                   throws java.lang.Exception
Populates the specified template document with data from the specified sources making it a ready report.

Using this overload you can reference multiple data source objects and their members in the template. The name of the first data source can be omitted (i.e. be an empty string or null) if you are going to reference the data source's members but not the data source object itself. Names of the other data sources must be specified and unique.

If you are going to use a single data source, consider using of buildReport(com.aspose.words.Document,java.lang.Object) and buildReport(com.aspose.words.Document,java.lang.Object,java.lang.String) overloads instead.

A data source object can be of one of the following types:

  • XmlDataSource
  • JsonDataSource
  • CsvDataSource
  • com.aspose.words.net.System.Data.DataSet
  • com.aspose.words.net.System.Data.DataTable
  • com.aspose.words.net.System.Data.DataRow
  • com.aspose.words.net.System.Data.IDataReader
  • com.aspose.words.net.System.Data.IDataRecord
  • com.aspose.words.net.System.Data.DataView
  • com.aspose.words.net.System.Data.DataRowView
  • Any other arbitrary Java type

For information on how to work with data sources of different types in template documents, see template syntax reference (https://docs.aspose.com/display/wordsjava/Template+Syntax).

Parameters:
document - A template document to be populated with data.
dataSources - An array of data source objects.
dataSourceNames - An array of names to reference the data source objects within the template.
Returns:
A flag indicating whether parsing of the template document was successful. The returned flag makes sense only if a value of the Options property includes the ReportBuildOptions.INLINE_ERROR_MESSAGES option.

Example:

Shows how to keep inserted numbering as is.
// By default, numbered lists from a template document are continued when their identifiers match those from a document being inserted.
// With "-sourceNumbering" numbering should be separated and kept as is.
Document template = DocumentHelper.createSimpleDocument("<<doc [src.getDocument()]>>" + System.lineSeparator() + "<<doc [src.getDocument()] -sourceNumbering>>");

DocumentTestClass doc = new DocumentTestBuilder()
        .withDocument(new Document(getMyDir() + "List item.docx")).build();

ReportingEngine engine = new ReportingEngine(); { engine.setOptions(ReportBuildOptions.REMOVE_EMPTY_PARAGRAPHS); }
engine.buildReport(template, new Object[] { doc }, new String[] { "src" });

template.save(getArtifactsDir() + "ReportingEngine.SourseListNumbering.docx");

Example:

Shows how to work with charts from word 2016.
Document doc = new Document(getMyDir() + "Reporting engine template - Word 2016 Charts (Java).docx");

ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, new Object[] { Common.getShares(), Common.getShareQuotes() },
        new String[] { "shares", "quotes" });

doc.save(getArtifactsDir() + "ReportingEngine.Word2016Charts.docx");

equals

public boolean equals(java.lang.Object obj)
Determines whether the specified object is equal in value to the current object.

getRestrictedTypes

public static java.lang.Class[] getRestrictedTypes()
Returns types, which members as well as which derived types' members should be inaccessible by the engine through template syntax.

The returned array contains items previously set using setRestrictedTypes(java.lang.Class[]).

Changing items of the returned array has no effect on restricted types. To change restricted types, use setRestrictedTypes(java.lang.Class[]) instead.

Returns:
Types, which members as well as which derived types' members should be inaccessible by the engine through template syntax.

setRestrictedTypes

public static void setRestrictedTypes(java.lang.Class[] types)
Specifies types, which members as well as which derived types' members should be inaccessible by the engine through template syntax.

Restricted types should be set before the very first building of a report. After buildReport is invoked, restricted types cannot be modified and an exception is thrown on attempt to do this. The best place to set restricted types is application startup.

Note that a big amount of restricted types may affect performance, so it is better to restrict only those types, access to which members is really sensitive.

Throws java.lang.IllegalArgumentException in the following cases:

- types is null.

- One of types items is null.

- One of types items represents an invisible type, i.e. a non-public type or a public nested type which has a non-public outer type.

- One of types items represents an array type.

- types contain duplicate entries.

Parameters:
types - Types to be restricted.

Example:

Shows how to deny access to members of types considered insecure.
Document doc =
        DocumentHelper.createSimpleDocument(
                "<<var [typeVar = \"\".getClass().getName()]>><<[typeVar]>>");

// Note, that you can't set restricted types during or after building a report.
ReportingEngine.setRestrictedTypes(Class.class);
// We set "AllowMissingMembers" option to avoid exceptions during building a report.
ReportingEngine engine = new ReportingEngine();
engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS);
engine.buildReport(doc, new Object());

// We get an empty string because we can't access the GetType() method.
Assert.assertEquals(doc.getText().trim(), "");

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.