KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.exoplatform.container.PortalContainer;
8 import org.exoplatform.services.grammar.converter.Text2HtmlConverter ;
9 /**
10  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
11  * @since Dec 19, 2004
12  * @version $Id$
13  */

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 JavaDoc 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 JavaDoc[] getHandleableTokenType() { return new String JavaDoc[]{"{java}"} ;}
50 }
Popular Tags