-
Notifications
You must be signed in to change notification settings - Fork 18
FreeMarkerAction
Can be used to filter a http://freemarker.sourceforge.net/docs/pgui_quickstart_createdatamodel.html freemarker template file. It get a list of http://freemarker.sourceforge.net/docs/dgui_quickstart_datamodel.html TemplateModel from the queue and a map of substitutions from the configuration; Using the obtained data model this action parse the template file and generate the output file.
It is an object which handle a TemplateModel data structure with a name (String).
The <filter> node of this xml file represents a simple FreeMarkerAction configuration serialized using Xstream.
- <?xml version="1.0" encoding="UTF-8"?>
-
<FlowConfiguration>
<id>FreeMarkerFlow</id> <description>FreeMarkerFlow</description> <name>FreeMarkerFlow</name>
<workingDirectory>freemarker/</workingDirectory> <autorun>true</autorun>
- <EventGeneratorConfiguration>
-
<wildCard>*.*</wildCard> <watchDirectory>freemarker/in</watchDirectory> <osType>OS_UNDEFINED</osType> <eventType>FILE_ADDED</eventType> <id>FreeMarkerFlow</id>
<serviceID>fsEventGeneratorService</serviceID>
<description>description</description> <name>test</name>
</EventGeneratorConfiguration>
- <EventConsumerConfiguration>
-
<id>FreeMarker</id> <description>FreeMarker</description> <name>FreeMarker</name>
<workingDirectory>freemarker/</workingDirectory> <performBackup>false</performBackup>
- <FileEventRule>
- <optional>false</optional> <originalOccurrencies>1</originalOccurrencies> <regex>.*.*</regex> <id>r1</id> <description>description</description> <name>test</name>
</FileEventRule>
- <filter>
-
<serviceID>FreeMarkerGeneratorService</serviceID> <id>FreeMarkerGeneratorService</id> <description>description</description> <name>FreeMarkerConfiguration</name>
<dirty>false</dirty> <listenerConfigurations/> <failIgnored>false</failIgnored>
<workingDirectory>freemarker/</workingDirectory> <input>test.xml</input> <output>test_out.xml</output> <root>
- <entry>
- <string>KEY</string> <string>value</string>
</entry>
</root>
</filter>
</EventConsumerConfiguration>
</FlowConfiguration>
.. toctree:: :maxdepth: 2
For each TemplateModelEvent object on the Queue (accept more than one event) FreeMarkerAction add a new key named with the name of the accepted object and append to the base configuration hash map that structure.
Look at http://freemarker.sourceforge.net/docs/pgui_quickstart_createdatamodel.html here for a quick example.
This is a template example which build an OctaveSheet serialized object:
- <?xml version="1.0" encoding="UTF-8"?>
-
<!-- OCTAVE ENV --> <octave> <sheets>
<!-- OCTAVE SHEET --> <sheet name="${SHEET_NAME}"> <commands>
- <OctaveCommand executed="false">
- <command>source "${event_1.SOURCE_PATH}";</command>
</OctaveCommand> <OctaveCommand executed="false">
<command>cd "${event_1.WORKING_DIR}";</command>
</OctaveCommand> <OctaveCommand executed="false">
<command>mars3d("${event_2.FILE_IN}","${event_2.FILE_OUT}");</command>
</OctaveCommand>
</commands> <definitions/> <returns/> </sheet>
</sheets> </octave>
.. toctree:: :maxdepth: 2
And this is the example code to build correctly the data model:
public static void main(String[] args) throws ActionException {
FreeMarkerConfiguration fmc=new FreeMarkerConfiguration();// SIMULATE THE XML FILE CONFIGURATION OF THE ACTION // fmc.setDescription("description"); // fmc.setDirty(false); // fmc.setFailIgnored(false); // fmc.setId("id"); // fmc.setName("name"); // fmc.setServiceID("serviceID");
fmc.setWorkingDirectory("/home/user/work/data/freemarker/"); fmc.setInput("test.xml"); fmc.setOutput("test_out.xml");
Map<String,Object> m=new HashMap<String, Object>(); m.put("SHEET_NAME", "MY_NEW_SHEET_NAME"); fmc.setRoot(m);
//SIMULATE THE EventObject on the queue Queue<EventObject> q=new ArrayBlockingQueue(2);
Map<String,Object> mev1=new HashMap<String, Object>(); mev1.put("SOURCE_PATH", "/path/to/source"); mev1.put("WORKING_DIR", "/absolute/working/dir"); q.add(new TemplateModelEvent(mev1,"event_1"));
Map<String,Object> mev2=new HashMap<String, Object>(); mev2.put("FILE_IN", "in_test_file.dat"); mev2.put("FILE_OUT", "out_test_file.dat"); q.add(new TemplateModelEvent(mev2,"event_2"));
FreeMarkerAction fma=new FreeMarkerAction(fmc);
fma.execute(q); return;
}
}
.. toctree:: :maxdepth: 2
After this test execution you'll get a file called '''/home/user/work/data/freemarker/test_out.xml''' as following:
- <?xml version="1.0" encoding="UTF-8"?>
-
<!-- OCTAVE ENV --> <octave> <sheets>
<!-- OCTAVE SHEET --> <sheet name="MY_NEW_SHEET_NAME"> <commands>
<OctaveCommand executed="false"> <command>source "/path/to/source";</command> </OctaveCommand>
- <OctaveCommand executed="false">
- <command>cd "/absolute/working/dir";</command>
</OctaveCommand> <OctaveCommand executed="false">
<command>mars3d("in_test_file.dat","out_test_file.dat");</command>
</OctaveCommand>
</commands> <definitions/> <returns/> </sheet>
</sheets> </octave>
.. toctree:: :maxdepth: 2