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

16:47:09.040 INFO  jd.cli.Main - Decompiling org.eclipse.mylyn.wikitext.textile.core_1.6.1.v20120425-0100.jar
package org.eclipse.mylyn.wikitext.textile.core;

import java.io.Writer;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import org.eclipse.mylyn.internal.wikitext.textile.core.TextileContentState;
import org.eclipse.mylyn.internal.wikitext.textile.core.TextileDocumentBuilder;
import org.eclipse.mylyn.internal.wikitext.textile.core.block.CodeBlock;
import org.eclipse.mylyn.internal.wikitext.textile.core.block.FootnoteBlock;
import org.eclipse.mylyn.internal.wikitext.textile.core.block.HeadingBlock;
import org.eclipse.mylyn.internal.wikitext.textile.core.block.ListBlock;
import org.eclipse.mylyn.internal.wikitext.textile.core.block.NotextileBlock;
import org.eclipse.mylyn.internal.wikitext.textile.core.block.ParagraphBlock;
import org.eclipse.mylyn.internal.wikitext.textile.core.block.PreformattedBlock;
import org.eclipse.mylyn.internal.wikitext.textile.core.block.QuoteBlock;
import org.eclipse.mylyn.internal.wikitext.textile.core.block.TableBlock;
import org.eclipse.mylyn.internal.wikitext.textile.core.block.TableOfContentsBlock;
import org.eclipse.mylyn.internal.wikitext.textile.core.block.TextileGlossaryBlock;
import org.eclipse.mylyn.internal.wikitext.textile.core.phrase.EscapeTextilePhraseModifier;
import org.eclipse.mylyn.internal.wikitext.textile.core.phrase.HyperlinkPhraseModifier;
import org.eclipse.mylyn.internal.wikitext.textile.core.phrase.ImageTextilePhraseModifier;
import org.eclipse.mylyn.internal.wikitext.textile.core.phrase.SimpleTextilePhraseModifier;
import org.eclipse.mylyn.internal.wikitext.textile.core.phrase.SimpleTextilePhraseModifier.Mode;
import org.eclipse.mylyn.internal.wikitext.textile.core.token.EntityReplacementToken;
import org.eclipse.mylyn.internal.wikitext.textile.core.token.FootnoteReferenceReplacementToken;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.SpanType;
import org.eclipse.mylyn.wikitext.core.parser.MarkupParser;
import org.eclipse.mylyn.wikitext.core.parser.builder.NoOpDocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.markup.AbstractMarkupLanguage;
import org.eclipse.mylyn.wikitext.core.parser.markup.Block;
import org.eclipse.mylyn.wikitext.core.parser.markup.ContentState;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage.PatternBasedSyntax;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguageConfiguration;
import org.eclipse.mylyn.wikitext.core.parser.markup.phrase.HtmlEndTagPhraseModifier;
import org.eclipse.mylyn.wikitext.core.parser.markup.phrase.HtmlStartTagPhraseModifier;
import org.eclipse.mylyn.wikitext.core.parser.markup.token.AcronymReplacementToken;
import org.eclipse.mylyn.wikitext.core.parser.markup.token.EntityReferenceReplacementToken;
import org.eclipse.mylyn.wikitext.core.parser.markup.token.EntityWrappingReplacementToken;
import org.eclipse.mylyn.wikitext.core.parser.markup.token.PatternEntityReferenceReplacementToken;

public class TextileLanguage
  extends AbstractMarkupLanguage
{
  private static final String BUNDLE_NAME = "org.eclipse.mylyn.wikitext.textile.core.language";
  private boolean preprocessFootnotes = false;
  private TextileContentState currentState;
  
  public TextileLanguage()
  {
    setName("Textile");
  }
  
  protected void addBlockExtensions(List<Block> blocks, List<Block> paragraphBreakingBlocks)
  {
    blocks.add(new TextileGlossaryBlock());
    blocks.add(new TableOfContentsBlock());
    super.addBlockExtensions(blocks, paragraphBreakingBlocks);
  }
  
  protected ContentState createState()
  {
    if (currentState != null)
    {
      TextileContentState temp = currentState;
      currentState = null;
      return temp;
    }
    return new TextileContentState();
  }
  
  protected void addStandardBlocks(List<Block> blocks, List<Block> paragraphBreakingBlocks)
  {
    blocks.add(new HeadingBlock());
    ListBlock listBlock = new ListBlock();
    blocks.add(listBlock);
    paragraphBreakingBlocks.add(listBlock);
    blocks.add(new PreformattedBlock());
    blocks.add(new QuoteBlock());
    blocks.add(new CodeBlock());
    blocks.add(new FootnoteBlock());
    blocks.add(new NotextileBlock());
    TableBlock tableBlock = new TableBlock();
    blocks.add(tableBlock);
    paragraphBreakingBlocks.add(tableBlock);
  }
  
  protected void addStandardPhraseModifiers(MarkupLanguage.PatternBasedSyntax phraseModifierSyntax)
  {
    boolean escapingHtml = configuration == null ? false : configuration.isEscapingHtmlAndXml();
    
    phraseModifierSyntax.add(new HtmlEndTagPhraseModifier(escapingHtml));
    phraseModifierSyntax.add(new HtmlStartTagPhraseModifier(escapingHtml));
    phraseModifierSyntax.beginGroup("(?:(?<=[\\s\\.,\\\"'?!;:\\)\\(\\{\\}\\[\\]])|^)(?:", 0);
    phraseModifierSyntax.add(new EscapeTextilePhraseModifier());
    phraseModifierSyntax.add(new SimpleTextilePhraseModifier("**", DocumentBuilder.SpanType.BOLD, SimpleTextilePhraseModifier.Mode.NESTING));
    phraseModifierSyntax.add(new SimpleTextilePhraseModifier("??", DocumentBuilder.SpanType.CITATION, SimpleTextilePhraseModifier.Mode.NESTING));
    phraseModifierSyntax.add(new SimpleTextilePhraseModifier("__", DocumentBuilder.SpanType.ITALIC, SimpleTextilePhraseModifier.Mode.NESTING));
    phraseModifierSyntax.add(new SimpleTextilePhraseModifier("_", DocumentBuilder.SpanType.EMPHASIS, SimpleTextilePhraseModifier.Mode.NESTING));
    phraseModifierSyntax.add(new SimpleTextilePhraseModifier("*", DocumentBuilder.SpanType.STRONG, SimpleTextilePhraseModifier.Mode.NESTING));
    phraseModifierSyntax.add(new SimpleTextilePhraseModifier("+", DocumentBuilder.SpanType.INSERTED, SimpleTextilePhraseModifier.Mode.NESTING));
    phraseModifierSyntax.add(new SimpleTextilePhraseModifier("~", DocumentBuilder.SpanType.SUBSCRIPT, SimpleTextilePhraseModifier.Mode.NORMAL));
    phraseModifierSyntax.add(new SimpleTextilePhraseModifier("^", DocumentBuilder.SpanType.SUPERSCRIPT, SimpleTextilePhraseModifier.Mode.NORMAL));
    phraseModifierSyntax.add(new SimpleTextilePhraseModifier("@", DocumentBuilder.SpanType.CODE, SimpleTextilePhraseModifier.Mode.SPECIAL));
    phraseModifierSyntax.add(new SimpleTextilePhraseModifier("%", DocumentBuilder.SpanType.SPAN, SimpleTextilePhraseModifier.Mode.NESTING));
    phraseModifierSyntax.add(new SimpleTextilePhraseModifier("-", DocumentBuilder.SpanType.DELETED, SimpleTextilePhraseModifier.Mode.NESTING));
    phraseModifierSyntax.add(new ImageTextilePhraseModifier());
    phraseModifierSyntax.add(new HyperlinkPhraseModifier());
    phraseModifierSyntax.endGroup(")(?=\\W|$)", 0);
  }
  
  protected void addStandardTokens(MarkupLanguage.PatternBasedSyntax tokenSyntax)
  {
    tokenSyntax.add(new EntityReferenceReplacementToken("(tm)", "#8482"));
    tokenSyntax.add(new EntityReferenceReplacementToken("(TM)", "#8482"));
    tokenSyntax.add(new EntityReferenceReplacementToken("(c)", "#169"));
    tokenSyntax.add(new EntityReferenceReplacementToken("(C)", "#169"));
    tokenSyntax.add(new EntityReferenceReplacementToken("(r)", "#174"));
    tokenSyntax.add(new EntityReferenceReplacementToken("(R)", "#174"));
    tokenSyntax.add(new FootnoteReferenceReplacementToken());
    if ((configuration == null) || (!configuration.isOptimizeForRepositoryUsage()))
    {
      ResourceBundle res = ResourceBundle.getBundle(
        "org.eclipse.mylyn.wikitext.textile.core.language", 
        (configuration == null) || (configuration.getLocale() == null) ? 
        Locale.ENGLISH : 
        configuration.getLocale());
      
      tokenSyntax.add(new EntityWrappingReplacementToken(
        "\"", res.getString("quote_left"), res.getString("quote_right")));
      tokenSyntax.add(new EntityWrappingReplacementToken(
        "'", res.getString("singlequote_left"), res.getString("singlequote_right")));
      
      tokenSyntax.add(new PatternEntityReferenceReplacementToken("(?:(?<=\\w)(')(?=\\w))", "#8217"));
    }
    tokenSyntax.add(new PatternEntityReferenceReplacementToken("(?:(--)(?=\\s\\w))", "#8212"));
    tokenSyntax.add(new PatternEntityReferenceReplacementToken("(?:(?<=\\w\\s)(-)(?=\\s\\w))", "#8211"));
    tokenSyntax.add(new PatternEntityReferenceReplacementToken("(?:(?<=\\d\\s)(x)(?=\\s\\d))", "#215"));
    if ((configuration == null) || (!configuration.isOptimizeForRepositoryUsage())) {
      tokenSyntax.add(new AcronymReplacementToken());
    }
    tokenSyntax.add(new EntityReplacementToken());
  }
  
  protected Block createParagraphBlock()
  {
    ParagraphBlock paragraphBlock = new ParagraphBlock();
    if ((configuration != null) && (!configuration.isEnableUnwrappedParagraphs())) {
      paragraphBlock.setEnableUnwrapped(false);
    }
    return paragraphBlock;
  }
  
  public boolean isPreprocessFootnotes()
  {
    return preprocessFootnotes;
  }
  
  public void setPreprocessFootnotes(boolean preprocessFootnotes)
  {
    this.preprocessFootnotes = preprocessFootnotes;
  }
  
  public void configure(MarkupLanguageConfiguration configuration)
    throws UnsupportedOperationException
  {
    if (configuration.isOptimizeForRepositoryUsage()) {
      setPreprocessFootnotes(true);
    }
    super.configure(configuration);
  }
  
  public TextileLanguage clone()
  {
    TextileLanguage copy = (TextileLanguage)super.clone();
    preprocessFootnotes = preprocessFootnotes;
    return copy;
  }
  
  public void processContent(MarkupParser parser, String markupContent, boolean asDocument)
  {
    if (preprocessFootnotes)
    {
      boolean previousBlocksOnly = isBlocksOnly();
      boolean previousFilterGenerativeContents = isFilterGenerativeContents();
      setBlocksOnly(true);
      setFilterGenerativeContents(true);
      
      DocumentBuilder builder = parser.getBuilder();
      parser.setBuilder(new NoOpDocumentBuilder());
      currentState = new TextileContentState();
      TextileContentState preprocessingState = currentState;
      super.processContent(parser, markupContent, asDocument);
      
      setBlocksOnly(previousBlocksOnly);
      setFilterGenerativeContents(previousFilterGenerativeContents);
      
      currentState = new TextileContentState();
      currentState.setFootnoteNumbers(preprocessingState.getFootnoteNumbers());
      parser.setBuilder(builder);
      super.processContent(parser, markupContent, asDocument);
      
      currentState = null;
    }
    else
    {
      currentState = null;
      super.processContent(parser, markupContent, asDocument);
    }
  }
  
  public DocumentBuilder createDocumentBuilder(Writer out)
  {
    return new TextileDocumentBuilder(out);
  }
}

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

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.mylyn.wikitext.core.parser.markup.ContentState;

public class TextileContentState
  extends ContentState
{
  private static final Pattern NAMED_LINK_PATTERN = Pattern.compile("\\[(\\S+)\\]([a-zA-Z]{3,5}:\\S+)", 
    8);
  private final Map<String, String> nameToUrl = new HashMap();
  private Set<String> footnoteNumbers;
  
  protected void setMarkupContent(String markupContent)
  {
    super.setMarkupContent(markupContent);
    preprocessContent(markupContent);
  }
  
  private void preprocessContent(String markupContent)
  {
    Matcher matcher = NAMED_LINK_PATTERN.matcher(markupContent);
    while (matcher.find())
    {
      String name = matcher.group(1);
      String href = matcher.group(2);
      nameToUrl.put(name, href);
    }
  }
  
  public String getNamedLinkUrl(String name)
  {
    return (String)nameToUrl.get(name);
  }
  
  public Set<String> getFootnoteNumbers()
  {
    return footnoteNumbers;
  }
  
  public void setFootnoteNumbers(Set<String> footnoteNumbers)
  {
    this.footnoteNumbers = footnoteNumbers;
  }
  
  public void footnoteBlockDetected(String footnoteNumber)
  {
    if (footnoteNumbers == null) {
      footnoteNumbers = new HashSet();
    }
    footnoteNumbers.add(footnoteNumber);
  }
  
  public boolean hasFootnoteNumber(String footnoteNumber)
  {
    return (footnoteNumbers != null) && (footnoteNumbers.contains(footnoteNumber));
  }
}

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

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;
import org.eclipse.mylyn.wikitext.core.parser.markup.block.GlossaryBlock;

public class TextileGlossaryBlock
  extends GlossaryBlock
{
  static final Pattern startPattern = Pattern.compile("\\s*\\{glossary(?::([^\\}]+))?\\}\\s*");
  private Matcher matcher;
  
  public int processLineContent(String line, int offset)
  {
    if (blockLineNumber == 0)
    {
      String options = matcher.group(1);
      if (options != null)
      {
        String[] optionPairs = options.split("\\s*\\|\\s*");
        String[] arrayOfString1;
        int j = (arrayOfString1 = optionPairs).length;
        for (int i = 0; i < j; i++)
        {
          String optionPair = arrayOfString1[i];
          String[] keyValue = optionPair.split("\\s*=\\s*");
          if (keyValue.length == 2)
          {
            String key = keyValue[0].trim();
            String value = keyValue[1].trim();
            if (key.equals("style")) {
              setStyle(value);
            }
          }
        }
      }
    }
    return super.processLineContent(line, offset);
  }
  
  public boolean canStart(String line, int lineOffset)
  {
    if ((lineOffset == 0) && (!markupLanguage.isFilterGenerativeContents()))
    {
      matcher = startPattern.matcher(line);
      return matcher.matches();
    }
    matcher = null;
    return false;
  }
}

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

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.mylyn.internal.wikitext.textile.core.Textile;
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.markup.Block;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;

public class PreformattedBlock
  extends Block
{
  private static final int LINE_REMAINDER_GROUP_OFFSET = 9;
  private static final int EXTENDED_GROUP = 8;
  static final Pattern startPattern = Pattern.compile("pre(\\(+)?(\\)+)?(\\<|\\>|\\=|\\<\\>)?(?:(?:\\(([^#\\)]+)?(?:#([^\\(\\)]+))?\\))|(?:\\{([^\\{\\}]+)\\})|(?:\\[([^\\[\\]]+)\\])){0,3}\\.(\\.)?\\s+(.*)");
  private boolean extended;
  private int blockLineCount = 0;
  private Matcher matcher;
  
  public int processLineContent(String line, int offset)
  {
    if (blockLineCount == 0)
    {
      Attributes attributes = new Attributes();
      
      Textile.configureAttributes(attributes, matcher, 1, true);
      offset = matcher.start(9);
      extended = (matcher.group(8) != null);
      
      builder.beginBlock(DocumentBuilder.BlockType.PREFORMATTED, attributes);
    }
    if ((markupLanguage.isEmptyLine(line)) && (!extended))
    {
      setClosed(true);
      return 0;
    }
    if ((extended) && (Textile.explicitBlockBegins(line, offset)))
    {
      setClosed(true);
      return offset;
    }
    blockLineCount += 1;
    
    String lineText = offset > 0 ? line.substring(offset) : line;
    if ((blockLineCount > 1) || (lineText.trim().length() > 0))
    {
      builder.characters(lineText);
      builder.characters("\n");
    }
    return -1;
  }
  
  public boolean canStart(String line, int lineOffset)
  {
    blockLineCount = 0;
    if (lineOffset == 0)
    {
      matcher = startPattern.matcher(line);
      return matcher.matches();
    }
    matcher = null;
    return false;
  }
  
  public void setClosed(boolean closed)
  {
    if ((closed) && (!isClosed())) {
      builder.endBlock();
    }
    super.setClosed(closed);
  }
}

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

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

class ListBlock$ListState
{
  int level;
  DocumentBuilder.BlockType type;
  boolean openItem;
  
  private ListBlock$ListState(int level, DocumentBuilder.BlockType type)
  {
    this.level = level;
    this.type = type;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.textile.core.block.ListBlock.ListState
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.textile.core.block;

import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.mylyn.internal.wikitext.textile.core.Textile;
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.markup.Block;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;

public class ListBlock
  extends Block
{
  private static final int LINE_REMAINDER_GROUP_OFFSET = 9;
  static final Pattern startPattern = Pattern.compile("((?:(?:\\*)|(?:#))+)(\\(+)?(\\)+)?(\\<|\\>|\\=|\\<\\>)?(?:(?:\\(([^#\\)]+)?(?:#([^\\(\\)]+))?\\))|(?:\\{([^\\{\\}]+)\\})|(?:\\[([^\\[\\]]+)\\])){0,3}\\s(.*+)");
  private int blockLineCount = 0;
  private Matcher matcher;
  private Stack<ListState> listState;
  
  public int processLineContent(String line, int offset)
  {
    if (blockLineCount == 0)
    {
      this.listState = new Stack();
      Attributes attributes = new Attributes();
      String listSpec = this.matcher.group(1);
      int level = calculateLevel(listSpec);
      DocumentBuilder.BlockType type = calculateType(listSpec);
      
      Textile.configureAttributes(attributes, this.matcher, 2, true);
      offset = this.matcher.start(9);
      
      this.listState.push(new ListState(1, type, null));
      builder.beginBlock(type, attributes);
      
      adjustLevel(this.matcher, level, type);
    }
    else
    {
      Matcher matcher = startPattern.matcher(line);
      if (!matcher.matches())
      {
        setClosed(true);
        return 0;
      }
      String listSpec = matcher.group(1);
      int level = calculateLevel(listSpec);
      DocumentBuilder.BlockType type = calculateType(listSpec);
      offset = matcher.start(9);
      
      adjustLevel(matcher, level, type);
    }
    blockLineCount += 1;
    
    ListState listState = (ListState)this.listState.peek();
    if (openItem) {
      builder.endBlock();
    }
    openItem = true;
    builder.beginBlock(DocumentBuilder.BlockType.LIST_ITEM, new Attributes());
    
    markupLanguage.emitMarkupLine(getParser(), state, line, offset);
    
    return -1;
  }
  
  private void adjustLevel(Matcher matcher, int level, DocumentBuilder.BlockType type)
  {
    for (ListState previousState = (ListState)listState.peek(); (level != level) || (type != type); previousState = (ListState)listState.peek()) {
      if (level > level)
      {
        if (!openItem)
        {
          builder.beginBlock(DocumentBuilder.BlockType.LIST_ITEM, new Attributes());
          openItem = true;
        }
        Attributes blockAttributes = new Attributes();
        if (level + 1 == level) {
          Textile.configureAttributes(blockAttributes, matcher, 2, true);
        }
        listState.push(new ListState(level + 1, type, null));
        builder.beginBlock(type, blockAttributes);
      }
      else
      {
        closeOne();
        if (listState.isEmpty())
        {
          Attributes blockAttributes = new Attributes();
          Textile.configureAttributes(blockAttributes, matcher, 2, true);
          
          listState.push(new ListState(1, type, null));
          builder.beginBlock(type, blockAttributes);
        }
      }
    }
  }
  
  private int calculateLevel(String listSpec)
  {
    return listSpec.length();
  }
  
  private DocumentBuilder.BlockType calculateType(String listSpec)
  {
    return listSpec.charAt(listSpec.length() - 1) == '#' ? DocumentBuilder.BlockType.NUMERIC_LIST : DocumentBuilder.BlockType.BULLETED_LIST;
  }
  
  public boolean canStart(String line, int lineOffset)
  {
    blockLineCount = 0;
    listState = null;
    if (lineOffset == 0)
    {
      matcher = startPattern.matcher(line);
      return matcher.matches();
    }
    matcher = null;
    return false;
  }
  
  public void setClosed(boolean closed)
  {
    if ((closed) && (!isClosed()))
    {
      while ((listState != null) && (!listState.isEmpty())) {
        closeOne();
      }
      listState = null;
    }
    super.setClosed(closed);
  }
  
  private void closeOne()
  {
    ListState e = (ListState)listState.pop();
    if (openItem) {
      builder.endBlock();
    }
    builder.endBlock();
  }
  
  private static class ListState
  {
    int level;
    DocumentBuilder.BlockType type;
    boolean openItem;
    
    private ListState(int level, DocumentBuilder.BlockType type)
    {
      this.level = level;
      this.type = type;
    }
  }
}

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

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.mylyn.internal.wikitext.textile.core.Textile;
import org.eclipse.mylyn.wikitext.core.parser.Attributes;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.IdGenerator;
import org.eclipse.mylyn.wikitext.core.parser.markup.Block;
import org.eclipse.mylyn.wikitext.core.parser.markup.ContentState;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;

public class HeadingBlock
  extends Block
{
  private static final int LINE_REMAINDER_GROUP_OFFSET = 9;
  static final Pattern startPattern = Pattern.compile("h([1-6])(\\(+)?(\\)+)?(\\<|\\>|\\=|\\<\\>)?(?:(?:\\(([^#\\)]+)?(?:#([^\\(\\)]+))?\\))|(?:\\{([^\\{\\}]+)\\})|(?:\\[([^\\[\\]]+)\\])){0,3}\\.\\s+(.*)");
  private int blockLineCount = 0;
  private int level = -1;
  private Matcher matcher;
  
  public int processLineContent(String line, int offset)
  {
    if (blockLineCount == 0)
    {
      Attributes attributes = new Attributes();
      if (offset == 0)
      {
        level = Integer.parseInt(matcher.group(1));
        Textile.configureAttributes(attributes, matcher, 2, true);
        offset = matcher.start(9);
      }
      if (attributes.getId() == null) {
        attributes.setId(state.getIdGenerator().newId("h" + level, line.substring(offset)));
      }
      builder.beginHeading(level, attributes);
    }
    if (markupLanguage.isEmptyLine(line))
    {
      setClosed(true);
      return 0;
    }
    if (blockLineCount != 0) {
      getMarkupLanguage().emitMarkupText(getParser(), state, "\n");
    }
    blockLineCount += 1;
    
    getMarkupLanguage().emitMarkupLine(getParser(), state, line, offset);
    
    return -1;
  }
  
  public boolean canStart(String line, int lineOffset)
  {
    blockLineCount = 0;
    if (lineOffset == 0)
    {
      matcher = startPattern.matcher(line);
      return matcher.matches();
    }
    matcher = null;
    return false;
  }
  
  public void setClosed(boolean closed)
  {
    if ((closed) && (!isClosed())) {
      builder.endHeading();
    }
    super.setClosed(closed);
  }
}

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

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.mylyn.internal.wikitext.textile.core.Textile;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.BlockType;
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.parser.markup.Block;
import org.eclipse.mylyn.wikitext.core.parser.markup.ContentState;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;

public class TableBlock
  extends Block
{
  static final Pattern startPattern = Pattern.compile("(table(\\(+)?(\\)+)?(\\<|\\>|\\=|\\<\\>)?(?:(?:\\(([^#\\)]+)?(?:#([^\\(\\)]+))?\\))|(?:\\{([^\\{\\}]+)\\})|(?:\\[([^\\[\\]]+)\\])){0,3}\\.\\s*)|(\\|(.*)?(\\|\\s*$))");
  static final Pattern rowAttributesPattern = Pattern.compile("(\\(+)?(\\)+)?(\\<|\\>|\\=|\\<\\>)?(?:(?:\\(([^#\\)]+)?(?:#([^\\(\\)]+))?\\))|(?:\\{([^\\{\\}]+)\\})|(?:\\[([^\\[\\]]+)\\])){0,3}\\.\\s*.*");
  static final Pattern TABLE_ROW_PATTERN = Pattern.compile("\\|(?:\\\\(\\d+))?(?:/(\\d+))?((?:\\<\\>)|\\<|\\>|\\^)?(?:(?:\\(([^#\\)]+)?(?:#([^\\(\\)]+))?\\))|(?:\\{([^\\{\\}]+)\\})|(?:\\[([^\\[\\]]+)\\])){0,3}(_|\\|)?\\.?\\s?([^\\|]*)(\\|\\|?\\s*$)?");
  private int blockLineCount = 0;
  private Matcher matcher;
  
  public int processLineContent(String line, int offset)
  {
    if (blockLineCount == 0)
    {
      TableAttributes attributes = new TableAttributes();
      if (matcher.group(1) != null)
      {
        Textile.configureAttributes(attributes, matcher, 2, true);
        offset = line.length();
      }
      builder.beginBlock(DocumentBuilder.BlockType.TABLE, attributes);
    }
    else if (markupLanguage.isEmptyLine(line))
    {
      setClosed(true);
      return 0;
    }
    blockLineCount += 1;
    if (offset == line.length()) {
      return -1;
    }
    String textileLine = offset == 0 ? line : line.substring(offset);
    Matcher rowMatcher = TABLE_ROW_PATTERN.matcher(textileLine);
    if (!rowMatcher.find())
    {
      setClosed(true);
      return 0;
    }
    TableRowAttributes rowAttributes = new TableRowAttributes();
    int rowStart = rowMatcher.start();
    if (rowStart > 0)
    {
      Matcher rowAttributesMatcher = rowAttributesPattern.matcher(textileLine);
      if (rowAttributesMatcher.matches()) {
        Textile.configureAttributes(rowAttributes, rowAttributesMatcher, 1, true);
      }
    }
    builder.beginBlock(DocumentBuilder.BlockType.TABLE_ROW, rowAttributes);
    do
    {
      int start = rowMatcher.start();
      if (start == textileLine.length() - 1) {
        break;
      }
      String colSpan = rowMatcher.group(1);
      String rowSpan = rowMatcher.group(2);
      String alignment = rowMatcher.group(3);
      String headerIndicator = rowMatcher.group(8);
      String text = rowMatcher.group(9);
      int textLineOffset = rowMatcher.start(9);
      
      boolean header = (headerIndicator != null) && (("_".equals(headerIndicator)) || ("|".equals(headerIndicator)));
      
      String textAlign = null;
      if (alignment != null) {
        if (alignment.equals("<>")) {
          textAlign = "text-align: center;";
        } else if (alignment.equals(">")) {
          textAlign = "text-align: right;";
        } else if (alignment.equals("<")) {
          textAlign = "text-align: left;";
        } else if (alignment.equals("^")) {
          textAlign = "vertical-align: top;";
        }
      }
      TableCellAttributes attributes = new TableCellAttributes();
      attributes.setCssStyle(textAlign);
      attributes.setRowspan(rowSpan);
      attributes.setColspan(colSpan);
      Textile.configureAttributes(attributes, rowMatcher, 4, false);
      
      state.setLineCharacterOffset(start);
      builder.beginBlock(header ? DocumentBuilder.BlockType.TABLE_CELL_HEADER : DocumentBuilder.BlockType.TABLE_CELL_NORMAL, attributes);
      
      markupLanguage.emitMarkupLine(getParser(), state, textLineOffset, text, 0);
      
      builder.endBlock();
    } while (
    
      rowMatcher.find());
    builder.endBlock();
    
    return -1;
  }
  
  public boolean canStart(String line, int lineOffset)
  {
    blockLineCount = 0;
    if (lineOffset == 0)
    {
      matcher = startPattern.matcher(line);
      return matcher.matches();
    }
    matcher = null;
    return false;
  }
  
  public void setClosed(boolean closed)
  {
    if ((closed) && (!isClosed())) {
      builder.endBlock();
    }
    super.setClosed(closed);
  }
}

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

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.mylyn.internal.wikitext.textile.core.Textile;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.markup.Block;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;

public class NotextileBlock
  extends Block
{
  private static final int LINE_REMAINDER_GROUP_OFFSET = 2;
  private static final int EXTENDED_GROUP = 1;
  static final Pattern startPattern = Pattern.compile("notextile\\.(\\.)?\\s+(.*)");
  private boolean extended;
  private int blockLineCount = 0;
  private Matcher matcher;
  
  public int processLineContent(String line, int offset)
  {
    if (blockLineCount == 0)
    {
      offset = matcher.start(2);
      extended = (matcher.group(1) != null);
    }
    if ((markupLanguage.isEmptyLine(line)) && (!extended))
    {
      setClosed(true);
      return 0;
    }
    if ((extended) && (Textile.explicitBlockBegins(line, offset)))
    {
      setClosed(true);
      return offset;
    }
    blockLineCount += 1;
    
    String lineText = offset > 0 ? line.substring(offset) : line;
    if ((blockLineCount > 1) || (lineText.trim().length() > 0))
    {
      builder.charactersUnescaped(lineText);
      builder.characters("\n");
    }
    return -1;
  }
  
  public boolean canStart(String line, int lineOffset)
  {
    blockLineCount = 0;
    if (lineOffset == 0)
    {
      matcher = startPattern.matcher(line);
      return matcher.matches();
    }
    matcher = null;
    return false;
  }
}

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

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.mylyn.internal.wikitext.textile.core.Textile;
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.markup.Block;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;
import org.eclipse.mylyn.wikitext.textile.core.TextileLanguage;

public class ParagraphBlock
  extends Block
{
  private static final int LINE_REMAINDER_GROUP_OFFSET = 8;
  static final Pattern startPattern = Pattern.compile("p(\\(+)?(\\)+)?(\\<|\\>|\\=|\\<\\>)?(?:(?:\\(([^#\\)]+)?(?:#([^\\(\\)]+))?\\))|(?:\\{([^\\{\\}]+)\\})|(?:\\[([^\\[\\]]+)\\])){0,3}\\.\\s+(.*)");
  private int blockLineCount = 0;
  private boolean unwrapped = false;
  private boolean enableUnwrapped = true;
  
  public int processLineContent(String line, int offset)
  {
    if (blockLineCount == 0)
    {
      Attributes attributes = new Attributes();
      if (offset == 0)
      {
        Matcher matcher = startPattern.matcher(line);
        if (matcher.matches())
        {
          Textile.configureAttributes(attributes, matcher, 1, true);
          offset = matcher.start(8);
        }
        else if (line.charAt(0) == ' ')
        {
          offset = 1;
          if (enableUnwrapped) {
            unwrapped = true;
          }
        }
      }
      if (!unwrapped) {
        builder.beginBlock(DocumentBuilder.BlockType.PARAGRAPH, attributes);
      }
    }
    if (markupLanguage.isEmptyLine(line))
    {
      setClosed(true);
      return 0;
    }
    TextileLanguage textileLanguage = (TextileLanguage)getMarkupLanguage();
    for (Block block : textileLanguage.getParagraphBreakingBlocks()) {
      if (block.canStart(line, offset))
      {
        setClosed(true);
        return 0;
      }
    }
    if (blockLineCount != 0) {
      if (unwrapped) {
        builder.characters("\n");
      } else {
        builder.lineBreak();
      }
    }
    blockLineCount += 1;
    
    textileLanguage.emitMarkupLine(getParser(), state, line, offset);
    
    return -1;
  }
  
  public boolean canStart(String line, int lineOffset)
  {
    unwrapped = false;
    blockLineCount = 0;
    return true;
  }
  
  public void setClosed(boolean closed)
  {
    if ((closed) && (!isClosed()) && 
      (!unwrapped)) {
      builder.endBlock();
    }
    super.setClosed(closed);
  }
  
  public void setEnableUnwrapped(boolean enableUnwrapped)
  {
    this.enableUnwrapped = enableUnwrapped;
  }
  
  public boolean isEnableUnwrapped()
  {
    return enableUnwrapped;
  }
}

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

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.mylyn.internal.wikitext.textile.core.Textile;
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.markup.Block;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;

public class CodeBlock
  extends Block
{
  private static final int LINE_REMAINDER_GROUP_OFFSET = 9;
  private static final int EXTENDED_GROUP = 8;
  static final Pattern startPattern = Pattern.compile("bc(\\(+)?(\\)+)?(\\<|\\>|\\=|\\<\\>)?(?:(?:\\(([^#\\)]+)?(?:#([^\\(\\)]+))?\\))|(?:\\{([^\\{\\}]+)\\})|(?:\\[([^\\[\\]]+)\\])){0,3}\\.(\\.)?\\s+(.*)");
  private boolean extended;
  private int blockLineCount = 0;
  private Matcher matcher;
  
  public int processLineContent(String line, int offset)
  {
    if (blockLineCount == 0)
    {
      Attributes attributes = new Attributes();
      
      Textile.configureAttributes(attributes, matcher, 1, true);
      offset = matcher.start(9);
      extended = (matcher.group(8) != null);
      
      builder.beginBlock(DocumentBuilder.BlockType.PREFORMATTED, attributes);
      builder.beginBlock(DocumentBuilder.BlockType.CODE, new Attributes());
    }
    if ((markupLanguage.isEmptyLine(line)) && (!extended))
    {
      setClosed(true);
      return 0;
    }
    if ((extended) && (Textile.explicitBlockBegins(line, offset)))
    {
      setClosed(true);
      return offset;
    }
    blockLineCount += 1;
    
    String lineText = offset > 0 ? line.substring(offset) : line;
    if ((blockLineCount > 1) || (lineText.trim().length() > 0))
    {
      builder.characters(lineText);
      builder.characters("\n");
    }
    return -1;
  }
  
  public boolean canStart(String line, int lineOffset)
  {
    blockLineCount = 0;
    if (lineOffset == 0)
    {
      matcher = startPattern.matcher(line);
      return matcher.matches();
    }
    matcher = null;
    return false;
  }
  
  public void setClosed(boolean closed)
  {
    if ((closed) && (!isClosed()))
    {
      builder.endBlock();
      builder.endBlock();
    }
    super.setClosed(closed);
  }
}

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

import java.util.List;
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.markup.Block;
import org.eclipse.mylyn.wikitext.core.parser.outline.OutlineItem;

public abstract class AbstractTableOfContentsBlock
  extends Block
{
  private String style = "none";
  private String cssClass = "toc";
  protected int maxLevel = Integer.MAX_VALUE;
  
  protected void emitToc(OutlineItem item)
  {
    Attributes nullAttributes = new Attributes();
    
    emitToc(item, 0, nullAttributes);
  }
  
  private void emitToc(OutlineItem item, int level, Attributes nullAttributes)
  {
    if (item.getChildren().isEmpty()) {
      return;
    }
    if (item.getLevel() + 1 > maxLevel) {
      return;
    }
    Attributes listAttributes = new Attributes(null, level == 0 ? cssClass : null, 
      "list-style: " + style + ";", null);
    builder.beginBlock(DocumentBuilder.BlockType.NUMERIC_LIST, listAttributes);
    for (OutlineItem child : item.getChildren())
    {
      builder.beginBlock(DocumentBuilder.BlockType.LIST_ITEM, nullAttributes);
      builder.link('#' + child.getId(), child.getLabel());
      emitToc(child, level + 1, nullAttributes);
      builder.endBlock();
    }
    builder.endBlock();
  }
  
  public String getStyle()
  {
    return style;
  }
  
  public void setStyle(String style)
  {
    this.style = style;
  }
  
  public String getCssClass()
  {
    return cssClass;
  }
  
  public void setCssClass(String cssClass)
  {
    this.cssClass = cssClass;
  }
  
  public int getMaxLevel()
  {
    return maxLevel;
  }
  
  public void setMaxLevel(int maxLevel)
  {
    this.maxLevel = maxLevel;
  }
}

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

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.mylyn.wikitext.core.parser.markup.ContentState;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;
import org.eclipse.mylyn.wikitext.core.parser.outline.OutlineItem;
import org.eclipse.mylyn.wikitext.core.parser.outline.OutlineParser;
import org.eclipse.mylyn.wikitext.textile.core.TextileLanguage;

public class TableOfContentsBlock
  extends AbstractTableOfContentsBlock
{
  private static final String OPTION_MAX_LEVEL = "maxLevel";
  private static final String OPTION_STYLE = "style";
  private static final String OPTION_CLASS = "class";
  static final Pattern startPattern = Pattern.compile("\\s*\\{toc(?::([^\\}]+))?\\}\\s*");
  private int blockLineNumber = 0;
  private Matcher matcher;
  
  public int processLineContent(String line, int offset)
  {
    if (blockLineNumber++ > 0)
    {
      setClosed(true);
      return 0;
    }
    if (!getMarkupLanguage().isFilterGenerativeContents())
    {
      String options = matcher.group(1);
      if (options != null)
      {
        String[] optionPairs = options.split("\\s*\\|\\s*");
        String[] arrayOfString1;
        int j = (arr
1 2 3

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