View Javadoc

1   /*
2    * $Id: OWLNameRule.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.IToken;
12  import org.eclipse.jface.text.rules.Token;
13  import org.eclipse.jface.text.rules.WordRule;
14  import org.eclipse.swt.SWT;
15  
16  import com.bbn.swede.core.dom.OASTNode;
17  import com.bbn.swede.editor.OWLColorProvider;
18  
19  /***
20   * Word rule for identifying language tags vs. non-language tags.  This rule
21   * does not differentiate between things and predicates.  If the scanner using
22   * the rule does not do any additional processing, both types of generics
23   * will be colored as things.
24   * @author jlerner
25   */
26  public class OWLNameRule extends WordRule
27  {
28     private boolean _bTagFound;
29     /***
30      * Return token for generic tags and attributes.
31      */
32     public static final IToken TOKEN_GENERIC = new Token(
33        OWLColorProvider.getColorProvider().createTextAttribute(
34           OWLColorProvider.GENERIC_TAG));
35     /***
36      * Return token for language tags and attributes.
37      */
38     public static final IToken TOKEN_LANG = new Token(
39        OWLColorProvider.getColorProvider().createTextAttribute(
40           OWLColorProvider.LANG,
41           SWT.BOLD));
42     
43     /***
44      * Creates a new OWLNameRule with OWLNameRule.TOKEN_GENERIC as its default
45      * return token.
46      */
47     public OWLNameRule()
48     {
49        super(new XMLNameDetector(), TOKEN_GENERIC);
50        createWords();
51     }
52     
53     /***
54      * Builds the list of words that are considered language elements.  This
55      * list is based on the values used in com.bbn.swede.core.dom to 
56      * differentiate between langauage elements and generics.
57      */
58     private void createWords()
59     {
60        String[] as = OASTNode.AS_RDF;
61        for (int i = 0; i < as.length; i++)
62        {
63           addWord("rdf:" + as[i], TOKEN_LANG);
64        }
65        as = OASTNode.AS_RDFS;
66        for (int i = 0; i < as.length; i++)
67        {
68           addWord("rdfs:" + as[i], TOKEN_LANG);
69        }
70        as = OASTNode.AS_OWL;
71        for (int i = 0; i < as.length; i++)
72        {
73           addWord("owl:" + as[i], TOKEN_LANG);
74        }
75     }
76  }