6. Making File|Print dependant on the type of the document to be printed
Prev | Chapter 2. Tutorial | Next

## 6. Making File|Print dependant on the type of the document to be printed

tutorial/tutorial6.xxe_gui:

      <action name="printAction" label="_Print..."
              icon="xxe-gui:app/icons/printAction.gif"
              accelerator="mod P">
        <context editingContextSensitive="false">
          <configuration name="XHTML">
            <command name="xhtml.convertToPS" parameter='pdf |pdf' />
          </configuration>

          <configuration name="DocBook">
            <command name="docb.convertToPS"
                     parameter='pdf |pdf "/book toc /article toc" 1' />
          </configuration>

          <configuration name="Simplified DocBook">
            <command name="docb.convertToPS"
                     parameter='pdf |pdf "/book toc /article toc" 1' />
          </configuration>

          <configuration name="Slides">
            <command name="slides.convertToPS" parameter='pdf |pdf' />
          </configuration>

          <default>
            <class>com.xmlmind.xmleditapp.kit.part.PrintAction</class>
          </default>
        </context>
      </action>

URLs starting with "`xxe-gui:`" work because XXE dynamically adds to its XML catalog a rule similar to this one:

    <rewriteURI uriStartString="xxe-gui:"
                rewritePrefix="jar:file:/opt/xxe/bin/xxe-app.jar!/gui/" />

The standard print action (i.e. the action referenced by the standard File menu) is defined as follows in common.xxe_gui:

      <action name="printAction" label="_Print..."
              icon="icons/printAction.gif"
              accelerator="mod P">
        <class>com.xmlmind.xmleditapp.kit.part.PrintAction</class>
      </action>

Therefore if we define a contextual action having the same name, "`printAction`", this suffices to install our custom action. Note how the `icon` attribute is specified in our redefinition of the print action.

The above contextual action can be described as follows:

- If the document to be printed is associated with a configuration named "`XHTML`", invoke command `xhtml.convertToPS` with parameter "`pdf |pdf`" to print it.

- Same with documents associated to configurations named "`DocBook`", "`Simplified DocBook`" or "`Slides`".

- If the document to be printed has no associated configuration or is associated with a configuration other than the above ones, print it using action implemented by Java™ class `com.xmlmind.xmleditapp.kit.part.PrintAction` (same as stock print action).

Elements `configuration` and `default` can contain actions implemented in Java™ or can contain commands (see Chapter 6, Commands written in the Java™ programming language in XMLmind XML Editor - Commands). Referencing an action is easy to understand, but what is this command `xhtml.convertToPS` used to print XHTML documents?

The configuration file for XHTML documents is ``XXE_install_dir`/addon/config/xhtml/xhtml.xxe`. The `name` attribute of the root element of this configuration file is `XHTML` (see Section 3, “configuration” in XMLmind XML Editor - Configuration and Deployment).

This configuration file includes another configuration file ``XXE_install_dir`/addon/config/xhtml/xslMenu.incl`. A process command called `xhtml.convertToPS` is defined in `xslMenu.incl`. This process command, with parameter "`pdf |pdf`", converts the document being edited to PDF[3].

[3] In the future, a process command will be able to directly send the result of the conversion to a printer — typically a PostScript™ printer — chosen by the user.

Prev | Up | Next
5. Adding a vertical tool bar | Home | 7. Adding a Characters menu