All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.com.ibm.as400.util.CommandHelpRetriever Maven / Gradle / Ivy

There is a newer version: 11.1
Show newest version
///////////////////////////////////////////////////////////////////////////////
//                                                                             
// JTOpen (IBM Toolbox for Java - OSS version)                              
//                                                                             
// Filename: CommandHelpRetriever.java
//                                                                             
// The source code contained herein is licensed under the IBM Public License   
// Version 1.0, which has been approved by the Open Source Initiative.         
// Copyright (C) 1997-2002 International Business Machines Corporation and     
// others. All rights reserved.                                                
//                                                                             
///////////////////////////////////////////////////////////////////////////////

package com.ibm.as400.util;

// JDK classes.
import java.io.*;
import java.util.*;

// XSL classes.
import javax.xml.transform.*;
import javax.xml.transform.stream.*;

// Toolbox classes.
import com.ibm.as400.access.*;

// WebSphere 4.0 ships only a stub XML4J.jar, and XML4J.jar goes away in the future. We need to 
// use xerces.jar to be compatible with the version used by WebSphere.
//import org.apache.xerces.parsers.SAXParser;
//import javax.xml.parsers.*;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
//import org.xml.sax.helpers.*;


/**
 *  Generates IBM-formatted CL command help documentation.
 *  This class requires that valid XML and XSL processors (e.g. Xerces and Xalan) be in the CLASSPATH.
 *
 *   CommandHelpRetriever can be run as a command line program, as follows:
 *  
 *  java com.ibm.as400.util.CommandHelpRetriever  -library <library> -command <command> [ -system <systemName> -userid <userid> -password <password> -showChoicePgmValues -output <outputDirectory> -debug ]
 *  
* Options: * *
* *
-help *
Displays the help text. * The -help option may be abbreviated to -h or -?. *
*

* Parameters: * *

* *
-library IBM i library.
*
Specifies the IBM i library. * This parameter may be abbreviated -l or -lib. *
* *
-command IBM i command.
*
Specifies the IBM i command. * This parameter may be abbreviated -c or -cmd. *
* *
-system IBM i system name
*
Specifies the IBM i system. If an IBM i system name is not provided, a signon dialog will be displayed. * This optional parameter may be abbreviated -s or -sys. *
* *
-userid IBM i userID.
*
Specifies the IBM i userId. If an IBM i userID is not provided, a signon dialog will be displayed. * This optional parameter may be abbreviated -u or -uid. *
* *
-password IBM i password.
*
Specifies the IBM i password. If an IBM i password is not provided, a signon dialog will be displayed. * This optional parameter may be abbreviated -p or -pwd. *
* *
-showChoicePgmValues [true | false]
*
Specifies whether or not parameter choices returned from choice programs are shown in the Choices cells of the parameter summary table. * The default is false. * This optional parameter may be abbreviated -scpv. *
* *
-output output location. *
Specifies the output location for the generated help. The default is the current directory. The output * cannot be a file when the command (-c) parameter contains a wildcard (*). * This optional parameter may be abbreviated -o. *
* *
-debug [true | false] *
Specifies whether to output the source command help and xml files to the output location specified by the -output parameter. The default is false. * This optional parameter may be abbreviated -d. *
* *
* * @see com.ibm.as400.access.Command * @see com.ibm.as400.access.CommandList **/ public class CommandHelpRetriever { private boolean debug_ = false; // The Templates object is threadsafe. We use it to pre-compile // the XSL code and generate new Transformer objects. private static Templates htmlTemplate_; private static Templates uimTemplate_; private static URIResolver defaultResolver_; private static String library_ = null; private static String command_ = null; private boolean showChoices_ = false; private String outputDirectory_ = "."; // Default to current directory // This instance has its own copy of the XSL transformer, // SAX parser, URI resolver, and entity resolver/handler. // Hence, the generateHTML() method is synchronized. private Transformer htmlTransformer_; private Transformer uimTransformer_; private final HelpResolver resolver_ = new HelpResolver(); // Objects used to load the MRI and transform it into something // that the output HTML document can use. private static final String[] mriHTMLTags_ = new String[] { "ALLOW_ALL", "ALLOW_COMPILED_CL_OR_REXX1", "ALLOW_COMPILED_CL_OR_REXX2", "ALLOW_INTERACTIVE1", "ALLOW_INTERACTIVE2", "ALLOW_JOB_BATCH", "ALLOW_JOB_INTERACTIVE", "ALLOW_MODULE_BATCH", "ALLOW_MODULE_INTERACTIVE", "ALLOW_PROGRAM_BATCH", "ALLOW_PROGRAM_INTERACTIVE", "ALLOW_REXX_BATCH", "ALLOW_REXX_INTERACTIVE", "ALLOW_USING_COMMAND_API", "CHOICES", "ELEMENT", "ERRORS", "EXAMPLES", "KEY", "KEYWORD", "NAME_LOWERCASE", "NONE", "NOTES", "OPTIONAL", "PARAMETERS", "POSITIONAL", "QUALIFIER", "REQUIRED", "THREADSAFE", "THREADSAFE_CONDITIONAL", "TOP_OF_PAGE", "TYPE_CL_VARIABLE_NAME", "TYPE_COMMAND_STRING", "TYPE_COMMUNICATIONS_NAME", "TYPE_DATE", "TYPE_DECIMAL_NUMBER", "TYPE_ELEMENT_LIST", "TYPE_GENERIC_NAME", "TYPE_INTEGER", "TYPE_NOT_RESTRICTED", "TYPE_PATH_NAME", "TYPE_QUALIFIED_JOB_NAME", "TYPE_QUALIFIED_OBJECT_NAME", "TYPE_QUALIFIER_LIST", "TYPE_SIMPLE_NAME", "TYPE_TIME", "TYPE_VALUE_LOGICAL", "TYPE_VALUE_CHARACTER", "TYPE_VALUE_HEX", "TYPE_UNSIGNED_INTEGER", "UNKNOWN", "VALUES_OTHER", "VALUES_OTHER_REPEAT", "VALUES_REPEAT", "VALUES_SINGLE", "WHERE_ALLOWED_TO_RUN" }; // Objects used to load the MRI and transform it into something // that the output UIM document can use. private static final String[] mriUIMTags_ = new String[] { "HELP", "HELP_FOR_COMMAND", "INTRO_COMMAND_HELP", "DESCRIBE_COMMAND", "RESTRICTIONS_HEADING", "RESTRICTION_AUT", "RESTRICTION_THREADSAFE", "LIST_SPECIAL_AUT", "LIST_OTHER_AUT", "LIST_THREADSAFE_RESTRICTIONS", "DESCRIBE_OTHER_RESTRICTION", "RESTRICTION_COMMENT", "NO_PARAMETERS", "EXAMPLES_HEADING", "EXAMPLE_1_TITLE", "DESCRIBE_EXAMPLE_1", "EXAMPLE_2_TITLE", "DESCRIBE_EXAMPLE_2", "INTRO_EXAMPLE_HELP", "ERROR_MESSAGES_HEADING", "ERROR_MESSAGES_COMMENT_1", "ERROR_MESSAGES_COMMENT_2", "ERROR_MESSAGES_COMMENT_3", "HELP_FOR_PARAMETER", "INTRO_PARAMETER_HELP", "DESCRIBE_PARAMETER", "REQUIRED_PARAMETER", "ELEMENT", "QUALIFIER", "VALUES_OTHER", "VALUES_OTHER_REPEAT", "VALUES_REPEAT", "VALUES_SINGLE", "VALUE_CHARACTER", "VALUE_CL_VARIABLE_NAME", "VALUE_COMMAND_STRING", "VALUE_COMMUNICATIONS_NAME", "VALUE_DATE", "VALUE_DECIMAL_NUMBER", "VALUE_GENERIC_NAME", "VALUE_HEX", "VALUE_INTEGER", "VALUE_LOGICAL", "VALUE_NAME", "VALUE_NOT_RESTRICTED", "VALUE_PATH_NAME", "VALUE_SIMPLE_NAME", "VALUE_TIME", "VALUE_UNSIGNED_INTEGER", "SPECIFY_VALUE", "SPECIFY_NAME", "SPECIFY_GENERIC_NAME", "SPECIFY_PATH_NAME", "SPECIFY_NUMBER", "SPECIFY_CL_VARIABLE_NAME", "SPECIFY_COMMAND_STRING", "SPECIFY_DATE", "SPECIFY_TIME", "MULTIPLE_PARAMETER_VALUES_ALLOWED", "MULTIPLE_ELEMENT_VALUES_ALLOWED", "DESCRIBE_PREDEFINED_PARAMETER_VALUE", "DESCRIBE_USERDEFINED_PARAMETER_VALUE", "DESCRIBE_PARAMETER_DEFAULT", "DESCRIBE_PARAMETER_VALUE_WITH_RANGE" }; private static final String[][] transformedHTMLParms_ = getTransformedHTMLParms(Locale.getDefault()); // Don't ask for UIM MRI unless someone calls the UIM methods. Do this so this tool // works with V5R2 MRI. // private static final String[][] transformedUIMParms_ = getTransformedUIMParms(Locale.getDefault()); //private static String[][] transformedUIMParms_; // Find the XSL document, generate an XSL template, load the resource bundles, // and generate the MRI strings. static { try { if (Trace.isTraceOn()) { Trace.log(Trace.DIAGNOSTIC, "Loading gencmddoc.xsl."); } ClassLoader classloader = CommandHelpRetriever.class.getClassLoader(); if (classloader == null) { classloader = ClassLoader.getSystemClassLoader(); } String docXSLURI = classloader.getResource("com/ibm/as400/util/gencmddoc.xsl").toString(); if (Trace.isTraceOn()) { Trace.log(Trace.DIAGNOSTIC, "Loading gencmdhlp.xsl."); } String hlpXSLURI = classloader.getResource("com/ibm/as400/util/gencmdhlp.xsl").toString(); if (Trace.isTraceOn()) { Trace.log(Trace.DIAGNOSTIC, "Loading XSL templates."); } TransformerFactory factory = TransformerFactory.newInstance(); defaultResolver_ = factory.getURIResolver(); htmlTemplate_ = factory.newTemplates(new StreamSource(docXSLURI)); uimTemplate_ = factory.newTemplates(new StreamSource(hlpXSLURI)); } catch (Exception e) { if (Trace.isTraceOn()) { Trace.log(Trace.ERROR, "Unable to initialize CommandHelpRetriever XSL and MRI.", e); } throw new RuntimeException(e.toString()); } } // Resolver used in XSL transform. private static class HelpResolver implements URIResolver { public String helpResults_; public Source resolve(String href, String base) throws TransformerException { // This gets called when the XSL transformer encounters a document() call. if (href.indexOf("myCommandHelpResolver") > -1) { return new StreamSource(new StringReader(helpResults_)); } // If the transformer happens to load the __NO_HELP document, make something // available. In Sun's later JVMs this gets called. For the J9 JVM this // doesn't get called. @C2A if (href.indexOf("__NO_HELP") > -1) { return new StreamSource(new StringReader("NO HELP AVAILABLE")); } return defaultResolver_.resolve(href, base); } } private static boolean genUIM_ = false; private static boolean genHTML_ = true; /** * Performs the actions specified in the invocation arguments. * @param args The command line arguments. **/ public static void main(String[] args) { PrintWriter writer = new PrintWriter(System.out, true); //The PrintWriter used when running via the command line. if (args.length == 0) { writer.println(); usage(); } try { CommandHelpRetriever utility = new CommandHelpRetriever(); AS400 system = parseParms(args, utility); CommandList list = new CommandList(system, utility.library_, utility.command_); Command[] cmds = list.generateList(); File outDir = new File(utility.outputDirectory_); boolean isDir = outDir.isDirectory(); if (!isDir && cmds.length>1) { if (Trace.isTraceOn()) Trace.log(Trace.DIAGNOSTIC, "The output parameter cannot be a file when a wildcard command is specified"); throw new ExtendedIllegalArgumentException("output", ExtendedIllegalArgumentException.PARAMETER_VALUE_NOT_VALID); } for (int i=0; i': dest.append(">"); break; default: dest.append(buf[i]); break; } } return dest.toString(); } /** * We don't want to HTML-encode the UIM strings, but we still * need to replace the ampersands so the XSL doesn't get confused. **/ private static final String encodeAmp(String source) { StringBuffer dest = new StringBuffer(); char[] buf = source.toCharArray(); for (int i=0; iNote: While the String being returned is a typical UTF-16 Java String, the contents * of the String is an HTML file with a META tag that defines the charset as UTF-8. * Applications that use the String returned by this method should then be sure to convert * the contents to UTF-8 bytes, or replace the charset tag inside the HTML with whichever * encoding the application chooses to convert to. See {@link #generateHTMLBytes generateHTMLBytes()}. * * @param command The command. * @return An HTML string consisting of the help documentation for the command. * @throws AS400Exception * @throws AS400SecurityException * @throws ErrorCompletingRequestException * @throws IOException * @throws InterruptedException * @throws ObjectDoesNotExistException * @throws SAXException * @throws ParserConfigurationException * @throws TransformerConfigurationException * @throws TransformerException * @see java.util.Locale * @see com.ibm.as400.access.AS400 * @see com.ibm.as400.access.Command **/ public synchronized String generateHTML(Command command) throws AS400Exception, AS400SecurityException, ErrorCompletingRequestException, IOException, InterruptedException, ObjectDoesNotExistException, SAXException, ParserConfigurationException, TransformerConfigurationException, TransformerException { if (command == null) throw new NullPointerException("command"); return generate(command, null); } /** * Generates IBM-formatted command help documentation for the specified CL command. * Portions of the resulting HTML will contain strings that were translated using * the {@link java.util.Locale Locale} specified on the {@link com.ibm.as400.access.AS400 AS400} * object for the given {@link com.ibm.as400.access.Command Command}. * *

Note: While the String being returned is a typical UTF-16 Java String, the contents * of the String is an HTML file with a META tag that defines the charset as UTF-8. * Applications that use the String returned by this method should then be sure to convert * the contents to UTF-8 bytes, or replace the charset tag inside the HTML with whichever * encoding the application chooses to convert to. See {@link #generateHTMLBytes generateHTMLBytes()}. * * @param command The command. * @param panelGroup The panel group used to generate the help text, instead of the Command's defined panel group. * @return An HTML string consisting of the help documentation for the command. * @throws AS400Exception * @throws AS400SecurityException * @throws ErrorCompletingRequestException * @throws IOException * @throws InterruptedException * @throws ObjectDoesNotExistException * @throws SAXException * @throws ParserConfigurationException * @throws TransformerConfigurationException * @throws TransformerException * @see java.util.Locale * @see com.ibm.as400.access.AS400 * @see com.ibm.as400.access.Command * @see com.ibm.as400.access.PanelGroup **/ public synchronized String generateHTML(Command command, PanelGroup panelGroup) throws AS400Exception, AS400SecurityException, ErrorCompletingRequestException, IOException, InterruptedException, ObjectDoesNotExistException, SAXException, ParserConfigurationException, TransformerConfigurationException, TransformerException { if (command == null) throw new NullPointerException("command"); if (panelGroup == null) throw new NullPointerException("panelGroup"); return generate(command, panelGroup); } /** * Generates IBM-formatted command help documentation for the specified CL command. * Portions of the resulting HTML will contain strings that were translated using * the {@link java.util.Locale Locale} specified on the {@link com.ibm.as400.access.AS400 AS400} * object for the given {@link com.ibm.as400.access.Command Command}. * *

Note: The byte array returned by this method has already been encoded in UTF-8 in order to * match the charset tag within the HTML document. * * @param command The command. * @param panelGroup The panel group used to generate the help text. Specify null to use the Command's defined panel group. * @return An HTML document encoded in UTF-8 bytes, consisting of the help documentation for the command. * @throws AS400Exception * @throws AS400SecurityException * @throws ErrorCompletingRequestException * @throws IOException * @throws InterruptedException * @throws ObjectDoesNotExistException * @throws SAXException * @throws ParserConfigurationException * @throws TransformerConfigurationException * @throws TransformerException * @see java.util.Locale * @see com.ibm.as400.access.AS400 * @see com.ibm.as400.access.Command * @see com.ibm.as400.access.PanelGroup **/ public synchronized byte[] generateHTMLBytes(Command command, PanelGroup panelGroup) throws AS400Exception, AS400SecurityException, ErrorCompletingRequestException, IOException, InterruptedException, ObjectDoesNotExistException, SAXException, ParserConfigurationException, TransformerConfigurationException, TransformerException { if (command == null) throw new NullPointerException("command"); return generate(command, panelGroup).getBytes("UTF-8"); } /** * Generates IBM-formatted command help documentation for the specified CL command. * Portions of the resulting HTML will contain strings that were translated using * the {@link java.util.Locale Locale} specified on the {@link com.ibm.as400.access.AS400 AS400} * object for the given {@link com.ibm.as400.access.Command Command}. * @param command The command. * @param panelGroup The panel group used to generate the help text, instead of the Command's defined panel group. * @return An HTML string consisting of the help documentation for the command. * @see java.util.Locale * @see com.ibm.as400.access.AS400 * @see com.ibm.as400.access.Command * @see com.ibm.as400.access.PanelGroup **/ private synchronized String generate(Command command, PanelGroup panelGroup) throws AS400Exception, AS400SecurityException, ErrorCompletingRequestException, IOException, InterruptedException, ObjectDoesNotExistException, SAXException, ParserConfigurationException, TransformerConfigurationException, TransformerException { if (Trace.isTraceOn()) Trace.log(Trace.DIAGNOSTIC, "Generating HTML documentation for '"+command+"' and panel group '"+panelGroup+"'."); String xml = command.getXML(); if (debug_) { String path = command.getPath(); QSYSObjectPathName pn = new QSYSObjectPathName(path); String lib = pn.getLibraryName(); String name = pn.getObjectName(); File outDir = new File(outputDirectory_); boolean isDir = outDir.isDirectory(); File outFile = null; if (isDir) outFile = new File(outDir, lib + "_" + name + "_XML.xml"); else outFile = new File(outputDirectory_ + "_XML.xml"); FileWriter fw = new FileWriter(outFile); try { fw.write(xml); } finally { if (fw != null) fw.close(); } } if (Trace.isTraceOn()) Trace.log(Trace.DIAGNOSTIC, "Retrieved command XML:\n"+xml+"\n"); String threadSafe = null; String whereAllowedToRun = null; try { switch (command.getThreadSafety()) { case Command.THREADSAFE_NO: threadSafe = "0"; break; case Command.THREADSAFE_YES: threadSafe = "1"; break; case Command.THREADSAFE_CONDITIONAL: threadSafe = "2"; break; default: break; } whereAllowedToRun = command.getWhereAllowedToRun(); } catch (AS400Exception e) { AS400Message[] msgs = e.getAS400MessageList(); // CPF6250 - Can't retrieve info for command. Probably because it is a system command. if (msgs.length != 1 || !msgs[0].getID().toUpperCase().trim().equals("CPF6250")) throw new AS400Exception(msgs); } if (Trace.isTraceOn()) Trace.log(Trace.DIAGNOSTIC, "Using command threadsafety = "+threadSafe+" and where allowed to run = "+whereAllowedToRun+"."); String helpResults = null; try { helpResults = (panelGroup == null ? command.getXMLHelpText() : command.getXMLHelpText(panelGroup)); } catch (AS400Exception e) { AS400Message[] msgs = e.getAS400MessageList(); // // Note: It is also possible to get a CPF6E3B when the user is not authorized to the help text. // However, we do not see the underlying message that the user is not authorized. // @C2A // CPF6250 - Can't retrieve info for command. Probably because it is a system command. if (msgs.length != 1 || ( !msgs[0].getID().toUpperCase().trim().equals("CPF6250") && !msgs[0].getID().toUpperCase().trim().equals("CPF6E3B") )) throw new AS400Exception(msgs); } if (debug_ && helpResults != null) { String path = command.getPath(); QSYSObjectPathName pn = new QSYSObjectPathName(path); String lib = pn.getLibraryName(); String name = pn.getObjectName(); File outDir = new File(outputDirectory_); boolean isDir = outDir.isDirectory(); File outFile = null; if (isDir) outFile = new File(outDir, lib + "_" + name + "_HTMLHelp.html"); else outFile = new File(outputDirectory_ + "_HTMLHelp.html"); FileWriter fw = new FileWriter(outFile); try { fw.write(helpResults); } finally { if (fw != null) fw.close(); } } // Reset the transformer. We could re-use the same Transformer object, // but the problem is that any document() calls in the XSL are resolved // and cached by the transformer, so that the second time through, our // help text would still be from the previous command. // One way around this is to DOM parse the help text ourselves and pass // that in to the transformer, instead of coding a document() call in // the XSL; however, this is INCREDIBLY slow since the DOM tree can // consist of a large number of objects, all of which the transformer // has to marshal into its own internal format. It turns out that // using a document() call in the XSL code is faster, especially since // we don't get any re-use out of the help text's DOM tree. setupHTMLTransformer(command.getSystem().getLocale()); htmlTransformer_.setParameter("CommandHelp", helpResults == null || helpResults.trim().length() == 0 ? "__NO_HELP" : "myCommandHelpResolver"); htmlTransformer_.setParameter("ShowChoicePgmValues", showChoices_ ? "1" : "0"); htmlTransformer_.setParameter("ThreadSafe", threadSafe == null ? "0" : threadSafe); htmlTransformer_.setParameter("WhereAllowed", whereAllowedToRun == null ? "000000000000000" : whereAllowedToRun); resolver_.helpResults_ = helpResults; StreamSource sourceXML = new StreamSource(new StringReader(xml)); StringWriter buf = new StringWriter(); StreamResult output = new StreamResult(buf); if (Trace.isTraceOn()) { Trace.log(Trace.DIAGNOSTIC, "Performing XSL transform."); Trace.log(Trace.DIAGNOSTIC, "Help Results is "+helpResults); } try { htmlTransformer_.transform(sourceXML, output); } catch (TransformerException e) { if (Trace.isTraceOn()) { Trace.log(Trace.DIAGNOSTIC, "Exception from transform."); Trace.log(Trace.DIAGNOSTIC, e); } throw e; } if (Trace.isTraceOn()) Trace.log(Trace.DIAGNOSTIC, "Successfully generated help documentation."); return buf.toString(); } /** * Generates an IBM-formatted UIM template for the specified CL command. * Portions of the resulting UIM output will contain strings that were translated using * the {@link java.util.Locale Locale} specified on the {@link com.ibm.as400.access.AS400 AS400} * object for the given {@link com.ibm.as400.access.Command Command}. * @param command The command. * @return A UIM string consisting of the UIM template for the command. * @throws AS400Exception * @throws AS400SecurityException * @throws ErrorCompletingRequestException * @throws IOException * @throws InterruptedException * @throws ObjectDoesNotExistException * @throws SAXException * @throws ParserConfigurationException * @throws TransformerConfigurationException * @throws TransformerException * @see java.util.Locale * @see com.ibm.as400.access.AS400 * @see com.ibm.as400.access.Command **/ public synchronized String generateUIM(Command command) throws AS400Exception, AS400SecurityException, ErrorCompletingRequestException, IOException, InterruptedException, ObjectDoesNotExistException, SAXException, ParserConfigurationException, TransformerConfigurationException, TransformerException { if (command == null) throw new NullPointerException("command"); if (Trace.isTraceOn()) Trace.log(Trace.DIAGNOSTIC, "Generating UIM documentation for "+command+"."); String xml = null; try { xml = command.getXMLExtended(); } catch(AS400Exception ae) { AS400Message[] msgs = ae.getAS400MessageList(); if (msgs.length == 1 && msgs[0].getID().equalsIgnoreCase("CPF3C21")) { if (Trace.isTraceOn()) { Trace.log(Trace.WARNING, "Extended command XML format not supported by this system. Using older version."); } xml = command.getXML(); } else { throw ae; } } if (debug_) { String path = command.getPath(); QSYSObjectPathName pn = new QSYSObjectPathName(path); String lib = pn.getLibraryName(); String name = pn.getObjectName(); File outDir = new File(outputDirectory_); boolean isDir = outDir.isDirectory(); File outFile = null; if (isDir) outFile = new File(outDir, lib + "_" + name + "_XML_X.xml"); else outFile = new File(outputDirectory_ + "_XML_X.xml"); FileWriter fw = new FileWriter(outFile); try { fw.write(xml); } finally { if (fw != null) fw.close(); } } if (Trace.isTraceOn()) { Trace.log(Trace.DIAGNOSTIC, "Retrieved extended command XML:\n"+xml+"\n"); } // Reset the transformer. We could re-use the same Transformer object, // but the problem is that any document() calls in the XSL are resolved // and cached by the transformer, so that the second time through, our // help text would still be from the previous command. // One way around this is to DOM parse the help text ourselves and pass // that in to the transformer, instead of coding a document() call in // the XSL; however, this is INCREDIBLY slow since the DOM tree can // consist of a large number of objects, all of which the transformer // has to marshal into its own internal format. It turns out that // using a document() call in the XSL code is faster, especially since // we don't get any re-use out of the help text's DOM tree. setupUIMTransformer(command.getSystem().getLocale()); StreamSource sourceXML = new StreamSource(new StringReader(xml)); StringWriter buf = new StringWriter(); StreamResult output = new StreamResult(buf); if (Trace.isTraceOn()) { Trace.log(Trace.DIAGNOSTIC, "Performing XSL transform of UIM."); } uimTransformer_.transform(sourceXML, output); if (Trace.isTraceOn()) { Trace.log(Trace.DIAGNOSTIC, "Successfully generated UIM documentation."); } return buf.toString(); } /** * Returns whether or not the source XML and source command HTML help, which are used in * generating the resulting command help HTML documentation, are saved to the current output location. * * @return true if the source XML and source HTML files will be generated; false otherwise. The default is false. * @see #setDebug **/ public boolean getDebug() { return debug_; } /** * Returns the output location for the source XML and source command HTML help when running programatically. The default is the current directory. * * @return The output location of the source files. * @see #setOutputLocation **/ public String getOutputLocation() { return outputDirectory_; } /** * Returns whether or not the generated HTML documentation will contain parameter values * returned by a "choices program". * @return true if the extra parameters will be shown; false otherwise. The default is false. * @see #setShowChoiceProgramValues **/ public boolean getShowChoiceProgramValues() { return showChoices_; } /** * Used to get the translated MRI for a given Locale. **/ private static final String[][] getTransformedHTMLParms(Locale locale) { String[][] parms = new String[mriHTMLTags_.length+4][]; if (Trace.isTraceOn()) { Trace.log(Trace.DIAGNOSTIC, "Transforming CommandHelpRetriever HTML MRI for locale: "+locale); } ResourceBundle bundle = ResourceBundle.getBundle("com.ibm.as400.access.MRI", locale); ResourceBundle bundle2 = ResourceBundle.getBundle("com.ibm.as400.access.MRI2", locale); int i=0; for (; i





© 2015 - 2024 Weber Informatics LLC | Privacy Policy