KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > grammar > wiki > impl > LinkTokenHandler


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.grammar.wiki.impl;
6
7 /**
8  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
9  * @since Dec 19, 2004
10  * @version $Id$
11  */

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 JavaDoc 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 JavaDoc 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 JavaDoc[] getHandleableTokenType() { return new String JavaDoc[]{Token.LINK_TOKEN} ;}
39 }
Popular Tags