~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to xml/lexer/src/org/netbeans/api/xml/lexer/XMLTokenId.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
If you wish your version of this file to be governed by only the CDDL
 
14
or only the GPL Version 2, indicate your decision by adding
 
15
"[Contributor] elects to include this software in this distribution
 
16
under the [CDDL or GPL Version 2] license." If you do not indicate a
 
17
single choice of license, a recipient has the option to distribute
 
18
your version of this file under either the CDDL, the GPL Version 2 or
 
19
to extend the choice of license to its licensees as provided above.
 
20
However, if you add GPL Version 2 code and therefore, elected the GPL
 
21
Version 2 license, then the option applies only if the new code is
 
22
made subject to such option by the copyright holder.
 
23
 
 
24
If you wish your version of this file to be governed by only the CDDL
 
25
or only the GPL Version 2, indicate your decision by adding
 
26
"[Contributor] elects to include this software in this distribution
 
27
under the [CDDL or GPL Version 2] license." If you do not indicate a
 
28
single choice of license, a recipient has the option to distribute
 
29
your version of this file under either the CDDL, the GPL Version 2 or
 
30
to extend the choice of license to its licensees as provided above.
 
31
However, if you add GPL Version 2 code and therefore, elected the GPL
 
32
Version 2 license, then the option applies only if the new code is
 
33
made subject to such option by the copyright holder.
 
34
 */
 
35
package org.netbeans.api.xml.lexer;
 
36
 
 
37
import java.util.Collection;
 
38
import java.util.EnumSet;
 
39
import java.util.HashMap;
 
40
import java.util.Map;
 
41
import org.netbeans.api.lexer.InputAttributes;
 
42
import org.netbeans.api.lexer.Language;
 
43
import org.netbeans.api.lexer.LanguagePath;
 
44
import org.netbeans.api.lexer.Token;
 
45
import org.netbeans.api.lexer.TokenId;
 
46
import org.netbeans.lib.xml.lexer.XMLLexer;
 
47
import org.netbeans.spi.lexer.LanguageEmbedding;
 
48
import org.netbeans.spi.lexer.LanguageHierarchy;
 
49
import org.netbeans.spi.lexer.Lexer;
 
50
import org.netbeans.spi.lexer.LexerRestartInfo;
 
51
 
 
52
/**
 
53
 * Token ids of XML language
 
54
 */
 
55
public enum XMLTokenId implements TokenId {
 
56
    
 
57
    /** Plain text */
 
58
    TEXT("xml-text"),
 
59
    /** Erroneous Text */
 
60
    WS("xml-ws"),
 
61
    /** Plain Text*/
 
62
    ERROR("xml-error"),
 
63
    /** XML Tag */
 
64
    TAG("xml-tag"),
 
65
    /** Argument of a tag */
 
66
    ARGUMENT("xml-attribute"),
 
67
    /** Operators - '=' between arg and value */
 
68
    OPERATOR("xml-operator"),
 
69
    /** Value - value of an argument */
 
70
    VALUE("xml-value"),
 
71
    /** Block comment */
 
72
    BLOCK_COMMENT("xml-comment"),
 
73
    /** SGML declaration in XML document - e.g. <!DOCTYPE> */
 
74
    DECLARATION("xml-doctype"),
 
75
    /** Character reference, e.g. &amp;lt; = &lt; */
 
76
    CHARACTER("xml-ref"),
 
77
    /** End of line */
 
78
    EOL("xml-EOL"),
 
79
    /* PI start delimiter <sample><b>&lt;?</b>target content of pi ?></sample> */
 
80
    PI_START("xml-pi-start"),    
 
81
    /* PI target <sample>&lt;?<b>target</b> content of pi ?></sample> */
 
82
    PI_TARGET("xml-pi-target"),
 
83
    /* PI conetnt <sample>&lt;?target <b>content of pi </b>?></sample> */
 
84
    PI_CONTENT("pi-content"),
 
85
    /* PI end delimiter <sample>&lt;?target <content of pi <b>?></b></sample> */
 
86
    PI_END("pi-end"),
 
87
    /** Cdata section including its delimiters. */
 
88
    CDATA_SECTION("xml-cdata-section");
 
89
 
 
90
    private final String primaryCategory;
 
91
 
 
92
    XMLTokenId() {
 
93
        this(null);
 
94
    }
 
95
 
 
96
    XMLTokenId(String primaryCategory) {
 
97
        this.primaryCategory = primaryCategory;
 
98
    }
 
99
 
 
100
    public String primaryCategory() {
 
101
        return primaryCategory;
 
102
    }
 
103
 
 
104
    private static final Language<XMLTokenId> language = new LanguageHierarchy<XMLTokenId>() {
 
105
        @Override
 
106
        protected Collection<XMLTokenId> createTokenIds() {
 
107
            return EnumSet.allOf(XMLTokenId.class);
 
108
        }
 
109
        
 
110
        @Override
 
111
        protected Map<String,Collection<XMLTokenId>> createTokenCategories() {
 
112
            Map<String,Collection<XMLTokenId>> cats = new HashMap<String,Collection<XMLTokenId>>();
 
113
            
 
114
            // Incomplete literals
 
115
            //cats.put("incomplete", EnumSet.of());
 
116
            // Additional literals being a lexical error
 
117
            //cats.put("error", EnumSet.of());
 
118
            
 
119
            return cats;
 
120
        }
 
121
        
 
122
        @Override
 
123
        public Lexer<XMLTokenId> createLexer(LexerRestartInfo<XMLTokenId> info) {
 
124
            return new XMLLexer(info);
 
125
        }
 
126
        
 
127
        @Override
 
128
        public LanguageEmbedding<?> embedding(
 
129
        Token<XMLTokenId> token, LanguagePath languagePath, InputAttributes inputAttributes) {
 
130
            return null; // No embedding
 
131
        }
 
132
        
 
133
        @Override
 
134
        public String mimeType() {
 
135
            return "text/xml";
 
136
        }
 
137
    }.language();
 
138
    
 
139
    public static Language<XMLTokenId> language() {
 
140
        return language;
 
141
    }
 
142
    
 
143
}