Altova StyleVision Server 2024

The example below shows how to use Java code to generate an output RTF file using a PXF file and an input XML file. Ensure that StyleVision Server is installed and licensed and that it is available as a server object. Registration as a server object usually takes place during installation of StyleVision Server. The example program below can be built and run using the batch file named buildAndRun.bat, which is located in the etc\Examples\Java folder of your StyleVision Server installation folder.

 

For information about the interface, see About the Java Interface.

 

Note:We recommend that you copy the Examples folder to your home directory or any other suitable folder, and then navigate to the Java folder to access Program.java and buildAndRun.bat.

 

Program.java

public class Program

{

 

  public static void main(String[] args)

   {

     com.altova.stylevisionserver.StyleVisionServer objSVS

      try

      {

          //Create a StyleVision Server object

          objSVS = new com.altova.stylevisionserver.StyleVisionServer();

         

          //The default location of server binary is the folder containing the Java native library

          //Select a different server binary with the following line:

          //obj.SVS.setServerPath(strServerPath);

 

         //The sample data is located in the parent folder of the Java sample code

         //Set this parent folder to be the working directory:

          objSVS.setWorkingDirectory( ".." );

                 

         System.out.println("Running " + objSVS.getProductNameAndVersion());

       

        //Prepare the name of the working XML

         //This can be an absolute/relative path if the file is external (not inside PXF)

         //   objSVS.setInputXML( "ExpReport.xml" );

         //Or it can contain the path INSIDE the PXF

         //   objSVS.setInputXML( "C:\\Program Files (x86)\\Altova\\StyleVisionServer" + majorVersionYear + "\\etc\\Examples\\ExpReport.pxf|zip\\ExpReport.xml" );

         //The easiest way is to refer to the file as being embedded in the transformation file

         objSVS.setInputXML( "altova://packagedfile/ExpReport.xml" );

       

          //Add output paths (absolute or relative to WorkingDirectory) for all formats that should be generated

          objSVS.setOutputRTF( "ExpReport.rtf" );

       

          //Prepare the parameters, if your design uses parameters

          //objSVS.AddParameter( "testparam1", "value 1" );

       

          //Run the transformation; the output will be stored at C:\temp\ExpReport.rtf

          // NOTE Please adapt the path to the input file in order to run the sample

          if ( objSVS.generate( "ExpReport.pxf" ) )

               System.out.println( "Success"  +  objSVS.getLastExecutionMessage() );

          else

               System.out.println( objSVS.getLastExecutionMessage() );

       }

      catch ( Exception e)

       {

          System.out.println(e.getMessage());

       }

  }

 

}

 

© 2017-2023 Altova GmbH