Adding an HDS to a Catalog
There are two ways to add an HDS to a catalog:
- Adding a general HDS
- Create a catalog or open a catalog.
- In the Catalog Manager, right-click the node of a data source and choose New General Hierarchical Data Source from the shortcut menu.
If you want to add the HDS to a new data source in the catalog, select any of the existing catalog data source, select New Data Source on the Catalog Manager toolbar, then in the New Data source dialog, specify the name of the data source, select the Hierarchicalconnection type and select OK.
- In the New General Hierarchical Data Source dialog, select the Browse button to specify the HDS class name, and type a number in the Parameter box.
- Select Load Tree. The data source tree will then be parsed. Modify the column properties in the Columns box as required.
- Select OK to add the HDS.
- Importing an HDS from an XML file
- Create a catalog or open a catalog.
- In the Catalog Manager, right-click the node of a data source and choose New XML Hierarchical Data Source from the shortcut menu.
If you want to add the HDS to a new data source in the catalog, select any of the existing catalog data source, select New Data Source on the Catalog Manager toolbar, then in the New Data source dialog, specify the name of the data source, select the XMLconnection type, check the Hierarchical Data Source radio button and select OK.
- In the New XML Hierarchical Data Source dialog, select the Browse buttons to specify the XML URI and XSD URI as required.
- Select the Load Tree button to load the structure of the XML file. The root of the file will then be listed in the Root Name text box. Modify the column properties in the Columns box as required.
- Select OK to import the HDS into the catalog.
The following examples explain the above two methods in detail.
Example 1: Adding a general HDS
There are three classes used in this example. Their source code files are HierarchicalDataSource.java, HierarchicalDatasetMetaData.java, and HierarchicalDataset.java, which are available in <install_root>\help\samples\APIUDS\hierarchicalUDS
. In this example, the HierarchicalDataSource.java will return the result set from the demo HSQL DB.
- Copy the above three files to
<install_root>\help
. Modify the demo HSQL DB path in both HierarchicalDatasetMetaData.java and HierarchicalDataset.java. - Compile the Java files to generate HierarchicalDataSource.class, HierarchicalDatasetMetaData.class, and HierarchicalDataset.class.
- Append the path
<install_root>\help
into the ADDCLASSPATH variable of the batch file setenv.bat in<install_root>\bin
, so that at runtime HierarchicalDataSource can be found. - Start Logi JReport Designer with the batch file you just modified and open an existing catalog.
- In the Catalog Manager, right-click the data source to which to add the HDS, then select New General Hierarchical Data Source from the shortcut menu. The New General Hierarchical Data Source dialog appears.
- Select the Browse button to find the class HierarchicalDataSource.class.
- Type a number in the Parameter box. Then, only the records whose employee ID is less than this number will be fetched.
- Select Load Tree. The data source tree will then be parsed.
- Modify the column properties in the Columns box as required.
- Select OK to add the HDS.
Example 2: Importing an HDS from an XML file to a catalog
To import an HDS from an XML file, follow the steps below:
- Start Logi JReport Designer and open the catalog file SampleReports.cat in
<install_root>\Demo\Reports\SampleReports
. - In the Catalog Manager, right-click the data source to which to add the HDS, and then select New XML Hierarchical Data Source from the shortcut menu. The New XML Hierarchical Data Source dialog appears.
- Provide the information respectively according to your data source information.
Logi JReport Designer supports all kinds of URI as the XML data source.
- If you want to specify a schema file for the XML data source file, you must first make sure that the schema file path specified in the XML data source file is consistent with the path you specified in the XSD URI field, and that this file actually exists. Select the Load Tree button to load the structure of the XML file. The root of the file will then be listed in the Root Name field. Modify the column properties in the Columns box as required.
- Logi JReport Designer supports static string inline with multiple parameters, for example:
"http://localhost:8888/jrserver%2fSampleReports%2fSampleReports.cat/StockMarket.cls?jrs.cmd=jrs.try_vw&jrs.result_type=7&jrs.param$p_Year=2007&jrs.param$p_Month=2"
It is the URL used to run the sample report StockMarket.cls to the XML format in Logi JReport Server. Type the URL into the XML URI text field, and select the Load Tree button, the structure of the returned XML stream will be loaded in the Structure box (before doing so, make sure that Logi JReport Server is started). Modify the column properties in the Columns box as required.
The colon ':' and '@' symbols are used to identify Logi JReport parameter names. If these symbols are used in your XML URI and you do not want Logi JReport to parse them as parameters, you must add quotation marks to them. For example, when you browse to
d:\test\employee.xml
, you can quote it either as"d:\test\employee.xml"
ord":"\test\employee.xml
.Note that you should check the No Security Checking option on the Logi JReport Server Administration > Configuration > Advanced page before parsing this URL. In addition, Logi JReport parameters can be dynamically referenced in the URI for setting different values at runtime.
When importing the XML file, you have to define the types of some data in the Format column. For example, if it is Date type, such as 1978-03-12, in the corresponding Format column, type in yyyy-MM-dd. If the data is $12,345.32, in the corresponding Format column, type in $##,###.##. By default, the value of the Scale column is 0, therefore, for decimal type data, you will have to specify the scale value in its corresponding Scale column, that is, modify this value to the number of digits that you want to appear to the right of the decimal point, for example, if the data is 123.23, then in the Scale column, modify this value to 2. For the Currency and Array columns, check them if required.
- Select OK to import the HDS.
The XSD file
When you import an XML format HDS with an XSD file, the XML file only provides the data to the Logi JReport Designer reports, while the structure, data type, and so on of the data from the XML file is defined in the XSD file. That is, the structure of the HDS is determined by the XSD file. You should be aware of the following points about the XSD file in order to generate a correct report based on an XML format HDS with an XSD file.
Data type conversion table
Before the data type defined in the XSD file can function with Logi JReport Designer, it should first be converted into a corresponding data type when the XML format hierarchical data source is imported, following the rules in the conversion table below.
XML Data Type | Logi JReport Data Type |
---|---|
SchemaSymbols.ATTVAL_BOOLEAN | java.sql.Types.BIT |
SchemaSymbols.ATTVAL_INT | java.sql.Types.INTEGER |
SchemaSymbols.ATTVAL_SHORT | java.sql.Types.SMALLINT |
SchemaSymbols.ATTVAL_BYTE | java.sql.Types.TINYINT |
SchemaSymbols.ATTVAL_INTEGER | java.sql.Types.INTEGER |
SchemaSymbols.ATTVAL_NONPOSITIVEINTEGER | java.sql.Types.INTEGER |
SchemaSymbols.ATTVAL_NEGATIVEINTEGER | java.sql.Types.INTEGER |
SchemaSymbols.ATTVAL_NONNEGATIVEINTEGER | java.sql.Types.INTEGER |
SchemaSymbols.ATTVAL_UNSIGNEDLONG | java.sql.Types.BIGINT |
SchemaSymbols.ATTVAL_LONG | java.sql.Types.BIGINT |
SchemaSymbols.ATTVAL_UNSIGNEDINT, //4294967295 | java.sql.Types.BIGINT |
SchemaSymbols.ATTVAL_UNSIGNEDSHORT, //65535 | java.sql.Types.INTEGER |
SchemaSymbols.ATTVAL_UNSIGNEDBYTE, //255 | java.sql.Types.SMALLINT |
SchemaSymbols.ATTVAL_POSITIVEINTEGER | java.sql.Types.INTEGER |
SchemaSymbols.ATTVAL_FLOAT | java.sql.Types.FLOAT |
SchemaSymbols.ATTVAL_DOUBLE | java.sql.Types.DOUBLE |
SchemaSymbols.ATTVAL_DECIMAL | java.sql.Types.DECIMAL |
SchemaSymbols.ATTVAL_STRING | java.sql.Types.VARCHAR |
SchemaSymbols.ATTVAL_DATE | java.sql.Types.DATE |
SchemaSymbols.ATTVAL_TIME | java.sql.Types.TIME |
SchemaSymbols.ATTVAL_DATETIME | java.sql.Types.TIMESTAMP |
SchemaSymbols.ATTVAL_HEXBINARY | java.sql.Types.LONGVARBINARY |
Note:
XSD structure supported by Logi JReport Designer
In Logi JReport Designer, not all XSD structures can be supported. The following diagrams show which structures are supported by Logi JReport Designer.
- The ComplexType
The Element type in the diagram can be of simpleType, ref, or complexType (it is different from the ComplexType in the root of this diagram. It can be global complexType but cannot be the anonymous one. If you have defined a complexType named A, and in this complexType A redefined an element as complexType named B, then the elements belong to complexType B must be of the simpleType).
The Attribute type in the diagram should be of the anonymous type or of the schema built-in type, such as xs:string.
- The SimpleType
SimpleType here should be of the schema built-in type, such as xs:string. List type here cannot support some functions, such as minLength, and maxLength.
- The Element
ComplexType here can include both global and anonymous complexType. The anonymous type means you do not give a name to the type, for example:
<xs:element name="aa"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="Julie P. Adams"/> </xs:restriction> </xs:simpleType> </xs:element>
From the code above, you can see that the simpleType in the element aa has no name specified.
Notes:
- An XML data source file without any schema file is also allowed. That is, you can leave the XSD URI entry empty. However, the data type VARCHAR will be used for all the columns in the data source.
- When you import data of List type from an XSD file, you can define the delimiter through the property List Delimiter in the Report Inspector.
- Logi JReport Designer also supports dynamic XML URI. The XSD file defines the structure of the XML format HDS and the XML file in fact only provides the data, so one XSD file can match more than one XML file. That enables you to develop reports with dynamic XML URI. For details, see Example 1: Developing a report from an HDS with dynamic XML URI.
- When specifying a schema file for the XML data source file, due to the schema file being complex, there are some limitations:
- Namespace: Now, default namespace (3w) and target namespace are supported by Logi JReport Designer. You can define a prefix for the default namespace, such as xs, or xsd, but the value of elementFormDefault must be qualified. The value of attributeFormDefault should be unqualified, but Logi JReport Designer will not allow you to add prefixes before the attributes of the elements.
- Type: If a customized complexType or simpleType is used, do not add the prefix to the value of the type, while if the built-in simpleType or complexType is used, the prefix must be added.