org.eclipse.mylyn.wikitext.core_1.6.1.v20120425-0100

 Byte code:
    //   0: aload_2
    //   1: ifnull +17 -> 18
    //   4: aload_2
    //   5: invokevirtual 100	java/lang/String:length	()I
    //   8: ifeq +10 -> 18
    //   11: aload_0
    //   12: getfield 97	org/eclipse/mylyn/wikitext/core/parser/outline/OutlineParser:markupLanguage	Lorg/eclipse/mylyn/wikitext/core/parser/markup/MarkupLanguage;
    //   15: ifnonnull +21 -> 36
    //   18: aload_1
    //   19: aload_2
    //   20: ifnonnull +7 -> 27
    //   23: iconst_0
    //   24: goto +7 -> 31
    //   27: aload_2
    //   28: invokevirtual 100	java/lang/String:length	()I
    //   31: invokevirtual 109	org/eclipse/mylyn/wikitext/core/parser/outline/OutlineItem:setLength	(I)V
    //   34: aload_1
    //   35: areturn
    //   36: aload_1
    //   37: aload_2
    //   38: invokevirtual 100	java/lang/String:length	()I
    //   41: invokevirtual 109	org/eclipse/mylyn/wikitext/core/parser/outline/OutlineItem:setLength	(I)V
    //   44: aload_0
    //   45: getfield 97	org/eclipse/mylyn/wikitext/core/parser/outline/OutlineParser:markupLanguage	Lorg/eclipse/mylyn/wikitext/core/parser/markup/MarkupLanguage;
    //   48: iconst_1
    //   49: invokevirtual 107	org/eclipse/mylyn/wikitext/core/parser/markup/MarkupLanguage:setFilterGenerativeContents	(Z)V
    //   52: aload_0
    //   53: getfield 97	org/eclipse/mylyn/wikitext/core/parser/outline/OutlineParser:markupLanguage	Lorg/eclipse/mylyn/wikitext/core/parser/markup/MarkupLanguage;
    //   56: aload_0
    //   57: invokevirtual 111	org/eclipse/mylyn/wikitext/core/parser/outline/OutlineParser:isBlocksOnly	()Z
    //   60: invokevirtual 106	org/eclipse/mylyn/wikitext/core/parser/markup/MarkupLanguage:setBlocksOnly	(Z)V
    //   63: aload_0
    //   64: aload_1
    //   65: invokevirtual 113	org/eclipse/mylyn/wikitext/core/parser/outline/OutlineParser:createOutlineUpdater	(Lorg/eclipse/mylyn/wikitext/core/parser/outline/OutlineItem;)Lorg/eclipse/mylyn/wikitext/core/parser/DocumentBuilder;
    //   68: checkcast 55	org/eclipse/mylyn/wikitext/core/parser/outline/OutlineParser$OutlineBuilder
    //   71: astore_3
    //   72: aload_3
    //   73: getfield 98	org/eclipse/mylyn/wikitext/core/parser/outline/OutlineParser$OutlineBuilder:idGenerator	Lorg/eclipse/mylyn/wikitext/core/parser/IdGenerator;
    //   76: aload_0
    //   77: getfield 97	org/eclipse/mylyn/wikitext/core/parser/outline/OutlineParser:markupLanguage	Lorg/eclipse/mylyn/wikitext/core/parser/markup/MarkupLanguage;
    //   80: invokevirtual 108	org/eclipse/mylyn/wikitext/core/parser/markup/MarkupLanguage:getIdGenerationStrategy	()Lorg/eclipse/mylyn/wikitext/core/parser/markup/IdGenerationStrategy;
    //   83: invokevirtual 101	org/eclipse/mylyn/wikitext/core/parser/IdGenerator:setGenerationStrategy	(Lorg/eclipse/mylyn/wikitext/core/parser/markup/IdGenerationStrategy;)V
    //   86: new 51	org/eclipse/mylyn/wikitext/core/parser/MarkupParser
    //   89: dup
    //   90: invokespecial 102	org/eclipse/mylyn/wikitext/core/parser/MarkupParser:<init>	()V
    //   93: astore 4
    //   95: aload 4
    //   97: aload_3
    //   98: invokevirtual 104	org/eclipse/mylyn/wikitext/core/parser/MarkupParser:setBuilder	(Lorg/eclipse/mylyn/wikitext/core/parser/DocumentBuilder;)V
    //   101: aload 4
    //   103: aload_0
    //   104: getfield 97	org/eclipse/mylyn/wikitext/core/parser/outline/OutlineParser:markupLanguage	Lorg/eclipse/mylyn/wikitext/core/parser/markup/MarkupLanguage;
    //   107: invokevirtual 105	org/eclipse/mylyn/wikitext/core/parser/MarkupParser:setMarkupLanguage	(Lorg/eclipse/mylyn/wikitext/core/parser/markup/MarkupLanguage;)V
    //   110: aload 4
    //   112: aload_2
    //   113: invokevirtual 103	org/eclipse/mylyn/wikitext/core/parser/MarkupParser:parse	(Ljava/lang/String;)V
    //   116: goto +24 -> 140
    //   119: astore 5
    //   121: aload_0
    //   122: getfield 97	org/eclipse/mylyn/wikitext/core/parser/outline/OutlineParser:markupLanguage	Lorg/eclipse/mylyn/wikitext/core/parser/markup/MarkupLanguage;
    //   125: iconst_0
    //   126: invokevirtual 107	org/eclipse/mylyn/wikitext/core/parser/markup/MarkupLanguage:setFilterGenerativeContents	(Z)V
    //   129: aload_0
    //   130: getfield 97	org/eclipse/mylyn/wikitext/core/parser/outline/OutlineParser:markupLanguage	Lorg/eclipse/mylyn/wikitext/core/parser/markup/MarkupLanguage;
    //   133: iconst_0
    //   134: invokevirtual 106	org/eclipse/mylyn/wikitext/core/parser/markup/MarkupLanguage:setBlocksOnly	(Z)V
    //   137: aload 5
    //   139: athrow
    //   140: aload_0
    //   141: getfield 97	org/eclipse/mylyn/wikitext/core/parser/outline/OutlineParser:markupLanguage	Lorg/eclipse/mylyn/wikitext/core/parser/markup/MarkupLanguage;
    //   144: iconst_0
    //   145: invokevirtual 107	org/eclipse/mylyn/wikitext/core/parser/markup/MarkupLanguage:setFilterGenerativeContents	(Z)V
    //   148: aload_0
    //   149: getfield 97	org/eclipse/mylyn/wikitext/core/parser/outline/OutlineParser:markupLanguage	Lorg/eclipse/mylyn/wikitext/core/parser/markup/MarkupLanguage;
    //   152: iconst_0
    //   153: invokevirtual 106	org/eclipse/mylyn/wikitext/core/parser/markup/MarkupLanguage:setBlocksOnly	(Z)V
    //   156: aload_1
    //   157: areturn
    // Line number table:
    //   Java source line #68	-> byte code offset #0
    //   Java source line #69	-> byte code offset #18
    //   Java source line #70	-> byte code offset #34
    //   Java source line #72	-> byte code offset #36
    //   Java source line #74	-> byte code offset #44
    //   Java source line #75	-> byte code offset #52
    //   Java source line #77	-> byte code offset #63
    //   Java source line #78	-> byte code offset #72
    //   Java source line #79	-> byte code offset #86
    //   Java source line #80	-> byte code offset #95
    //   Java source line #81	-> byte code offset #101
    //   Java source line #82	-> byte code offset #110
    //   Java source line #83	-> byte code offset #119
    //   Java source line #84	-> byte code offset #121
    //   Java source line #85	-> byte code offset #129
    //   Java source line #86	-> byte code offset #137
    //   Java source line #84	-> byte code offset #140
    //   Java source line #85	-> byte code offset #148
    //   Java source line #88	-> byte code offset #156
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	158	0	this	OutlineParser
    //   0	158	1	root	OutlineItem
    //   0	158	2	markup	String
    //   71	27	3	outlineBuilder	OutlineBuilder
    //   93	18	4	markupParser	org.eclipse.mylyn.wikitext.core.parser.MarkupParser
    //   119	19	5	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   63	119	119	finally
  }
  
  protected boolean isBlocksOnly()
  {
    return true;
  }
  
  protected OutlineItem createOutlineItem(OutlineItem current, int level, String id, int offset, int length, String label)
  {
    return new OutlineItem(current, level, id, offset, length, label);
  }
  
  public DocumentBuilder createOutlineUpdater(OutlineItem rootItem)
  {
    return new OutlineBuilder(rootItem, labelMaxLength);
  }
  
  protected class OutlineBuilder
    extends DocumentBuilder
  {
    private OutlineItem currentItem;
    private int level;
    private StringBuilder buf;
    protected final IdGenerator idGenerator = new IdGenerator();
    private int offset;
    private int length;
    private final OutlineItem rootItem;
    private final int labelMaxLength;
    private Attributes attributes;
    
    public OutlineBuilder(OutlineItem root, int labelMaxLength)
    {
      currentItem = root;
      rootItem = root;
      this.labelMaxLength = labelMaxLength;
    }
    
    public void acronym(String text, String definition) {}
    
    public void beginBlock(DocumentBuilder.BlockType type, Attributes attributes)
    {
      registerId(attributes.getId());
    }
    
    public void beginDocument()
    {
      rootItem.clear();
      currentItem = rootItem;
    }
    
    public void beginHeading(int level, Attributes attributes)
    {
      this.level = level;
      this.attributes = attributes;
      buf = new StringBuilder();
      offset = getLocator().getDocumentOffset();
      length = getLocator().getLineLength();
    }
    
    public void beginSpan(DocumentBuilder.SpanType type, Attributes attributes)
    {
      registerId(attributes.getId());
    }
    
    public void characters(String text)
    {
      if (buf != null) {
        buf.append(text);
      }
    }
    
    public void charactersUnescaped(String literal)
    {
      if (buf != null) {
        buf.append(literal);
      }
    }
    
    public void endBlock() {}
    
    public void endDocument() {}
    
    public void endHeading()
    {
      boolean includeInToc = true;
      if ((attributes instanceof HeadingAttributes))
      {
        HeadingAttributes headingAttributes = (HeadingAttributes)attributes;
        if (headingAttributes.isOmitFromTableOfContents()) {
          includeInToc = false;
        }
      }
      if (includeInToc)
      {
        String label = buf.toString();
        String fullLabelText = label;
        if (label == null) {
          label = "";
        } else if ((labelMaxLength > 0) && (label.length() > labelMaxLength)) {
          label = label.substring(0, labelMaxLength) + "...";
        }
        String kind = "h" + level;
        while (level <= currentItem.getLevel()) {
          currentItem = currentItem.getParent();
        }
        String id = attributes.getId();
        if (id != null) {
          idGenerator.reserveId(id);
        } else {
          id = idGenerator.newId(kind, fullLabelText);
        }
        currentItem = createOutlineItem(currentItem, level, id, offset, length, label);
        currentItem.setTooltip(fullLabelText);
        currentItem.setKind(kind);
      }
      else
      {
        registerId(attributes.getId());
      }
      buf = null;
      offset = 0;
      length = 0;
      attributes = null;
    }
    
    public void endSpan() {}
    
    public void entityReference(String entity) {}
    
    public void image(Attributes attributes, String url)
    {
      registerId(attributes.getId());
    }
    
    public void imageLink(Attributes linkAttributes, Attributes imageAttributes, String href, String imageUrl)
    {
      registerId(linkAttributes.getId());
      registerId(imageAttributes.getId());
    }
    
    public void lineBreak() {}
    
    public void link(Attributes attributes, String hrefOrHashName, String text)
    {
      registerId(attributes.getId());
      if (buf != null) {
        buf.append(text);
      }
    }
    
    private void registerId(String id)
    {
      idGenerator.reserveId(id);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.wikitext.core.parser.outline.OutlineParser
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.wikitext.core.parser.builder;

import org.eclipse.mylyn.wikitext.core.util.FormattingXMLStreamWriter;
import org.eclipse.mylyn.wikitext.core.util.XmlStreamWriter;

class HtmlDocumentBuilder$1
  extends FormattingXMLStreamWriter
{
  HtmlDocumentBuilder$1(XmlStreamWriter $anonymous0)
  {
    super($anonymous0);
  }
  
  protected boolean preserveWhitespace(String elementName)
  {
    return (elementName.equals("pre")) || (elementName.equals("code"));
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.wikitext.core.parser.builder.HtmlDocumentBuilder.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.wikitext.core.parser.builder;

import org.eclipse.mylyn.wikitext.core.parser.Attributes;

class DocBookDocumentBuilder$3
  implements DocBookDocumentBuilder.ContentEmitter
{
  DocBookDocumentBuilder$3(DocBookDocumentBuilder paramDocBookDocumentBuilder, Attributes paramAttributes, String paramString) {}
  
  public void emit()
  {
    DocBookDocumentBuilder.access$2(this$0, val$imageAttributes, val$imageUrl, true);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.wikitext.core.parser.builder.DocBookDocumentBuilder.3
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.wikitext.core.parser.builder;

import org.eclipse.mylyn.wikitext.core.parser.Attributes;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.BlockType;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.SpanType;

public class NoOpDocumentBuilder
  extends DocumentBuilder
{
  public void acronym(String text, String definition) {}
  
  public void beginBlock(DocumentBuilder.BlockType type, Attributes attributes) {}
  
  public void beginDocument() {}
  
  public void beginHeading(int level, Attributes attributes) {}
  
  public void beginSpan(DocumentBuilder.SpanType type, Attributes attributes) {}
  
  public void characters(String text) {}
  
  public void charactersUnescaped(String literal) {}
  
  public void endBlock() {}
  
  public void endDocument() {}
  
  public void endHeading() {}
  
  public void endSpan() {}
  
  public void entityReference(String entity) {}
  
  public void image(Attributes attributes, String url) {}
  
  public void imageLink(Attributes linkAttributes, Attributes imageAttributes, String href, String imageUrl) {}
  
  public void lineBreak() {}
  
  public void link(Attributes attributes, String hrefOrHashName, String text) {}
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.wikitext.core.parser.builder.NoOpDocumentBuilder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.wikitext.core.parser.builder;

import java.util.logging.Logger;
import org.eclipse.mylyn.wikitext.core.parser.Attributes;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.BlockType;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.SpanType;

public class EventLoggingDocumentBuilder
  extends DocumentBuilder
{
  private final Logger logger = Logger.getLogger(EventLoggingDocumentBuilder.class.getName());
  private int blockDepth = 0;
  
  public void acronym(String text, String definition)
  {
    logger.info("ACRONYM:" + text + "," + definition);
  }
  
  public void beginBlock(DocumentBuilder.BlockType type, Attributes attributes)
  {
    blockDepth += 1;
    logger.info("BLOCK START[" + blockDepth + "]:" + type);
  }
  
  public void beginDocument()
  {
    logger.info("DOCUMENT START");
  }
  
  public void beginHeading(int level, Attributes attributes)
  {
    logger.info("HEADING START:" + level);
  }
  
  public void beginSpan(DocumentBuilder.SpanType type, Attributes attributes)
  {
    logger.info("SPAN START:" + type);
  }
  
  public void characters(String text)
  {
    logger.info("CHARACTERS:" + text);
  }
  
  public void charactersUnescaped(String text)
  {
    logger.info("HTML LITERAL:" + text);
  }
  
  public void endBlock()
  {
    logger.info("END BLOCK[" + blockDepth + "]");
    blockDepth -= 1;
  }
  
  public void endDocument()
  {
    logger.info("END DOCUMENT");
  }
  
  public void endHeading()
  {
    logger.info("END HEADING");
  }
  
  public void endSpan()
  {
    logger.info("END SPAN");
  }
  
  public void entityReference(String entity)
  {
    logger.info("ENTITY: " + entity);
  }
  
  public void image(Attributes attributes, String url)
  {
    logger.info("IMAGE: " + url);
  }
  
  public void imageLink(Attributes linkAttributes, Attributes imageAttributes, String href, String imageUrl)
  {
    logger.info("IMAGE LINK: " + href + ", " + imageUrl);
  }
  
  public void lineBreak()
  {
    logger.info("LINE BREAK");
  }
  
  public void link(Attributes attributes, String hrefOrHashName, String text)
  {
    logger.info("LINK: " + hrefOrHashName + ", " + text);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.wikitext.core.parser.builder.EventLoggingDocumentBuilder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.wikitext.core.parser.builder;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.net.URI;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.mylyn.wikitext.core.parser.Attributes;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.BlockType;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.SpanType;
import org.eclipse.mylyn.wikitext.core.parser.ImageAttributes;
import org.eclipse.mylyn.wikitext.core.parser.ImageAttributes.Align;
import org.eclipse.mylyn.wikitext.core.parser.LinkAttributes;
import org.eclipse.mylyn.wikitext.core.parser.ListAttributes;
import org.eclipse.mylyn.wikitext.core.parser.QuoteAttributes;
import org.eclipse.mylyn.wikitext.core.parser.TableAttributes;
import org.eclipse.mylyn.wikitext.core.parser.TableCellAttributes;
import org.eclipse.mylyn.wikitext.core.parser.TableRowAttributes;
import org.eclipse.mylyn.wikitext.core.util.DefaultXmlStreamWriter;
import org.eclipse.mylyn.wikitext.core.util.FormattingXMLStreamWriter;
import org.eclipse.mylyn.wikitext.core.util.XmlStreamWriter;

public class HtmlDocumentBuilder
  extends AbstractXmlDocumentBuilder
{
  private static final Pattern ABSOLUTE_URL_PATTERN = Pattern.compile("[a-zA-Z]{3,8}://?.*");
  private static final Map<String, String> entityReferenceToNumericEquivalent = new HashMap();
  private static final Map<DocumentBuilder.SpanType, String> spanTypeToElementName;
  private static final Map<DocumentBuilder.BlockType, ElementInfo> blockTypeToElementInfo;
  
  static
  {
    entityReferenceToNumericEquivalent.put("nbsp", "#160");
    entityReferenceToNumericEquivalent.put("iexcl", "#161");
    entityReferenceToNumericEquivalent.put("cent", "#162");
    entityReferenceToNumericEquivalent.put("pound", "#163");
    entityReferenceToNumericEquivalent.put("curren", "#164");
    entityReferenceToNumericEquivalent.put("yen", "#165");
    entityReferenceToNumericEquivalent.put("brvbar", "#166");
    entityReferenceToNumericEquivalent.put("sect", "#167");
    entityReferenceToNumericEquivalent.put("uml", "#168");
    entityReferenceToNumericEquivalent.put("copy", "#169");
    entityReferenceToNumericEquivalent.put("ordf", "#170");
    entityReferenceToNumericEquivalent.put("laquo", "#171");
    entityReferenceToNumericEquivalent.put("not", "#172");
    entityReferenceToNumericEquivalent.put("shy", "#173");
    entityReferenceToNumericEquivalent.put("reg", "#174");
    entityReferenceToNumericEquivalent.put("macr", "#175");
    entityReferenceToNumericEquivalent.put("deg", "#176");
    entityReferenceToNumericEquivalent.put("plusmn", "#177");
    entityReferenceToNumericEquivalent.put("sup2", "#178");
    entityReferenceToNumericEquivalent.put("sup3", "#179");
    entityReferenceToNumericEquivalent.put("acute", "#180");
    entityReferenceToNumericEquivalent.put("micro", "#181");
    entityReferenceToNumericEquivalent.put("para", "#182");
    entityReferenceToNumericEquivalent.put("middot", "#183");
    entityReferenceToNumericEquivalent.put("cedil", "#184");
    entityReferenceToNumericEquivalent.put("sup1", "#185");
    entityReferenceToNumericEquivalent.put("ordm", "#186");
    entityReferenceToNumericEquivalent.put("raquo", "#187");
    entityReferenceToNumericEquivalent.put("frac14", "#188");
    entityReferenceToNumericEquivalent.put("frac12", "#189");
    entityReferenceToNumericEquivalent.put("frac34", "#190");
    entityReferenceToNumericEquivalent.put("iquest", "#191");
    entityReferenceToNumericEquivalent.put("times", "#215");
    entityReferenceToNumericEquivalent.put("divide", "#247");
    entityReferenceToNumericEquivalent.put("Agrave", "#192");
    entityReferenceToNumericEquivalent.put("Aacute", "#193");
    entityReferenceToNumericEquivalent.put("Acirc", "#194");
    entityReferenceToNumericEquivalent.put("Atilde", "#195");
    entityReferenceToNumericEquivalent.put("Auml", "#196");
    entityReferenceToNumericEquivalent.put("Aring", "#197");
    entityReferenceToNumericEquivalent.put("AElig", "#198");
    entityReferenceToNumericEquivalent.put("Ccedil", "#199");
    entityReferenceToNumericEquivalent.put("Egrave", "#200");
    entityReferenceToNumericEquivalent.put("Eacute", "#201");
    entityReferenceToNumericEquivalent.put("Ecirc", "#202");
    entityReferenceToNumericEquivalent.put("Euml", "#203");
    entityReferenceToNumericEquivalent.put("Igrave", "#204");
    entityReferenceToNumericEquivalent.put("Iacute", "#205");
    entityReferenceToNumericEquivalent.put("Icirc", "#206");
    entityReferenceToNumericEquivalent.put("Iuml", "#207");
    entityReferenceToNumericEquivalent.put("ETH", "#208");
    entityReferenceToNumericEquivalent.put("Ntilde", "#209");
    entityReferenceToNumericEquivalent.put("Ograve", "#210");
    entityReferenceToNumericEquivalent.put("Oacute", "#211");
    entityReferenceToNumericEquivalent.put("Ocirc", "#212");
    entityReferenceToNumericEquivalent.put("Otilde", "#213");
    entityReferenceToNumericEquivalent.put("Ouml", "#214");
    entityReferenceToNumericEquivalent.put("Oslash", "#216");
    entityReferenceToNumericEquivalent.put("Ugrave", "#217");
    entityReferenceToNumericEquivalent.put("Uacute", "#218");
    entityReferenceToNumericEquivalent.put("Ucirc", "#219");
    entityReferenceToNumericEquivalent.put("Uuml", "#220");
    entityReferenceToNumericEquivalent.put("Yacute", "#221");
    entityReferenceToNumericEquivalent.put("THORN", "#222");
    entityReferenceToNumericEquivalent.put("szlig", "#223");
    entityReferenceToNumericEquivalent.put("agrave", "#224");
    entityReferenceToNumericEquivalent.put("aacute", "#225");
    entityReferenceToNumericEquivalent.put("acirc", "#226");
    entityReferenceToNumericEquivalent.put("atilde", "#227");
    entityReferenceToNumericEquivalent.put("auml", "#228");
    entityReferenceToNumericEquivalent.put("aring", "#229");
    entityReferenceToNumericEquivalent.put("aelig", "#230");
    entityReferenceToNumericEquivalent.put("ccedil", "#231");
    entityReferenceToNumericEquivalent.put("egrave", "#232");
    entityReferenceToNumericEquivalent.put("eacute", "#233");
    entityReferenceToNumericEquivalent.put("ecirc", "#234");
    entityReferenceToNumericEquivalent.put("euml", "#235");
    entityReferenceToNumericEquivalent.put("igrave", "#236");
    entityReferenceToNumericEquivalent.put("iacute", "#237");
    entityReferenceToNumericEquivalent.put("icirc", "#238");
    entityReferenceToNumericEquivalent.put("iuml", "#239");
    entityReferenceToNumericEquivalent.put("eth", "#240");
    entityReferenceToNumericEquivalent.put("ntilde", "#241");
    entityReferenceToNumericEquivalent.put("ograve", "#242");
    entityReferenceToNumericEquivalent.put("oacute", "#243");
    entityReferenceToNumericEquivalent.put("ocirc", "#244");
    entityReferenceToNumericEquivalent.put("otilde", "#245");
    entityReferenceToNumericEquivalent.put("ouml", "#246");
    entityReferenceToNumericEquivalent.put("oslash", "#248");
    entityReferenceToNumericEquivalent.put("ugrave", "#249");
    entityReferenceToNumericEquivalent.put("uacute", "#250");
    entityReferenceToNumericEquivalent.put("ucirc", "#251");
    entityReferenceToNumericEquivalent.put("uuml", "#252");
    entityReferenceToNumericEquivalent.put("yacute", "#253");
    entityReferenceToNumericEquivalent.put("thorn", "#254");
    entityReferenceToNumericEquivalent.put("yuml", "#255");
    
    spanTypeToElementName = new HashMap();
    
    spanTypeToElementName.put(DocumentBuilder.SpanType.LINK, "a");
    spanTypeToElementName.put(DocumentBuilder.SpanType.BOLD, "b");
    spanTypeToElementName.put(DocumentBuilder.SpanType.CITATION, "cite");
    spanTypeToElementName.put(DocumentBuilder.SpanType.ITALIC, "i");
    spanTypeToElementName.put(DocumentBuilder.SpanType.EMPHASIS, "em");
    spanTypeToElementName.put(DocumentBuilder.SpanType.STRONG, "strong");
    spanTypeToElementName.put(DocumentBuilder.SpanType.DELETED, "del");
    spanTypeToElementName.put(DocumentBuilder.SpanType.INSERTED, "ins");
    spanTypeToElementName.put(DocumentBuilder.SpanType.QUOTE, "q");
    spanTypeToElementName.put(DocumentBuilder.SpanType.UNDERLINED, "u");
    spanTypeToElementName.put(DocumentBuilder.SpanType.SUPERSCRIPT, "sup");
    spanTypeToElementName.put(DocumentBuilder.SpanType.SUBSCRIPT, "sub");
    spanTypeToElementName.put(DocumentBuilder.SpanType.SPAN, "span");
    spanTypeToElementName.put(DocumentBuilder.SpanType.CODE, "code");
    spanTypeToElementName.put(DocumentBuilder.SpanType.MONOSPACE, "tt");
    
    blockTypeToElementInfo = new HashMap();
    
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.BULLETED_LIST, new ElementInfo("ul"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.CODE, new ElementInfo("code"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.DIV, new ElementInfo("div"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.FOOTNOTE, new ElementInfo("footnote"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.LIST_ITEM, new ElementInfo("li"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.NUMERIC_LIST, new ElementInfo("ol"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.DEFINITION_LIST, new ElementInfo("dl"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.DEFINITION_TERM, new ElementInfo("dt"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.DEFINITION_ITEM, new ElementInfo("dd"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.PARAGRAPH, new ElementInfo("p"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.PREFORMATTED, new ElementInfo("pre"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.QUOTE, new ElementInfo("blockquote"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.TABLE, new ElementInfo("table"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.TABLE_CELL_HEADER, new ElementInfo("th"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.TABLE_CELL_NORMAL, new ElementInfo("td"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.TABLE_ROW, new ElementInfo("tr"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.TIP, new ElementInfo("div", "tip", 
      "border: 1px solid #090;background-color: #dfd;margin: 20px;padding: 0px 6px 0px 6px;"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.WARNING, new ElementInfo("div", "warning", 
      "border: 1px solid #c00;background-color: #fcc;margin: 20px;padding: 0px 6px 0px 6px;"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.INFORMATION, new ElementInfo("div", "info", 
      "border: 1px solid #3c78b5;background-color: #D8E4F1;margin: 20px;padding: 0px 6px 0px 6px;"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.NOTE, new ElementInfo("div", "note", 
      "border: 1px solid #F0C000;background-color: #FFFFCE;margin: 20px;padding: 0px 6px 0px 6px;"));
    blockTypeToElementInfo.put(DocumentBuilder.BlockType.PANEL, new ElementInfo("div", "panel", 
      "border: 1px solid #ccc;background-color: #FFFFCE;margin: 10px;padding: 0px 6px 0px 6px;"));
  }
  
  private String htmlNsUri = "http://www.w3.org/1999/xhtml";
  private String htmlDtd = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
  private boolean xhtmlStrict = false;
  private boolean emitAsDocument = true;
  private boolean emitDtd = false;
  private String encoding = "utf-8";
  private String title;
  private String defaultAbsoluteLinkTarget;
  private List<Stylesheet> stylesheets = null;
  private boolean useInlineStyles = true;
  private boolean suppressBuiltInStyles = false;
  private String linkRel;
  private String prependImagePrefix;
  private boolean filterEntityReferences = false;
  
  public HtmlDocumentBuilder(Writer out)
  {
    this(out, false);
  }
  
  public HtmlDocumentBuilder(Writer out, boolean formatting)
  {
    super(formatting ? createFormattingXmlStreamWriter(out) : new DefaultXmlStreamWriter(out));
  }
  
  public HtmlDocumentBuilder(XmlStreamWriter writer)
  {
    super(writer);
  }
  
  public void copyConfiguration(HtmlDocumentBuilder other)
  {
    other.setBase(getBase());
    other.setBaseInHead(isBaseInHead());
    other.setDefaultAbsoluteLinkTarget(getDefaultAbsoluteLinkTarget());
    other.setEmitAsDocument(isEmitAsDocument());
    other.setEmitDtd(isEmitDtd());
    other.setHtmlDtd(getHtmlDtd());
    other.setHtmlNsUri(getHtmlNsUri());
    other.setLinkRel(getLinkRel());
    other.setTitle(getTitle());
    other.setUseInlineStyles(isUseInlineStyles());
    other.setSuppressBuiltInStyles(isSuppressBuiltInStyles());
    other.setXhtmlStrict(xhtmlStrict);
    other.setPrependImagePrefix(prependImagePrefix);
    if (stylesheets != null)
    {
      stylesheets = new ArrayList();
      stylesheets.addAll(stylesheets);
    }
  }
  
  protected static XmlStreamWriter createFormattingXmlStreamWriter(Writer out)
  {
    new FormattingXMLStreamWriter(new DefaultXmlStreamWriter(out))
    {
      protected boolean preserveWhitespace(String elementName)
      {
        return (elementName.equals("pre")) || (elementName.equals("code"));
      }
    };
  }
  
  public String getHtmlNsUri()
  {
    return htmlNsUri;
  }
  
  public void setHtmlNsUri(String htmlNsUri)
  {
    this.htmlNsUri = htmlNsUri;
  }
  
  public String getHtmlDtd()
  {
    return htmlDtd;
  }
  
  public void setHtmlDtd(String htmlDtd)
  {
    this.htmlDtd = htmlDtd;
  }
  
  public boolean isEmitAsDocument()
  {
    return emitAsDocument;
  }
  
  public void setEmitAsDocument(boolean emitAsDocument)
  {
    this.emitAsDocument = emitAsDocument;
  }
  
  public boolean isEmitDtd()
  {
    return emitDtd;
  }
  
  public void setEmitDtd(boolean emitDtd)
  {
    this.emitDtd = emitDtd;
  }
  
  public String getEncoding()
  {
    return encoding;
  }
  
  public void setEncoding(String encoding)
  {
    this.encoding = encoding;
  }
  
  public String getTitle()
  {
    return title;
  }
  
  public void setTitle(String title)
  {
    this.title = title;
  }
  
  public String getDefaultAbsoluteLinkTarget()
  {
    return defaultAbsoluteLinkTarget;
  }
  
  public void setDefaultAbsoluteLinkTarget(String defaultAbsoluteLinkTarget)
  {
    this.defaultAbsoluteLinkTarget = defaultAbsoluteLinkTarget;
  }
  
  public boolean isXhtmlStrict()
  {
    return xhtmlStrict;
  }
  
  public void setXhtmlStrict(boolean xhtmlStrict)
  {
    this.xhtmlStrict = xhtmlStrict;
  }
  
  @Deprecated
  public void addCssStylesheet(String url)
  {
    addCssStylesheet(new Stylesheet(url));
  }
  
  @Deprecated
  public void addCssStylesheet(File file)
  {
    addCssStylesheet(new Stylesheet(file));
  }
  
  public void addCssStylesheet(Stylesheet stylesheet)
  {
    if (file != null) {
      checkFileReadable(file);
    }
    if (stylesheets == null) {
      stylesheets = new ArrayList();
    }
    stylesheets.add(stylesheet);
  }
  
  protected void checkFileReadable(File file)
  {
    if (!file.exists()) {
      throw new IllegalArgumentException(MessageFormat.format(Messages.getString("HtmlDocumentBuilder.3"), new Object[] { file }));
    }
    if (!file.isFile()) {
      throw new IllegalArgumentException(MessageFormat.format(Messages.getString("HtmlDocumentBuilder.1"), new Object[] { file }));
    }
    if (!file.canRead()) {
      throw new IllegalArgumentException(MessageFormat.format(Messages.getString("HtmlDocumentBuilder.2"), new Object[] { file }));
    }
  }
  
  public boolean isUseInlineStyles()
  {
    return useInlineStyles;
  }
  
  public void setUseInlineStyles(boolean useInlineStyles)
  {
    this.useInlineStyles = useInlineStyles;
  }
  
  public boolean isSuppressBuiltInStyles()
  {
    return suppressBuiltInStyles;
  }
  
  public void setSuppressBuiltInStyles(boolean suppressBuiltInStyles)
  {
    this.suppressBuiltInStyles = suppressBuiltInStyles;
  }
  
  public String getLinkRel()
  {
    return linkRel;
  }
  
  public void setLinkRel(String linkRel)
  {
    this.linkRel = linkRel;
  }
  
  public void beginDocument()
  {
    writer.setDefaultNamespace(htmlNsUri);
    if (emitAsDocument)
    {
      if ((encoding != null) && (encoding.length() > 0)) {
        writer.writeStartDocument(encoding, "1.0");
      } else {
        writer.writeStartDocument();
      }
      if ((emitDtd) && (htmlDtd != null)) {
        writer.writeDTD(htmlDtd);
      }
      writer.writeStartElement(htmlNsUri, "html");
      writer.writeDefaultNamespace(htmlNsUri);
      
      writer.writeStartElement(htmlNsUri, "head");
      emitHeadContents();
      writer.writeEndElement();
      beginBody();
    }
    else if ((stylesheets != null) && (!stylesheets.isEmpty()))
    {
      throw new IllegalStateException(Messages.getString("HtmlDocumentBuilder.0"));
    }
  }
  
  protected void emitHeadContents()
  {
    if ((encoding != null) && (encoding.length() > 0))
    {
      writer.writeEmptyElement(htmlNsUri, "meta");
      writer.writeAttribute("http-equiv", "Content-Type");
      writer.writeAttribute("content", String.format("text/html; charset=%s", new Object[] { encoding }));
    }
    if ((base != null) && (baseInHead))
    {
      writer.writeEmptyElement(htmlNsUri, "base");
      writer.writeAttribute("href", base.toString());
    }
    if (title != null)
    {
      writer.writeStartElement(htmlNsUri, "title");
      writer.writeCharacters(title);
      writer.writeEndElement();
    }
    if ((!useInlineStyles) && (!suppressBuiltInStyles))
    {
      writer.writeStartElement(htmlNsUri, "style");
      writer.writeAttribute("type", "text/css");
      writer.writeCharacters("\n");
      for (Map.Entry<DocumentBuilder.BlockType, ElementInfo> ent : blockTypeToElementInfo.entrySet())
      {
        ElementInfo elementInfo = (ElementInfo)ent.getValue();
        if ((cssStyles != null) && (cssClass != null))
        {
          String[] classes = cssClass.split("\\s+");
          String[] arrayOfString1;
          int j = (arrayOfString1 = classes).length;
          for (int i = 0; i < j; i++)
          {
            String cssClass = arrayOfString1[i];
            writer.writeCharacters(".");
            writer.writeCharacters(cssClass);
            writer.writeCharacters(" ");
          }
          writer.writeCharacters("{");
          writer.writeCharacters(cssStyles);
          writer.writeCharacters("}\n");
        }
      }
      writer.writeEndElement();
    }
    if (stylesheets != null) {
      for (Stylesheet stylesheet : stylesheets) {
        emitStylesheet(stylesheet);
      }
    }
  }
  
  private void emitStylesheet(Stylesheet stylesheet)
  {
    if (url != null)
    {
      writer.writeEmptyElement(htmlNsUri, "link");
      writer.writeAttribute("type", "text/css");
      writer.writeAttribute("rel", "stylesheet");
      writer.writeAttribute("href", makeUrlAbsolute(url));
      for (Map.Entry<String, String> attr : attributes.entrySet())
      {
        String attrName = (String)attr.getKey();
        if ((!"type".equals(attrName)) && (!"rel".equals(attrName)) && (!"href".equals(attrName))) {
          writer.writeAttribute(attrName, (String)attr.getValue());
        }
      }
    }
    else
    {
      writer.writeStartElement(htmlNsUri, "style");
      writer.writeAttribute("type", "text/css");
      for (Map.Entry<String, String> attr : attributes.entrySet())
      {
        String attrName = (String)attr.getKey();
        if (!"type".equals(attrName)) {
          writer.writeAttribute(attrName, (String)attr.getValue());
        }
      }
      if (file != null) {
        try
        {
          css = readFully(file);
        }
        catch (IOException e)
        {
          String css;
          throw new IllegalStateException(MessageFormat.format(Messages.getString("HtmlDocumentBuilder.4"), new Object[] {
            file }), e);
        }
      } else {
        try
        {
          css = readFully(reader, 1024);
        }
        catch (IOException e)
        {
          String css;
          throw new IllegalStateException(Messages.getString("HtmlDocumentBuilder.5"), e);
        }
      }
      String css;
      writer.writeCharacters(css);
      writer.writeEndElement();
    }
  }
  
  public void endDocument()
  {
    if (emitAsDocument)
    {
      endBody();
      writer.writeEndElement();
      writer.writeEndDocument();
    }
    writer.close();
  }
  
  protected void beginBody()
  {
    writer.writeStartElement(htmlNsUri, "body");
  }
  
  protected void endBody()
  {
    writer.writeEndElement();
  }
  
  public void entityReference(String entity)
  {
    if (filterEntityReferences)
    {
      String emitEntity = (entity.length() > 0) && (entity.charAt(0) == '#') ? 
        entity : 
        (String)entityReferenceToNumericEquivalent.get(entity);
      if (emitEntity == null)
      {
        writer.writeCharacters("&");
        writer.writeCharacters(entity);
        writer.writeCharacters(";");
      }
      else
      {
        writer.writeEntityRef(emitEntity);
      }
    }
    else
    {
      writer.writeEntityRef(entity);
    }
  }
  
  public void acronym(String text, String definition)
  {
    writer.writeStartElement(htmlNsUri, "acronym");
    writer.writeAttribute("title", definition);
    writer.writeCharacters(text);
    writer.writeEndElement();
  }
  
  public void link(Attributes attributes, String hrefOrHashName, String text)
  {
    writer.writeStartElement(htmlNsUri, "a");
    emitAnchorHref(hrefOrHashName);
    applyLinkAttributes(attributes, hrefOrHashName);
    characters(text);
    writer.writeEndElement();
  }
  
  public void beginBlock(DocumentBuilder.BlockType type, Attributes attributes)
  {
    ElementInfo elementInfo = (ElementInfo)blockTypeToElementInfo.get(type);
    if (elementInfo == null) {
      throw new IllegalStateException(type.name());
    }
    writer.writeStartElement(htmlNsUri, name);
    if (cssClass != null) {
      if (attributes.getCssClass() == null) {
        attributes.setCssClass(cssClass);
      } else {
        attributes.setCssClass(cssClass + ' ' + attributes.getCssClass());
      }
    }
    if ((useInlineStyles) && (!suppressBuiltInStyles) && (cssStyles != null)) {
      if (attributes.getCssStyle() == null) {
        attributes.setCssStyle(cssStyles);
      } else {
        attributes.setCssStyle(cssStyles + attributes.getCssStyle());
      }
    }
    if (type == DocumentBuilder.BlockType.TABLE)
    {
      applyTableAttributes(attributes);
    }
    else if (type == DocumentBuilder.BlockType.TABLE_ROW)
    {
      applyTableRowAttributes(attributes);
    }
    else if ((type == DocumentBuilder.BlockType.TABLE_CELL_HEADER) || (type == DocumentBuilder.BlockType.TABLE_CELL_NORMAL))
    {
      applyCellAttributes(attributes);
    }
    else if ((type == DocumentBuilder.BlockType.BULLETED_LIST) || (type == DocumentBuilder.BlockType.NUMERIC_LIST))
    {
      applyListAttributes(attributes);
    }
    else if (type == DocumentBuilder.BlockType.QUOTE)
    {
      applyQuoteAttributes(attributes);
    }
    else
    {
      applyAttributes(attributes);
      if (attributes.getTitle() != null)
      {
        beginBlock(DocumentBuilder.BlockType.PARAGRAPH, new Attributes());
        beginSpan(DocumentBuilder.SpanType.BOLD, new Attributes());
        characters(attributes.getTitle());
        endSpan();
        endBlock();
      }
    }
  }
  
  public void beginHeading(int level, Attributes attributes)
  {
    if (level > 6) {
      level = 6;
    }
    writer.writeStartElement(htmlNsUri, "h" + level);
    applyAttributes(attributes);
  }
  
  public void beginSpan
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd