⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 java2xhtml.java

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* gnu.classpath.tools.java2xhtml.Java2xhtml   Copyright (C) 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version. GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA. *//** Java2xhtml.java  Version 0.9 *  Produces an XHTML file from Java source code with syntax highlighting, *  includes additional options (line numbering, tab spacing, etc.) * <P> * NOTE: Common java naming structure is assumed *       Capitalize the first letter that appears in a class or interface name *       Use lowercase for the first letter in a method or variable name *       Use only uppercase letters when naming constants  * * @version     0.9, March 2003 * @author      Shayne Steele */package gnu.classpath.tools.java2xhtml;import java.io.*;import java.util.*;public class Java2xhtml{    //--- define CSS classes for individual output elements    private static final String sourceCodeStyle = "source";    private static final String lineNumberStyle = "line-number even";    private static final String modulusLineNumberStyle = "line-number odd";    private static final String keywordStyle = "keyword";    private static final String methodStyle = "method member";    private static final String variableStyle = "variable member";    private static final String singleLineCommentStyle = "line comment";    private static final String traditionalCommentStyle = "c comment";    private static final String javadocCommentStyle = "javadoc comment";    private static final String javadocTagStyle = "javadoc tag";    private static final String importNameStyle = "import header type";    private static final String packageNameStyle = "package header type";    private static final String primitiveTypeStyle = "primitive type";    private static final String nonPrimitiveTypeStyle = "non-primitive type";    private static final String constructorStyle = "constructor member";    private static final String constantStyle = "constant member";    private static final String doubleQuoteStyle = "double quote";    private static final String singleQuoteStyle = "single quote";    private static final String numericLiteralStyle = "numeric literal";    private static final String primitiveLiteralStyle = "primitive literal";    private static final String iconStyle = "icon";    // parse the command line arguments    // give a decent responce for bad input    // call the HTMLifier on good input    public static void main(String args[])    {        // parse the invokation arguments         if (args.length < 1 || args.length > 3) // invoked program incorrectly        {            System.out.println("Java2xhtml Version 0.9 (C) 2005 Free Software Foundation");            System.out.println("    Produces an XHTML file of Java source" +                               " code with syntax highlighting,");            System.out.println("    includes additional options " +                               "(line numbering, tab spacing, etc.)");            System.out.println("    This tool is part of GNU Classpath.");            System.out.println("    GNU Classpath is free software; you can redistribute it and/or modify");            System.out.println("    it under the terms of the GNU General Public License as published by");            System.out.println("    the Free Software Foundation; either version 2, or (at your option)");            System.out.println("    any later version.");            System.out.println("    NOTE: Common java naming structure is " +                               "assumed");            System.out.println("");            System.out.println("USAGE:");            System.out.println("java  [java options]  Java2xhtml  " +                               "source.java  [options file]  " +                               "[output file]");            System.out.println("");            System.out.println("  - java is the name of the Java interpreter");            System.out.println("  - [java options] are the optional options " +                               "of the Java interpreter");            System.out.println("  - Java2xhtml is the name of this " +                               "application");            System.out.println("  - source is a file or the directory to the " +                               "Java source file(s)");            System.out.println("  - [options file] is the optional " +                               "path of a file with");            System.out.println("    a structure like this:");            System.out.println("        externalStyleSheetName=file_name" +                               " (default style.css)");            System.out.println("        tabSize=integer  (default value is 4)");            System.out.println("        extraIndentation=integer  " +                               "(default value is 0)");            System.out.println("        lineModulus=integer (default value 5)");            System.out.println("        isCodeSnippet=boolean" +                               " (default false)");            System.out.println("        isXHTML_1_1=boolean" +                               " (default true)");            System.out.println("        hasInternalStyleSheet=boolean" +                               " (default true)");            System.out.println("        hasExternalStyleSheet=boolean" +                               " (default true)");            System.out.println("        hasTitle=boolean" +                               " (default false)");            System.out.println("        hasLegend=boolean" +                               " (default false)");            System.out.println("        hasAllBoldSourceCode=boolean" +                               " (default false)");            System.out.println("        hasLineNumbers=boolean" +                               " (default false)");            System.out.println("        hasLineModulusDrawnLines=boolean" +                                " (default false)");            System.out.println("        hasLineModulusCodeBlocks=boolean" +                               " (default false)");            System.out.println("        hasFooter=boolean" +                                " (default false)");            System.out.println("        hasFooterIcons=boolean" +                                " (default false)");            System.out.println("        hasFooterDate=boolean" +                                " (default true)");            System.out.println("    NOTE: filename must end with '.prop'");            System.out.println("    Default [options file] is " +                               "options.prop");            System.out.println("  - [output file] is name of the XHTML file " +                               "that is produced");            System.out.println("    Default [output file] is source_java.html");            System.out.println("");            System.out.println("Output: source.java --> [output file]");            System.out.println("    Default Output is ");            System.out.println("    source.java --> source_java.html");            System.out.println("");            System.out.println("Examples of calling the program:");            System.out.println(" process one file (say Java2xhtml.java):");            System.out.println("    java  Java2xhtml  Java2xhtml.java");            System.out.println(" process one directory (say C:\\HOME):");            System.out.println("    java  Java2xhtml  C:\\HOME");            System.out.println(" process one directory (say C:\\HOME with a " +                               "given options file (options.prop)):");            System.out.println("    java  Java2xhtml  C:\\HOME options.prop");        }        else          {            // invoked program correctly, now get command line arguments            // get the source file name            String sourceName;            sourceName = args[0];            // make sure that the source file exist and if so HTMLify it            File sourceFilePath = new File(sourceName);            if (sourceFilePath.exists())              {                // good pathname so HTMLify it                // get the default html options file name                String propertiesFileName = "options.prop";                // create a unique default html file name,                 // bubba.java -> bubba_java.html                String htmlFileName = sourceName.replace('.', '_') + ".html";                if (args.length == 2 || args.length == 3)                {                    if (args[1].endsWith(".prop"))                    {                        // get the user supplied html options file name                        propertiesFileName = args[1];                    }                    else                    {                        // get the user supplied html outputfile name                        htmlFileName = args[1];                    }                }                if (args.length == 3)                 {                    if (args[2].endsWith(".prop"))                    {                        // get the user supplied html options file name                        propertiesFileName = args[2];                    }                    else                    {                        // get the user supplied html outputfile name                        htmlFileName = args[2];                    }                }                new Java2xhtml(propertiesFileName, sourceFilePath,                                htmlFileName);            }            else // source file does not exist, print message and exit normally            {                System.out.println("The source parameter must be an existent" +                                   " file or directory");                System.out.println("Run Java2xHtml without parameters for " +                                   "help");            }                         }    }        // collect various sets of keywords    static Collection keywordCollection;    static Collection primitiveTypeCollection;    static Collection primitiveLiteralCollection;    static Collection javadocTagCollection;    // all these variables are changeable by a options file    int extraIndentation = 0;    int tabSize = 4;    int lineModulus = 5;    boolean hasLegend = false;    boolean hasLineNumbers = false;    boolean hasLineModulusDrawnLines = false;    boolean hasLineModulusCodeBlocks = false;    boolean hasFooter = false;    boolean hasFooterIcons = false;    boolean hasFooterDate = true;    boolean isCodeSnippet = false;    boolean isXHTML_1_1 = true;    boolean hasTitle = false;    boolean hasAllBoldSourceCode = false;    boolean hasInternalStyleSheet = true;    boolean hasExternalStyleSheet = true;    String externalStyleSheetName = "style.css";    static     {        // collection type is Hashset for unique elements and fast retieval         String keywordArray[] =            {                "abstract", "default",      "if",           "private",                      "do",       "implements",   "protected",    "throws",                "break",    "import",       "public",       "transient",                "else",     "instanceof",   "return",       "try",                "case",     "extends",      "throw",        "static",                "catch",    "final",        "interface",    "while",                       "volatile", "finally",      "super",        "synchronized",                "class",    "native",       "switch",       "package",                "const",    "for",          "new",          "goto",                "continue", "this",         "assert",       "strictfp"                   };        keywordCollection = new HashSet(Arrays.asList(keywordArray));        String primitiveTypeArray[] =            {                "boolean",  "char",     "byte",         "short",        "int",                "long",     "float",    "double",       "void"            };        primitiveTypeCollection =             new HashSet(Arrays.asList(primitiveTypeArray));        String primitiveLiteralArray[]=            {                "false", "null", "true"            };        primitiveLiteralCollection =             new HashSet(Arrays.asList(primitiveLiteralArray));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -