Example Java Project
The StyleVision 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 | C:\Users\<username>\Documents\ |
This folder contains Java examples for the StyleVision 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).
AltovaAutomation(_x64).dll | Java-COM bridge: DLL part |
AltovaAutomation.jar | Java-COM bridge: Java library part |
StyleVisionAPI.jar | Java classes of the StyleVision API |
RunStyleVision.java | Java example source code |
BuildAndRun.bat | Batch file to compile and run example code from the command line prompt. Expects folder where Java Virtual Machine resides as parameter. |
.classpath | Eclipse project helper file |
.project | Eclipse project file |
StyleVision_JavaDoc.zip | Javadoc file containing help documentation for the Java API |
What the example does
The example starts up StyleVision and performs a few operations, including opening and closing documents. When done, StyleVision stays open. You must close it manually.
•Start StyleVision: Starts StyleVision, which is registered as an automation server, or activates StyleVision if it is already running.
•Open OrgChart.pxf: Locates one of the example documents installed with StyleVision and opens it.
•Iteration and Changing the View Mode: Shows how to iterate through open documents.
•Event Handling: Shows how to handle StyleVision events.
•Shut down StyleVision: Shuts down StyleVision.
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 1.5 or later installation on your computer. Press the Return key. The Java source in RunStyleVision.java 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 RunStyleVision 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 RunStyleVision.java is listed below with comments.
01 // Access general JAVA-COM bridge classes
02 import com.altova.automation.libs.*;
03
04 // Access StyleVision Java-COM bridge
05 import com.altova.automation.StyleVision.*;
06 import com.altova.automation.StyleVision.Enums.ENUMApplicationStatus;
07
08 /**
09 * A simple example that starts the COM server and performs a View operations on it.
10 * Feel free to extend.
11 */
12 public class RunStyleVision
13 {
14 public static void main(String[] args)
15 {
16 // An instance of the application.
17 Application stylevision = null;
18
19 // Instead of COM error-handling, use Java exception mechanism.
20 try
21 {
22 // Start StyleVision as COM server.
23 stylevision = new Application();
24
25 ENUMApplicationStatus status = ENUMApplicationStatus.eApplicationRunning;
26 do{
27 // Check the application status
28 status = stylevision.getStatus();
29 System.out.println("status : " + status + "\");
30 } while (status != ENUMApplicationStatus.eApplicationRunning);
31
32 // COM servers start up invisible, so we make the server visible
33 stylevision.setVisible(true);
34
35 // Locate samples installed with the product.
36 String strExamplesFolder = System.getenv("USERPROFILE") + "\\My Documents\\Altova\\StyleVision2012\\StyleVisionExamples\\";
37
38 // Open two files from the product samples.
39 stylevision.getDocuments().openDocument(strExamplesFolder + "OrgChart.pxf");
40 stylevision.getDocuments().openDocument(strExamplesFolder + "BiggestCitiesPerContinent.sps");
41
42 // Iterate through all open documents
43 for (Document doc:stylevision.getDocuments())
44 {
45 System.out.println("Document name : " + doc.getName() + "\");
46 SchemaSources sources = doc.getSchemaSources();
47
48 for (int i = 1; i <= sources.getCount(); i++)
49 {
50 SchemaSource source = sources.getItem(i);
51 System.out.println("\tSchema file name : " + source.getSchemaFileName() + "\");
52 System.out.println("\tWorking XML file name : " + source.getWorkingXMLFileName() + "\");
53 System.out.println("\tIs main schema source : " + source.getIsMainSchemaSource() + "\tType name : " + source.getTypeName() + "\");
54 }
55 }
56 // The following lines attach to the document events using a default implementation
57 // for the events and override one of its methods.
58 // If you want to override all document events it is better to derive your listener class
59 // from DocumentEvents and implement all methods of this interface.
60 Document doc = stylevision.getActiveDocument();
61 doc.addListener(new DocumentEventsDefaultHandler()
62 {
63 @Override
64 public void onDocumentClosed(Document i_ipDoc) throws AutomationException
65 {
66 System.out.println("Document " + i_ipDoc.getName() + " requested closing.");
67 }
68 });
69 doc.close();
70 doc = null;
71
72 System.out.println("Watch StyleVision!");
73 }
74 catch (AutomationException e)
75 {
76 e.printStackTrace();
77 }
78 finally
79 {
80 // Make sure that StyleVision can shut down properly.
81 if (stylevision != null)
82 stylevision.dispose();
83
84 // Since the COM server was made visible and still is visible, it will keep running
85 // and needs to be closed manually.
86 System.out.println("Now close StyleVision!");
87 }
88 }
89 }