## This template is made up of usable macros for PDS4 Velocity Templates. ## This file must be placed in the same directory as the Velocity Templates ## to be used, otherwise the VelocityEngine will not be able to find it. ## ## To include this file in your template and use the macros, add the following ## at the top of your Velocity template: ## ## #parse ( "extra_velocity_macros.txt" ) ## ## this test code. eventually it should become a part of pds_velocity_macros.txt ###set ( $DEBUG = 1 ) ################################## ## identification macro ## ## VICAR labels and PDS3 labels built from a ## vicar file have the same set of early keywords ## VICAR keywords add IDENTIFICATION. in front of the keyword ## PDS keywords do not ## This macro is intended to allow the same velocity template to use ## a vicar or PDS3 version of the same file ## PROPERTY or GROUP things look the same ## ## could check the $generate.reader_format == "vicar" or "pds" ### ## $generate_file_name is the input filename ## #macro(identification $var) ## try prepending "IDENTIFICATION." #set ($val = "") #set ($id = "IDENTIFICATION.") #set ($v = $id.concat($var)) ## #set ($val = $label.get($v)) #if ($val) $val## #else ## use the input value as-is #set ($val = $label.get($var)) ## #if ($val) $val## #else error## #end #end #end ################################## ################################## ## identification_asList macro ## ## VICAR labels and PDS3 labels built from a ## vicar file have the same set of early keywords ## VICAR keywords add IDENTIFICATION. in front of the keyword ## PDS keywords do not ## This macro is intended to allow the same velocity template to use ## a vicar or PDS3 version of the same file ## PROPERTY or GROUP things look the same ## ## could check the $generate.reader_format == "vicar" or "pds" ### ## $generate_file_name is the input filename ## #macro(identification_asList $var) ## try prepending "IDENTIFICATION." #set ($val = "") #set ($id = "IDENTIFICATION.") #set ($v = $id.concat($var)) ## #set ($val = $label.getList($v)) #set ($val_size = $val.size() )## #if ($val_size > 0) $val## #else ## use the input value as-is #set ($val = $label.getList($var)) #set ($val_size = $val.size() )## #if ($val_size > 0) $val## #else error## #end #end #end ################################## ################################## ## asArray macro ## ## return a single value as an array ## some values may be either a single vaue or an array of values ## array values are In () parens, values seperated by commas ## make a single value look like an array so it can be looped over ## #macro(asArray $var) ## check if this value starts, ends with parens #if ($var.startsWith("(") && $var.endsWith(")")) $var## #else ## add parens to it #set ($p1 = "(") #set ($pvar = ($p1.concat($var).concat(")") )) $pvar## #end #end ################################## ################################## ## isArray macro ## ## return a single value as an array ## some values may be either a single vaue or an array of values ## array values are In () parens, values separated by commas ## make a single value look like an array so it can be looped over ## how do I return true or false? 1 == true, 0 == false ## #macro(isArray $var) #if (! $default) #set ($default = "FALSE") #end ## check if this value starts, ends with parens #if ($var.startsWith("(") && $var.endsWith(")")) TRUE## #else $default## #end #end ##################################