alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */
package org.netbeans.modules.xml.tools.doclet;

import java.util.*;
import java.text.DateFormat;

import org.xml.sax.Locator;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.AttributeList;

import org.xml.sax.DocumentHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.ErrorHandler;
import org.xml.sax.EntityResolver;

import org.netbeans.tax.*;
import org.netbeans.tax.decl.*;

/**
 * Creates [X]HTML documentation for DTD. 
 * 

There is a special doclet comment preceding element declaration. * The comment is delimited by "" i.e. starting * delimiter uses three "---". * *

Generated element content model consists of hyperlinked structure. * * @author Petr Kuzel * @version 1.0 */ public class DTDDoclet { private RefList s; //tmp holding whole result private RefList elementIndex = new RefList(); private String comment; //last suitable comment or null if none /* This ellement is just being commented. * Used for "referenced by" creation. */ private String currentElement = null; /* Hold element name keyed RefLists used at * "referenced by" section. */ private HashMap elementRefs = new HashMap(); // configurable output format private final String HEADLINE1 = "h2"; // NOI18N private final String HEADLINE2 = "b"; // NOI18N private final String LIST = "ul"; // NOI18N private final String LIST_ITEM = "li"; // NOI18N private final String PAR = "p"; // NOI18N private final String ROOT = "html"; // NOI18N private final String BODY = "body"; // NOI18N /** Creates new DTDDoclet engine*/ public DTDDoclet() { } /** * @return a String representing XHTML content */ public String createDoclet (TreeDTD dtd) { if (dtd == null) return ""; // NOI18N Iterator it; s = new RefList(); s.append("\n"); // NOI18N s.appendStartTag(ROOT).append("\n\n" + Util.THIS.getString("PAGE_TITLE") + "\n"); // NOI18N s.append("\n"); s.append("\n"); s.append("\n\n"); // NOI18N s.appendStartTag(BODY); headline1(Util.THIS.getString("TEXT_Element_Index")); s.append(elementIndex); headline1(Util.THIS.getString("TEXT_Element_Details")); it = dtd.getChildNodes(TreeChild.class, true).iterator(); Vector list = new Vector(); while (it.hasNext()) { TreeNode child = (TreeNode)it.next(); if (child instanceof TreeElementDecl) { commentElement((TreeElementDecl) child); comment = null; } else if (child instanceof TreeComment) { comment = decodeComment((TreeComment) child); } else if (child instanceof TreeText || child instanceof TreeParameterEntityReference) { // do not clear comment #30094 } else { // disable comment comment = null; } } // create index at elementIndex reference position. // strings are sorted by alphabet TreeSet index = new TreeSet(); it = elementRefs.keySet().iterator(); while (it.hasNext()) { index.add(it.next()); } elementIndex.appendStartTag(LIST); it = index.iterator(); while (it.hasNext()) { Object next = it.next(); listitem(elementIndex, "" + next + ""); // NOI18N } elementIndex.appendEndTag(LIST); // terminate the html page // s.appendEndTag(BODY).appendEndTag(ROOT); return s.toString(); } //~~~~~~~~~~~~~~~ DOCUMENTATION STUFF ~~~~~~~~~~~~~~~~~~~~~~~~ /** Comment is paired just with the next element declaration and * it must statt with