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

er.html;

import java.util.ArrayList;
import java.util.List;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.nodes.TextNode;

public abstract class DocumentProcessor
{
  public abstract void process(Document paramDocument);
  
  protected static void normalizeTextNodes(Element parentElement)
  {
    List<Node> children = parentElement.childNodes();
    if (!children.isEmpty())
    {
      children = new ArrayList(children);
      for (Node child : children) {
        if ((child instanceof TextNode))
        {
          Node previousSibling = child.previousSibling();
          if ((previousSibling instanceof TextNode))
          {
            TextNode childTextNode = (TextNode)child;
            TextNode previousSiblingTextNode = (TextNode)previousSibling;
            childTextNode.text(previousSiblingTextNode.text() + childTextNode.text());
            previousSibling.remove();
          }
        }
      }
    }
  }
}

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

import java.util.Stack;
import org.jsoup.nodes.Element;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;

class HtmlParser$EndElementHandler
  extends HtmlParser.NodeHandler
{
  private final Element element;
  
  public HtmlParser$EndElementHandler(Element element)
  {
    super(null);
    this.element = element;
  }
  
  public void process(Stack<HtmlParser.NodeHandler> stack, ContentHandler contentHandler)
    throws SAXException
  {
    contentHandler.endElement(null, element.nodeName(), element.nodeName());
  }
}

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

import org.xml.sax.Attributes;

class AbstractSaxHtmlParser$DocumentBuilderAdapter$ContentElementHandler
  extends AbstractSaxHtmlParser.DocumentBuilderAdapter.ElementHandler
{
  private AbstractSaxHtmlParser$DocumentBuilderAdapter$ContentElementHandler(AbstractSaxHtmlParser.DocumentBuilderAdapter paramDocumentBuilderAdapter)
  {
    super(paramDocumentBuilderAdapter, null);
  }
  
  public void start(Attributes atts) {}
  
  public void end() {}
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.core.parser.html.AbstractSaxHtmlParser.DocumentBuilderAdapter.ContentElementHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.core.parser.html;

import java.util.Stack;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;

class HtmlParser$EndDocumentHandler
  extends HtmlParser.NodeHandler
{
  public HtmlParser$EndDocumentHandler()
  {
    super(null);
  }
  
  public void process(Stack<HtmlParser.NodeHandler> stack, ContentHandler contentHandler)
    throws SAXException
  {
    contentHandler.endDocument();
  }
}

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

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

class AbstractSaxHtmlParser$DocumentBuilderAdapter$BlockElementHandler
  extends AbstractSaxHtmlParser.DocumentBuilderAdapter.ElementHandler
{
  private final DocumentBuilder.BlockType blockType;
  
  private AbstractSaxHtmlParser$DocumentBuilderAdapter$BlockElementHandler(AbstractSaxHtmlParser.DocumentBuilderAdapter paramDocumentBuilderAdapter, DocumentBuilder.BlockType blockType)
  {
    super(paramDocumentBuilderAdapter, null);
    this.blockType = blockType;
  }
  
  public void start(Attributes atts)
  {
    AbstractSaxHtmlParser.DocumentBuilderAdapter.access$0(this$1).beginBlock(blockType, AbstractSaxHtmlParser.access$2(AbstractSaxHtmlParser.DocumentBuilderAdapter.access$1(this$1), atts));
  }
  
  public void end()
  {
    AbstractSaxHtmlParser.DocumentBuilderAdapter.access$0(this$1).endBlock();
  }
  
  public void characters(String s)
  {
    AbstractSaxHtmlParser.DocumentBuilderAdapter.access$0(this$1).characters(s);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.core.parser.html.AbstractSaxHtmlParser.DocumentBuilderAdapter.BlockElementHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.core.parser.html;

import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.BlockType;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.AttributesImpl;

class AbstractSaxHtmlParser$DocumentBuilderAdapter$PreformattedBlockElementHandler
  extends AbstractSaxHtmlParser.DocumentBuilderAdapter.ElementHandler
{
  private Attributes atts;
  
  private AbstractSaxHtmlParser$DocumentBuilderAdapter$PreformattedBlockElementHandler(AbstractSaxHtmlParser.DocumentBuilderAdapter paramDocumentBuilderAdapter)
  {
    super(paramDocumentBuilderAdapter, null);
  }
  
  void start(Attributes atts)
  {
    this.atts = new AttributesImpl(atts);
  }
  
  void end()
  {
    if (atts == null) {
      AbstractSaxHtmlParser.DocumentBuilderAdapter.access$0(this$1).endBlock();
    }
  }
  
  void characters(String s)
  {
    if (atts != null)
    {
      AbstractSaxHtmlParser.DocumentBuilderAdapter.access$0(this$1).beginBlock(DocumentBuilder.BlockType.PREFORMATTED, AbstractSaxHtmlParser.access$2(AbstractSaxHtmlParser.DocumentBuilderAdapter.access$1(this$1), atts));
      atts = null;
    }
    super.characters(s);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.core.parser.html.AbstractSaxHtmlParser.DocumentBuilderAdapter.PreformattedBlockElementHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.core.parser.html;

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

class AbstractSaxHtmlParser$DocumentBuilderAdapter$SpanElementHandler
  extends AbstractSaxHtmlParser.DocumentBuilderAdapter.ElementHandler
{
  private final DocumentBuilder.SpanType spanType;
  private boolean noop;
  
  private AbstractSaxHtmlParser$DocumentBuilderAdapter$SpanElementHandler(AbstractSaxHtmlParser.DocumentBuilderAdapter paramDocumentBuilderAdapter, DocumentBuilder.SpanType spanType)
  {
    super(paramDocumentBuilderAdapter, null);
    this.spanType = spanType;
  }
  
  public void start(org.xml.sax.Attributes atts)
  {
    org.eclipse.mylyn.wikitext.core.parser.Attributes attributes = AbstractSaxHtmlParser.access$3(AbstractSaxHtmlParser.DocumentBuilderAdapter.access$1(this$1), spanType, atts);
    if ((spanType == DocumentBuilder.SpanType.SPAN) && (attributes.getCssClass() == null) && (attributes.getCssStyle() == null) && 
      (attributes.getId() == null)) {
      noop = true;
    } else {
      AbstractSaxHtmlParser.DocumentBuilderAdapter.access$0(this$1).beginSpan(spanType, attributes);
    }
  }
  
  public void end()
  {
    if (!noop) {
      AbstractSaxHtmlParser.DocumentBuilderAdapter.access$0(this$1).endSpan();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.core.parser.html.AbstractSaxHtmlParser.DocumentBuilderAdapter.SpanElementHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.core.parser.html;

import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.xml.sax.Attributes;

abstract class AbstractSaxHtmlParser$DocumentBuilderAdapter$ElementHandler
{
  private AbstractSaxHtmlParser$DocumentBuilderAdapter$ElementHandler(AbstractSaxHtmlParser.DocumentBuilderAdapter paramDocumentBuilderAdapter) {}
  
  abstract void start(Attributes paramAttributes);
  
  abstract void end();
  
  void characters(String s)
  {
    AbstractSaxHtmlParser.DocumentBuilderAdapter.access$0(this$1).characters(s);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.core.parser.html.AbstractSaxHtmlParser.DocumentBuilderAdapter.ElementHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.core.parser.html;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Attribute;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.nodes.TextNode;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;

public class HtmlParser
  extends AbstractSaxHtmlParser
{
  private static class TextHandler
    extends HtmlParser.NodeHandler
  {
    private final TextNode node;
    
    public TextHandler(TextNode node)
    {
      super();
      this.node = node;
    }
    
    public void process(Stack<HtmlParser.NodeHandler> stack, ContentHandler contentHandler)
      throws SAXException
    {
      String text = isPreserveWhitespace() ? node.getWholeText() : node.text();
      contentHandler.characters(text.toCharArray(), 0, text.length());
    }
    
    private boolean isPreserveWhitespace()
    {
      Node parent = node.parent();
      while (parent != null)
      {
        if (parent.nodeName().equals("pre")) {
          return true;
        }
        parent = parent.parent();
      }
      return false;
    }
  }
  
  private static class ElementHandler
    extends HtmlParser.NodeHandler
  {
    private final Element element;
    
    public ElementHandler(Element element)
    {
      super();
      this.element = element;
    }
    
    public void process(Stack<HtmlParser.NodeHandler> stack, ContentHandler contentHandler)
      throws SAXException
    {
      contentHandler.startElement(null, element.nodeName(), element.nodeName(), computeAttributes());
      
      stack.push(new HtmlParser.EndElementHandler(element));
      List<Node> childNodes = element.childNodes();
      if (!childNodes.isEmpty()) {
        for (int x = childNodes.size() - 1; x >= 0; x--)
        {
          Node child = (Node)childNodes.get(x);
          if ((child instanceof Element)) {
            stack.push(new ElementHandler((Element)child));
          } else if ((child instanceof TextNode)) {
            stack.push(new HtmlParser.TextHandler((TextNode)child));
          }
        }
      }
    }
    
    private Attributes computeAttributes()
    {
      AttributesImpl attributes = new AttributesImpl();
      for (Attribute attr : element.attributes()) {
        attributes.addAttribute(null, attr.getKey(), null, null, attr.getValue());
      }
      return attributes;
    }
  }
  
  private static class EndElementHandler
    extends HtmlParser.NodeHandler
  {
    private final Element element;
    
    public EndElementHandler(Element element)
    {
      super();
      this.element = element;
    }
    
    public void process(Stack<HtmlParser.NodeHandler> stack, ContentHandler contentHandler)
      throws SAXException
    {
      contentHandler.endElement(null, element.nodeName(), element.nodeName());
    }
  }
  
  private static class DocumentHandler
    extends HtmlParser.NodeHandler
  {
    private final Document document;
    
    public DocumentHandler(Document doc)
    {
      super();
      document = doc;
    }
    
    public void process(Stack<HtmlParser.NodeHandler> stack, ContentHandler contentHandler)
      throws SAXException
    {
      contentHandler.startDocument();
      
      stack.push(new HtmlParser.EndDocumentHandler());
      
      stack.push(new HtmlParser.ElementHandler(document.body()));
    }
  }
  
  private static class EndDocumentHandler
    extends HtmlParser.NodeHandler
  {
    public EndDocumentHandler()
    {
      super();
    }
    
    public void process(Stack<HtmlParser.NodeHandler> stack, ContentHandler contentHandler)
      throws SAXException
    {
      contentHandler.endDocument();
    }
  }
  
  private List<DocumentProcessor> processors = new ArrayList();
  
  protected void parse(InputSource input, DocumentBuilder builder, ContentHandler contentHandler)
    throws IOException, SAXException
  {
    Document document = Jsoup.parse(readContent(input));
    for (DocumentProcessor processor : processors) {
      processor.process(document);
    }
    Stack<NodeHandler> stack = new Stack();
    stack.push(new DocumentHandler(document));
    while (!stack.isEmpty())
    {
      NodeHandler handler = (NodeHandler)stack.pop();
      handler.process(stack, contentHandler);
    }
  }
  
  public List<DocumentProcessor> getProcessors()
  {
    return processors;
  }
  
  public void setProcessors(List<DocumentProcessor> processors)
  {
    this.processors = processors;
  }
  
  private String readContent(InputSource input)
    throws IOException
  {
    Reader reader = input.getCharacterStream();
    try
    {
      if (reader == null)
      {
        InputStream bytes = input.getByteStream();
        if (bytes == null)
        {
          String systemId = input.getSystemId();
          if (systemId != null) {
            bytes = new BufferedInputStream(new FileInputStream(systemId));
          }
          if (bytes == null) {
            throw new IllegalArgumentException();
          }
        }
        reader = new InputStreamReader(bytes, input.getEncoding() == null ? "utf-8" : input.getEncoding());
      }
      StringWriter writer = new StringWriter(2048);
      for (int i = reader.read(); i != -1; i = reader.read()) {
        writer.write(i);
      }
      return writer.toString();
    }
    finally
    {
      if (reader != null) {
        reader.close();
      }
    }
  }
  
  private static abstract class NodeHandler
  {
    public abstract void process(Stack<NodeHandler> paramStack, ContentHandler paramContentHandler)
      throws SAXException;
  }
}

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

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

class AbstractSaxHtmlParser$DocumentBuilderAdapter$ImageElementHandler
  extends AbstractSaxHtmlParser.DocumentBuilderAdapter.ElementHandler
{
  private AbstractSaxHtmlParser$DocumentBuilderAdapter$ImageElementHandler(AbstractSaxHtmlParser.DocumentBuilderAdapter paramDocumentBuilderAdapter)
  {
    super(paramDocumentBuilderAdapter, null);
  }
  
  public void start(org.xml.sax.Attributes atts)
  {
    org.eclipse.mylyn.wikitext.core.parser.Attributes attributes = AbstractSaxHtmlParser.access$3(AbstractSaxHtmlParser.DocumentBuilderAdapter.access$1(this$1), DocumentBuilder.SpanType.SPAN, atts);
    AbstractSaxHtmlParser.DocumentBuilderAdapter.access$0(this$1).image(attributes, AbstractSaxHtmlParser.access$4(AbstractSaxHtmlParser.DocumentBuilderAdapter.access$1(this$1), "src", atts));
  }
  
  public void end() {}
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.core.parser.html.AbstractSaxHtmlParser.DocumentBuilderAdapter.ImageElementHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.core.parser.html;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import org.eclipse.mylyn.internal.wikitext.core.util.ConcatenatingReader;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

public class XHtmlParser
  extends AbstractSaxHtmlParser
{
  protected void parse(InputSource input, DocumentBuilder builder, ContentHandler contentHandler)
    throws IOException, SAXException
  {
    if (input == null) {
      throw new IllegalArgumentException();
    }
    if (builder == null) {
      throw new IllegalArgumentException();
    }
    XMLReader xmlReader = XMLReaderFactory.createXMLReader();
    xmlReader.setContentHandler(contentHandler);
    
    Reader reader = input.getCharacterStream();
    if (reader == null)
    {
      InputStream in = input.getByteStream();
      if (in == null) {
        throw new IllegalArgumentException("input must provide a byte stream or a character stream");
      }
      reader = new InputStreamReader(in, input.getEncoding() == null ? "utf-8" : input.getEncoding());
    }
    reader = new ConcatenatingReader(new Reader[] {
      new StringReader(
      "<?xml version='1.0'?><!DOCTYPE html [ <!ENTITY nbsp \"&#160;\"> <!ENTITY copy \"&#169;\"> <!ENTITY reg \"&#174;\"> <!ENTITY euro \"&#8364;\"> ]>"), reader });
    
    input = new InputSource(reader);
    xmlReader.parse(input);
  }
}

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

import java.util.List;
import java.util.Stack;
import org.jsoup.nodes.Attribute;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.nodes.TextNode;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;

class HtmlParser$ElementHandler
  extends HtmlParser.NodeHandler
{
  private final Element element;
  
  public HtmlParser$ElementHandler(Element element)
  {
    super(null);
    this.element = element;
  }
  
  public void process(Stack<HtmlParser.NodeHandler> stack, ContentHandler contentHandler)
    throws SAXException
  {
    contentHandler.startElement(null, element.nodeName(), element.nodeName(), computeAttributes());
    
    stack.push(new HtmlParser.EndElementHandler(element));
    List<Node> childNodes = element.childNodes();
    if (!childNodes.isEmpty()) {
      for (int x = childNodes.size() - 1; x >= 0; x--)
      {
        Node child = (Node)childNodes.get(x);
        if ((child instanceof Element)) {
          stack.push(new ElementHandler((Element)child));
        } else if ((child instanceof TextNode)) {
          stack.push(new HtmlParser.TextHandler((TextNode)child));
        }
      }
    }
  }
  
  private Attributes computeAttributes()
  {
    AttributesImpl attributes = new AttributesImpl();
    for (Attribute attr : element.attributes()) {
      attributes.addAttribute(null, attr.getKey(), null, null, attr.getValue());
    }
    return attributes;
  }
}

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

import java.util.ArrayList;
import java.util.List;
import org.jsoup.nodes.Document;

public class HtmlCleaner
{
  private final List<DocumentProcessor> processors;
  
  public HtmlCleaner()
  {
    processors = new ArrayList();
    
    processors.add(new WhitespaceCleanupProcessor());
    processors.add(new RemoveEmptySpansProcessor());
    processors.add(new RemoveExcessiveStylesProcessor());
  }
  
  public void configure(HtmlParser parser)
  {
    parser.getProcessors().addAll(processors);
  }
  
  public void apply(Document document)
  {
    for (DocumentProcessor processor : processors) {
      processor.process(document);
    }
  }
}

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

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.nodes.TextNode;

class WhitespaceCleanupProcessor
  extends DocumentProcessor
{
  public void process(Document document)
  {
    Element body = document.body();
    
    Set<Node> affectedParents = new HashSet();
    for (Element element : body.getAllElements()) {
      if (!Html.isWhitespacePreserve(element))
      {
        List<Node> children = element.childNodes();
        Node lastChild;
        if (!children.isEmpty())
        {
          Node firstChild = (Node)children.get(0);
          if ((firstChild instanceof TextNode))
          {
            TextNode textNode = (TextNode)firstChild;
            String text = textNode.getWholeText();
            int nonWhitespaceIndex = firstIndexOfNonWhitespace(text);
            if (nonWhitespaceIndex > 0)
            {
              affectedParents.add(textNode.parent());
              
              textNode.splitText(nonWhitespaceIndex);
              
              textNode.remove();
              computeBeforeTarget(element).before(textNode);
              
              affectedParents.add(textNode.parent());
            }
            else if (nonWhitespaceIndex == -1)
            {
              textNode.remove();
              computeAfterTarget(element).after(textNode);
              
              affectedParents.add(textNode.parent());
            }
          }
          children = element.childNodes();
          if (!children.isEmpty())
          {
            lastChild = (Node)children.get(children.size() - 1);
            if ((lastChild instanceof TextNode))
            {
              TextNode textNode = (TextNode)lastChild;
              String text = textNode.getWholeText();
              int lastNonWhitespaceIndex = lastIndexOfNonWhitespace(text);
              if (lastNonWhitespaceIndex < 0)
              {
                textNode.remove();
                computeAfterTarget(element).after(textNode);
                
                affectedParents.add(textNode.parent());
              }
              else if (lastNonWhitespaceIndex < text.length() - 1)
              {
                affectedParents.add(textNode.parent());
                
                textNode.splitText(lastNonWhitespaceIndex + 1);
                
                textNode = (TextNode)textNode.nextSibling();
                textNode.remove();
                computeAfterTarget(element).after(textNode);
                
                affectedParents.add(textNode.parent());
              }
            }
          }
        }
        if (!affectedParents.isEmpty())
        {
          for (Node parent : affectedParents) {
            if ((parent instanceof Element)) {
              normalizeTextNodes((Element)parent);
            }
          }
          affectedParents.clear();
        }
      }
    }
  }
  
  private Element computeAfterTarget(Element element)
  {
    if ((element.parent() != null) && (!element.nodeName().equalsIgnoreCase("html")))
    {
      List<Node> elementParentChildNodes = element.parent().childNodes();
      if ((elementParentChildNodes.size() == 1) || 
        (elementParentChildNodes.get(elementParentChildNodes.size() - 1) == element)) {
        return computeAfterTarget(element.parent());
      }
    }
    return element;
  }
  
  private Element computeBeforeTarget(Element element)
  {
    if ((element.parent() != null) && (!element.parent().nodeName().equalsIgnoreCase("html")))
    {
      List<Node> elementParentChildNodes = element.parent().childNodes();
      if ((elementParentChildNodes.size() == 1) || (elementParentChildNodes.get(0) == element)) {
        return computeBeforeTarget(element.parent());
      }
    }
    return element;
  }
  
  private static int lastIndexOfNonWhitespace(String text)
  {
    int i = text.length() - 1;
    while (i > -1)
    {
      if (!Character.isWhitespace(text.charAt(i))) {
        return i;
      }
      i--;
    }
    return i;
  }
  
  private static int firstIndexOfNonWhitespace(String text)
  {
    int i = 0;
    while (i < text.length())
    {
      if (!Character.isWhitespace(text.charAt(i))) {
        return i;
      }
      i++;
    }
    return -1;
  }
}

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

import java.util.HashSet;
import java.util.Set;
import org.jsoup.nodes.Element;

class Html
{
  private static final Set<String> spanElements = new HashSet();
  
  static
  {
    spanElements.add("a");
    spanElements.add("b");
    spanElements.add("cite");
    spanElements.add("i");
    spanElements.add("em");
    spanElements.add("strong");
    spanElements.add("del");
    spanElements.add("ins");
    spanElements.add("q");
    spanElements.add("u");
    spanElements.add("sup");
    spanElements.add("sub");
    spanElements.add("span");
    spanElements.add("font");
    spanElements.add("code");
    spanElements.add("tt");
    spanElements.add("font");
  }
  
  public static boolean isSpanElement(Element element)
  {
    return spanElements.contains(element.tagName().toLowerCase());
  }
  
  public static boolean isWhitespacePreserve(Element element)
  {
    if ((element.tagName().equalsIgnoreCase("pre")) || (element.tagName().equalsIgnoreCase("code"))) {
      return true;
    }
    if (element.parent() != null) {
      return isWhitespacePreserve(element.parent());
    }
    return false;
  }
}

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

public class NoSplittingStrategy
  extends SplittingStrategy
{
  public String getSplitTarget()
  {
    return null;
  }
  
  public void heading(int level, String id, String label) {}
  
  public boolean isSplit()
  {
    return false;
  }
}

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

import java.util.Set;

final class AbstractSaxHtmlParser$ElementState
{
  final String elementName;
  final ElementState parent;
  final boolean preserveWhitespace;
  final boolean blockElement;
  final boolean noWhitespaceTextContainer;
  final boolean collapsesAdjacentWhitespace;
  
  private AbstractSaxHtmlParser$ElementState(ElementState parent, String elementName)
  {
    this.parent = parent;
    this.elementName = elementName;
    blockElement = AbstractSaxHtmlParser.access$0().contains(elementName);
    collapsesAdjacentWhitespace = AbstractSaxHtmlParser.access$1().contains(elementName);
    noWhitespaceTextContainer = "body".equals(elementName);
    preserveWhitespace = (((parent != null) && (preserveWhitespace)) || ("pre".equals(elementName)));
    if (parent != null) {
      lastChild = this;
    }
  }
  
  int childCount = 0;
  int textChildCount = 0;
  ElementState lastChild;
}

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

public abstract class SplittingStrategy
{
  public abstract void heading(int paramInt, String paramString1, String paramString2);
  
  public abstract boolean isSplit();
  
  public abstract String getSplitTarget();
}

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

import java.io.Writer;
import java.util.HashSet;
import java.util.Set;
import java.util.Stack;
import java.util.logging.Logger;
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.LinkAttributes;
import org.eclipse.mylyn.wikitext.core.parser.builder.AbstractXmlDocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.builder.DocBookDocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.outline.OutlineItem;
import org.eclipse.mylyn.wikitext.core.util.FormattingXMLStreamWriter;
import org.eclipse.mylyn.wikitext.core.util.XmlStreamWriter;

public class DitaTopicDocumentBuilder
  extends AbstractXmlDocumentBuilder
{
  private static final String __TOPIC = "__topic";
  private static Set<Integer> entityReferenceToUnicode = new HashSet();
  
  static
  {
    entityReferenceToUnicode.add(Integer.valueOf(215));
    entityReferenceToUnicode.add(Integer.valueOf(8211));
    entityReferenceToUnicode.add(Integer.valueOf(8212));
    entityReferenceToUnicode.add(Integer.valueOf(8220));
    entityReferenceToUnicode.add(Integer.valueOf(8221));
    entityReferenceToUnicode.add(Integer.valueOf(8216));
    entityReferenceToUnicode.add(Integer.valueOf(8217));
  }
  
  private final Stack<BlockDescription> blockDescriptions = new Stack();
  private String doctype = "<!DOCTYPE topic PUBLIC \"-//OASIS//DTD DITA 1.1 Topic//EN\" \"http://docs.oasis-open.org/dita/v1.1/OS/dtd/topic.dtd\">";
  private final Stack<TopicInfo> topicInfos = new Stack();
  private OutlineItem outline;
  private String filename;
  private int topicBreakLevel = Integer.MAX_VALUE;
  private String rootTitle;
  
  public DitaTopicDocumentBuilder(Writer out)
  {
    super(out);
  }
  
  public DitaTopicDocumentBuilder(XmlStreamWriter writer)
  {
    this(writer, true);
  }
  
  public DitaTopicDocumentBuilder(XmlStreamWriter writer, boolean formatting)
  {
    super(formatting ? wrapStreamWriter(writer) : writer);
  }
  
  protected XmlStreamWriter createXmlStreamWriter(Writer out)
  {
    XmlStreamWriter writer = super.createXmlStreamWriter(out);
    return wrapStreamWriter(writer);
  }
  
  private static FormattingXMLStreamWriter wrapStreamWriter(XmlStreamWriter writer)
  {
    new FormattingXMLStreamWriter(writer)
    {
      protected boolean preserveWhitespace(String elementName)
      {
        return (elementName.equals("codeblock")) || (elementName.startsWith("pre"));
      }
    };
  }
  
  public void setDoctype(String doctype)
  {
    this.doctype = doctype;
  }
  
  public String getDoctype()
  {
    return doctype;
  }
  
  public void acronym(String text, String definition)
  {
    ensureOpenTopic();
    
    writer.writeStartElement("term");
    characters(text);
    writer.writeEndElement();
  }
  
  private BlockDescription findBlockDescription(DocumentBuilder.BlockType type)
  {
    for (int x = blockDescriptions.size() - 1; x >= 0; x--)
    {
      BlockDescription blockDescription = (BlockDescription)blockDescriptions.get(x);
      if (type == type) {
        return blockDescription;
      }
    }
    return null;
  }
  
  private static class BlockDescription
  {
    DocumentBuilder.BlockType type;
    int size;
    int entrySize;
    final String[] nestedElementNames;
    final boolean closeElementsOnBlockStart;
    
    public BlockDescription(DocumentBuilder.BlockType type, int size, String[] nestedElementNames, boolean closeElementsOnBlockStart)
    {
      this.size = size;
      entrySize = (nestedElementNames == null ? 0 : nestedElementNames.length);
      this.type = type;
      this.nestedElementNames = nestedElementNames;
      this.closeElementsOnBlockStart = closeElementsOnBlockStart;
    }
  }
  
  public void beginBlock(DocumentBuilder.BlockType type, Attributes attributes)
  {
    ensureOpenTopic();
    
    String[] elementNames = null;
    boolean allowTitle = false;
    boolean closeElementsOnBlockStart = false;
    BlockDescription previousBlock = null;
    if (!blockDescriptions.isEmpty()) {
      previousBlock = (BlockDescription)blockDescriptions.peek();
    }
    boolean phraseTitle = false;
    String elementName;
    String elementName;
    String elementName;
    String elementName;
    String elementName;
    String elementName;
    String elementName;
    String elementName;
    String elementName;
    String elementName;
    String elementName;
    String elementName;
    String elementName;
    switch (type)
    {
    case PARAGRAPH: 
      elementName = "ul";
      break;
    case PANEL: 
      elementName = "ol";
      break;
    case TABLE_ROW: 
      elementName = "dl";
      break;
    case TIP: 
      BlockDescription blockDescription = findBlockDescription(DocumentBuilder.BlockType.DEFINITION_LIST);
      if (entrySize > 0) {
        endBlockEntry(blockDescription);
      }
      openBlockEntry(blockDescription, new String[] { "dlentry" });
      
      elementName = "dt";
      break;
    case WARNING: 
      String elementName = "dd";
      elementNames = new String[] { "p" };
      closeElementsOnBlockStart = true;
      break;
    case BULLETED_LIST: 
    case INFORMATION: 
      elementName = "p";
      break;
    case NOTE: 
      elementName = "codeph";
      break;
    case NUMERIC_LIST: 
      elementName = "pre";
      break;
    case LIST_ITEM: 
      elementName = "lq";
      break;
    case PREFORMATTED: 
      String elementName = "li";
      elementNames = new String[] { "p" };
      closeElementsOnBlockStart = true;
      break;
    case QUOTE: 
      elementName = "simpletable";
      break;
    case TABLE_CELL_HEADER: 
      elementName = "stentry";
      break;
    case TABLE_CELL_NORMAL: 
      elementName = "stentry";
      break;
    case TABLE: 
      elementName = "strow";
      break;
    case CODE: 
    case DEFINITION_ITEM: 
    case DEFINITION_LIST: 
    case DEFINITION_TERM: 
    case DIV: 
      String elementName = "note";
      allowTitle = true;
      phraseTitle = true;
      break;
    case FOOTNOTE: 
      elementName = null;
      break;
    default: 
      throw new IllegalStateException(type.name());
    }
    String elementName;
    int blockSize;
    if (elementName != null)
    {
      int blockSize = 1;
      if ((previousBlock != null) && (closeElementsOnBlockStart)) {
        endBlockEntry(previousBlock);
      }
      writer.writeStartElement(elementName);
      switch (type)
      {
      case DEFINITION_LIST: 
        writer.writeAttribute("type", "important");
        break;
      case DEFINITION_TERM: 
        writer.writeAttribute("type", "note");
        break;
      case DEFINITION_ITEM: 
        writer.writeAttribute("type", "caution");
        break;
      case CODE: 
        writer.writeAttribute("type", "tip");
        break;
      case DIV: 
        writer.writeAttribute("type", "other");
      }
      applyAttributes(attributes);
      if (elementNames != null)
      {
        String[] arrayOfString1;
        int j = (arrayOfString1 = elementNames).length;
        for (int i = 0; i < j; i++)
        {
          String name = arrayOfString1[i];
          writer.writeStartElement(name);
        }
      }
      if ((allowTitle) && (attributes.getTitle() != null)) {
        if (phraseTitle)
        {
          writer.writeStartElement("ph");
          writer.writeAttribute("outputclass", "title");
          writer.writeCharacters(attributes.getTitle());
          writer.writeEndElement();
        }
        else
        {
          writer.writeStartElement("title");
          writer.writeCharacters(attributes.getTitle());
          writer.writeEndElement();
        }
      }
    }
    else
    {
      blockSize = 0;
    }
    blockDescriptions.push(new BlockDescription(type, blockSize, elementNames, closeElementsOnBlockStart));
  }
  
  public void endBlock()
  {
    BlockDescription blockDescription = (BlockDescription)blockDescriptions.pop();
    int size = size + entrySize;
    for (int x = 0; x < size; x++) {
      writer.writeEndElement();
    }
  }
  
  private void endBlockEntry(BlockDescription blockDescription)
  {
    for (int x = 0; x < entrySize; x++) {
      writer.writeEndElement();
    }
    entrySize = 0;
  }
  
  private void openBlockEntry(BlockDescription blockDescription, String[] entry)
  {
    String[] arrayOfString;
    int j = (arrayOfString = entry).length;
    for (int i = 0; i < j; i++)
    {
      String ent = arrayOfString[i];
      writer.writeStartElement(ent);
    }
    entrySize += entry.length;
  }
  
  public void beginDocument()
  {
    writer.writeStartDocument();
    writer.writeDTD(doctype);
    if (rootTitle != null)
    {
      writer.writeStartElement("topic");
      writer.writeStartElement("title");
      writer.writeCharacters(rootTitle);
      writer.writeEndElement();
    }
  }
  
  public void beginHeading(int level, Attributes attributes)
  {
    closeTopics(Math.max(level - 1, 0));
    if ((topicInfos.isEmpty()) || (topicInfos.peek()).headingLevel < level))
    {
      TopicInfo topicInfo = new TopicInfo(null);
      headingLevel = level;
      openElements = 2;
      
      topicInfos.push(topicInfo);
      
      writer.writeStartElement("topic");
      if (attributes != null)
      {
        applyAttributes(attributes);
        attributes = null;
      }
      writer.writeStartElement("title");
    }
  }
  
  private void applyAttributes(Attributes attributes)
  {
    if (attributes.getId() != null) {
      writer.writeAttribute("id", attributes.getId());
    }
    if (attributes.getCssClass() != null) {
      writer.writeAttribute("outputclass", attributes.getCssClass());
    }
  }
  
  public void beginSpan(DocumentBuilder.SpanType type, Attributes attributes)
  {
    ensureOpenTopic();
    switch (type)
    {
    case CITATION: 
    case DELETED: 
      writer.writeStartElement("b");
      break;
    case EMPHASIS: 
      writer.writeStartElement("cite");
      break;
    case SPAN: 
      writer.writeStartElement("codeph");
      break;
    case INSERTED: 
      writer.writeStartElement("ph");
      attributes.setCssClass(attributes.getCssClass() + " deleted");
      break;
    case BOLD: 
      writer.writeStartElement("i");
      break;
    case ITALIC: 
      writer.writeStartElement("ph");
      attributes.setCssClass(attributes.getCssClass() + 
        " inserted");
      break;
    case SUBSCRIPT: 
      writer.writeStartElement("u");
      break;
    case CODE: 
      writer.writeStartElement("i");
      break;
    case QUOTE: 
      writer.writeStartElement("ph");
      break;
    case MONOSPACE: 
      writer.writeStartElement("sub");
      break;
    case LINK: 
      writer.writeStartElement("sup");
      break;
    case STRONG: 
      writer.writeStartElement("tt");
      break;
    case SUPERSCRIPT: 
      writer.writeStartElement("q");
      break;
    case UNDERLINED: 
      LinkAttributes linkAttributes = (LinkAttributes)attributes;
      writer.writeStartElement("xref");
      writer.writeAttribute("href", computeDitaXref(linkAttributes.getHref()));
      
      break;
    default: 
      Logger.getLogger(DocBookDocumentBuilder.class.getName()).warning("No
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-2017. Infinite Loop Ltd