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

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

import java.util.ArrayList;
import java.util.List;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.AbstractMediaWikiLanguage;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.BuiltInTemplateResolver;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.MediaWikiIdGenerationStrategy;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.block.CommentBlock;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.block.EscapeBlock;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.block.HeadingBlock;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.block.ListBlock;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.block.ParagraphBlock;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.block.PreformattedBlock;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.block.SourceBlock;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.block.TableBlock;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.block.TableOfContentsBlock;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.phrase.EscapePhraseModifier;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.phrase.SimplePhraseModifier;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.token.HyperlinkExternalReplacementToken;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.token.HyperlinkInternalReplacementToken;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.token.ImageReplacementToken;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.token.LineBreakToken;
import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.SpanType;
import org.eclipse.mylyn.wikitext.core.parser.markup.Block;
import org.eclipse.mylyn.wikitext.core.parser.markup.IdGenerationStrategy;
import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;
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.HtmlCommentPhraseModifier;
import org.eclipse.mylyn.wikitext.core.parser.markup.phrase.LimitedHtmlEndTagPhraseModifier;
import org.eclipse.mylyn.wikitext.core.parser.markup.phrase.LimitedHtmlStartTagPhraseModifier;
import org.eclipse.mylyn.wikitext.core.parser.markup.token.ImpliedHyperlinkReplacementToken;
import org.eclipse.mylyn.wikitext.core.parser.markup.token.PatternLiteralReplacementToken;

public class MediaWikiLanguage
  extends AbstractMediaWikiLanguage
{
  private List<Template> templates = new ArrayList();
  private List<TemplateResolver> templateProviders = new ArrayList();
  private String templateExcludes;
  
  public MediaWikiLanguage()
  {
    setName("MediaWiki");
    setInternalLinkPattern("/wiki/{0}");
    
    templateProviders.add(new BuiltInTemplateResolver());
  }
  
  public String toInternalHref(String pageName)
  {
    return super.mapPageNameToHref(pageName);
  }
  
  public IdGenerationStrategy getIdGenerationStrategy()
  {
    return new MediaWikiIdGenerationStrategy();
  }
  
  protected void addStandardBlocks(List<Block> blocks, List<Block> paragraphBreakingBlocks)
  {
    blocks.add(new HeadingBlock());
    blocks.add(new ListBlock());
    if (hasPreformattedBlock()) {
      blocks.add(new PreformattedBlock());
    }
    blocks.add(new SourceBlock());
    
    blocks.add(new TableBlock());
    blocks.add(new TableOfContentsBlock());
    blocks.add(new EscapeBlock());
    blocks.add(new CommentBlock());
    for (Block block : blocks) {
      if (!(block instanceof ParagraphBlock)) {
        paragraphBreakingBlocks.add(block);
      }
    }
  }
  
  private boolean hasPreformattedBlock()
  {
    return configuration == null;
  }
  
  protected void addStandardPhraseModifiers(MarkupLanguage.PatternBasedSyntax phraseModifierSyntax)
  {
    phraseModifierSyntax.add(new EscapePhraseModifier());
    phraseModifierSyntax.beginGroup("(?:(?<=[\\s\\.,\\\"'?!;:\\)\\(\\{\\}\\[\\]=>])|^)(?:", 0);
    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.endGroup(")", 0);
    
    boolean escapingHtml = configuration == null ? false : configuration.isEscapingHtmlAndXml();
    if (!escapingHtml)
    {
      String[] allowedHtmlTags = {
      
        "b", "big", "blockquote", "caption", "center", "cite", "code", "dd", "del", "div", "dl", "dt", "em", 
        "font", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "i", "ins", "li", "ol", "p", "pre", "rb", "rp", "rt", 
        "ruby", "s", "small", "span", "strike", "strong", "sub", "sup", "table", "td", "th", "tr", "tt", "u", 
        "ul", "var" };
      phraseModifierSyntax.add(new LimitedHtmlEndTagPhraseModifier(allowedHtmlTags));
      phraseModifierSyntax.add(new LimitedHtmlStartTagPhraseModifier(allowedHtmlTags));
      phraseModifierSyntax.add(new HtmlCommentPhraseModifier());
    }
  }
  
  protected void addStandardTokens(MarkupLanguage.PatternBasedSyntax tokenSyntax)
  {
    tokenSyntax.add(new LineBreakToken());
    tokenSyntax.add(new org.eclipse.mylyn.wikitext.core.parser.markup.token.EntityReferenceReplacementToken("(tm)", "#8482"));
    tokenSyntax.add(new org.eclipse.mylyn.wikitext.core.parser.markup.token.EntityReferenceReplacementToken("(TM)", "#8482"));
    tokenSyntax.add(new org.eclipse.mylyn.wikitext.core.parser.markup.token.EntityReferenceReplacementToken("(c)", "#169"));
    tokenSyntax.add(new org.eclipse.mylyn.wikitext.core.parser.markup.token.EntityReferenceReplacementToken("(C)", "#169"));
    tokenSyntax.add(new org.eclipse.mylyn.wikitext.core.parser.markup.token.EntityReferenceReplacementToken("(r)", "#174"));
    tokenSyntax.add(new org.eclipse.mylyn.wikitext.core.parser.markup.token.EntityReferenceReplacementToken("(R)", "#174"));
    tokenSyntax.add(new ImageReplacementToken());
    tokenSyntax.add(new HyperlinkInternalReplacementToken());
    tokenSyntax.add(new HyperlinkExternalReplacementToken());
    tokenSyntax.add(new ImpliedHyperlinkReplacementToken());
    tokenSyntax.add(new PatternLiteralReplacementToken("(?:(?<=^|\\w\\s)(----)(?=$|\\s\\w))", "<hr/>"));
    tokenSyntax.add(new org.eclipse.mylyn.internal.wikitext.mediawiki.core.token.EntityReferenceReplacementToken());
  }
  
  protected Block createParagraphBlock()
  {
    ParagraphBlock paragraphBlock = new ParagraphBlock(hasPreformattedBlock());
    if ((configuration != null) && (configuration.isNewlinesMustCauseLineBreak())) {
      paragraphBlock.setNewlinesCauseLineBreak(true);
    }
    return paragraphBlock;
  }
  
  public List<Template> getTemplates()
  {
    return templates;
  }
  
  public void setTemplates(List<Template> templates)
  {
    if (templates == null) {
      throw new IllegalArgumentException();
    }
    this.templates = templates;
  }
  
  public List<TemplateResolver> getTemplateProviders()
  {
    return templateProviders;
  }
  
  public void setTemplateProviders(List<TemplateResolver> templateProviders)
  {
    if (templateProviders == null) {
      throw new IllegalArgumentException();
    }
    this.templateProviders = templateProviders;
  }
  
  public MarkupLanguage clone()
  {
    MediaWikiLanguage copy = (MediaWikiLanguage)super.clone();
    templates = new ArrayList(templates);
    templateProviders = new ArrayList(templateProviders);
    templateExcludes = templateExcludes;
    return copy;
  }
  
  public void setTemplateExcludes(String templateExcludes)
  {
    this.templateExcludes = templateExcludes;
  }
  
  public String getTemplateExcludes()
  {
    return templateExcludes;
  }
}

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

public class Template
{
  private String name;
  private String templateMarkup;
  
  public Template() {}
  
  public Template(String name, String templateMarkup)
  {
    this.name = name;
    this.templateMarkup = templateMarkup;
  }
  
  public String getTemplateMarkup()
  {
    return templateMarkup;
  }
  
  public void setTemplateMarkup(String templateMarkup)
  {
    this.templateMarkup = templateMarkup;
  }
  
  public String getTemplateContent()
  {
    return getTemplateMarkup();
  }
  
  public String getName()
  {
    return name;
  }
  
  public void setName(String name)
  {
    this.name = name;
  }
}

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

public abstract class TemplateResolver
{
  public abstract Template resolveTemplate(String paramString);
}

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

import java.text.SimpleDateFormat;
import java.util.Date;
import org.eclipse.mylyn.wikitext.mediawiki.core.Template;

public class DateTimeTemlate
  extends Template
{
  public DateTimeTemlate() {}
  
  public DateTimeTemlate(String name, String templateMarkup)
  {
    super(name, templateMarkup);
  }
  
  public String getTemplateContent()
  {
    String markup = getTemplateMarkup();
    if (markup != null)
    {
      SimpleDateFormat format = new SimpleDateFormat(markup);
      markup = format.format(new Date());
    }
    return markup;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.mediawiki.core.DateTimeTemlate
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.mediawiki.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 PreformattedBlock
  extends Block
{
  private static final Pattern PRE_OPEN_PATTERN = Pattern.compile(
    "(<pre((?:\\s+[a-zA-Z][a-zA-Z0-9_:-]*=\"[^\"]*\")*)\\s*>).*", 2);
  private static final Pattern PRE_CLOSE_PATTERN = Pattern.compile("(</pre*\\s*>)", 2);
  private int blockLineCount = 0;
  private boolean usesTag = false;
  
  public boolean canStart(String line, int lineOffset)
  {
    if ((lineOffset == 0) && (line.length() > 0) && (line.charAt(0) == ' '))
    {
      usesTag = false;
      return true;
    }
    Matcher matcher = PRE_OPEN_PATTERN.matcher(line);
    if (lineOffset > 0) {
      matcher.region(lineOffset, line.length());
    }
    if (matcher.matches())
    {
      usesTag = true;
      return true;
    }
    return false;
  }
  
  public int processLineContent(String line, int offset)
  {
    int lineStart = usesTag ? 0 : 1;
    if (blockLineCount++ == 0)
    {
      Attributes attributes = new Attributes();
      if (usesTag)
      {
        Matcher matcher = PRE_OPEN_PATTERN.matcher(line);
        if (offset > 0) {
          matcher.region(offset, line.length());
        }
        if (matcher.matches())
        {
          String htmlAttributes = matcher.group(2);
          processHtmlAttributes(attributes, htmlAttributes);
          
          lineStart = matcher.end(1);
          offset = lineStart;
        }
        else
        {
          throw new IllegalStateException();
        }
      }
      builder.beginBlock(DocumentBuilder.BlockType.PREFORMATTED, attributes);
    }
    if (usesTag)
    {
      if (blockLineCount > 0)
      {
        Matcher closeMatcher = PRE_CLOSE_PATTERN.matcher(line);
        if (offset > 0) {
          closeMatcher.region(offset, line.length());
        }
        if (closeMatcher.find())
        {
          int contentEnd = closeMatcher.start(1);
          int newContentStart = closeMatcher.end(1);
          if (contentEnd > 0)
          {
            String content = line.substring(offset, contentEnd);
            builder.characters(content);
            builder.characters("\n");
          }
          setClosed(true);
          if (newContentStart < line.length()) {
            return newContentStart;
          }
          return -1;
        }
      }
    }
    else if ((markupLanguage.isEmptyLine(line)) || ((offset == 0) && (line.charAt(0) != ' ')))
    {
      setClosed(true);
      return 0;
    }
    if (line.length() >= lineStart)
    {
      builder.characters(line.substring(lineStart));
      builder.characters("\n");
    }
    return -1;
  }
  
  private void processHtmlAttributes(Attributes attributes, String htmlAttributes)
  {
    if (htmlAttributes != null)
    {
      Pattern pattern = Pattern.compile("\\s+([a-zA-Z][a-zA-Z0-9_:-]*)=\"([^\"]*)\"");
      Matcher matcher = pattern.matcher(htmlAttributes);
      while (matcher.find())
      {
        String attrName = matcher.group(1);
        String attrValue = matcher.group(2);
        if ("id".equals(attrName)) {
          attributes.setId(attrValue);
        } else if ("style".equals(attrName)) {
          attributes.setCssStyle(attrValue);
        } else if ("class".equals(attrName)) {
          attributes.setCssClass(attrValue);
        }
      }
    }
  }
  
  public void setClosed(boolean closed)
  {
    if ((closed) && (!isClosed()))
    {
      builder.endBlock();
      usesTag = false;
    }
    super.setClosed(closed);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.mediawiki.core.block.PreformattedBlock
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.mediawiki.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 EscapeBlock
  extends Block
{
  private static final Pattern START_PATTERN = Pattern.compile("\\s*(<nowiki>).*", 2);
  private static final Pattern END_PATTERN = Pattern.compile("(</nowiki>)", 2);
  private int blockLineCount = 0;
  
  protected int processLineContent(String line, int offset)
  {
    if (blockLineCount++ == 0)
    {
      Matcher matcher = START_PATTERN.matcher(line);
      if (offset > 0) {
        matcher.region(offset, line.length());
      }
      if (matcher.matches()) {
        offset = matcher.end(1);
      }
    }
    Matcher closeMatcher = END_PATTERN.matcher(line);
    if (offset > 0) {
      closeMatcher.region(offset, line.length());
    }
    int contentEnd = line.length();
    int end = -1;
    if (closeMatcher.find())
    {
      int newContentStart = closeMatcher.end(1);
      setClosed(true);
      if (newContentStart < line.length())
      {
        end = newContentStart;
        contentEnd = closeMatcher.start(1);
      }
    }
    getBuilder().characters(line.substring(offset, contentEnd));
    
    return end;
  }
  
  public boolean canStart(String line, int lineOffset)
  {
    if (lineOffset == 0)
    {
      Matcher matcher = START_PATTERN.matcher(line);
      if (lineOffset > 0) {
        matcher.region(lineOffset, line.length());
      }
      if (matcher.matches()) {
        return true;
      }
    }
    return false;
  }
}

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

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

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

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.mediawiki.core.block.ListBlock.ListState
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.mediawiki.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
{
  private static final int LINE_REMAINDER_GROUP_OFFSET = 2;
  static final Pattern startPattern = Pattern.compile("((?:(?:\\*)|(?:#)|(?:\\;)|(?:\\:))+)\\s?(.+)");
  static final Pattern definitionPattern = Pattern.compile("(\\s+\\:\\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);
      char lastChar = listSpec.charAt(listSpec.length() - 1);
      int level = calculateLevel(listSpec);
      DocumentBuilder.BlockType type = calculateType(lastChar);
      DocumentBuilder.BlockType itemType = calculateItemType(lastChar);
      if ((type == DocumentBuilder.BlockType.BULLETED_LIST) && ('-' == lastChar)) {
        attributes.setCssStyle("list-style: square");
      }
      offset = this.matcher.start(2);
      
      this.listState.push(new ListState(1, type, itemType, null));
      builder.beginBlock(type, attributes);
      
      adjustLevel(lastChar, level, type, itemType);
    }
    else
    {
      Matcher matcher = startPattern.matcher(line);
      if (!matcher.matches())
      {
        setClosed(true);
        return 0;
      }
      String listSpec = matcher.group(1);
      char lastChar = listSpec.charAt(listSpec.length() - 1);
      int lineLevel = calculateLevel(listSpec);
      DocumentBuilder.BlockType type = calculateType(lastChar);
      DocumentBuilder.BlockType itemType = calculateItemType(lastChar);
      
      offset = matcher.start(2);
      
      continuation = adjustLevel(lastChar, lineLevel, type, itemType);
    }
    blockLineCount += 1;
    
    ListState listState = (ListState)this.listState.peek();
    if ((!continuation) && (openItem))
    {
      openItem = false;
      builder.endBlock();
    }
    if (!openItem)
    {
      openItem = true;
      builder.beginBlock(itemType, new Attributes());
    }
    String definition = null;
    int definitionOffset = -1;
    if (itemType == DocumentBuilder.BlockType.DEFINITION_TERM)
    {
      Matcher definitionMatcher = definitionPattern.matcher(line);
      if (offset > 0) {
        definitionMatcher.region(offset, line.length());
      }
      if (definitionMatcher.find())
      {
        line = line.substring(offset, definitionMatcher.start(1));
        offset = 0;
        definition = definitionMatcher.group(2);
        definitionOffset = definitionMatcher.start(2);
      }
    }
    if (definition == null) {
      markupLanguage.emitMarkupLine(getParser(), state, line, offset);
    } else {
      markupLanguage.emitMarkupLine(getParser(), state, offset, line, 0);
    }
    if (definition != null)
    {
      openItem = false;
      builder.endBlock();
      
      adjustLevel(' ', level, DocumentBuilder.BlockType.DEFINITION_LIST, DocumentBuilder.BlockType.DEFINITION_ITEM);
      
      listState = (ListState)this.listState.peek();
      if (openItem) {
        builder.endBlock();
      }
      openItem = true;
      builder.beginBlock(itemType, new Attributes());
      
      markupLanguage.emitMarkupLine(parser, state, definitionOffset, definition, 0);
    }
    return -1;
  }
  
  private boolean adjustLevel(char lastChar, int lineLevel, DocumentBuilder.BlockType type, DocumentBuilder.BlockType itemType)
  {
    boolean continuation = false;
    for (ListState previousState = (ListState)listState.peek(); (lineLevel != level) || (type != type) || 
          (itemType != itemType); previousState = (ListState)listState.peek()) {
      if (lineLevel > level)
      {
        if (!openItem)
        {
          builder.beginBlock(itemType, new Attributes());
          openItem = true;
        }
        Attributes blockAttributes = new Attributes();
        if ((type == DocumentBuilder.BlockType.BULLETED_LIST) && ('-' == lastChar)) {
          blockAttributes.setCssStyle("list-style: square");
        }
        listState.push(new ListState(level + 1, type, itemType, null));
        builder.beginBlock(type, blockAttributes);
      }
      else if ((lineLevel == level) && (type == type) && 
        (itemType != itemType))
      {
        if (openItem)
        {
          builder.endBlock();
          openItem = false;
        }
        itemType = itemType;
      }
      else
      {
        if ((lineLevel == level) && (lastChar == ':')) {
          if ((itemType != DocumentBuilder.BlockType.DEFINITION_ITEM) && 
            (itemType != DocumentBuilder.BlockType.DEFINITION_TERM))
          {
            continuation = true;
            break;
          }
        }
        closeOne();
        if (listState.isEmpty())
        {
          Attributes blockAttributes = new Attributes();
          if ((type == DocumentBuilder.BlockType.BULLETED_LIST) && ('-' == lastChar)) {
            blockAttributes.setCssStyle("list-style: square");
          }
          listState.push(new ListState(1, type, itemType, null));
          builder.beginBlock(type, blockAttributes);
        }
      }
    }
    return continuation;
  }
  
  private int calculateLevel(String listSpec)
  {
    return listSpec.length();
  }
  
  private DocumentBuilder.BlockType calculateType(char lastChar)
  {
    switch (lastChar)
    {
    case '#': 
      return DocumentBuilder.BlockType.NUMERIC_LIST;
    case ':': 
    case ';': 
      return DocumentBuilder.BlockType.DEFINITION_LIST;
    }
    return DocumentBuilder.BlockType.BULLETED_LIST;
  }
  
  private DocumentBuilder.BlockType calculateItemType(char lastChar)
  {
    switch (lastChar)
    {
    case ';': 
      return DocumentBuilder.BlockType.DEFINITION_TERM;
    case ':': 
      return DocumentBuilder.BlockType.DEFINITION_ITEM;
    }
    return DocumentBuilder.BlockType.LIST_ITEM;
  }
  
  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;
    DocumentBuilder.BlockType itemType;
    boolean openItem;
    
    private ListState(int level, DocumentBuilder.BlockType type, DocumentBuilder.BlockType itemType)
    {
      this.level = level;
      this.type = type;
      this.itemType = itemType;
    }
  }
}

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

public class HeadingBlock
  extends Block
{
  private static final Pattern pattern = Pattern.compile("\\s*(\\={1,6})\\s*(.+?)\\s*\\1\\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);
    
    Attributes attributes = new Attributes();
    if (attributes.getId() == null) {
      attributes.setId(state.getIdGenerator().newId("h" + level, text));
    }
    builder.beginHeading(level, attributes);
    
    offset = matcher.start(2);
    line = text;
    getMarkupLanguage().emitMarkupLine(getParser(), state, offset, line, 0);
    
    builder.endHeading();
    
    setClosed(true);
    return -1;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.internal.wikitext.mediawiki.core.block.HeadingBlock
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.mediawiki.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.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
{
  private static final Pattern rowCellSplitter = Pattern.compile("\\s*(\\|\\||!!)\\s*");
  private static final Pattern startPattern = Pattern.compile("\\{\\|\\s*(.+)?");
  private static final Pattern optionsPattern = Pattern.compile("([a-zA-Z]+)=\"([^\"]*)\"");
  private static final Pattern newRowPattern = Pattern.compile("\\|-\\s*(.+)?");
  private static final Pattern cellPattern = Pattern.compile("(\\||!)\\s*(.+)?");
  private static final Pattern cellSplitterPattern = Pattern.compile("\\s*(?:([^\\|\\[]+)?\\|)?\\s*(.+)?");
  private static final Pattern endPattern = Pattern.compile("\\|\\}\\s*(.+)?");
  private int blockLineCount;
  private Matcher matcher;
  private boolean openRow;
  
  public int processLineContent(String line, int offset)
  {
    if (blockLineCount++ == 0)
    {
      TableAttributes attributes = new TableAttributes();
      
      String options = matcher.group(1);
      if (options != null)
      {
        Matcher optionsMatcher = optionsPattern.matcher(options);
        while (optionsMatcher.find())
        {
          String optionName = optionsMatcher.group(1);
          String optionValue = optionsMatcher.group(2);
          if (optionName.equalsIgnoreCase("id")) {
            attributes.setId(optionValue);
          } else if (optionName.equalsIgnoreCase("style")) {
            attributes.setCssStyle(optionValue);
          } else if (optionName.equalsIgnoreCase("class")) {
            attributes.setCssClass(optionValue);
          } else if (optionName.equalsIgnoreCase("title")) {
            attributes.setTitle(optionValue);
          } else if (optionName.equalsIgnoreCase("border")) {
            attributes.setBorder(optionValue);
          } else if (optionName.equalsIgnoreCase("summary")) {
            attributes.setSummary(optionValue);
          } else if (optionName.equalsIgnoreCase("width")) {
            attributes.setWidth(optionValue);
          } else if (optionName.equalsIgnoreCase("frame")) {
            attributes.setFrame(optionValue);
          } else if (optionName.equalsIgnoreCase("rules")) {
            attributes.setRules(optionValue);
          } else if (optionName.equalsIgnoreCase("cellspacing")) {
            attributes.setCellspacing(optionValue);
          } else if (optionName.equalsIgnoreCase("cellpadding")) {
            attributes.setCellpadding(optionValue);
          } else if (optionName.equalsIgnoreCase("bgcolor")) {
            attributes.setBgcolor(optionValue);
          }
        }
      }
      builder.beginBlock(DocumentBuilder.BlockType.TABLE, attributes);
      
      return -1;
    }
    Matcher newRowMatcher = newRowPattern.matcher(line);
    if (newRowMatcher.matches())
    {
      TableRowAttributes attributes = new TableRowAttributes();
      String newRowOptions = newRowMatcher.group(1);
      if (newRowOptions != null)
      {
        Matcher optionsMatcher = optionsPattern.matcher(newRowOptions);
        while (optionsMatcher.find())
        {
          String optionName = optionsMatcher.group(1);
          String optionValue = optionsMatcher.group(2);
          if (optionName.equalsIgnoreCase("id")) {
            attributes.setId(optionValue);
          } else if (optionName.equalsIgnoreCase("style")) {
            attributes.setCssStyle(optionValue);
          } else if (optionName.equalsIgnoreCase("class")) {
            attributes.setCssClass(optionValue);
          } else if (optionName.equalsIgnoreCase("title")) {
            attributes.setTitle(optionValue);
          } else if (optionName.equalsIgnoreCase("align")) {
            attributes.setAlign(optionValue);
          } else if (optionName.equalsIgnoreCase("valign")) {
            attributes.setValign(optionValue);
          } else if (optionName.equalsIgnoreCase("bgcolor")) {
            attributes.setBgcolor(optionValue);
          }
        }
      }
      openRow(newRowMatcher.start(), attributes);
      return -1;
    }
    Matcher endMatcher = endPattern.matcher(line);
    if (endMatcher.matches())
    {
      setClosed(true);
      return endMatcher.start(1);
    }
    Matcher cellMatcher = cellPattern.matcher(line);
    if (cellMatcher.matches())
    {
      String kind = cellMatcher.group(1);
      String contents = cellMatcher.group(2);
      if (contents == null) {
        return -1;
      }
      int contentsStart = cellMatcher.start(2);
      DocumentBuilder.BlockType type = "!".equals(kind) ? DocumentBuilder.BlockType.TABLE_CELL_HEADER : DocumentBuilder.BlockType.TABLE_CELL_NORMAL;
      if (!openRow) {
        openRow(cellMatcher.start(), new Attributes());
      }
      emitCells(contentsStart, type, contents);
      
      return -1;
    }
    return -1;
  }
  
  private void emitCells(int contentsStart, DocumentBuilder.BlockType type, String contents)
  {
    int lastEnd = 0;
    Matcher matcher = rowCellSplitter.matcher(contents);
    while (matcher.find())
    {
      int found = matcher.start();
      String cell;
      String cell;
      if (found > lastEnd) {
        cell = contents.substring(lastEnd, found);
      } else {
        cell = "";
      }
      emitCell(lastEnd + contentsStart, type, cell);
      
      String splitterSpec = matcher.group(1);
      if ("!!".equals(splitterSpec)) {
        type = DocumentBuilder.BlockType.TABLE_CELL_HEADER;
      } else {
        type = DocumentBuilder.BlockType.TABLE_CELL_NORMAL;
      }
      lastEnd = matcher.end();
    }
    if (lastEnd < contents.length()) {
      emitCell(lastEnd + contentsStart, type, contents.substring(lastEnd));
    }
  }
  
  private void emitCell(int lineCharacterOffset, DocumentBuilder.BlockType type, String cell)
  {
    Matcher cellSplitterMatcher = cellSplitterPattern.matcher(cell);
    if (!cellSplitterMatcher.matches()) {
      throw new IllegalStateException();
    }
    String cellOptions = cellSplitterMatcher.group(1);
    String cellContents = cellSplitterMatcher.group(2);
    if (cellContents == null) {
      return;
    }
    int contentsStart = cellSplitterMatcher.start(2);
    
    TableCellAttributes attributes = new TableCellAttributes();
    if (cellOptions != null)
    {
      Matcher optionsMatcher = optionsPattern.matcher(cellOptions);
      while (optionsMatcher.find())
      {
        String optionName = optionsMatcher.group(1);
        String optionValue = optionsMatcher.group(2);
        if (optionName.equalsIgnoreCase("id")) {
          attributes.setId(optionValue);
        } else if (optionName.equalsIgnoreCase("style")) {
          attributes.setCssStyle(optionValue);
        } else if (optionName.equalsIgnoreCase("class")) {
          attributes.setCssClass(optionValue);
        } else if (optionName.equalsIgnoreCase("title")) {
          attributes.setTitle(optionValue);
        } else if (optionName.equalsIgnoreCase("align")) {
          attributes.setAlign(optionValue);
        } else if (optionName.equalsIgnoreCase("valign")) {
          attributes.setValign(optionValue);
        } else if (optionName.equalsIgnoreCase("bgcolor")) {
          attributes.setBgcolor(optionValue);
        } else if (optionName.equalsIgnoreCase("colspan")) {
          attributes.setColspan(optionValue);
        } else if (optionName.equalsIgnoreCase("rowspan")) {
          attributes.setRowspan(optionValue);
        }
      }
    }
    state.setLineCharacterOffset(lineCharacterOffset);
    
    builder.beginBlock(type, attributes);
    
    markupLanguage.emitMarkupLine(parser, state, lineCharacterOffset + contentsStart, cellContents, 0);
    builder.endBlock();
  }
  
  private void openRow(int lineOffset, Attributes attributes)
  {
    closeRow();
    state.setLineCharacterOffset(lineOffset);
    builder.beginBlock(DocumentBuilder.BlockType.TABLE_ROW, attributes);
    openRow = true;
  }
  
  private void closeRow()
  {
    if (openRow)
    {
      builder.endBlock();
      openRow = false;
    }
  }
  
  public boolean canStart(String line, int lineOffset)
  {
    blockLineCount = 0;
    openRow = false;
    if (lineOffset == 0)
    {
      matcher = startPattern.matcher(line);
      return matcher.matches();
    }
    matcher = null;
    return false;
  }
  
  public void setClosed(boolean closed)
  {
    if ((closed) && (!isClosed()))
    {
      closeRow();
      builder.endBlock();
    }
    super.setClosed(closed);
  }
}

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

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.mylyn.internal.wikitext.mediawiki.core.phrase.EscapePhraseModifier;
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.mediawiki.core.MediaWikiLanguage;

public class ParagraphBlock
  extends Block
{
  private static final Pattern ESCAPE_PHRASE_MODIFIER_PATTERN = Pattern.compile(new EscapePhraseModifier().getPattern(0));
  private static final Pattern NESTED_BLOCK_START_PATTERN = Pattern.compile("<!--", 2);
  private static final int NESTED_BLOCK_START_GROUP = 0;
  private int blockLineCount = 0;
  private boolean newlinesCauseLineBreak = false;
  private final boolean testPreformattedBlocks;
  private int nestedStartOffset = -1;
  private int nestedLineNumber = -1;
  private int lastLineNumber = -1;
  
  public ParagraphBlock(boolean testPreformattedBlocks)
  {
    this.testPreformattedBlocks = testPreformattedBlocks;
  }
  
  public boolean isNewlinesCauseLineBreak()
  {
    return newlinesCauseLineBreak;
  }
  
  public void setNewlinesCauseLineBreak(boolean newlinesCauseLineBreak)
  {
    this.newlinesCauseLineBreak = newlinesCauseLineBreak;
  }
  
  public int processLineContent(String line, int offset)
  {
    nestedStartOffset = -1;
    nestedLineNumber = -1;
    if (blockLineCount == 0)
    {
      Attributes attributes = new Attributes();
      
      builder.beginBlock(DocumentBuilder.BlockType.PARAGRAPH, attributes);
    }
    if (markupLanguage.isEmptyLine(line))
    {
      setClosed(true);
      return 0;
    }
    MediaWikiLanguage dialect = (MediaWikiLanguage)getMarkupLanguage();
    for (Block block : dialect.getParagraphBreakingBlocks()) {
      if (block.canStart(line, offset))
      {
        setClosed(true);
        return 0;
      }
    }
    Matcher nestedStartMatcher = NESTED_BLOCK_START_PATTERN.matcher(line);
    if (offset > 0) {
      nestedStartMatcher.region(offset, line.length());
    }
    if (nestedStartMatcher.find())
    {
      nestedStartOffset = nestedStartMatcher.start(0);
      if (isEscaped(line, offset, nestedStartOffset)) {
        nestedStartOffset = -1;
      } else {
        nestedLineNumber = getState().getLineNumber();
      }
    }
    blockLineCount += 1;
    if ((testPreformattedBlocks) && (offset == 0) && (line.length() > 0) && (line.charAt(0) == ' '))
    {
      setClosed(true);
      return 0;
    }
    if ((blockLineCount != 1) && (nestedStartOffset == -1) && (lastLineNumber != getState().getLineNumber())) {
      if (newlinesCauseLineBreak) {
        builder.lineBreak();
      } else {
        builder.characters("\n");
      }
    }
    if (nestedStartOffset > 0) {
      line = line.substring(0, nestedStartOffset);
    }
    dialect.emitMarkupLine(getParser(), state, line, offset);
    
    lastLineNumber = getState().getLineNumber();
    return nestedStartOffset;
  }
  
  private boolean isEscaped(String line, int lineOffset, int offset)
  {
    Matcher matcher = ESCAPE_PHRASE_MODIFIER_PATTERN.matcher(line);
    if (lineOffset > 0) {
      matcher.region(lineOffset, line.length());
    }
    while (matcher.find())
    {
      int start = matcher.start();
      int end = matcher.end();
      if ((start <= offset) && (end >= offset)) {
        return true;
      }
    }
    return false;
  }
  
  public boolean beginNesting()
  {
    return nestedStartOffset != -1;
  }
  
  public int findCloseOffset(String line, int lineOffset)
  {
    return -1;
  }
  
  public boolean canResume(String line, int lineOffset)
  {
    if ((getState().getLineNumber() == nestedLineNumber) && (lineOffset == nestedStartOffset)) {
      return false;
    }
    return true;
  }
  
  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.mediawiki.core.block.ParagraphBlock
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.internal.wikitext.mediawiki.core.block;

import java.util.List;
import org
1 2 3 4 5 6 7

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