Code Templates Preferences

Code templates are code fragments that can be inserted at the current editing position. Oxygen XML Developer includes a set of built-in templates for CSS, LESS, Schematron, XSL, XQuery, and XML Schema document types. You can also define your own code templates and share them with your colleagues using the template export and import functions.

To configure Code Templates, open the Preferences dialog box (Options > Preferences) and go to Editor > Templates > Code Templates.

This preferences page contains a list of all the available code templates (both built-in and custom created ones) and a code preview area. You can disable any code template by deselecting it.

The following actions are available:

New
Opens the Code template dialog box that allows you to define a new code template. You can define the following fields:
  • Name - The name of the code template.
  • Description - The description of the code template that will appear in the Code Templates preferences page and in the tooltip message when selecting it from the Content Completion Assistant. HTML markup can be used for better rendering.
  • Associate with - You can choose to set the code template to be associated with a specific type of editor or for all editor types.
  • Shortcut key - Allows you to configure a shortcut key that can be used to insert the code template. The + character separates keys. If the Enable platform-independent shortcut keys checkbox is enabled, the shortcut is platform-independent and the following modifiers are used:
    • M1 represents the Command key on MacOS X, and the Ctrl key on other platforms.
    • M2 represents the Shift key.
    • M3 represents the Option key on MacOS X, and the Alt key on other platforms.
    • M4 represents the Ctrl key on MacOS X, and is undefined on other platforms.
  • Content - Text box where you define the content that is used when the code template is inserted.
Edit
Opens the Code template dialog box and allows you to edit an existing code template. You can edit the following fields:
  • Description - The description of the code template that will appear in the Code Templates preferences page and in the tooltip message when selecting it from the Content Completion Assistant. HTML markup can be used for better rendering.
  • Shortcut key - Allows you to configure a shortcut key that can be used to insert the code template. The + character separates keys. If the Enable platform-independent shortcut keys checkbox is enabled, the shortcut is platform-independent and the following modifiers are used:
    • M1 represents the Command key on MacOS X, and the Ctrl key on other platforms.
    • M2 represents the Shift key.
    • M3 represents the Option key on MacOS X, and the Alt key on other platforms.
    • M4 represents the Ctrl key on MacOS X, and is undefined on other platforms.
  • Content - Text box where you define the content that is used when the code template is inserted.
Duplicate
Creates a duplicate of the currently selected code template.
Delete
Deletes the currently selected code template. This action is disabled for the built-in code templates.
Export
Exports a file with code templates.
Import
Imports a file with code templates that was created by the Export action.
You can use the following editor variables when you define a code template in the Content text box:
  • ${caret} - The position where the cursor is located. This variable can be used in a code template, in Author mode operations, or in a selection plugin.
  • ${selection} - The current selected text content in the current edited document. This variable can be used in a code template, in Author mode operations, or in a selection plugin.
  • ${ask('message', type, ('real_value1':'rendered_value1'; 'real_value2':'rendered_value2'; ...), 'default_value')} - To prompt for values at runtime, use the ask('message', type, ('real_value1':'rendered_value1'; 'real_value2':'rendered_value2'; ...), 'default-value'') editor variable. You can set the following parameters:
    • 'message' - The displayed message. Note the quotes that enclose the message.
    • type - Optional parameter, with one of the following values:
      Parameter  
      url Format: ${ask('message', url, 'default_value')}
      Description: Input is considered a URL. Oxygen XML Developer checks that the provided URL is valid.
      Example:
      • ${ask('Input URL', url)} - The displayed dialog box has the name Input URL. The expected input type is URL.
      • ${ask('Input URL', url, 'http://www.example.com')} - The displayed dialog box has the name Input URL. The expected input type is URL. The input field displays the default value http://www.example.com.
      password Format: ${ask('message', password, 'default')}
      Description: The input is hidden with bullet characters.
      Example:
      • ${ask('Input password', password)} - The displayed dialog box has the name 'Input password' and the input is hidden with bullet symbols.
      • ${ask('Input password', password, 'abcd')} - The displayed dialog box has the name 'Input password' and the input hidden with bullet symbols. The input field already contains the default abcd value.
      generic Format: ${ask('message', generic, 'default')}
      Description: The input is considered to be generic text that requires no special handling.
      Example:
      • ${ask('Hello world!')} - The dialog box has a Hello world! message displayed.
      • ${ask('Hello world!', generic, 'Hello again!')} - The dialog box has a Hello world! message displayed and the value displayed in the input box is 'Hello again!'.
      relative_url Format: ${ask('message', relative_url, 'default')}
      Description: Input is considered a URL. Oxygen XML Developer tries to make the URL relative to that of the document you are editing.
      Note: If the $ask editor variable is expanded in content that is not yet saved (such as an untitled file, whose path cannot be determined), then Oxygen XML Developer will transform it into an absolute URL.

      Example:

      • ${ask('File location', relative_url, 'C:/example.txt')} - The dialog box has the name 'File location'. The URL inserted in the input box is made relative to the current edited document location.
      combobox Format: ${ask('message', combobox, ('real_value1':'rendered_value1';...;'real_valueN':'rendered_valueN'), 'default')}
      Description: Displays a dialog box that offers a drop-down menu. The drop-down menu is populated with the given rendered_value values. Choosing such a value will return its associated value (real_value).
      Note: The 'default' parameter specifies the default selected value and can match either a key or a value.
      Example:
      • ${ask('Operating System', combobox, ('win':'Microsoft Windows';'osx':'Mac OS X';'lnx':'Linux/UNIX'), 'osx')} - The dialog box has the name 'Operating System'. The drop-down menu displays the three given operating systems. The associated value will be returned based upon your selection.
        Note: In this example, the default value is indicated by the osx key. However, the same result could be obtained if the default value is indicated by Mac OS X, as in the following example: ${ask('Operating System', combobox, ('win':'Microsoft Windows';'osx':'Mac OS X';'lnx':'Linux/UNIX'), 'Mac OS X')}
      • ${ask('Mobile OS', combobox, ('win':'Windows Mobile';'ios':'iOS';'and':'Android'), 'Android')}
      editable_combobox Format: ${ask('message', editable_combobox, ('real_value1':'rendered_value1';...;'real_valueN':'rendered_valueN'), 'default')}
      Description: Displays a dialog box that offers a drop-down menu with editable elements. The drop-down menu is populated with the given rendered_value values. Choosing such a value will return its associated real value (real_value) or the value inserted when you edit a list entry.
      Note: The 'default' parameter specifies the default selected value and can match either a key or a value.
      Example:
      • ${ask('Operating System', editable_combobox, ('win':'Microsoft Windows';'osx':'Mac OS X';'lnx':'Linux/UNIX'), 'osx')} - The dialog box has the name 'Operating System'. The drop-down menu displays the three given operating systems and also allows you to edit the entry. The associated value will be returned based upon your selection or the text you input.
      radio Format: ${ask('message', radio, ('real_value1':'rendered_value1';...;'real_valueN':'rendered_valueN'), 'default')}
      Description: Displays a dialog box that offers a series of radio buttons. Each radio button displays a 'rendered_value and will return an associated real_value.
      Note: The 'default' parameter specifies the default selected value and can match either a key or a value.
      Example:
      • ${ask('Operating System', radio, ('win':'Microsoft Windows';'osx':'Mac OS X';'lnx':'Linux/UNIX'), 'osx')} - The dialog box has the name 'Operating System'. The radio button group allows you to choose between the three operating systems.
        Note: In this example Mac OS X is the default selected value and if selected it would return osx for the output.
    • 'default-value' - optional parameter. Provides a default value.
  • ${timeStamp} - Time stamp, that is the current time in Unix format. For example, it can be used to save transformation results in multiple output files on each transformation.
  • ${uuid} - Universally unique identifier, a unique sequence of 32 hexadecimal digits generated by the Java UUID class.
  • ${id} - Application-level unique identifier. It is a short sequence of 10-12 letters and digits that is not guaranteed to be universally unique.
  • ${cfn} - Current file name without extension and without parent folder. The current file is the one currently opened and selected.
  • ${cfne} - Current file name with extension. The current file is the one currently opened and selected.
  • ${cf} - Current file as file path, that is the absolute file path of the current edited document.
  • ${cfd} - Current file folder as file path, that is the path of the current edited document up to the name of the parent folder.
  • ${frameworksDir} - The path (as file path) of the [OXYGEN_INSTALL_DIR]/frameworksdirectory.
  • ${pd} - Current project folder as file path. Usually the current folder selected in the Project View.
  • ${oxygenInstallDir} - Oxygen XML Developer installation folder as file path.
  • ${homeDir} - The path (as file path) of the user home folder.
  • ${pn} - Current project name.
  • ${env(VAR_NAME)} - Value of the VAR_NAME environment variable. The environment variables are managed by the operating system. If you are looking for Java System Properties, use the ${system(var.name)} editor variable.
  • ${system(var.name)} - Value of the var.name Java System Property. The Java system properties can be specified in the command line arguments of the Java runtime as -Dvar.name=var.value. If you are looking for operating system environment variables, use the ${env(VAR_NAME)} editor variable instead.
  • ${date(pattern)} - Current date. The allowed patterns are equivalent to the ones in the Java SimpleDateFormat class. Example: yyyy-MM-dd;
    Note: This editor variable supports both the xs:date and xs:datetime parameters. For details about xs:date, go to http://www.w3.org/TR/xmlschema-2/#date. For details about xs:datetime, go to http://www.w3.org/TR/xmlschema-2/#dateTime.