1 5 package org.exoplatform.services.grammar.wiki.impl; 6 7 import org.exoplatform.container.PortalContainer; 8 import org.exoplatform.services.grammar.converter.Text2HtmlConverter ; 9 14 public class JavaTokenHandler extends TokenHandler { 15 private Text2HtmlConverter converter_ ; 16 17 public JavaTokenHandler() { 18 PortalContainer container = PortalContainer.getInstance() ; 19 converter_ = 20 (Text2HtmlConverter) container.getComponentInstanceOfType(Text2HtmlConverter.class) ; 21 } 22 23 public Token handleToken(Token parent, Token token, ParsingContext context) { 24 int position = token.end + 1 ; 25 char[] buf = context.buf_ ; 26 for(; position < buf.length; position++) { 27 switch(buf[position]) { 28 case '{' : { 29 if(position + 5 < buf.length && 30 buf[position + 1] == 'j' && 31 buf[position + 2] == 'a' && 32 buf[position + 3] == 'v' && 33 buf[position + 4] == 'a' && 34 buf[position + 5] == '}') { 35 StringBuffer b = context.getOutputBuffer() ; 36 b.append("<div class='text'>") ; 37 converter_.toHtml(context.getSubBuffer(token.end + 1, position - 1), b) ; 38 b.append("</div>") ; 39 token.end = position + 5; 40 return context.nextToken(token) ; 41 } 42 } 43 } 44 } 45 context.out(token) ; 46 return context.nextToken(token) ; 47 } 48 49 public String [] getHandleableTokenType() { return new String []{"{java}"} ;} 50 } | Popular Tags |