KickJava   Java API By Example, From Geeks To Geeks.

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


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 17, 2004
10  * @version $Id$
11  */

12 public class Token {
13   final static public String JavaDoc DEFAULT_TOKEN = "default" ;
14   final static public String JavaDoc BOLD_TOKEN = "**" ;
15   final static public String JavaDoc ITALIC_TOKEN = "~~" ;
16   final static public String JavaDoc STRIKE_TOKEN = "--" ;
17   final static public String JavaDoc UNDERLINE_TOKEN = "__" ;
18   final static public String JavaDoc HORIZONTAL_LINE_TOKEN = "---" ;
19   final static public String JavaDoc SINGLE_NEW_LINE_TOKEN = "\n" ;
20   final static public String JavaDoc MULTIPLE_NEW_LINE_TOKEN = "\n+" ;
21   final static public String JavaDoc SMILEY_TOKEN = "smiley" ;
22   
23   final static public String JavaDoc TITLE_1_TOKEN = "\n 1 " ;
24   final static public String JavaDoc TITLE_1_1_TOKEN = "\n 1.1" ;
25   
26   final static public String JavaDoc LINK_TOKEN = "[.+]" ;
27   
28   final static public String JavaDoc LIST_LEVEL_1_TOKEN = "\n *" ;
29   final static public String JavaDoc LIST_LEVEL_2_TOKEN = "\n **" ;
30   final static public String JavaDoc LIST_LEVEL_3_TOKEN = "\n ***" ;
31   
32   final static public String JavaDoc ENUMERATED_TOKEN = "\n 1." ;
33   final static public String JavaDoc ALPHABETICAL_ENUMERATED_TOKEN = "\n a." ;
34   final static public String JavaDoc ROMAN_ENUMERATED_TOKEN = "\n i." ;
35   
36   final static public String JavaDoc CURLY_BRACES_TOKEN = "{.+}" ;
37   
38   final static public String JavaDoc SINGLE_TOKEN_GROUP = "single" ;
39   final static public String JavaDoc INLINE_TOKEN_GROUP = "inline" ;
40   final static public String JavaDoc BLOCK_TOKEN_GROUP = "block" ;
41   
42   int start ;
43   int end ;
44   String JavaDoc type ;
45   String JavaDoc group ;
46   Token parent ;
47   
48   Token(int start, int end) {
49     this.start = start ;
50     this.end = end ;
51   }
52   
53   Token(int start, int end, String JavaDoc type) {
54     this.start = start ;
55     this.end = end ;
56     this.type = type ;
57   }
58   
59   Token(Token token) {
60     this.start = token.start ;
61     this.end = token.end ;
62     this.type = token.type ;
63     this.group = token.group ;
64     parent = token.parent ;
65   }
66   
67   public void clone(Token token) {
68     this.start = token.start ;
69     this.end = token.end ;
70     this.type = token.type ;
71     this.group = token.group ;
72     this.parent = token.parent ;
73   }
74   
75   final public String JavaDoc getTokenImage(ParsingContext context) {
76     return context.getSubstring(start, end) ;
77   }
78   
79   public String JavaDoc getTokenType() { return type ; }
80   
81   public String JavaDoc getTokenGroup() { return group ; }
82   
83   public boolean hasAncestor(String JavaDoc type) {
84     Token p = parent ;
85     while(p != null) {
86       if(p.type == type) return true ;
87       p = p.parent ;
88     }
89    return false ;
90   }
91 }
Popular Tags