Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fix examples for filters on dynamic variables from windows registry

...

  • name
    The name of the dynamic variable used to refer to it.
  • checkonce:= "true" | "false" (optional, defaults to "false")
    Mark the dynamic variable to be evaluated just once, either when the installation starts or as soon as an optional condition gets true. This makes it behave like a normal variable, although with enhanced capabilities to gather a value.
    Values gathered by a dynamic variable definition with checkonce="true" can be overridden, if there is another dynamic variable with the same key (and different conditions which evaluate to  true ) found later.
  • ignorefailure:= "true" | "false" (optional, defaults to "true")
    Might be used to allow the installation to continue or abort if an error occurred during gathering the value for a certain dynamic variable.
  • condition (optional)
    The assignment of a dynamic variable itself can be made dependent on a certain condition, using the condition attribute, which refers to the ID of condition defined in the installer description elsewhere.
  • unset:= "true" | "false" (optional, defaults to "true")
    By defaut, if none of the conditions of a dynamic variable of one and the same name isn't met, a dynamic variable is unset for cleanup purposes.
    Setting unset false prevents unsetting a variable if the complex condition above is not met and leaves the variable value unchanged for that definition.

 


Note

As dynamic variables almost completely integrate with static IzPack variables, which means they are mapped to a normal IzPack variable, they can be used as direct variables in user input fields. Take care to have stable evaluation conditions after the user entered a value or use checkonce="true" for this purpose to not override the user value after leaving the panel.

...

The condition "izpack.selected.mycoolfeature" is generated automatically when a pack with the ID "mycoolfeature" was specified. You could now use ${XML_Comment_Start} and ${XML_Comment_End} in a file which should be parsed${XML_Comment_Start} and ${XML_Comment_End} in a file which should be parsed.

For example, there might be an input file test.xml installed to ${INSTALL_PATH}:

Code Block
languagexml
<?xml version="1.0"?>
<test>
	<a></a>
	${XmlCommentStart}<b></b>${XmlCommentEnd}
</test>

parsed like this in install.xml:

Code Block
languagexml
<parsable targetfile="$INSTALL_PATH/test.xml" encoding="UTF-8"/>

If the pack mycoolfeature would be enabled during the installation, the file would look like this at the end:

Code Block
languagexml
<?xml version="1.0"?>
<test>
	<a></a>
	<b></b>
</test>

otherwise the <b></b> element would be commented out:

Code Block
languagexml
<?xml version="1.0"?>
<test>
	<a></a>
	<!--<b></b>-->
</test>


Info

In the <parsable> tag don't use the type="xml" for this example, because it would replace the characters '<' and '>' in your comment XML elements by '&lt;' and '&gt;' in the resulting output.

Values from Environment Variables

...

Code Block
langxml
titleAssigning a dynamic variable value from the Windows registry
<dynamicvariables>
    <variable name="RegistryReadTest" checkonce="true"
              regkey="HKLM\HKEY_LOCAL_MACHINE\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"
              regvalue="Path"/>
</dynamicvariables>

...

Code Block
languagehtml/xml
titleDynamic Variable Filter Element Definition
<dynamicvariables>
   <variable ... <!-- other nested arguments might go here -->
      <filters>
         <filter1 .../>
         <filter2 .../>
         ... <!-- more filters might go here -->
      </filters>
   </variable>
</dynamicvariable>

...


Regular Expression Filter

...

Code Block
langxml
titleFiltering dynamic variable assignments using regular expressions
<dynamicvariables>

	<!--
      Read the property value of release.version in the resource release.properties from the root of the config.jar file.
	  Filter just the version string from the result, if there is one, otherwise return 'none'.
      -->
    <variable name="previous.version" jarfile="${INSTALL_PATH}/${INSTALL_SUBPATH}/libs/config.jar"
              entry="release.properties" type="options"
              key="release.version"
              checkonce="false" ignorefailure="true" condition="upgradecheck">
      <filters>
        <regex regexp="([0-9]+(\.[0-9]+){2})" select="\1" defaultvalue="none"/>
      </filters>
    </variable>

	<!--
      Read the value of the Windows system environment variable %PATH% directly from the Windows registry (can done smarter by ${SYSTEM[PATH]}).
      Filter just the first single path (if there are more separated by the ';' character). If there was a valid value, otherwise return '(unmatched)'.
      -->
    <variable name="RegExTest.Select.Windows" checkonce="true"
              regkey="HKLMHKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"
              regvalue="Path">
      <filters>
        <regex regexp="([^;]*)(.*)"
               select="\1"
               defaultvalue="(unmatched)"
               casesensitive="false"/>
      </filters>
    </variable>

	<!--
      Read the value of the Windows system environment variable %PATH% directly from the Windows registry (can done smarter by ${SYSTEM[PATH]}).
      Filter just the first single path (if there are more separated by the ';' character).
	  Prepend and append three plus signs to the resulting value, if there was a valid value, otherwise return '(unmatched)'.
      -->
    <variable name="RegExTest.ReplaceFirst.Windows" checkonce="true"
              regkey="HKLMHKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"
              regvalue="Path">
      <filters>
        <regex regexp="([^;]*)"
               replace="+++ \1 +++"
               defaultvalue="(unmatched)"
               casesensitive="false"
               global="false"/>
      </filters>
    </variable>

</dynamicvariables>

Location Filter

After straight evaluation, each dynamic variable value can be filtered to be canonicalized like a filename. This is done by the nested location element. Operating system-specific path conventions are considered when assembling the result.

...