/*
 Copyright © 2000, 2001 Metamatrix Development & Consulting AB.

 This file is subject to the terms and conditions of the GNU General Public
 License.  See the file COPYING in the main directory of this archive
 for more details.

 */
package test;

import se.metamatrix.mimedir.*;
import java.io.FileReader;

/**
 * This is a test class that uses the se.metamatrix.mimedir
 * package. The class implements the two interfaces ContentHandler and
 * ErrorHandler so that the parser can notify the an object of Test
 * that is created in main() of what it parsers and, if any, of
 * errors.
 */

class Test implements ContentHandler, ErrorHandler
{
    public static void main(String args[])
	throws Exception
    {
	Test t = new Test();
	Parser p = new Parser(t, t);
	FileReader fr = new FileReader(args[0]);

	// construct a value vector and feed to the parser
	Value v[] = new Value[3];
	v[0] = new Value("x-text-test", "text");
	v[1] = new Value("x-boolean-test", "boolean");
	v[2] = new Value("dtstart", "datetime");
	p.setValues(v);

	p.parse(fr);
    }

    /**
     * A simple error handling routine that prints every recieved
     * error to stdout
     */
    public void error(int level, int code, String details)
    {
	System.out.println("level: " + level + " detail: " + details);
    }

    /**
     * A simple content handler that prints every correctly parsed
     * line along with its parameters to stdout.
     */
    public void contentLine(String name, Parameter param[], Object value, String group)
    {
	System.out.println("name: [" + name + "] value: [" + value + "]");
	for(int i = 0; i < param.length; i++) {
	    System.out.println(" parameter name: [" + param[i].getName() 
			       + "] value: [" + param[i].getValue() + "]");
	}
    }
}

