jaxp/src/com/sun/org/apache/bcel/internal/util/Class2HTML.java
author joehw
Mon, 18 Feb 2013 11:33:35 -0800
changeset 16953 a44e04deb948
parent 12457 c348e06f0e82
child 25264 040625ce9b72
permissions -rw-r--r--
6657673: Issues with JAXP Reviewed-by: alanb, lancea, ahgross, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
package com.sun.org.apache.bcel.internal.util;
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
/* ====================================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * The Apache Software License, Version 1.1
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * Copyright (c) 2001 The Apache Software Foundation.  All rights
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 * reserved.
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 * Redistribution and use in source and binary forms, with or without
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * modification, are permitted provided that the following conditions
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * are met:
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * 1. Redistributions of source code must retain the above copyright
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 *    notice, this list of conditions and the following disclaimer.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 * 2. Redistributions in binary form must reproduce the above copyright
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 *    notice, this list of conditions and the following disclaimer in
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 *    the documentation and/or other materials provided with the
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
 *    distribution.
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
 * 3. The end-user documentation included with the redistribution,
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
 *    if any, must include the following acknowledgment:
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
 *       "This product includes software developed by the
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
 *        Apache Software Foundation (http://www.apache.org/)."
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
 *    Alternately, this acknowledgment may appear in the software itself,
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
 *    if and wherever such third-party acknowledgments normally appear.
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * 4. The names "Apache" and "Apache Software Foundation" and
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 *    "Apache BCEL" must not be used to endorse or promote products
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 *    derived from this software without prior written permission. For
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 *    written permission, please contact apache@apache.org.
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * 5. Products derived from this software may not be called "Apache",
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 *    "Apache BCEL", nor may "Apache" appear in their name, without
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 *    prior written permission of the Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
 * SUCH DAMAGE.
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 * ====================================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 * This software consists of voluntary contributions made by many
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 * individuals on behalf of the Apache Software Foundation.  For more
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 * information on the Apache Software Foundation, please see
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 * <http://www.apache.org/>.
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
import java.io.*;
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
import java.util.BitSet;
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
import com.sun.org.apache.bcel.internal.classfile.*;
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
import com.sun.org.apache.bcel.internal.Constants;
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
 * Read class file(s) and convert them into HTML files.
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
 * Given a JavaClass object "class" that is in package "package" five files
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
 * will be created in the specified directory.
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
 * <OL>
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
 * <LI> "package"."class".html as the main file which defines the frames for
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
 * the following subfiles.
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
 * <LI>  "package"."class"_attributes.html contains all (known) attributes found in the file
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
 * <LI>  "package"."class"_cp.html contains the constant pool
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
 * <LI>  "package"."class"_code.html contains the byte code
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
 * <LI>  "package"."class"_methods.html contains references to all methods and fields of the class
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
 * </OL>
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
 * All subfiles reference each other appropiately, e.g. clicking on a
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
 * method in the Method's frame will jump to the appropiate method in
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
 * the Code frame.
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
 *
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    85
 * @version $Id: Class2HTML.java,v 1.3 2007-07-19 04:34:52 ofung Exp $
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
 * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
*/
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
public class Class2HTML implements Constants
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
  private JavaClass java_class;     // current class object
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
  private String    dir;
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
  private static String       class_package;  // name of package, unclean to make it static, but ...
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
  private static String       class_name;     // name of current class, dito
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
  private static ConstantPool constant_pool;
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
   * Write contents of the given JavaClass into HTML files.
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
   * @param java_class The class to write
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
   * @param dir The directory to put the files in
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
  public Class2HTML(JavaClass java_class, String dir) throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
    Method[]     methods       = java_class.getMethods();
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
    this.java_class = java_class;
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    this.dir        = dir;
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
    class_name      = java_class.getClassName();     // Remember full name
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
    constant_pool   = java_class.getConstantPool();
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
    // Get package name by tacking off everything after the last `.'
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
    int index = class_name.lastIndexOf('.');
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
    if(index > -1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
      class_package = class_name.substring(0, index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
      class_package = ""; // default package
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
    ConstantHTML constant_html = new ConstantHTML(dir, class_name, class_package, methods,
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
                                                  constant_pool);
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
    /* Attributes can't be written in one step, so we just open a file
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
     * which will be written consequently.
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
    AttributeHTML attribute_html = new AttributeHTML(dir, class_name, constant_pool, constant_html);
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
    MethodHTML method_html = new MethodHTML(dir, class_name, methods, java_class.getFields(),
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
                                            constant_html, attribute_html);
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
    // Write main file (with frames, yuk)
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
    writeMainHTML(attribute_html);
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
    new CodeHTML(dir, class_name, methods, constant_pool, constant_html);
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
    attribute_html.close();
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
  public static void _main(String argv[])
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
    String[]    file_name = new String[argv.length];
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
    int         files=0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
    ClassParser parser=null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
    JavaClass   java_class=null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
    String      zip_file = null;
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   141
    char        sep = SecuritySupport.getSystemProperty("file.separator").toCharArray()[0];
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
    String      dir = "." + sep; // Where to store HTML files
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
    try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
      /* Parse command line arguments.
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
       */
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
      for(int i=0; i < argv.length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
        if(argv[i].charAt(0) == '-') {  // command line switch
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
          if(argv[i].equals("-d")) {   // Specify target directory, default '.'
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
            dir = argv[++i];
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
            if(!dir.endsWith("" + sep))
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
              dir = dir + sep;
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
            new File(dir).mkdirs(); // Create target directory if necessary
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
          else if(argv[i].equals("-zip"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
            zip_file = argv[++i];
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
            System.out.println("Unknown option " + argv[i]);
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
        else // add file name to list */
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
          file_name[files++] = argv[i];
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
      if(files == 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
        System.err.println("Class2HTML: No input files specified.");
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
      else { // Loop through files ...
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
        for(int i=0; i < files; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
          System.out.print("Processing " + file_name[i] + "...");
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
          if(zip_file == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
            parser = new ClassParser(file_name[i]); // Create parser object from file
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
            parser = new ClassParser(zip_file, file_name[i]); // Create parser object from zip file
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
          java_class = parser.parse();
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
          new Class2HTML(java_class, dir);
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
          System.out.println("Done.");
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
    } catch(Exception e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
      System.out.println(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
      e.printStackTrace(System.out);
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
   * Utility method that converts a class reference in the constant pool,
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
   * i.e., an index to a string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
  static String referenceClass(int index) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
    String str = constant_pool.getConstantString(index, CONSTANT_Class);
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    str = Utility.compactClassName(str);
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
    str = Utility.compactClassName(str, class_package + ".", true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
    return "<A HREF=\"" + class_name + "_cp.html#cp" + index +
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
      "\" TARGET=ConstantPool>" + str + "</A>";
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
  static final String referenceType(String type) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
    String short_type = Utility.compactClassName(type);
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
    short_type = Utility.compactClassName(short_type, class_package + ".", true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
    int index = type.indexOf('['); // Type is an array?
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
    if(index > -1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
      type = type.substring(0, index); // Tack of the `['
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
    // test for basic type
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
    if(type.equals("int")  || type.equals("short") || type.equals("boolean") || type.equals("void")   ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
       type.equals("char") || type.equals("byte")  || type.equals("long")    || type.equals("double") ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
       type.equals("float"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
      return "<FONT COLOR=\"#00FF00\">" + type + "</FONT>";
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
      return "<A HREF=\"" + type + ".html\" TARGET=_top>" + short_type + "</A>";
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
  static String toHTML(String str) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
    StringBuffer buf = new StringBuffer();
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
    try { // Filter any characters HTML doesn't like such as < and > in particular
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
      for(int i=0; i < str.length(); i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
        char ch;
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
        switch(ch=str.charAt(i)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
        case '<': buf.append("&lt;"); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
        case '>': buf.append("&gt;"); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
        case '\n': buf.append("\\n"); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
        case '\r': buf.append("\\r"); break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
        default:  buf.append(ch);
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
    } catch(StringIndexOutOfBoundsException e) {} // Never occurs
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
    return buf.toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
  private void writeMainHTML(AttributeHTML attribute_html) throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
    PrintWriter file       = new PrintWriter(new FileOutputStream(dir + class_name + ".html"));
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
    Attribute[] attributes = java_class.getAttributes();
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
    file.println("<HTML>\n" + "<HEAD><TITLE>Documentation for " + class_name + "</TITLE>" +
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
                 "</HEAD>\n" +
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
                 "<FRAMESET BORDER=1 cols=\"30%,*\">\n" +
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
                 "<FRAMESET BORDER=1 rows=\"80%,*\">\n" +
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
                 "<FRAME NAME=\"ConstantPool\" SRC=\"" + class_name + "_cp.html" + "\"\n MARGINWIDTH=\"0\" " +
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
                 "MARGINHEIGHT=\"0\" FRAMEBORDER=\"1\" SCROLLING=\"AUTO\">\n" +
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
                 "<FRAME NAME=\"Attributes\" SRC=\"" + class_name + "_attributes.html" +
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
                 "\"\n MARGINWIDTH=\"0\" " +
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
                 "MARGINHEIGHT=\"0\" FRAMEBORDER=\"1\" SCROLLING=\"AUTO\">\n" +
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
                 "</FRAMESET>\n" +
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
                 "<FRAMESET BORDER=1 rows=\"80%,*\">\n" +
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
                 "<FRAME NAME=\"Code\" SRC=\"" + class_name + "_code.html\"\n MARGINWIDTH=0 " +
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
                 "MARGINHEIGHT=0 FRAMEBORDER=1 SCROLLING=\"AUTO\">\n" +
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
                 "<FRAME NAME=\"Methods\" SRC=\"" + class_name + "_methods.html\"\n MARGINWIDTH=0 " +
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
                 "MARGINHEIGHT=0 FRAMEBORDER=1 SCROLLING=\"AUTO\">\n" +
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
                 "</FRAMESET></FRAMESET></HTML>"
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
                 );
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
    file.close();
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
    for(int i=0; i < attributes.length; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
      attribute_html.writeAttribute(attributes[i], "class" + i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
}