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

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

import java.text.MessageFormat;
import java.util.List;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.block.HeadingBlock;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.block.ListBlock;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.block.ParagraphBlock;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.block.PreformattedBlock;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.block.QuoteBlock;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.block.TableBlock;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.phrase.EscapePhraseModifier;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.phrase.MonospacePhraseModifier;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.phrase.SimplePhraseModifier;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.token.BangEscapeToken;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.token.ChangesetLinkReplacementToken;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.token.HyperlinkReplacementToken;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.token.LineBreakToken;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.token.MacroReplacementToken;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.token.MilestoneLinkReplacementToken;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.token.ReportLinkReplacementToken;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.token.RevisionLogReplacementToken;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.token.SourceLinkReplacementToken;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.token.TicketAttachmentLinkReplacementToken;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.token.TicketLinkReplacementToken;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.token.WikiLinkReplacementToken;
import org.eclipse.mylyn.internal.wikitext.tracwiki.core.token.WikiWordReplacementToken;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.SpanType;
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.MarkupLanguage.PatternBasedSyntax;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguageConfiguration;
import org.eclipse.mylyn.wikitext.core.parser.markup.token.ImpliedHyperlinkReplacementToken;

public class TracWikiLanguage
  extends AbstractMarkupLanguage
{
  private boolean autoLinking = true;
  private String serverUrl;
  
  public TracWikiLanguage()
  {
    setName("TracWiki");
  }
  
  public String toInternalHref(String pageName)
  {
    String pageId = pageName;
    if (pageId.startsWith("#")) {
      return pageId;
    }
    return MessageFormat.format(internalLinkPattern, new Object[] { pageId });
  }
  
  public String toTicketHref(String ticketId, String commentNumber)
  {
    String url = serverUrl + "ticket/" + ticketId;
    if (commentNumber != null) {
      url = url + "#comment:" + commentNumber;
    }
    return url;
  }
  
  public String toChangesetHref(String changesetId, String restriction)
  {
    String url = serverUrl + "changeset/" + changesetId;
    if (restriction != null) {
      url = url + "/" + restriction;
    }
    return url;
  }
  
  public String toRevisionLogHref(String revision1, String revision2, String restriction)
  {
    String url = serverUrl + "log/";
    if (restriction != null) {
      url = url + restriction;
    }
    url = url + "?revs=" + revision1 + "-" + revision2;
    return url;
  }
  
  public String toReportHref(String reportId)
  {
    String url = serverUrl + "report/" + reportId;
    return url;
  }
  
  public String toMilestoneHref(String milestoneId)
  {
    String url = serverUrl + "milestone/" + milestoneId;
    return url;
  }
  
  public String toTicketAttachmentHref(String ticketId, String attachment)
  {
    String url = serverUrl + "ticket/" + ticketId + "/" + attachment;
    return url;
  }
  
  public String toSourceBrowserHref(String source, String revision, String line)
  {
    String url = serverUrl + "browser";
    if (source.charAt(0) != '/') {
      url = url + '/';
    }
    url = url + source;
    if (revision != null) {
      url = url + "?rev=" + revision;
    }
    if (line != null) {
      url = url + "#L" + line;
    }
    return url;
  }
  
  public boolean computeInternalLinkExists(String link)
  {
    return true;
  }
  
  public boolean isAutoLinking()
  {
    return autoLinking;
  }
  
  public void setAutoLinking(boolean autoLinking)
  {
    this.autoLinking = autoLinking;
  }
  
  public void setServerUrl(String url)
  {
    if ((url != null) && (!url.endsWith("/"))) {
      url = url + "/";
    }
    serverUrl = url;
  }
  
  public String getServerUrl()
  {
    return serverUrl;
  }
  
  protected void addStandardBlocks(List<Block> blocks, List<Block> paragraphBreakingBlocks)
  {
    ListBlock listBlock = new ListBlock();
    blocks.add(listBlock);
    paragraphBreakingBlocks.add(listBlock);
    HeadingBlock headingBlock = new HeadingBlock();
    blocks.add(headingBlock);
    paragraphBreakingBlocks.add(headingBlock);
    PreformattedBlock preformattedBlock = new PreformattedBlock();
    blocks.add(preformattedBlock);
    paragraphBreakingBlocks.add(preformattedBlock);
    QuoteBlock quoteBlock = new QuoteBlock();
    blocks.add(quoteBlock);
    paragraphBreakingBlocks.add(quoteBlock);
    TableBlock tableBlock = new TableBlock();
    blocks.add(tableBlock);
    paragraphBreakingBlocks.add(tableBlock);
  }
  
  protected void addStandardPhraseModifiers(MarkupLanguage.PatternBasedSyntax phraseModifierSyntax)
  {
    phraseModifierSyntax.add(new MonospacePhraseModifier());
    phraseModifierSyntax.beginGroup("(?:(?<=[\\s\\.\\\"'?!;:\\)\\(\\{\\}\\[\\]-])|^)(?:", 0);
    phraseModifierSyntax.add(new EscapePhraseModifier());
    phraseModifierSyntax.add(new SimplePhraseModifier("'''''", new DocumentBuilder.SpanType[] { DocumentBuilder.SpanType.BOLD, DocumentBuilder.SpanType.ITALIC }, 
      true));
    phraseModifierSyntax.add(new SimplePhraseModifier("'''", DocumentBuilder.SpanType.BOLD, true));
    phraseModifierSyntax.add(new SimplePhraseModifier("''", DocumentBuilder.SpanType.ITALIC, true));
    phraseModifierSyntax.add(new SimplePhraseModifier("__", DocumentBuilder.SpanType.UNDERLINED, true));
    phraseModifierSyntax.add(new SimplePhraseModifier("~~", DocumentBuilder.SpanType.DELETED, true));
    phraseModifierSyntax.add(new SimplePhraseModifier("^", DocumentBuilder.SpanType.SUPERSCRIPT, true));
    phraseModifierSyntax.add(new SimplePhraseModifier(",,", DocumentBuilder.SpanType.SUBSCRIPT, true));
    phraseModifierSyntax.endGroup(")(?=\\W|$)", 0);
  }
  
  protected void addStandardTokens(MarkupLanguage.PatternBasedSyntax tokenSyntax)
  {
    tokenSyntax.add(new BangEscapeToken());
    tokenSyntax.add(new LineBreakToken());
    tokenSyntax.beginGroup("(?:(?<=[\\s\\.\\\"'?!;:\\)\\(\\{\\}\\[\\]-])|^)(?:", 0);
    tokenSyntax.add(new MacroReplacementToken());
    tokenSyntax.add(new RevisionLogReplacementToken());
    tokenSyntax.add(new ChangesetLinkReplacementToken());
    tokenSyntax.add(new HyperlinkReplacementToken());
    tokenSyntax.add(new ImpliedHyperlinkReplacementToken());
    tokenSyntax.add(new TicketAttachmentLinkReplacementToken());
    tokenSyntax.add(new TicketLinkReplacementToken());
    tokenSyntax.add(new ReportLinkReplacementToken());
    tokenSyntax.add(new MilestoneLinkReplacementToken());
    tokenSyntax.add(new SourceLinkReplacementToken());
    tokenSyntax.add(new WikiLinkReplacementToken());
    if ((configuration == null) || (configuration.isWikiWordLinking() == null) || (configuration.isWikiWordLinking().booleanValue())) {
      tokenSyntax.add(new WikiWordReplacementToken());
    }
    tokenSyntax.endGroup(")(?=\\W|$)", 0);
  }
  
  protected Block createParagraphBlock()
  {
    return new ParagraphBlock();
  }
}

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

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;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.BlockType;
import org.eclipse.mylyn.wikitext.core.parser.markup.Block;

public class PreformattedBlock
  extends Block
{
  private static final Pattern startPattern = Pattern.compile("\\{\\{\\{(\\s*)");
  private static final Pattern endPattern = Pattern.compile("\\}\\}\\}(.*)");
  private int blockLineCount = 0;
  private Matcher matcher;
  
  public int processLineContent(String line, int offset)
  {
    if (blockLineCount++ == 0)
    {
      offset = matcher.start(1);
      builder.beginBlock(DocumentBuilder.BlockType.PREFORMATTED, new Attributes());
    }
    else
    {
      Matcher endMatcher = endPattern.matcher(line);
      if (endMatcher.matches())
      {
        setClosed(true);
        return endMatcher.start(1);
      }
    }
    builder.characters(offset == 0 ? line : line.substring(offset));
    builder.characters("\n");
    return -1;
  }
  
  public void setClosed(boolean closed)
  {
    if ((closed) && (!isClosed())) {
      builder.endBlock();
    }
    super.setClosed(closed);
  }
  
  public boolean canStart(String line, int lineOffset)
  {
    if (lineOffset == 0)
    {
      matcher = startPattern.matcher(line);
      return matcher.matches();
    }
    matcher = null;
    return false;
  }
}

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

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

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

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

import java.util.Stack;
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;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.BlockType;
import org.eclipse.mylyn.wikitext.core.parser.ListAttributes;
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 = 4;
  static final Pattern startPattern = Pattern.compile("(?:(\\s+)(?:(\\*|-)|(?:(\\d+)\\.)))\\s+(.*+)");
  private int blockLineCount = 0;
  private Matcher matcher;
  private final Stack<ListState> listState = new Stack();
  
  public int processLineContent(String line, int offset)
  {
    if (blockLineCount == 0)
    {
      ListAttributes attributes = new ListAttributes();
      String spaces = this.matcher.group(1);
      String listSpec = this.matcher.group(2);
      String numericListSpec = this.matcher.group(3);
      if ((numericListSpec != null) && (!"1".equals(numericListSpec))) {
        attributes.setStart(numericListSpec);
      }
      int level = calculateLevel(spaces);
      
      DocumentBuilder.BlockType type = listSpec == null ? DocumentBuilder.BlockType.NUMERIC_LIST : DocumentBuilder.BlockType.BULLETED_LIST;
      
      offset = this.matcher.start(4);
      
      this.listState.push(new ListState(level, spaces.length(), type, null));
      builder.beginBlock(type, attributes);
    }
    else
    {
      ListAttributes attributes = new ListAttributes();
      Matcher matcher = startPattern.matcher(line);
      if (!matcher.matches())
      {
        setClosed(true);
        return 0;
      }
      String spaces = matcher.group(1);
      String listSpec = matcher.group(2);
      String numericListSpec = matcher.group(3);
      if ((numericListSpec != null) && (!"1".equals(numericListSpec))) {
        attributes.setStart(numericListSpec);
      }
      int level = calculateLevel(spaces);
      
      DocumentBuilder.BlockType type = listSpec == null ? DocumentBuilder.BlockType.NUMERIC_LIST : DocumentBuilder.BlockType.BULLETED_LIST;
      
      offset = matcher.start(4);
      for (ListState listState = (ListState)this.listState.peek(); (level != level) || (type != type); listState = (ListState)this.listState.peek()) {
        if ((level > level) || ((level == level) && (type != type)))
        {
          closeOne();
          if (this.listState.isEmpty())
          {
            this.listState.push(new ListState(1, spaces.length(), type, null));
            builder.beginBlock(type, attributes);
          }
        }
        else
        {
          this.listState.push(new ListState(level, spaces.length(), type, null));
          builder.beginBlock(type, attributes);
        }
      }
    }
    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 int calculateLevel(String spaces)
  {
    int length = spaces.length();
    if (length == 0) {
      throw new IllegalStateException();
    }
    int level = 1;
    for (int x = 1; x < listState.size(); x++)
    {
      ListState state = (ListState)listState.get(x);
      if (numSpaces > length) {
        break;
      }
      level = level;
    }
    if (!listState.isEmpty())
    {
      ListState outerState = (ListState)listState.peek();
      if ((level == level) && (length > numSpaces)) {
        level = level + 1;
      }
    }
    return level;
  }
  
  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())) {
      while (!listState.isEmpty()) {
        closeOne();
      }
    }
    super.setClosed(closed);
  }
  
  private void closeOne()
  {
    ListState e = (ListState)listState.pop();
    if (openItem) {
      builder.endBlock();
    }
    builder.endBlock();
  }
  
  private static class ListState
  {
    int level;
    int numSpaces;
    DocumentBuilder.BlockType type;
    boolean openItem;
    
    private ListState(int level, int numSpaces, DocumentBuilder.BlockType type)
    {
      this.level = level;
      this.numSpaces = numSpaces;
      this.type = type;
    }
  }
}

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

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;
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;

public class HeadingBlock
  extends Block
{
  private static final Pattern pattern = Pattern.compile("\\s*(\\={1,6})\\s*([^=]*[^=\\s])\\s*\\1(?:\\s+\\#(\\S+)?)?\\s*");
  private int blockLineCount = 0;
  private Matcher matcher;
  
  public boolean canStart(String line, int lineOffset)
  {
    blockLineCount = 0;
    if (lineOffset == 0)
    {
      matcher = pattern.matcher(line);
      return matcher.matches();
    }
    matcher = null;
    return false;
  }
  
  public int processLineContent(String line, int offset)
  {
    if (blockLineCount > 0) {
      throw new IllegalStateException();
    }
    blockLineCount += 1;
    
    int level = matcher.group(1).length();
    
    String text = matcher.group(2);
    
    String id = matcher.group(3);
    
    Attributes attributes = new Attributes();
    attributes.setId(id);
    if (attributes.getId() == null) {
      attributes.setId(state.getIdGenerator().newId("h" + level, text));
    }
    builder.beginHeading(level, attributes);
    builder.characters(text);
    builder.endHeading();
    
    setClosed(true);
    return -1;
  }
}

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

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;
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.ContentState;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;

public class TableBlock
  extends Block
{
  static final Pattern tableRowPattern = Pattern.compile("(\\|\\|(.*)?(\\|\\|\\s*$))");
  static final Pattern TABLE_ROW_PATTERN = Pattern.compile("\\|\\|\\s*([^\\|]*)\\s*(\\|\\|\\s*$)?");
  private int blockLineCount = 0;
  private Matcher matcher;
  
  public int processLineContent(String line, int offset)
  {
    if (blockLineCount == 0)
    {
      Attributes attributes = new Attributes();
      builder.beginBlock(DocumentBuilder.BlockType.TABLE, attributes);
    }
    else
    {
      matcher = tableRowPattern.matcher(line);
      if (!matcher.matches())
      {
        setClosed(true);
        return 0;
      }
    }
    blockLineCount += 1;
    
    String textileLine = offset == 0 ? line : line.substring(offset);
    Matcher rowMatcher = TABLE_ROW_PATTERN.matcher(textileLine);
    if (!rowMatcher.find())
    {
      setClosed(true);
      return 0;
    }
    builder.beginBlock(DocumentBuilder.BlockType.TABLE_ROW, new Attributes());
    do
    {
      int start = rowMatcher.start();
      if (start == textileLine.length() - 1) {
        break;
      }
      String text = rowMatcher.group(1);
      int textOffset = rowMatcher.start(1);
      
      Attributes attributes = new Attributes();
      state.setLineCharacterOffset(start);
      builder.beginBlock(DocumentBuilder.BlockType.TABLE_CELL_NORMAL, attributes);
      
      markupLanguage.emitMarkupLine(getParser(), state, textOffset, text, 0);
      
      builder.endBlock();
    } while (
    
      rowMatcher.find());
    builder.endBlock();
    
    return -1;
  }
  
  public boolean canStart(String line, int lineOffset)
  {
    blockLineCount = 0;
    if (lineOffset == 0)
    {
      matcher = tableRowPattern.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.tracwiki.core.block.TableBlock
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.tracwiki.core.block;

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.tracwiki.core.TracWikiLanguage;

public class ParagraphBlock
  extends Block
{
  private int blockLineCount = 0;
  
  public int processLineContent(String line, int offset)
  {
    if (blockLineCount == 0)
    {
      Attributes attributes = new Attributes();
      builder.beginBlock(DocumentBuilder.BlockType.PARAGRAPH, attributes);
    }
    if (this.markupLanguage.isEmptyLine(line))
    {
      setClosed(true);
      return -1;
    }
    blockLineCount += 1;
    
    TracWikiLanguage markupLanguage = (TracWikiLanguage)getMarkupLanguage();
    for (Block block : markupLanguage.getParagraphBreakingBlocks()) {
      if (block.canStart(line, offset))
      {
        setClosed(true);
        return 0;
      }
    }
    if (blockLineCount != 1) {
      builder.characters("\n");
    }
    markupLanguage.emitMarkupLine(getParser(), state, line, offset);
    
    return -1;
  }
  
  public boolean canStart(String line, int lineOffset)
  {
    blockLineCount = 0;
    return true;
  }
  
  public void setClosed(boolean closed)
  {
    if ((closed) && (!isClosed())) {
      builder.endBlock();
    }
    super.setClosed(closed);
  }
}

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

import java.util.Stack;
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;
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 QuoteBlock
  extends Block
{
  static final Pattern startPattern = Pattern.compile("(?:(?:(>+)\\s+)|(  ))(.*)");
  private int blockLineCount = 0;
  private Matcher matcher;
  private Stack<BlockState> quoteBlockState;
  
  public int processLineContent(String line, int offset)
  {
    if (blockLineCount == 0)
    {
      quoteBlockState = new Stack();
    }
    else
    {
      matcher = startPattern.matcher(line);
      if (!matcher.matches())
      {
        setClosed(true);
        return 0;
      }
    }
    String quoteStartGroup = matcher.group(1);
    int level = quoteStartGroup == null ? 1 : quoteStartGroup.length();
    offset = matcher.start(3);
    while (quoteBlockState.size() > level) {
      closeOne();
    }
    while (quoteBlockState.size() < level) {
      openOne(new Attributes());
    }
    BlockState blockState = (BlockState)quoteBlockState.peek();
    if (!paraOpen)
    {
      builder.beginBlock(DocumentBuilder.BlockType.PARAGRAPH, new Attributes());
      paraOpen = true;
    }
    else if (blockLineCount != 0)
    {
      builder.lineBreak();
    }
    blockLineCount += 1;
    
    getMarkupLanguage().emitMarkupLine(getParser(), state, line, offset);
    
    return -1;
  }
  
  private void openOne(Attributes attributes)
  {
    if (!quoteBlockState.isEmpty())
    {
      BlockState blockState = (BlockState)quoteBlockState.peek();
      if (paraOpen)
      {
        paraOpen = false;
        builder.endBlock();
      }
    }
    builder.beginBlock(DocumentBuilder.BlockType.QUOTE, attributes);
    quoteBlockState.push(new BlockState(null));
  }
  
  public boolean canStart(String line, int lineOffset)
  {
    quoteBlockState = null;
    blockLineCount = 0;
    matcher = startPattern.matcher(line);
    if (lineOffset > 0) {
      matcher.region(lineOffset, line.length());
    }
    return matcher.matches();
  }
  
  public void setClosed(boolean closed)
  {
    if ((closed) && (!isClosed()))
    {
      while ((quoteBlockState != null) && (!quoteBlockState.isEmpty())) {
        closeOne();
      }
      quoteBlockState = null;
    }
    super.setClosed(closed);
  }
  
  private void closeOne()
  {
    BlockState blockState = (BlockState)quoteBlockState.pop();
    if (paraOpen) {
      builder.endBlock();
    }
    builder.endBlock();
  }
  
  private static class BlockState
  {
    boolean paraOpen;
  }
}

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

class QuoteBlock$BlockState
{
  boolean paraOpen;
}

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

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElementProcessor;
import org.eclipse.mylyn.wikitext.tracwiki.core.TracWikiLanguage;

class WikiWordReplacementToken$WikiWordProcessor
  extends PatternBasedElementProcessor
{
  private WikiWordReplacementToken$WikiWordProcessor(WikiWordReplacementToken paramWikiWordReplacementToken) {}
  
  public void emit()
  {
    String escaped = group(1);
    String word = group(2);
    TracWikiLanguage twikiLanguage = (TracWikiLanguage)markupLanguage;
    if ((escaped != null) || (!twikiLanguage.isAutoLinking()))
    {
      builder.characters(word);
    }
    else
    {
      String target = WikiWordReplacementToken.access$0().matcher(word).replaceAll("");
      boolean exists = twikiLanguage.computeInternalLinkExists(target);
      
      String internalHref = twikiLanguage.toInternalHref(target);
      if (!exists)
      {
        builder.characters(word);
        builder.link(internalHref, "?");
      }
      else
      {
        builder.link(internalHref, word);
      }
    }
  }
}

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

import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElementProcessor;
import org.eclipse.mylyn.wikitext.tracwiki.core.TracWikiLanguage;

class MilestoneLinkReplacementToken$LinkReplacementTokenProcessor
  extends PatternBasedElementProcessor
{
  public void emit()
  {
    String text = group(1);
    String milestoneId = group(2);
    
    String href = ((TracWikiLanguage)markupLanguage).toMilestoneHref(milestoneId);
    builder.link(href, text);
  }
}

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

import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElement;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElementProcessor;
import org.eclipse.mylyn.wikitext.tracwiki.core.TracWikiLanguage;

public class HyperlinkReplacementToken
  extends PatternBasedElement
{
  protected String getPattern(int groupOffset)
  {
    return "\\[\\s*(wiki:)?([^\\]\\s]+)\\s*([^\\]]+)?\\s*\\]";
  }
  
  protected int getPatternGroupCount()
  {
    return 3;
  }
  
  protected PatternBasedElementProcessor newProcessor()
  {
    return new HyperlinkReplacementTokenProcessor(null);
  }
  
  private static class HyperlinkReplacementTokenProcessor
    extends PatternBasedElementProcessor
  {
    public void emit()
    {
      String wikiUrl = group(1);
      String href = group(2);
      String text = group(3);
      if (text == null)
      {
        text = href;
      }
      else
      {
        text = text.trim();
        if (text.length() == 0) {
          text = href;
        }
      }
      if (wikiUrl != null) {
        href = ((TracWikiLanguage)markupLanguage).toInternalHref(href);
      }
      builder.link(href, text);
    }
  }
}

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

import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElement;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElementProcessor;
import org.eclipse.mylyn.wikitext.tracwiki.core.TracWikiLanguage;

public class ReportLinkReplacementToken
  extends PatternBasedElement
{
  protected String getPattern(int groupOffset)
  {
    return "(\\{(\\d+)\\})|(report:(\\d+))";
  }
  
  protected int getPatternGroupCount()
  {
    return 4;
  }
  
  protected PatternBasedElementProcessor newProcessor()
  {
    return new ReportLinkReplacementTokenProcessor(null);
  }
  
  private static class ReportLinkReplacementTokenProcessor
    extends PatternBasedElementProcessor
  {
    public void emit()
    {
      String text = group(1);
      String reportId = group(2);
      if (reportId == null)
      {
        text = group(3);
        reportId = group(4);
      }
      String href = ((TracWikiLanguage)markupLanguage).toReportHref(reportId);
      builder.link(href, text);
    }
  }
}

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

import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElement;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElementProcessor;
import org.eclipse.mylyn.wikitext.tracwiki.core.TracWikiLanguage;

public class SourceLinkReplacementToken
  extends PatternBasedElement
{
  protected String getPattern(int groupOffset)
  {
    return "(source:([^\\s@#]+)(?:@(\\d+))?(?:#L(\\d+))?)";
  }
  
  protected int getPatternGroupCount()
  {
    return 4;
  }
  
  protected PatternBasedElementProcessor newProcessor()
  {
    return new LinkReplacementTokenProcessor(null);
  }
  
  private static class LinkReplacementTokenProcessor
    extends PatternBasedElementProcessor
  {
    public void emit()
    {
      String text = group(1);
      String source = group(2);
      String revision = group(3);
      String line = group(4);
      String href = ((TracWikiLanguage)markupLanguage).toSourceBrowserHref(source, revision, line);
      builder.link(href, text);
    }
  }
}

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

import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElementProcessor;
import org.eclipse.mylyn.wikitext.tracwiki.core.TracWikiLanguage;

class RevisionLogReplacementToken$RevisionLogReplacementTokenProcessor
  extends PatternBasedElementProcessor
{
  public void emit()
  {
    String text = group(1);
    String revision1 = group(2);
    String revision2 = group(3);
    String restriction = null;
    if (revision1 == null)
    {
      text = group(4);
      revision1 = group(5);
      revision2 = group(6);
      restriction = group(7);
      if (revision1 == null)
      {
        text = group(8);
        revision1 = group(10);
        revision2 = group(11);
        restriction = group(9);
      }
    }
    String href = ((TracWikiLanguage)markupLanguage).toRevisionLogHref(revision1, revision2, restriction);
    builder.link(href, text);
  }
}

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

import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElementProcessor;
import org.eclipse.mylyn.wikitext.tracwiki.core.TracWikiLanguage;

class TicketAttachmentLinkReplacementToken$LinkReplacementTokenProcessor
  extends PatternBasedElementProcessor
{
  public void emit()
  {
    String text = group(1);
    String attachment = group(2);
    String ticketId = group(3);
    
    String href = ((TracWikiLanguage)markupLanguage).toTicketAttachmentHref(ticketId, attachment);
    builder.link(href, text);
  }
}

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

import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElement;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElementProcessor;
import org.eclipse.mylyn.wikitext.core.parser.markup.phrase.LiteralPhraseModifierProcessor;

public class BangEscapeToken
  extends PatternBasedElement
{
  protected String getPattern(int groupOffset)
  {
    return "!(['\\}\\{\\^,_\\-])";
  }
  
  protected int getPatternGroupCount()
  {
    return 1;
  }
  
  protected PatternBasedElementProcessor newProcessor()
  {
    return new LiteralPhraseModifierProcessor(false);
  }
}

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

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElement;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElementProcessor;
import org.eclipse.mylyn.wikitext.tracwiki.core.TracWikiLanguage;

public class WikiWordReplacementToken
  extends PatternBasedElement
{
  private static final Pattern replacementPattern = Pattern.compile("\\W");
  
  protected String getPattern(int groupOffset)
  {
    return "(?<![a-zA-Z])(!)?([A-Z][a-z]+([A-Z][a-z]+)+)";
  }
  
  protected int getPatternGroupCount()
  {
    return 2;
  }
  
  protected PatternBasedElementProcessor newProcessor()
  {
    return new WikiWordProcessor(null);
  }
  
  private class WikiWordProcessor
    extends PatternBasedElementProcessor
  {
    private WikiWordProcessor() {}
    
    public void emit()
    {
      String escaped = group(1);
      String word = group(2);
      TracWikiLanguage twikiLanguage = (TracWikiLanguage)markupLanguage;
      if ((escaped != null) || (!twikiLanguage.isAutoLinking()))
      {
        builder.characters(word);
      }
      else
      {
        String target = WikiWordReplacementToken.replacementPattern.matcher(word).replaceAll("");
        boolean exists = twikiLanguage.computeInternalLinkExists(target);
        
        String internalHref = twikiLanguage.toInternalHref(target);
        if (!exists)
        {
          builder.characters(word);
          builder.link(internalHref, "?");
        }
        else
        {
          builder.link(internalHref, word);
        }
      }
    }
  }
}

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

import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElement;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElementProcessor;

public class LineBreakToken
  extends PatternBasedElement
{
  protected String getPattern(int groupOffset)
  {
    return "(\\[\\[BR\\]\\])";
  }
  
  protected int getPatternGroupCount()
  {
    return 1;
  }
  
  protected PatternBasedElementProcessor newProcessor()
  {
    return new LineBreakProcessor(null);
  }
  
  private static class LineBreakProcessor
    extends PatternBasedElementProcessor
  {
    public void emit()
    {
      builder.lineBreak();
    }
  }
}

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

import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElement;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElementProcessor;
import org.eclipse.mylyn.wikitext.tracwiki.core.TracWikiLanguage;

public class TicketLinkReplacementToken
  extends PatternBasedElement
{
  protected String getPattern(int groupOffset)
  {
    return "((?:comment:(\\d+):)?(?:#|ticket:)(\\d+))";
  }
  
  protected int getPatternGroupCount()
  {
    return 3;
  }
  
  protected PatternBasedElementProcessor newProcessor()
  {
    return new TicketLinkReplacementTokenProcessor(null);
  }
  
  private static class TicketLinkReplacementTokenProcessor
    extends PatternBasedElementProcessor
  {
    public void emit()
    {
      String text = group(1);
      String ticketId = group(3);
      String commentNumber = group(2);
      String href = ((TracWikiLanguage)markupLanguage).toTicketHref(ticketId, commentNumber);
      builder.link(href, text);
    }
  }
}

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

import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElement;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElementProcessor;
import org.eclipse.mylyn.wikitext.tracwiki.core.TracWikiLanguage;

public class MilestoneLinkReplacementToken
  extends PatternBasedElement
{
  protected String getPattern(int groupOffset)
  {
    return "(milestone:([0-9a-zA-Z_\\.-]+))";
  }
  
  protected int getPatternGroupCount()
  {
    return 2;
  }
  
  protected PatternBasedElementProcessor newProcessor()
  {
    return new LinkReplacementTokenProcessor(null);
  }
  
  private static class LinkReplacementTokenProcessor
    extends PatternBasedElementProcessor
  {
    public void emit()
    {
      String text = group(1);
      String milestoneId = group(2);
      
      String href = ((TracWikiLanguage)markupLanguage).toMilestoneHref(milestoneId);
      builder.link(href, text);
    }
  }
}

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

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.markup.Pat
1 2

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