Scripts 

Scripts written in the Boo or Python languages can be invoked within Curiosity. Scripts can be used in order to further manipulate acquired data before archiving or "providing" it, or in order to write new Providers.

You have two options for defining a set of scripts.

A more "verbose" format:

<scripts>
    <script>
        <file>script1.boo</file>
        <paramList>
            <param>
                <name>p1</name>
                <value>v1</value>
            </param>
            <param>
                ...
            </param>
        </paramList>
    </script>
    <script>
        ...
    </script>
</scripts>

And a more concise format, where parameters are expressed in a url-like way (you can use the utils\urlEncode.boo script in order to find out the url-encoding of a parameter name or value):

<scripts> script1.boo?p1 =v1&amp;p2=v2 script2.boo</scripts>

When a script is invoked, a number of global variables are set from within Curiosity. Three variables are always set:

  • action: of type com.goCuriosity.providers.scripting.Script.ScriptActions (defined in CuriosityIProvider.dll) holds the action type that is requested to the script (it depends on where the script has been declared - see later);
  • log: of type com.goCuriosity.utils.logging.Logger (defined in CuriosityUtils.dll), can be used in order to write log messages to the standard Curiosity log (e.g. log.Debug("Hello world"));
  • paramList: of type System.Collections.Generic.Dictionary<String, Object>, which holds the user defined parameters for the script.

Manipulating acquired data

As a first option, scripts can be invoked in order to manipulate acquired data before the data is checked against the history (ScriptActions.POST_BROKERING).

<webSource name="sourceName" urlSource="http://...">
    <scripts>aScript.boo?p1=v1&amp;p2=v2</scripts>
    ...
</webSource>

In this case two global variables are set:

  • data: of type System.Xml.XmlElement, which holds the acquired data;
  • source: of type com.goCuriosity.InfoSourceSchema (defined in CuriosityCore.dll), which holds the information related to the "calling" Source (e.g. source.schemaName gives the name of the Source).
Modifications applied to the data node and its children will be kept in the Source archive and transmitted to all its Providers.

As a second option, you can manipulate acquired data but on a "per-Provider" basis - that is, the modifications will be applied after the data has been checked against the Source history, and before it is passed to a specific Provider (ScriptActions.PRE_PROVIDING).

<provider>
    <class>com.curiosity.providers.AProvider</class>
    <scripts>aScript.boo?p1=v1&amp;p2=v2</scripts>
    ...
</provider>

Please, note that if you are defining a Provider Template you must employ the concise format in order to define its scripts.

In this case, besides the data and source variables previously described, another variable is set:

  • provider: of type com.goCuriosity.providers.IProvider (defined in CuriosityIProvider.dll), which holds information about the Provider that will be subsequently called (e.g. provider.providerName).

Implement a Provider

You can also use scripts in order to implement a new Provider (ScriptActions.PROVIDE).

<provider>
    <class>com.curiosity.providers. InfoProviderScript</class>
    <scripts>aScript.boo?p1=v1&amp;p2=v2</scripts>
    ...
</provider>

In this case the scripts attached to the provider definition won't be used in order to manipulate the acquired data as previously explained, but are meant to execute themselves some providing action.

Please, note that in this case you can defined just one script within the scripts tag (remaining scripts will be ignored).

In this case, besised the data and source variables, the following ones are set:

  • xls: of type String, which holds the related xsl file path;
  • recoveryPoints: of type System.Collections.Generic.List<RecoveryPoint>, which holds the RecoveryPoints to be filled if the providing action cannot be completed - see Implement Providers for more details about the recovery facility.

Moreover, it is expected that the script will set the stream global variable of type System.IO.Stream - as also explained in the Implement Providers section.

If the provider is invoked in order to recover from a RecoveryPoint (ScriptActions.RECOVER), besides the previously defined recoveryPoints variable, the following one is set:

  • recoveryPoint: of type com.goCuriosity.providers.recovery.RecoveryPoint (defined in CuriosityIProvider.dll), which holds the information about the data to be recovered by this Provider.

next