Altova Authentic 2024 Desktop

The Authentic Desktop installation package contains an example Java project, located in the the API\Java subfolder of the Examples folder :



Windows 7, Windows 8, Windows 10, Windows 11



This folder contains Java examples for the Authentic Desktop API. You can test it directly from the command line using the batch file BuildAndRun.bat, or you can compile and run the example project from within Eclipse. See below for instructions on how to use these procedures.


File list

The Java examples folder contains all the files required to run the example project. These files are listed below. If you are using a 64-bit version of the application, some filenames contain _x64 in the name. These filenames are indicated with (_x64).



Java-COM bridge: DLL part


Java-COM bridge: Java library part


Java classes of the Authentic Desktop API

Java example source code


Batch file to compile and run example code from the command line prompt. Expects folder where Java Virtual Machine resides as parameter.


Eclipse project helper file


Eclipse project file

Javadoc file containing help documentation for the Java API




What the example does

The example starts up Authentic Desktop and performs a few operations, including opening and closing documents. When done, Authentic Desktop stays open. You must close it manually.


Start Authentic Desktop: Starts Authentic Desktop, which is registered as an automation server, or activates Authentic Desktop if it is already running.

Open example files: Locates example documents installed with Authentic Desktop and opens them.

Iteration and Changing the View Mode: Changes the view of all open documents to Browser View. The code also shows how to iterate through open documents.

Iteration, validation, output parameters: Validates the active document and shows the result in a message box. The code shows how to use output parameters.

Event Handling: Shows how to handle Authentic Desktop events.

Shut down Authentic Desktop: Shuts down Authentic Desktop.


You can modify the example in any way you like and run it.


Running the example from the command line

To run the example from the command line, open a command prompt window, go to the Java folder of the API Examples folder (see above for location), and then type:


 buildAndRun.bat "<Path-to-the-Java-bin-folder>"


The Java binary folder must be that of a JDK 14 or later installation on your computer. Press the Return key. The Java source in will be compiled and then executed.


Loading the example in Eclipse

Open Eclipse and use the Import | Existing Projects into Workspace command to add the Eclipse project file (.project) located in the Java folder of the API Examples folder (see above for location). The project RunAuthenticDesktop will then appear in your Package Explorer or Navigator. Select the project and then the command Run as | Java Application to execute the example.


Note:You can select a class name or method of the Java API and press F1 to get help for that class or method.


Java source code listing

The Java source code in the example file is listed below with comments.



01 // Access general JAVA-COM bridge classes

02 import com.altova.automation.libs.*;


04 // Access AuthenticDesktop Java-COM bridge

05 import com.altova.automation.AuthenticDesktop.*;

06 import com.altova.automation.AuthenticDesktop.Enums.SPYViewModes;


08 /**

09  * A simple example that starts AuthenticDesktop COM server and performs a view operations on it.

10  * Feel free to extend.

11  */

12 public class RunAuthenticDesktop

13 {

14   public static void main(String[] args)

15   {

16     // An instance of the application.

17     Application authenticDesktop = null;


19     // Instead of COM error-handling, use Java exception mechanism.

20     try

21     {

22       // Start AuthenticDesktop as COM server.

23       authenticDesktop = new Application();

24       // COM servers start up invisible so we make it visible

25       authenticDesktop.setVisible(true);


27       // Locate samples installed with the product.

28       String strExamplesFolder = System.getenv("USERPROFILE") + "\\My Documents\\Altova\\Authentic2012\\AuthenticExamples\\";


30       // Open two files from the product samples.

31       authenticDesktop.getDocuments().openFile(strExamplesFolder + "OrgChart.pxf", false);

32       authenticDesktop.getDocuments().openFile(strExamplesFolder + "ExpReport.xml", false);


34       // Iterate through all open documents and set the View Mode to 'Text'.

35       for (Document doc:authenticDesktop.getDocuments())

36         if ( doc.getCurrentViewMode() != SPYViewModes.spyViewText)

37           doc.switchViewMode(SPYViewModes.spyViewText);


39       // An alternative iteration mode is index-based. COM indices are typically zero-based.

40       Documents documents = authenticDesktop.getDocuments();

41       for (int i = 1; i <= documents.getCount(); i++)

42       {

43         Document doc = documents.getItem(i);


45         // Validation is one of the few methods that have output parameters.

46         // The class JVariant is the correct type for parameters in these cases.

47         // To get values back mark them with the by-reference flag.

48         JVariant validationErrorText = new JVariant.JStringVariant("");     validationErrorText.setByRefFlag();

49         JVariant validationErrorCount = new JVariant.JIntVariant(0);      validationErrorCount.setByRefFlag();

50         JVariant validationErrorXMLData = new JVariant.JIDispatchVariant(0);  validationErrorXMLData.setByRefFlag();

51         if (!doc.isValid(validationErrorText, validationErrorCount, validationErrorXMLData))

52           System.out.println("Document " + doc.getName() + " is not wellformed - " + validationErrorText.getStringValue());

53         else

54           System.out.println("Document " + doc.getName() + " is wellformed.");

55       }


57       // The following lines attach to the document events using a default implementation

58       // for the events and override one of its methods.

59       // If you want to override all document events it is better to derive your listener class

60       // from DocumentEvents and implement all methods of this interface.

61       Document doc = authenticDesktop.getActiveDocument();

62       doc.addListener(new DocumentEventsDefaultHandler()

63       {

64         @Override

65         public boolean onBeforeCloseDocument(Document i_ipDoc) throws AutomationException

66         {

67           System.out.println("Document " + i_ipDoc.getName() + " requested closing.");


69           // Allow closing of document

70           return true;

71         }

72       });

73       doc.close(true);

74       doc = null;


76       System.out.println("Watch AuthenticDesktop!");

77     }

78     catch (AutomationException e)

79     {

80       // e.printStackTrace();

81     }

82     finally

83     {

84       // Make sure that AuthenticDesktop can shut down properly.

85       if (authenticDesktop != null)

86         authenticDesktop.dispose();


88       // Since the COM server was made visible and still is visible, it will keep running

89       // and needs to be closed manually.

90       System.out.println("Now close AuthenticDesktop!");

91     }

92   }

93 }


© 2017-2023 Altova GmbH