alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 * Util.java
 *
 * Created on July 19, 2002, 11:40 AM
 */

package org.netbeans.modules.xml.text.syntax;

import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import org.netbeans.editor.BaseDocument;
import org.netbeans.editor.TokenItem;
import org.netbeans.modules.xml.text.syntax.XMLSyntaxSupport;

/**
 *
 * @author  Petr Kuzel 
 */
public class Utils {

    /**
     * List all XMLKit tokens in given stream.
     */
    static void dumpXMLTokens(InputStream in) throws Exception {
        
        BaseDocument doc = new BaseDocument(XMLKit.class, false);        
        InputStreamReader isr = new InputStreamReader(new BufferedInputStream(in), "UTF8");
        StringBuffer buf = new StringBuffer();
        for (int c = isr.read(); c!= -1; c = isr.read()) {
            buf.append((char)c);
        }        
        doc.insertString(0, buf.toString(), null);
        XMLSyntaxSupport sup = new XMLSyntaxSupport(doc);

        // perform test

        TokenItem token = sup.getTokenChain(0, doc.getLength());
        while (token != null) {
            System.out.println(">" + token);
            token = token.getNext();
        }        
        System.out.println("==DONE==");
    }
    
    public static void main(String[] args) throws Exception {
        URL doctypes = Utils.class.getResource("data/Doctypes.xml");
        dumpXMLTokens(doctypes.openStream());
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.