Skip to content

Configuration

carlosame edited this page Sep 2, 2022 · 1 revision

The configuration file

An XML configuration file is at the center of Carte. If you look into the Carte sources, many classes are initialised with a:

void init(DOMElement configRoot) throws ReportException;

where the configRoot is the root configuration element (reportdef), although it may not necessarily be the document root.

There are configuration example files in the examples directory of carte-jmh, like sac-benchmark.xml.


The root element: reportdef

The configuration root is a <reportdef> element in the http://carte.sourceforge.io/report namespace, with its id attribute being the ID of the report. The <name> child element gives the report name, and then there are other important elements.


The reportset

The <reportset> element tells which reports you are going to produce.

For example:

<reportset basedir="templates">
    <report>
        <renderer>io.sf.carte.chart.SVGBarChartRenderer</renderer>
        <template>barchart.svg</template>
        <store-id>fileStore</store-id>
        <store-id>documentStore</store-id>
    </report>
    <report>
        <renderer>io.sf.carte.chart.external.XChartRenderer</renderer>
    </report>
</reportset>

tells Carte that there will be two report renderers. First, SVGBarChartRenderer will be used together with the fileStore and documentStore stores. Then, XChartRenderer will be used.

Now let's talk about the stores.


storage and store

The <storage> element has one or more <store> child elements that define how the charts will be used.

You generally use DocumentStore (which internally uses HTMLTableStore if the document contains <table> elements with the carteitem class) and FileStore.


DocumentStore

The DocumentStore is just an HTML file where certain elements have the carteitem class.

In the XML configuration, the document specified by the <pathname> element (in the next example, doc_store.html) is the store, and the fallback images will be in the PNG format, stored at the my_fallback_dir directory which will be visible over HTTP with the uri imagefallback as given by the baseuri attribute (typically, baseuri will coincide with the last part of the <fallback> element contents).

    <storage>
        <store id="documentStore" classname="io.sf.carte.report.DocumentStore">
            <pathname>${user.home}/path/to/doc_store.html</pathname>
            <fallback baseuri="imagefallback" format="png">
               ${user.home}/path/to/my_fallback_dir
            </fallback>
        </store>
    </storage>

It also uses a HTMLTableStore to look for HTML tables in the document.


HTMLTableStore

Stores data into an HTML table.

In the XML configuration file, you can use an optional <css-classes> element where you tell which class attribute the numbers and units will have (by default, number for numbers and no class for units).

 <css-classes>
     <number>numberclass</number>
     <unit>unitclass</unit>
 </css-classes>

Then, it will retrieve all the HTML tables with a carteitem class and fill in the report data accordingly.


FileStore

Stores charts in a directory.

In the following example, the store will be the $TMP/chart_dir directory:

    <storage>
        <store id="fileStore" classname="io.sf.carte.report.FileStore">
            <directory>${java.io.tmpdir}/chart_dir</directory>
        </store>
    </storage>

Other configurations

Your Carte-based application must define other configuration elements so you can specify how to obtain your data and configure the ChartRenderer instances. You are encouraged to read the JMH page as an example of a real application.