KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > xml > lexer > XMLTokenId


1 /*
2  * Sun Public License Notice
3  *
4  * The contents of this file are subject to the Sun Public License
5  * Version 1.0 (the "License"). You may not use this file except in
6  * compliance with the License. A copy of the License is available at
7  * http://www.sun.com/
8  *
9  * The Original Code is NetBeans. The Initial Developer of the Original
10  * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
11  * Microsystems, Inc. All Rights Reserved.
12  */

13 package org.netbeans.api.xml.lexer;
14
15 import java.util.Collection JavaDoc;
16 import java.util.EnumSet JavaDoc;
17 import java.util.HashMap JavaDoc;
18 import java.util.Map JavaDoc;
19 import org.netbeans.api.lexer.InputAttributes;
20 import org.netbeans.api.lexer.Language;
21 import org.netbeans.api.lexer.LanguagePath;
22 import org.netbeans.api.lexer.Token;
23 import org.netbeans.api.lexer.TokenId;
24 import org.netbeans.lib.xml.lexer.XMLLexer;
25 import org.netbeans.spi.lexer.LanguageEmbedding;
26 import org.netbeans.spi.lexer.LanguageHierarchy;
27 import org.netbeans.spi.lexer.Lexer;
28 import org.netbeans.spi.lexer.LexerRestartInfo;
29
30 /**
31  * Token ids of XML language
32  */

33 public enum XMLTokenId implements TokenId {
34     
35     /** Plain text */
36     TEXT("xml-text"),
37     /** Erroneous Text */
38     WS("xml-ws"),
39     /** Plain Text*/
40     ERROR("xml-error"),
41     /** XML Tag */
42     TAG("xml-tag"),
43     /** Argument of a tag */
44     ARGUMENT("xml-attribute"),
45     /** Operators - '=' between arg and value */
46     OPERATOR("xml-operator"),
47     /** Value - value of an argument */
48     VALUE("xml-value"),
49     /** Block comment */
50     BLOCK_COMMENT("xml-comment"),
51     /** SGML declaration in XML document - e.g. <!DOCTYPE> */
52     DECLARATION("xml-doctype"),
53     /** Character reference, e.g. &amp;lt; = &lt; */
54     CHARACTER("xml-ref"),
55     /** End of line */
56     EOL("xml-EOL"),
57     /* PI start delimiter <sample><b>&lt;?</b>target content of pi ?></sample> */
58     PI_START("xml-pi-start"),
59     /* PI target <sample>&lt;?<b>target</b> content of pi ?></sample> */
60     PI_TARGET("xml-pi-target"),
61     /* PI conetnt <sample>&lt;?target <b>content of pi </b>?></sample> */
62     PI_CONTENT("pi-content"),
63     /* PI end delimiter <sample>&lt;?target <content of pi <b>?></b></sample> */
64     PI_END("pi-end"),
65     /** Cdata section including its delimiters. */
66     CDATA_SECTION("xml-cdata-section");
67
68     private final String JavaDoc primaryCategory;
69
70     XMLTokenId() {
71         this(null);
72     }
73
74     XMLTokenId(String JavaDoc primaryCategory) {
75         this.primaryCategory = primaryCategory;
76     }
77
78     public String JavaDoc primaryCategory() {
79         return primaryCategory;
80     }
81
82     private static final Language<XMLTokenId> language = new LanguageHierarchy<XMLTokenId>() {
83         @Override JavaDoc
84         protected Collection JavaDoc<XMLTokenId> createTokenIds() {
85             return EnumSet.allOf(XMLTokenId.class);
86         }
87         
88         @Override JavaDoc
89         protected Map JavaDoc<String JavaDoc,Collection JavaDoc<XMLTokenId>> createTokenCategories() {
90             Map JavaDoc<String JavaDoc,Collection JavaDoc<XMLTokenId>> cats = new HashMap JavaDoc<String JavaDoc,Collection JavaDoc<XMLTokenId>>();
91             
92             // Incomplete literals
93
//cats.put("incomplete", EnumSet.of());
94
// Additional literals being a lexical error
95
//cats.put("error", EnumSet.of());
96

97             return cats;
98         }
99         
100         @Override JavaDoc
101         public Lexer<XMLTokenId> createLexer(LexerRestartInfo<XMLTokenId> info) {
102             return new XMLLexer(info);
103         }
104         
105         @Override JavaDoc
106         public LanguageEmbedding<? extends TokenId> embedding(
107         Token<XMLTokenId> token, LanguagePath languagePath, InputAttributes inputAttributes) {
108             return null; // No embedding
109
}
110         
111         @Override JavaDoc
112         public String JavaDoc mimeType() {
113             return "text/xml";
114         }
115     }.language();
116     
117     public static Language<XMLTokenId> language() {
118         return language;
119     }
120     
121 }
122
Popular Tags