80 likes | 206 Views
Velocity Templates. Site Support Team Office of Operational Services May,23 2008. NOAA’s National Weather Service. NOAA’s National Weather Service. What is Velocity?. Velocity is a Java-based template engine.
E N D
Velocity Templates Site Support Team Office of Operational Services May,23 2008 NOAA’s National Weather Service NOAA’s National Weather Service
What is Velocity? • Velocity is a Java-based template engine. • Templates contain Text, Variables (references) and Velocity Template Language (VTL). • Text is output unchanged. • Variables can be Java Objects. • VTL is a scripting language.
WarnGen GUI • The Warngen GUI is driven by: • config.xml • java code • <template>.cfg files. • The <template>.cfg files control many parameters about warnings <template>.cfg Values in GUI
WarnGen Templates • The Warngen Templates are the <template>.vm files • The <template>.vm files are processed when “CREATE TEXT” button is pressed. • The Velocity Engine inserts the variables and processes the logic in the templates. • The result is a text warning product.
Simple Template • THIS IS A TEST • #set( $office = "MANHATTAN, KANSAS" ) • THE NATIONAL WEATHER SERVICE IN $office HAS DONE NOTHING. The VLT command sets the variable $office which is then replaced into subsequent instances of the variable The output : THIS IS A TEST THE NATIONAL WEATHER SERVICE IN MANHATTAN, KANSAS HAS DONE NOTHING.
Tricky Template • ${officeLong} HAS ISSUED A • * ${testMessage}TORNADO WARNING FOR... • #foreach (${area} in ${areas}) • ## • #if(${area.partOfArea}) • #areaFormat(${area.partOfArea} 0) ## • #end $officeLong is a variable from a config.xml file $testMessage comes from the GUI settings $Areas is an array of JAVA area objects from the code #areaFormat is a VTL Macro ( in VM_global_library) ${area.partOfArea} is a method in the JAVA area object
Warngen loaded with Values from Config.xml Launch Warngen <template>.cfg Read <te,mplate>.cfg file Default Parameters Set from <template>.cfg file Set Warning Polygon and storm track GeoSpatiial Data Generated From Polygon Drawn on screen Java Objects, VTL Code and Text processed by velocity engine Select Create Text Button <template>.vm Edit Window Launched with product Prodcut Loads into Text Editor
References • Velocity Template User Guide • Velocity Reference Guide • Velocity VTL Reference • Velocity Examples Document • http://www.nws.noaa.gov/ost/SEC/AE/Site_Migration.htm