KickJava   Java API By Example, From Geeks To Geeks.

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


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 StrikeTokenHandler extends TokenHandler {
13   
14   private Token parent_ = new Token(0,0);
15   
16   public Token handleToken(Token parent, Token token, ParsingContext context) {
17     StringBuffer JavaDoc b = context.getOutputBuffer() ;
18     parent_.clone(token) ;
19     parent_.parent = parent ;
20     token = context.nextToken(token) ;
21     if(token.type == Token.DEFAULT_TOKEN) {
22       b.append("<strike>") ;
23       while(token != null) {
24         if(token.type == Token.DEFAULT_TOKEN) {
25           token = context.getTokenHandlerManager().handleToken(parent_, token, context) ;
26         } else if(token.type == Token.STRIKE_TOKEN) {
27           token = context.nextToken(token) ;
28           break ;
29         } else if(token.group == Token.SINGLE_TOKEN_GROUP || token.group == Token.INLINE_TOKEN_GROUP) {
30           if(parent_.hasAncestor(token.type)) {
31             break ;
32           }
33           token = context.getTokenHandlerManager().handleToken(parent_, token, context) ;
34         } else {
35           break ;
36         }
37       }
38       b.append("</strike>") ;
39       return token ;
40     }
41     b.append(context.buf_, parent_.start, parent_.end - parent_.start + 1) ;
42     return token ;
43   }
44   
45   public String JavaDoc[] getHandleableTokenType() { return new String JavaDoc[]{Token.STRIKE_TOKEN} ;}
46 }
Popular Tags