The Source for Java Technology Collaboration
User: Password:



Evan Summers

Evan Summers's Blog

Java Highlighter

Posted by evanx on May 08, 2007 at 02:10 AM | Comments (0)

In the Hyper Text Processor prequel, we processed half-baked HTML for this Foundation Beans series of articles.

Now let's meet the QHyperJavaProcessor, which highlights Java code in HTML pre blocks.


Code Snippet

We split up the Java text into an array of string tokens, using the following delimiter tokens, which include Java keywords to be highlighted.

public class QHyperJavaProcessor {
    static final String[] keywords = new String[] {
        "package", "import",
        "static", "final", "abstract", "synchronized", "transient",
        "default",
        "class", "interface", "@interface", "enum",
        "extends", "implements",
        "public", "private", "protected",
        "true", "false", "null",
        "instanceof",
        "void", "boolean", "int", "char", "long",
        "throws", "throw", "try", "catch", "finally",
        "new", "this", "super",
        "if", "else", "for", "while",
        "continue", "break",
        "return"
    };
    ...
}        



Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds