1 5 package org.exoplatform.services.grammar.wiki.impl; 6 7 12 public class LinkTokenHandler extends TokenHandler { 13 14 public Token handleToken(Token parent, Token token, ParsingContext context) { 15 int index = -1; 16 for(int i = token.start + 1; i < token.end; i++) { 17 if(context.buf_[i] == '>') { 18 index = i ; 19 break ; 20 } 21 } 22 String text = null , link = null ; 23 if(index > token.start + 1) { 24 text = context.getSubstring(token.start + 1, index -1) ; 25 link = context.getSubstring(index + 1, token.end - 1) ; 26 } else { 27 link = context.getSubstring(token.start + 1, token.end - 1) ; 28 text = link ; 29 } 30 StringBuffer b = context.getOutputBuffer() ; 31 b.append("<a HREF='"); 32 if(!link.startsWith("http://")) b.append("http://") ; 33 b.append(link); 34 b.append("'>").append(text).append("</a>") ; 35 return context.nextToken(token) ; 36 } 37 38 public String [] getHandleableTokenType() { return new String []{Token.LINK_TOKEN} ;} 39 } | Popular Tags |