View Javadoc

1   /*
2    * $Id: XMLNameRule.java,v 1.5 2004/09/20 03:51:39 jlerner Exp $
3    *
4    * Copyright (c) 1999-2004, BBN Technologies, LLC.
5    * All rights reserved.
6    * http://www.daml.org/legal/opensource/bbn_license.html
7    */
8    
9   package com.bbn.swede.editor.rules;
10  
11  import org.eclipse.jface.text.rules.ICharacterScanner;
12  import org.eclipse.jface.text.rules.IToken;
13  import org.eclipse.jface.text.rules.Token;
14  import org.eclipse.jface.text.rules.WordRule;
15  import org.eclipse.swt.SWT;
16  
17  import com.bbn.swede.editor.OWLColorProvider;
18  
19  /***
20   * Handles special-case name checking to identify xmlns: and xml: 
21   * attributes.
22   */
23  public class XMLNameRule extends WordRule
24  {
25     /***
26      * Return token for xml:base and namespace attributes.
27      */
28     public static final IToken TOKEN_XML = new Token(
29        OWLColorProvider.getColorProvider().createTextAttribute(
30           OWLColorProvider.XML_ATTRIBUTE, SWT.BOLD));
31  
32     private WordBeginRule _ruleNamespace;
33     private WordBeginRule _ruleXML;
34     
35     /***
36      * Creates a new XMLNameRule to detect xml: and xmlns: attributes.
37      */
38     public XMLNameRule()
39     {
40        super(new XMLNameDetector(), Token.UNDEFINED);
41        _ruleNamespace = new WordBeginRule(new XMLNameDetector(), "xmlns:", TOKEN_XML);
42        _ruleXML = new WordBeginRule(new XMLNameDetector(), "xml:", TOKEN_XML);
43        addWord("xmlns", TOKEN_XML);
44     }
45  
46     /* (non-Javadoc)
47      * @see org.eclipse.jface.text.rules.IRule#evaluate(org.eclipse.jface.text.rules.ICharacterScanner)
48      */
49     public IToken evaluate(ICharacterScanner scanner)
50     {
51        IToken token = super.evaluate(scanner);
52        if (!token.isUndefined())
53        {
54           return token;
55        }
56        
57        token = _ruleNamespace.evaluate(scanner);
58        if (!token.isUndefined())
59        {
60           return token;
61        }
62        
63        token = _ruleXML.evaluate(scanner);
64        return token;
65     }
66  
67  }