Add Buttons for Code Generation

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  ActiveX Integration > ActiveX Integration Examples > HTML > HTML Integration at Application Level >

Add Buttons for Code Generation

Although code-generation for the active document is available via menus, we want to have buttons that will generate code without asking the user for the location of the output. The method is similar to that used in the previous section.

 

First come the buttons:

 

<input type="button" value="Generate XSLT" onclick="BtnGenerate( 0 )">
<input type="button" value="Generate Java" onclick="BtnGenerate( 1 )">
<input type="button" value="Generate C++" onclick="BtnGenerate( 2 )">
<input type="button" value="Generate C#" onclick="BtnGenerate( 3 )">

 

Then we provide the script that will generate the code into sub-folders of the currently defined default output folders.

 

// ----------------------------------------------------------------------
// generate code for active document into language-specific subfolders of
// the current default output dicrectory. No user intercation necessary.
function BtnGenerate(languageID)
{
  // get top-level object of automation interface
  var objApp = objMapForceControl.Application;
 
  // get the active document
  var objDocument = objApp.ActiveDocument;
 
  // retrive object to set the generation output path
  var objOptions = objApp.Options;
 
  if ( objDocument == null )
     alert( "no active document found" );
  else
  {
     objOptions.XSLTDefaultOutputDirectory = objOptions.CodeDefaultOutputDirectory = GetDefaultOutputDirectory();
   
    if (languageID == 0)
     {
        objOptions.XSLTDefaultOutputDirectory = objOptions.XSLTDefaultOutputDirectory + "\\XSLTGen";
        objDocument .GenerateXSLT();
     }
    else if (languageID == 1)
     {
        objOptions.CodeDefaultOutputDirectory = objOptions.CodeDefaultOutputDirectory + "/JavaCode";
        objDocument .GenerateJavaCode();
     }
    else if (languageID == 2)
     {
        objOptions.CodeDefaultOutputDirectory = objOptions.CodeDefaultOutputDirectory + "/CPPCode";
        objDocument .GenerateCppCode();
     }
    else if (languageID == 3)
     {
        objOptions.CodeDefaultOutputDirectory = objOptions.CodeDefaultOutputDirectory + "/CSharpCode";
        objDocument .GenerateCHashCode();
     }
  }
}

 


© 2019 Altova GmbH