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

net.sourceforge.pldoc.Settings Maven / Gradle / Ivy

There is a newer version: 1.5.24
Show newest version
/* Copyright (C) 2002 Albert Tumanov

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

*/

package net.sourceforge.pldoc;

import java.io.*;
import java.util.*;

/** Represents all settings for the program.
* Setting values may be received from command line options and/or defaulted.
* This class should not have side effects.
* @author Albert Tumanov
* @version $Header: /cvsroot/pldoc/sources/src/java/net/sourceforge/pldoc/Settings.java,v 1.7 2005/11/29 08:25:00 gpaulissen Exp $
*/
public class Settings
{
  // Default settings 
  private static final String GET_METADATA_STATEMENT_DEFAULT = 
	"BEGIN" +
	"\n  DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM, 'SEGMENT_ATTRIBUTES', FALSE);" +
	"\n  DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM, 'CONSTRAINTS', FALSE);" +
	"\n  DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA. SESSION_TRANSFORM,'SQLTERMINATOR',true );" +
	"\n  :1 := DBMS_METADATA.GET_DDL(\n       :2 ,\n       :3 ,\n       :4 ,\n       :5 ,\n       :6 ,\n       :7 )  \n;" +
	"\nEND;" 
	;

  private static final String DRIVER_NAME_DEFAULT = "oracle.jdbc.OracleDriver";
  // settings and their defaults
  private String applicationName = "MyApplication";
  private File outputDirectory = new File("." + File.separator);
  private Collection inputFiles = new ArrayList();
  private String stylesheetfile = null;
  private File overviewfile = null;
  private Properties defines = null;
  private boolean ignoreInformalComments = false;
  private String defaultNamescase = "UPPER"; //SRT 20110419
  private String defaultKeywordscase = "UPPER"; //SRT 20110419
  private boolean namesDefaultcase = true;
  private boolean namesUppercase = false;
  private boolean namesLowercase = false;
  private boolean keywordsDefaultcase = true; //SRT 20110419
  private boolean keywordsUppercase = false; //SRT 20110419
  private boolean keywordsLowercase = false; //SRT 20110419
  // by default, assume system default encoding for all input files
  private String inputEncoding = System.getProperty("file.encoding");
  // we cannot yet set output encoding dynamically, because of XSLs
  private String outputEncoding = "UTF-8";
  private boolean exitOnError = false;
  private boolean verbose = false;
  private String driverName = DRIVER_NAME_DEFAULT ;
  private String getMetadataStatement = GET_METADATA_STATEMENT_DEFAULT ;
  private int    returnType = java.sql.Types.CLOB;
  private String dbUrl = null;
  private String dbUser = null;
  private String dbPassword = null;
  private Collection inputTypes = new ArrayList();
  private Collection inputObjects = new ArrayList();
  private boolean showSkippedPackages = false;
  /** Extract PL/Scope procedure call information from the database when runing against the database
      

This is used to generate "Calls:" and "Called From:" sections for each method with relevant PL/Scope information

*/ private boolean plscope = false; /** Save source code whilst parsing it.

This is used to generate visible source code, whilst reading source from the database

*/ private boolean saveSourceCode = false; /** Stylesheet file to display source code * */ private String sourcestylesheetfile = null; private static final String usage = "Arguments: [options] inputfile(s)\n" + "-verbose Verbose - report each object processed \n" + "-d Destination directory for output files [default: current]\n" + "-doctitle Application name [default: MyApplication]\n" + "-overview Read overview documentation from HTML file [default: none]\n" + "-defaultnamescase Case of unquoted names [default upper] - {upper, lower, mixed}\n" + "-defaultkeywordscase Case of keywords [default upper] - {upper, lower}\n" + "-namesdefaultcase Convert all names to defaultcase [default true]\n" + "-namesuppercase Convert all names to uppercase\n" + "-nameslowercase Convert all names to lowercase\n" + "-keywordsdefaultcase Convert all names to defaultcase [default true]\n" + "-keywordsuppercase Convert all keywords to uppercase\n" + "-keywordslowercase Convert all keywords to lowercase\n" + "-stylesheetfile File to change style of the generated document [default: defaultstylesheet.css]\n" + "-definesfile File containing SQL*Plus-style variable substitutions [default: none], for example:\n" + " &myvar1=123456\n" + " &myvar2=abcdef\n" + "-inputencoding Encoding used in the input files [default: operation system default encoding]\n" + "-exitonerror Force program to exit when some input file cannot be processed\n" + " [by default, the file is skipped and processing continues]\n" + "-driver Name of JDBC driver class, for example oracle.jdbc.OracleDriver, com.edb.Driver, or org.postgresql.Driver [default: " + DRIVER_NAME_DEFAULT + "].\n" + "-getmetadata SQL 92 CallableStatement Statement that retrieves the object source (EnterpriseDB does not support Oracle BEGIN .. END statements) [default: Oracle DBMS_METADATA anonymous block ].\n" + " Statement structure is (\"call\" and function are case sensitive} \"{ ? = call GET_SOURCE( ? , ? , ? , ? , ? , ? ) }\" where GET_SOURCE(...) mimics \n" + " \"{ = call DBMS_METADATA.GET_DDL( , , , 'COMPATIBLE' , 'ORACLE' , 'DDL' ) }\" \n" + "-returntype number corresponding to java.sql.Types.CLOB (2005) or java.sql.Types.VARCHAR (12) [default: java.sql.Types.CLOB].\n" + "-url Database URL, for example jdbc:oracle:thin:@HOST:PORT:SID, jdbc:oracle:thin:@HOST:PORT/SERVICE, jdbc:edb://HOST:PORT/DATABASE,\n" + " or jdbc:postgresql://HOST:PORT/DATABASE [default: none].\n" + " Required when generating from the Oracle dictionary.\n" + "-user Schema name.\n" + " Required when generating from the Oracle dictionary. The user name is\n" + " case sensitive since Oracle stores user/schema names like \"My schema\" (name wit \n" + " double quotes) as 'My schema' in the dictionary. Ordinary schema names\n" + " like scott are stored as 'SCOTT' (upper case).\n" + "-password Password of the logon user.\n" + " Required when generating from the Oracle dictionary.\n" + "-types Comma separated list of object type(s) to generate documentation for.\n" + " Defaults to all procedural types (PACKAGES, TYPES, FUNCTIONS PROCEDURES).\n" + "-sql Comma separated list of object name(s) to generate documentation for.\n" + " Required when generating from the Oracle dictionary.\n" + " An object name is case sensitive (the same rules as described for schema\n" + " names apply).\n" + " An object name may be prepended by a schema name and may have SQL\n" + " wildcards.\n" + " When the object belongs to a different schema than the logon user (as specified by\n" + " the -user parameter), the logon user must have been granted the SELECT_CATALOG_ROLE role or the SELECT ANY DICTIONARY system privilege.\n" + "-ignoreinformalcomments Ignore informal comments when generating documentation.\n" + "-showSkippedPackages Show the skipped packages in the summary of the documentation (generator.html)\n"+ "-plscope When extracting code from a database also extract PL/Scope call information and generate calling/called sections\n"+ "-saveSourceCode Save/extract database source code whilst parsing it\n"+ "-sourceStylesheetfile File to change display style of the extracted source code [default: defaultstylesheet.css]\n" + "" ; // " &myvar2=abcdef\n" + /** Consumes command line strings received by the main() method */ public void processCommandString(String args[]) throws Exception { if (args.length < 1) { System.out.println(usage); System.exit(0); } // Re-parse the argument string, to recognize strings with spaces inside. // list of arguments: ArrayList argumentList = new ArrayList(); // concatenate all the arguments StringBuffer arguments = new StringBuffer(); for(int i = 0; i < args.length; i++) { if(i > 0) { arguments.append(' '); } arguments.append(args[i]); } // parse into the argument list StreamTokenizer st = new StreamTokenizer(new StringReader(arguments.toString())); // reset syntax, because we do not want to parse numbers st.resetSyntax(); // whitespace is space, tabs, and all symbols in between st.whitespaceChars('\t', ' '); // words consists of all possible characters above the space character st.wordChars(' ' + 1, '\u00FF'); // two types of quote st.quoteChar('"'); st.quoteChar('\''); while(st.nextToken() != StreamTokenizer.TT_EOF) { switch(st.ttype) { case StreamTokenizer.TT_WORD: case '"': case '\'': argumentList.add(st.sval); default: ; // ignore } } // process the argument list "semantically" Iterator it = argumentList.iterator(); while(it.hasNext()) { String arg = (String) it.next(); if (arg.equalsIgnoreCase("-doctitle")) { // consume "-doctitle" if(!it.hasNext()) { processInvalidUsage("Option " + arg + " requires a value !"); } applicationName = (String) it.next(); } else if (arg.equalsIgnoreCase("-d")) { // consume "-d" if(!it.hasNext()) { processInvalidUsage("Option " + arg + " requires a value !"); } outputDirectory = new File((String) it.next() + File.separator); if (outputDirectory.isFile()) { processInvalidUsage("File name given instead of the output directory !"); } } else if (arg.equalsIgnoreCase("-overview")) { // consume "-overview" if(!it.hasNext()) { processInvalidUsage("Option " + arg + " requires a value !"); } overviewfile = new File((String) it.next()); if (!overviewfile.exists()) { processInvalidUsage("The specified overview file " + overviewfile + " does not exist !"); } } else if (arg.equalsIgnoreCase("-stylesheetfile")) { // consume "-stylesheetfile" if(!it.hasNext()) { processInvalidUsage("Option " + arg + " requires a value !"); } stylesheetfile = (String) it.next(); // check the file if (!(new File(stylesheetfile).exists())) { processInvalidUsage("The specified stylesheet file " + stylesheetfile + " does not exist !"); } } else if (arg.equalsIgnoreCase("-sourcestylesheetfile")) { // consume "-sourcestylesheetfile" if(!it.hasNext()) { processInvalidUsage("Option " + arg + " requires a value !"); } sourcestylesheetfile = (String) it.next(); // check the file if (!(new File(sourcestylesheetfile).exists())) { processInvalidUsage("The specified sourcestylesheet file " + sourcestylesheetfile + " does not exist !"); } } else if (arg.equalsIgnoreCase("-definesfile")) { // consume "-definesfile" if(!it.hasNext()) { processInvalidUsage("Option " + arg + " requires a value !"); } File definesfile = new File((String) it.next()); if (!definesfile.exists()) { processInvalidUsage("The specified defines file " + definesfile + " does not exist !"); } defines = new Properties(); defines.load(new FileInputStream(definesfile)); } else if (arg.equalsIgnoreCase("-ignoreinformalcomments")) { // consume "-ignoreinformalcomments" this.ignoreInformalComments = true; } else if (arg.equalsIgnoreCase("-namesdefaultcase")) { // consume "-namesuppercase" this.namesDefaultcase = true; } else if (arg.equalsIgnoreCase("-namesuppercase")) { // consume "-namesuppercase" this.namesUppercase = true; } else if (arg.equalsIgnoreCase("-nameslowercase")) { // consume "-nameslowercase" this.namesLowercase = true; } else if (arg.equalsIgnoreCase("-defaultnamescase")) { // consume "-defaultnamescase" if(!it.hasNext()) { processInvalidUsage("Option " + arg + " requires a value !"); } this.defaultNamescase = (String) it.next(); if (!this.defaultNamescase.equalsIgnoreCase("upper") && !this.defaultNamescase.equalsIgnoreCase("lower") && !this.defaultNamescase.equalsIgnoreCase("mixed") ) { processInvalidUsage( "Option " + arg + " had incorrect value \"" + this.defaultNamescase + "\" - this option requires a value of \"upper\" or \"lower\" or \"mixed\" " ); } } else if (arg.equalsIgnoreCase("-defaultkeywordscase")) { // consume "-defaultkeywordscase" if(!it.hasNext()) { processInvalidUsage("Option " + arg + " requires a value !"); } this.defaultKeywordscase = (String) it.next(); if (!this.defaultKeywordscase.equalsIgnoreCase("upper") && !this.defaultKeywordscase.equalsIgnoreCase("lower") ) { processInvalidUsage( "Option " + arg + " had incorrect value \"" + this.defaultKeywordscase + "\" - this option requires a value of \"upper\" or \"lower\" " ); } } else if (arg.equalsIgnoreCase("-keywordsdefaultcase")) { // consume "-keywordsuppercase" this.keywordsUppercase = true; } else if (arg.equalsIgnoreCase("-keywordsuppercase")) { // consume "-keywordsuppercase" this.keywordsUppercase = true; } else if (arg.equalsIgnoreCase("-keywordslowercase")) { // consume "-keywordslowercase" this.keywordsLowercase = true; } else if (arg.equalsIgnoreCase("-inputencoding")) { // consume "-inputencoding" if(!it.hasNext()) { processInvalidUsage("Option " + arg + " requires a value !"); } this.inputEncoding = (String) it.next(); } else if (arg.equalsIgnoreCase("-verbose")) { // consume "-verbose" this.verbose = true; } else if (arg.equalsIgnoreCase("-exitonerror")) { // consume "-exitonerror" this.exitOnError = true; } else if (arg.equalsIgnoreCase("-returntype")) { // consume "-returntype" if(!it.hasNext()) { processInvalidUsage("Option " + arg + " requires a value !"); } this.returnType = Integer.parseInt((String) it.next()); } else if (arg.equalsIgnoreCase("-driver")) { // consume "-driver" if(!it.hasNext()) { processInvalidUsage("Option " + arg + " requires a value !"); } this.driverName = (String) it.next(); } else if (arg.equalsIgnoreCase("-getmetadata")) { // consume "-getmetadata" if(!it.hasNext()) { processInvalidUsage("Option " + arg + " requires a value !"); } this.getMetadataStatement = (String) it.next(); } else if (arg.equalsIgnoreCase("-url")) { // consume "-url" if(!it.hasNext()) { processInvalidUsage("Option " + arg + " requires a value !"); } this.dbUrl = (String) it.next(); } else if (arg.equalsIgnoreCase("-user")) { if(!it.hasNext()) { processInvalidUsage("Option " + arg + " requires a value !"); } this.dbUser = (String) it.next(); } else if (arg.equalsIgnoreCase("-password")) { if(!it.hasNext()) { processInvalidUsage("Option " + arg + " requires a value !"); } this.dbPassword = (String) it.next(); } else if (arg.equalsIgnoreCase("-sql")) { if(!it.hasNext()) { processInvalidUsage("Option " + arg + " requires a value !"); } String inputObjectsList = (String)it.next(); inputObjects = Arrays.asList(inputObjectsList.split(",")); } else if (arg.equalsIgnoreCase("-types")) { if(!it.hasNext()) { processInvalidUsage("Option " + arg + " requires a value !"); } String inputTypesList = (String)it.next(); inputTypes = Arrays.asList(inputTypesList.split(",")); } else if (arg.equalsIgnoreCase("-showskippedpackages")) { // consume "-showskippedpackages" this.showSkippedPackages = true; } else if (arg.equalsIgnoreCase("-plscope")) { // consume "-plscope" this.plscope = true; } else if (arg.equalsIgnoreCase("-saveSourceCode")) { // consume "-saveSourceCode" this.saveSourceCode = true; } else if (arg.startsWith("-")) { System.err.println("WARN - unknown parameter \""+arg+"\""); processInvalidUsage("Unknown option " + arg); } else { // no option code recognized - assume it's a file name inputFiles.add(arg); } } // the input file(s) OR object name(s) MUST be given if ((inputFiles.isEmpty() && inputObjects.isEmpty()) || (!inputFiles.isEmpty() && !inputObjects.isEmpty())) { processInvalidUsage("Either input file name(s) or object name(s) must be given!"); } // When object name(s) are supplied, the connect info must be supplied. if (!inputObjects.isEmpty() && (this.dbUrl == null || this.dbUser == null || this.dbPassword == null)) { processInvalidUsage("Database url, db schema and db password are mandatory when object name(s) are supplied!"); } } public void setApplicationName(String applicationName) { this.applicationName = applicationName; } public void setOutputDirectory(File outputDirectory) { this.outputDirectory = outputDirectory; } public void setInputFiles(Collection inputFiles) { this.inputFiles = inputFiles; } public void setStylesheetfile(String stylesheetfile) { this.stylesheetfile = stylesheetfile; } public void setSourceStylesheetfile(String sourcestylesheetfile) { this.sourcestylesheetfile = sourcestylesheetfile; } public void setOverviewfile(File overviewfile) { this.overviewfile = overviewfile; } public void setDefines(Properties defines) { this.defines = defines; } public void setIgnoreInformalComments(boolean ignoreInformalComments) { this.ignoreInformalComments = ignoreInformalComments; } public void setNamesDefaultcase(boolean namesDefaultcase) { this.namesDefaultcase = namesDefaultcase; } public void setNamesUppercase(boolean namesUppercase) { this.namesUppercase = namesUppercase; } public void setNamesLowercase(boolean namesLowercase) { this.namesLowercase = namesLowercase; } public void setDefaultNamescase(String defaultNamescase) { this.defaultNamescase = defaultNamescase; } public void setDefaultKeywordscase(String defaultKeywordscase) { this.defaultKeywordscase = defaultKeywordscase; } public void setKeywordsDefaultcase(boolean keywordsDefaultcase) { this.keywordsDefaultcase = keywordsDefaultcase; } public void setKeywordsUppercase(boolean keywordsUppercase) { this.keywordsUppercase = keywordsUppercase; } public void setKeywordsLowercase(boolean keywordsLowercase) { this.keywordsLowercase = keywordsLowercase; } public void setInputEncoding(String inputEncoding) { this.inputEncoding = inputEncoding; } public void setVerbose(boolean verbose) { this.verbose = verbose; } public void setExitOnError(boolean exitOnError) { this.exitOnError = exitOnError; } public void setReturnType(int returnType) { this.returnType = returnType; } public void setDriverName(String driverName) { this.driverName = driverName; } public void setGetMetadataStatement(String getMetadataStatement) { this.getMetadataStatement = getMetadataStatement; } public void setDbUrl(String dbUrl) { this.dbUrl = dbUrl; } public void setDbUser(String dbUser) { this.dbUser = dbUser; } public void setDbPassword(String dbPassword) { this.dbPassword = dbPassword; } public void setInputObjects(Collection inputObjects) { this.inputObjects = inputObjects; } public void setInputTypes(Collection inputTypes) { this.inputTypes = inputTypes; } public void setShowSkippedPackages(boolean showSkippedPackages) { this.showSkippedPackages = showSkippedPackages; } public void setPlscope(boolean plscope) { this.plscope =plscope; } public void setSaveSourceCode(boolean saveSourceCode) { this.saveSourceCode =saveSourceCode; } public String getApplicationName() { return applicationName; } public File getOutputDirectory() { return outputDirectory; } public Collection getInputFiles() { return inputFiles; } public String getStylesheet() { return stylesheetfile; } public InputStream getStylesheetFile() throws IOException { // if some custom stylesheet was given, use it if (stylesheetfile != null && stylesheetfile.length() > 0) { return new FileInputStream(stylesheetfile); } // return default return ((new ResourceLoader()).getResourceStream("defaultstylesheet.css")); } public String getSourceStylesheet() { return sourcestylesheetfile; } public InputStream getSourceStylesheetFile() throws IOException { // if some custom sourcestylesheet was given, use it if (sourcestylesheetfile != null && sourcestylesheetfile.length() > 0) { return new FileInputStream(sourcestylesheetfile); } // return default return ((new ResourceLoader()).getResourceStream("defaultstylesheet.css")); } public File getOverviewFile() { return overviewfile; } public Properties getDefines() { return defines; } public boolean isIgnoreInformalComments() { return ignoreInformalComments; } public boolean isNamesDefaultcase() { return namesDefaultcase; } public boolean isKeywordsDefaultcase() { return keywordsDefaultcase; } public boolean isNamesUppercase() { return namesUppercase; } public boolean isNamesLowercase() { return namesLowercase; } public String getDefaultNamescase() { return defaultNamescase; } public String getDefaultKeywordscase() { return defaultKeywordscase; } public boolean isKeywordsUppercase() { return keywordsUppercase; } public boolean isKeywordsLowercase() { return keywordsLowercase; } public String getInputEncoding() { return inputEncoding; } public String getOutputEncoding() { return outputEncoding; } public boolean isVerbose() { return verbose; } public boolean isExitOnError() { return exitOnError; } public String getDbUrl() { return dbUrl; } public String getGetMetadataStatement() { return getMetadataStatement; } public int getReturnType() { return returnType; } public String getDriverName() { return driverName; } public String getDbUser() { return dbUser; } public String getDbPassword() { return dbPassword; } public Collection getInputObjects() { return inputObjects; } public Collection getInputTypes() { return inputTypes; } public boolean isShowSkippedPackages() { return showSkippedPackages; } public boolean isPlscope() { return plscope; } public boolean isSaveSourceCode() { return saveSourceCode; } /** Processes invalid usage: prints the error message and the usage instruction * and halts. */ private void processInvalidUsage(String message) { System.out.println("Error: " + message); System.out.println(usage); System.exit(0); } }