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

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

import java.text.MessageFormat;
import java.util.List;
import org.eclipse.mylyn.internal.wikitext.twiki.core.block.DefinitionListBlock;
import org.eclipse.mylyn.internal.wikitext.twiki.core.block.HeadingBlock;
import org.eclipse.mylyn.internal.wikitext.twiki.core.block.HorizontalRuleBlock;
import org.eclipse.mylyn.internal.wikitext.twiki.core.block.ListBlock;
import org.eclipse.mylyn.internal.wikitext.twiki.core.block.LiteralBlock;
import org.eclipse.mylyn.internal.wikitext.twiki.core.block.ParagraphBlock;
import org.eclipse.mylyn.internal.wikitext.twiki.core.block.TableOfContentsBlock;
import org.eclipse.mylyn.internal.wikitext.twiki.core.block.VerbatimBlock;
import org.eclipse.mylyn.internal.wikitext.twiki.core.phrase.AutoLinkSwitchPhraseModifier;
import org.eclipse.mylyn.internal.wikitext.twiki.core.phrase.SimplePhraseModifier;
import org.eclipse.mylyn.internal.wikitext.twiki.core.token.IconReplacementToken;
import org.eclipse.mylyn.internal.wikitext.twiki.core.token.ImpliedEmailLinkReplacementToken;
import org.eclipse.mylyn.internal.wikitext.twiki.core.token.LinkReplacementToken;
import org.eclipse.mylyn.internal.wikitext.twiki.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.phrase.HtmlEndTagPhraseModifier;
import org.eclipse.mylyn.wikitext.core.parser.markup.phrase.HtmlStartTagPhraseModifier;
import org.eclipse.mylyn.wikitext.core.parser.markup.token.EntityReferenceReplacementToken;
import org.eclipse.mylyn.wikitext.core.parser.markup.token.ImpliedHyperlinkReplacementToken;

public class TWikiLanguage
  extends AbstractMarkupLanguage
{
  private final MarkupLanguage.PatternBasedSyntax literalTokenSyntax = new MarkupLanguage.PatternBasedSyntax();
  private final MarkupLanguage.PatternBasedSyntax literalPhraseModifierSyntax = new MarkupLanguage.PatternBasedSyntax();
  private boolean literalMode;
  private boolean isAutoLinking = true;
  private String iconPattern = "TWikiDocGraphics/{0}.gif";
  
  public TWikiLanguage()
  {
    setName("TWiki");
    setInternalLinkPattern("/cgi-bin/view/{0}/{1}");
  }
  
  protected MarkupLanguage.PatternBasedSyntax getPhraseModifierSyntax()
  {
    return literalMode ? literalPhraseModifierSyntax : phraseModifierSyntax;
  }
  
  protected MarkupLanguage.PatternBasedSyntax getReplacementTokenSyntax()
  {
    return literalMode ? literalTokenSyntax : tokenSyntax;
  }
  
  protected void clearLanguageSyntax()
  {
    super.clearLanguageSyntax();
    literalTokenSyntax.clear();
    literalPhraseModifierSyntax.clear();
  }
  
  private Block paragraphBreakingBlock(Block block)
  {
    paragraphBreakingBlocks.add(block);
    return block;
  }
  
  public boolean computeInternalLinkExists(String link)
  {
    return true;
  }
  
  public String toInternalHref(String pageName)
  {
    String[] parts = pageName.split("\\.");
    if (parts.length == 1) {
      parts = new String[] { "Main", parts[0] };
    }
    return MessageFormat.format(internalLinkPattern, parts);
  }
  
  public String toIconUrl(String iconType)
  {
    return MessageFormat.format(getIconPattern(), new Object[] { iconType });
  }
  
  public boolean isLiteralMode()
  {
    return literalMode;
  }
  
  public void setLiteralMode(boolean literalMode)
  {
    this.literalMode = literalMode;
  }
  
  public void setIconPattern(String iconPattern)
  {
    this.iconPattern = iconPattern;
  }
  
  public String getIconPattern()
  {
    return iconPattern;
  }
  
  public boolean isAutoLinking()
  {
    return isAutoLinking;
  }
  
  public void setAutoLinking(boolean isAutoLinking)
  {
    this.isAutoLinking = isAutoLinking;
  }
  
  protected void addStandardBlocks(List<Block> blocks, List<Block> paragraphBreakingBlocks)
  {
    blocks.add(paragraphBreakingBlock(new VerbatimBlock()));
    blocks.add(paragraphBreakingBlock(new LiteralBlock()));
    blocks.add(paragraphBreakingBlock(new HorizontalRuleBlock()));
    blocks.add(paragraphBreakingBlock(new HeadingBlock()));
    blocks.add(paragraphBreakingBlock(new DefinitionListBlock()));
    blocks.add(paragraphBreakingBlock(new TableOfContentsBlock()));
    blocks.add(paragraphBreakingBlock(new ListBlock()));
  }
  
  protected void addStandardPhraseModifiers(MarkupLanguage.PatternBasedSyntax phraseModifierSyntax)
  {
    boolean escapingHtml = configuration == null ? false : configuration.isEscapingHtmlAndXml();
    
    phraseModifierSyntax.add(new AutoLinkSwitchPhraseModifier());
    if (!escapingHtml)
    {
      phraseModifierSyntax.add(new HtmlStartTagPhraseModifier());
      phraseModifierSyntax.add(new HtmlEndTagPhraseModifier());
    }
    phraseModifierSyntax.beginGroup("(?:(?<=[\\s\\.,\\\"'?!;:\\)\\(\\{\\}\\[\\]])|^)(?:", 0);
    phraseModifierSyntax.add(new SimplePhraseModifier("*", DocumentBuilder.SpanType.BOLD));
    phraseModifierSyntax.add(new SimplePhraseModifier("__", new DocumentBuilder.SpanType[] { DocumentBuilder.SpanType.BOLD, DocumentBuilder.SpanType.ITALIC }));
    phraseModifierSyntax.add(new SimplePhraseModifier("_", DocumentBuilder.SpanType.ITALIC));
    phraseModifierSyntax.add(new SimplePhraseModifier("==", new DocumentBuilder.SpanType[] { DocumentBuilder.SpanType.BOLD, DocumentBuilder.SpanType.MONOSPACE }));
    phraseModifierSyntax.add(new SimplePhraseModifier("=", DocumentBuilder.SpanType.MONOSPACE));
    phraseModifierSyntax.endGroup(")(?=\\W|$)", 0);
    
    literalPhraseModifierSyntax.add(new HtmlStartTagPhraseModifier());
    literalPhraseModifierSyntax.add(new HtmlEndTagPhraseModifier());
  }
  
  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 LinkReplacementToken());
    tokenSyntax.add(new ImpliedHyperlinkReplacementToken());
    tokenSyntax.add(new ImpliedEmailLinkReplacementToken());
    tokenSyntax.add(new WikiWordReplacementToken());
    tokenSyntax.add(new IconReplacementToken());
    
    literalTokenSyntax.add(new ImpliedHyperlinkReplacementToken());
  }
  
  protected Block createParagraphBlock()
  {
    return new ParagraphBlock();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.wikitext.twiki.core.TWikiLanguage
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.twiki.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.MarkupLanguage;

public class DefinitionListBlock
  extends Block
{
  private static final Pattern startPattern = Pattern.compile(" {3}\\$\\s+([^:]+):\\s+(.+)");
  private int blockLineCount;
  private Matcher matcher;
  
  protected int processLineContent(String line, int offset)
  {
    if (blockLineCount == 0)
    {
      builder.beginBlock(DocumentBuilder.BlockType.DEFINITION_LIST, new Attributes());
    }
    else
    {
      matcher = startPattern.matcher(line);
      if (!matcher.matches())
      {
        setClosed(true);
        return 0;
      }
    }
    blockLineCount += 1;
    
    builder.beginBlock(DocumentBuilder.BlockType.DEFINITION_TERM, new Attributes());
    markupLanguage.emitMarkupLine(parser, state, matcher.start(1), matcher.group(1), 0);
    builder.endBlock();
    
    builder.beginBlock(DocumentBuilder.BlockType.DEFINITION_ITEM, new Attributes());
    markupLanguage.emitMarkupLine(parser, state, matcher.start(2), matcher.group(2), 0);
    builder.endBlock();
    
    return -1;
  }
  
  public boolean canStart(String line, int lineOffset)
  {
    if (lineOffset == 0)
    {
      matcher = startPattern.matcher(line);
      blockLineCount = 0;
      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.twiki.core.block.DefinitionListBlock
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.twiki.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.twiki.core.block.ListBlock.ListState
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.twiki.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 ListBlock
  extends Block
{
  static final Pattern startPattern = Pattern.compile("((?: {3})+)(\\*|(?:1|a|A|i|I)\\.)\\s(.*+)");
  static final Pattern continuationPattern = Pattern.compile(" {3}\\s*(.*+)");
  private int blockLineCount = 0;
  private Matcher matcher;
  private Stack<ListState> listState;
  
  public int processLineContent(String line, int offset)
  {
    boolean continuation = false;
    if (blockLineCount == 0)
    {
      this.listState = new Stack();
      Attributes attributes = new Attributes();
      String listSpec = this.matcher.group(1);
      int level = calculateLevel(listSpec);
      String typeSpec = this.matcher.group(2);
      DocumentBuilder.BlockType type = calculateType(typeSpec);
      
      computeAttributes(attributes, type, typeSpec);
      
      offset = this.matcher.start(3);
      
      this.listState.push(new ListState(1, type, null));
      builder.beginBlock(type, attributes);
      
      adjustLevel(type, listSpec, level);
    }
    else
    {
      Matcher matcher = startPattern.matcher(line);
      if (!matcher.matches())
      {
        matcher = continuationPattern.matcher(line);
        if ((this.listState.isEmpty()) || (!matcher.matches()))
        {
          setClosed(true);
          return 0;
        }
        continuation = true;
        offset = matcher.start(1) - 1;
      }
      else
      {
        String listSpec = matcher.group(1);
        int level = calculateLevel(listSpec);
        String typeSpec = matcher.group(2);
        
        DocumentBuilder.BlockType type = calculateType(typeSpec);
        offset = matcher.start(3);
        
        adjustLevel(type, typeSpec, level);
      }
    }
    blockLineCount += 1;
    
    ListState listState = (ListState)this.listState.peek();
    if ((!continuation) && (openItem))
    {
      builder.endBlock();
      openItem = false;
    }
    if (!openItem)
    {
      openItem = true;
      builder.beginBlock(DocumentBuilder.BlockType.LIST_ITEM, new Attributes());
    }
    markupLanguage.emitMarkupLine(getParser(), state, line, offset);
    
    return -1;
  }
  
  private void computeAttributes(Attributes attributes, DocumentBuilder.BlockType type, String typeSpec)
  {
    if (type == DocumentBuilder.BlockType.NUMERIC_LIST) {
      switch (typeSpec.charAt(0))
      {
      case 'a': 
        attributes.setCssStyle("list-style: lower-alpha;");
        break;
      case 'A': 
        attributes.setCssStyle("list-style: upper-alpha;");
        break;
      case 'i': 
        attributes.setCssStyle("list-style: lower-roman;");
        break;
      case 'I': 
        attributes.setCssStyle("list-style: upper-roman;");
      }
    }
  }
  
  private void adjustLevel(DocumentBuilder.BlockType type, String typeSpec, int level)
  {
    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();
        computeAttributes(blockAttributes, type, typeSpec);
        
        listState.push(new ListState(level + 1, type, null));
        builder.beginBlock(type, blockAttributes);
      }
      else
      {
        closeOne();
        if (listState.isEmpty())
        {
          Attributes blockAttributes = new Attributes();
          computeAttributes(blockAttributes, type, typeSpec);
          
          listState.push(new ListState(1, type, null));
          builder.beginBlock(type, blockAttributes);
        }
      }
    }
  }
  
  private int calculateLevel(String listSpec)
  {
    return listSpec.length() / 3;
  }
  
  private DocumentBuilder.BlockType calculateType(String listSpec)
  {
    return listSpec.charAt(listSpec.length() - 1) == '*' ? DocumentBuilder.BlockType.BULLETED_LIST : DocumentBuilder.BlockType.NUMERIC_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.twiki.core.block.ListBlock
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.twiki.core.block;

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.HeadingAttributes;
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 startPattern = Pattern.compile("---(\\+{1,6})\\s*(!!\\s*)?(.*)");
  private Matcher matcher;
  
  public int processLineContent(String line, int offset)
  {
    offset = matcher.start(3);
    int level = matcher.group(1).length();
    
    String bangEscape = matcher.group(2);
    boolean omitFromToc = false;
    if ((bangEscape != null) && (bangEscape.length() > 0)) {
      omitFromToc = true;
    }
    if ((offset > 0) && (level > 0))
    {
      HeadingAttributes attributes = new HeadingAttributes();
      attributes.setOmitFromTableOfContents(omitFromToc);
      attributes.setId(state.getIdGenerator().newId("h" + level, line.substring(offset)));
      
      builder.beginHeading(level, attributes);
      builder.characters(line.substring(offset).trim());
      builder.endHeading();
    }
    setClosed(true);
    return -1;
  }
  
  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.twiki.core.block.HeadingBlock
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.twiki.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.twiki.core.TWikiLanguage;

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 (markupLanguage.isEmptyLine(line))
    {
      setClosed(true);
      return 0;
    }
    TWikiLanguage textileLanguage = (TWikiLanguage)getMarkupLanguage();
    for (Block block : textileLanguage.getParagraphBreakingBlocks()) {
      if (block.canStart(line, offset))
      {
        setClosed(true);
        return 0;
      }
    }
    if (blockLineCount != 0) {
      builder.lineBreak();
    }
    blockLineCount += 1;
    
    textileLanguage.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.twiki.core.block.ParagraphBlock
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.twiki.core.block;

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

public class TableOfContentsBlock
  extends Block
{
  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())
    {
      OutlineParser outlineParser = new OutlineParser(new TWikiLanguage());
      OutlineItem rootItem = outlineParser.parse(state.getMarkupContent());
      
      emitToc(rootItem);
    }
    return -1;
  }
  
  private void emitToc(OutlineItem item)
  {
    if (item.getChildren().isEmpty()) {
      return;
    }
    Attributes nullAttributes = new Attributes();
    
    builder.beginBlock(DocumentBuilder.BlockType.NUMERIC_LIST, new Attributes());
    for (OutlineItem child : item.getChildren())
    {
      builder.beginBlock(DocumentBuilder.BlockType.LIST_ITEM, nullAttributes);
      builder.link('#' + child.getId(), child.getLabel());
      emitToc(child);
      builder.endBlock();
    }
    builder.endBlock();
  }
  
  public boolean canStart(String line, int lineOffset)
  {
    if ((lineOffset == 0) && (!getMarkupLanguage().isFilterGenerativeContents()))
    {
      matcher = startPattern.matcher(line);
      blockLineNumber = 0;
      return matcher.matches();
    }
    matcher = null;
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.twiki.core.block.TableOfContentsBlock
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.twiki.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 VerbatimBlock
  extends Block
{
  private static final Pattern startPattern = Pattern.compile("\\s*<verbatim>(.*)");
  private static final Pattern endPattern = Pattern.compile("\\s*</verbatim>(.*)");
  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.PARAGRAPH, 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);
      blockLineCount = 0;
      return matcher.matches();
    }
    matcher = null;
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.twiki.core.block.VerbatimBlock
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.twiki.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.MarkupLanguage;
import org.eclipse.mylyn.wikitext.twiki.core.TWikiLanguage;

public class LiteralBlock
  extends Block
{
  private static final Pattern startPattern = Pattern.compile("\\s*<literal>(.*)");
  private static final Pattern endPattern = Pattern.compile("\\s*</literal>(.*)");
  private int blockLineCount = 0;
  private Matcher matcher;
  
  public int processLineContent(String line, int offset)
  {
    if (blockLineCount++ == 0)
    {
      offset = matcher.start(1);
      ((TWikiLanguage)markupLanguage).setLiteralMode(true);
      builder.beginBlock(DocumentBuilder.BlockType.PARAGRAPH, new Attributes());
    }
    else
    {
      Matcher endMatcher = endPattern.matcher(line);
      if (endMatcher.matches())
      {
        setClosed(true);
        return endMatcher.start(1);
      }
    }
    markupLanguage.emitMarkupLine(parser, state, line, offset);
    builder.characters("\n");
    return -1;
  }
  
  public void setClosed(boolean closed)
  {
    if ((closed) && (!isClosed()))
    {
      builder.endBlock();
      ((TWikiLanguage)markupLanguage).setLiteralMode(false);
    }
    super.setClosed(closed);
  }
  
  public boolean canStart(String line, int lineOffset)
  {
    if (lineOffset == 0)
    {
      matcher = startPattern.matcher(line);
      blockLineCount = 0;
      return matcher.matches();
    }
    matcher = null;
    return false;
  }
}

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

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

public class HorizontalRuleBlock
  extends Block
{
  private static final Pattern startPattern = Pattern.compile("-{3,}\\s*");
  private Matcher matcher;
  
  public int processLineContent(String line, int offset)
  {
    builder.charactersUnescaped("<hr/>");
    setClosed(true);
    return -1;
  }
  
  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.twiki.core.block.HorizontalRuleBlock
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.twiki.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.twiki.core.TWikiLanguage;

class WikiWordReplacementToken$WikiWordProcessor
  extends PatternBasedElementProcessor
{
  private WikiWordReplacementToken$WikiWordProcessor(WikiWordReplacementToken paramWikiWordReplacementToken) {}
  
  public void emit()
  {
    String escaped = group(1);
    String word = group(2);
    TWikiLanguage twikiLanguage = (TWikiLanguage)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.twiki.core.token.WikiWordReplacementToken.WikiWordProcessor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.twiki.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.twiki.core.TWikiLanguage;

public class WikiWordReplacementToken
  extends PatternBasedElement
{
  private static final Pattern replacementPattern = Pattern.compile("\\W");
  
  protected String getPattern(int groupOffset)
  {
    return "(!)?([A-Z]\\w+(?:[A-Z]\\w*)+)";
  }
  
  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);
      TWikiLanguage twikiLanguage = (TWikiLanguage)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.twiki.core.token.WikiWordReplacementToken
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.twiki.core.token;

import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
import org.eclipse.mylyn.wikitext.core.parser.ImageAttributes;
import org.eclipse.mylyn.wikitext.core.parser.markup.PatternBasedElementProcessor;
import org.eclipse.mylyn.wikitext.twiki.core.TWikiLanguage;

class IconReplacementToken$IconProcessor
  extends PatternBasedElementProcessor
{
  public void emit()
  {
    String iconType = group(1);
    String iconUrl = ((TWikiLanguage)markupLanguage).toIconUrl(iconType);
    builder.image(new ImageAttributes(), iconUrl);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.twiki.core.token.IconReplacementToken.IconProcessor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.twiki.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.twiki.core.TWikiLanguage;

class LinkReplacementToken$LinkProcessor
  extends PatternBasedElementProcessor
{
  public void emit()
  {
    String escaped = group(1);
    if (escaped != null)
    {
      String escapedText = group(2);
      builder.characters(escapedText);
    }
    else
    {
      String link = group(3);
      String text = group(5);
      if ((text == null) || (text.trim().length() == 0)) {
        text = link;
      }
      boolean looksLikeEmail = link.indexOf('@') != -1;
      if ((link.indexOf('/') != -1) || (link.indexOf('#') != -1) || (looksLikeEmail))
      {
        if (looksLikeEmail) {
          text = text.replaceFirst("\\s*mailto:", "");
        }
        builder.link(link, text);
      }
      else
      {
        link = camelCaseWordBoundaries(link);
        String target = LinkReplacementToken.access$0().matcher(link).replaceAll("");
        TWikiLanguage twikiLanguage = (TWikiLanguage)markupLanguage;
        boolean exists = twikiLanguage.computeInternalLinkExists(target);
        
        String internalHref = twikiLanguage.toInternalHref(target);
        if (!exists)
        {
          builder.characters(text);
          builder.link(internalHref, "?");
        }
        else
        {
          builder.link(internalHref, text);
        }
      }
    }
  }
  
  private String camelCaseWordBoundaries(String text)
  {
    Matcher matcher = LinkReplacementToken.access$1().matcher(text);
    String newText = Character.toString(Character.toUpperCase(text.charAt(0)));
    int start = 1;
    while (matcher.find())
    {
      int offset = matcher.start();
      newText = newText + text.substring(start, offset);
      
      newText = newText + Character.toUpperCase(text.charAt(offset + 1));
      
      start = offset + 2;
    }
    if (start < text.length()) {
      newText = newText + text.substring(start);
    }
    return newText;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.twiki.core.token.LinkReplacementToken.LinkProcessor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.twiki.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.twiki.core.TWikiLanguage;

public class LinkReplacementToken
  extends PatternBasedElement
{
  private static final Pattern replacementPattern = Pattern.compile("\\W");
  private static final Pattern wordBoundaryPattern = Pattern.compile("\\W\\w");
  
  protected String getPattern(int groupOffset)
  {
    return "(!)?(\\[\\[([^\\]]+)(?:(\\]\\[)([^\\]]*))?\\]\\])";
  }
  
  protected int getPatternGroupCount()
  {
    return 5;
  }
  
  protected PatternBasedElementProcessor newProcessor()
  {
    return new LinkProcessor(null);
  }
  
  private static class LinkProcessor
    extends PatternBasedElementProcessor
  {
    public void emit()
    {
      String escaped = group(1);
      if (escaped != null)
      {
        String escapedText = group(2);
        builder.characters(escapedText);
      }
      else
      {
        String link = group(3);
        String text = group(5);
        if ((text == null) || (text.trim().length() == 0)) {
          text = link;
        }
        boolean looksLikeEmail = link.indexOf('@') != -1;
        if ((link.indexOf('/') != -1) || (link.indexOf('#') != -1) || (looksLikeEmail))
        {
          if (looksLikeEmail) {
            text = text.replaceFirst("\\s*mailto:", "");
          }
          builder.link(link, text);
        }
        else
        {
          link = camelCaseWordBoundaries(link);
          String target = LinkReplacementToken.replacementPattern.matcher(link).replaceAll("");
          TWikiLanguage twikiLanguage = (TWikiLanguage)markupLanguage;
          boolean exists = twikiLanguage.computeInternalLinkExists(target);
          
          String internalHref = twikiLanguage.toInternalHref(target);
          if (!exists)
          {
            builder.characters(text);
            builder.link(internalHref, "?");
          }
          else
          {
            builder.link(internalHref, text);
          }
        }
      }
    }
    
    private String camelCaseWordBoundaries(String text)
    {
      Matcher matcher = LinkReplacementToken.wordBoundaryPattern.matcher(text);
      String newText = Character.toString(Character.toUpperCase(text.charAt(0)));
      int start = 1;
      while (matcher.find())
      {
        int offset = matcher.start();
        newText = newText + text.substring(start, offset);
        
        newText = newText + Character.toUpperCase(text.charAt(offset + 1));
        
        start = offset + 2;
      }
      if (start < text.length()) {
        newText = newText + text.substring(start);
      }
      return newText;
    }
  }
}

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

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

public class IconReplacementToken
  extends PatternBasedElement
{
  protected String getPattern(int groupOffset)
  {
    return "%ICON\\{\"([a-zA-Z]+)\"\\}%";
  }
  
  protected int getPatternGroupCount()
  {
    return 1;
  }
  
  protected PatternBasedElementProcessor newProcessor()
  {
    return new IconProcessor(null);
  }
  
  private static class IconProcessor
    extends PatternBasedElementProcessor
  {
    public void emit()
    {
      String iconType = group(1);
      String iconUrl = ((TWikiLanguage)markupLanguage).toIconUrl(iconType);
      builder.image(new ImageAttributes(), iconUrl);
    }
  }
}

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

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

class ImpliedEmailLinkReplacementToken$EmailLinkProcessor
  extends PatternBasedElementProcessor
{
  public void emit()
  {
    String email = group(1);
    builder.link(new LinkAttributes(), "mailto:" + email, email);
  }
}

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

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

public class ImpliedEmailLinkReplacementToken
  extends PatternBasedElement
{
  protected String getPattern(int groupOffset)
  {
    return "([a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+(?:[a-zA-Z]{2,6}))";
  }
  
  protected int getPatternGroupCount()
  {
    return 1;
  }
  
  protected PatternBasedElementProcessor newProcessor()
  {
    return new EmailLinkProcessor(null);
  }
  
  private static class EmailLinkProcessor
    extends PatternBasedElementProcessor
  {
    public void emit()
    {
      String email = group(1);
      builder.link(new LinkAttributes(), "mailto:" + email, email);
    }
  }
}

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

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.mylyn.wikitext.core.validation.ValidationProblem;
import org.eclipse.mylyn.wikitext.core.validation.ValidationProblem.Severity;
import org.eclipse.mylyn.wikitext.core.validation.ValidationRule;

public class ListWhitespaceValidationRule
  extends ValidationRule
{
  private static final Pattern almostListPattern = Pattern.compile("^((?: |\t)*)(\\*|((i|I|a|A|1)\\.))(\\S)?", 
    8);
  
  public ValidationProblem findProblem(String markup, int offset, int length)
  {
    Matcher matcher = almostListPattern.matcher(markup);
    if ((offset > 0) || (length != markup.length())) {
      matcher.region(offset, offset + length);
    }
    while (matcher.find())
    {
      String spaces = matcher.group(1);
      if ((spaces == null) || (spaces.length() == 0) || (spaces.length() % 3 != 0) || (containsNonSpace(spaces)))
      {
        int problemOffset = matcher.start();
        int problemLength = Math.max(2, matcher.end(2) - problemOffset);
        return new ValidationProblem(ValidationProblem.Severity.WARNING, 
          Messages.getString("ListWhitespaceValidationRule.1"), problemOffset, problemLength);
      }
      String after = matcher.group(5);
      if (after != null)
      {
        int problemOffset = matcher.start();
        int problemLength = Math.ma
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