JavaScriptRetriever

From GreenVulcano Wiki
Jump to: navigation, search

Description

The JavaScriptRetriever element allows you to define a helper to use into the XSL transformations.

We define the functions that run JavaScript code and return the last assignment/function result.

The script to be executed can contain metadata resolved at runtime.

GreenVulcano® ESB configuration

JavaScriptRetriever element is used by RetrieverConfig.

The following table shows its attributes:

Attribute Type Description
type fixed retriever (unmodifiable)
class fixed it.greenvulcano.gvesb.datahandling.utils.JavaScriptRetriever

Might contain the sub-elements:


An example

Define the following JavaScriptRetriever:

    <JavaScriptRetriever class="it.greenvulcano.gvesb.datahandling.utils.JavaScriptRetriever" type="retriever">
        <DataRetriever method="getElementMapping" signature="ELEMENT">
            var mapping = {"Cognome":"1", "Nome":"2", "Indirizzo":"3", "Cap":"4", "Citta":"5", "Provincia":"6", "Nazione":"7",
                        "Telefono":"8", "EMail":"9"};
            var res = mapping["@{{ELEMENT}}"];
            if (res === undefined) {
                res =  "-1";
            } else {
                res;
            }
        </DataRetriever>
        <DataRetriever method="mustBeUpperCase" signature="ELEMENT">
            var mapping = {"Cognome":"true", "Nome":"true", "Indirizzo":"true", "Citta":"true", "Provincia":"true"};
            var res = mapping["@{{ELEMENT}}"];
            if (res === undefined) {
                res =  "false";
            } else {
                res;
            }
        </DataRetriever>
    </JavaScriptRetriever>

to be applied to the transformation:

    <xsl:variable name="element"   select="local-name(.)"/>
    <xsl:variable name="mapping"   select="java:it.greenvulcano.gvesb.datahandling.utils.JavaScriptRetriever.getData('getElementMapping', $element)"/>
    <xsl:variable name="uppercase" select="java:it.greenvulcano.gvesb.datahandling.utils.JavaScriptRetriever.getData('mustBeUpperCase', $element)"/>