package axsvg;

import java.io.*;
import fr.dyade.koala.dom.*;
import fr.dyade.koala.dom.util.*;
import org.w3c.dom.*;
import java.util.Hashtable;



public class Descriptor {
    public static void main(String[] args) throws Exception {
	int numberOfArgs = args.length;
	if(numberOfArgs != 1) {
	System.out.println("Usage: java -jar axsvg.jar SvgFile");
	return;
	}
       // Sets the sax parser property to use the xerces parser
       System.setProperty("org.xml.sax.driver",
			  "org.apache.xerces.parsers.SAXParser");
 
       // Opens a 'doc.xml' file located in the current directory
       String uri = args[0];
       DOMImplementation impl=GenericDOMImplementation.getDOMImplementation();
       Document doc = new DocumentFactory(impl).createDocument(
 "http://www.w3.org/TR/2000/03/WD-SVG-20000303/DTD/svg-20000303-stylable.dtd",
 "svg",uri);
 
       // The document can now be used through the DOM API.
       // ...
       
       DocumentMixte docMixte = new DocumentMixte(doc);
       printWholeDesc(docMixte);
    }
    
    public static void printWholeDesc(DocumentMixte docMixte)
    throws Exception {
       AElementSVG racineSVG = new AElementSVG(docMixte.getSVGRoot());
       Element racineRDF = docMixte.getRDFRoot();
       Hashtable tableRDF = docMixte.getTableRDF();
       String title = racineSVG.getTitle();
       String desc = racineSVG.getDesc();

       System.out.println();
       System.out.println();
       System.out.print("This document ");
       if(title.equals("")) {
	  System.out.print("has no title, and ");
       }
       else {
	   System.out.print("is entitled -"+title+"- and ");
       }
       if(desc.equals("")) {
	  System.out.println("has no description.");
       }
       else {
	   System.out.println(desc+".");
       }
       System.out.println("In this document: ");

       String about;
       Node node = racineRDF.getFirstChild();
       while(node != null) {
	   if((node.getNodeName()).equalsIgnoreCase("rdf:Description")) {
	       about = ((Element)node).getAttribute("about");
	       AElementRDF eltRDF = (AElementRDF)tableRDF.get(about);
	       if(eltRDF != null) {
		   eltRDF.spitDesc(docMixte);
		   tableRDF.remove(about);
	       }
	   }
	   node = node.getNextSibling();
       }
       System.out.println();
       System.out.println();
    }
}
    
