- Notifications
You must be signed in to change notification settings - Fork 33
Metamorph Integration of Java and JavaScript
In case the predefined functions for data processing be not suffiecient, two choices to extend Metamorph scripts with customized code are at disposal: The first is to write a Java class. The second is to load a JavaScript file.
You may use Java classes as function using the <java> tag:
<data source="data"> <java class="org.culturegraph.mf.morph.functions.Compose" prefix="Hula " /> </data>The class must implement the Function interface. For each attribute provided in the <java> tag, a respective set method is called right after instantiation. This mechanism correctly handles the types String, boolean and int. A separate class is instantiated for each use in Metamorph definition. A Function may thus maintain a state. See the JavaDoc and code for more details.
To invoke a JavaScript function use the <script> tag as shown in the following listing:
<data source="X"> <script file="script.js" invoke="emphasize" /> </data>The <script> takes as arguments the path to a JavaScript file and the name of the function to be invoked using the data as sole argument. The return value may be any object as Metamorph will call toString() on it before proceeding. The following snipped shows the file script.js:
function emphasize(val){ return "<em>" + val + "</em>"; }Find the user documentation for Metafacture here:
https://metafacture.org/metafacture-documentation/
- Code Quality and Style
- How to debug
- Things that are different between Catmandu and Metafacture
- Plugin and Tools
- Who uses Metafacture