/*
 * Created on 13 mai 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.injac.indexing.util;

import javax.xml.parsers.*;

import org.xml.sax.helpers.*;
import org.xml.sax.*;

import java.io.*;
import java.util.LinkedList;

/**
 * Classe utilisee par ExtragereMetadate pour parser
 * le fichier xml de definition des metadonnees inJac
 * @authors Marius Mirea, Francois Jannin
 */
class HandlerExtMeta extends DefaultHandler {
	LinkedList l;
	
	public HandlerExtMeta(){l = new LinkedList();}
	
	public void startDocument() throws SAXException {
		System.out.println("document parsing start:\n");
		}
	public void endDocument() throws SAXException {
		System.out.println("document parsing end\n");
		}
	public void startElement(String ns, String local,
	String numeLocal, Attributes atts) throws SAXException {
		if(numeLocal.equals("meta")){
			String name = atts.getValue("name");
			l.add(name);
			}
		
		}
	public void endElement(String ns, String local,
			String nume) throws SAXException {
		
		}
	
	public LinkedList getLinkedList() {return l;}
	
	}
/**
 *Classe pour extraire les metadonnees du fichier xml de 
 *definitions des metadonnees inJac
 * @author marius
 */
public class MetadataReader {
	public static void main(String[] args){
		SAXParserFactory factory = SAXParserFactory.newInstance();
		HandlerExtMeta handler = new HandlerExtMeta();
		SAXParser parser;
		
		try{
			parser = factory.newSAXParser();
			parser.parse("./Auxiliar/metadate.xml", handler);
			LinkedList l = handler.getLinkedList();
			Object[] T = l.toArray();
			String[] S = new String[T.length];
			for(int i = 0; i < T.length; i++)
				S[i] = (String)T[i];
			for(int i = 0; i < S.length; i++)
				System.out.println(S[i]);
			}
		catch(SAXException se){
			System.out.println("SAXException:\n" + 
					se.getMessage());
			}
		catch(IOException ioe){
			System.out.println("IOException:\n" + 
					ioe.getMessage());
			}
		catch(ParserConfigurationException pce){
			System.out.println("ParserConfigurationException:\n" + 
					pce.getMessage());
			}
		}
}
