/**
 * Class AElementSVG
 * This class implements some useful features for an Accessibility approach of
 * the DOM tree representing an SVG document.
 * An instance of this class will point to an SVG Element node of the DOM,
 * which is supposed to represent an entity of the drawing decribed by the SVG
 * code (most of the time then, a 'g' element).
 * The methods of this class will allow any user to access to the description
 * and title of the entity represented by the calling AElementSVG (ie the
 * childnodes of the SVG Element node pointed whose names are 'desc' or
 * 'title').
 **/

package axsvg;

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


public class AElementSVG {
    private final Element generator;


    /**
     * method AElementSVG
     * @param an Element node of the DOM, image of the SVG code.
     * The constructor of the class. It sets the attribute generator which
     * points to the Element node of the DOM which code (in SVG)
     * the entity of the drawing represented by the new object being built.
     **/
    public AElementSVG(Element elt) {
	generator = elt;
    }


    /**
     * method getTitle
     * @return the content of the calling object's generator childnode
     * whose name is 'title'.
     * ie, it returns the title of the entity represented by the calling
     * AElementSVG.
     **/
    public String getTitle() {
	Node elt = generator.getFirstChild();
	while(elt != null) {
	     if(elt.getNodeName().equalsIgnoreCase("title")) {
		 return(((Text)elt.getFirstChild()).getData());
	     }
	     elt = elt.getNextSibling();
	}
	return("");
    }


    /**
     * method getGenerator
     * @return the attribute generator of the calling object.
     * This attribute is the Element node of the DOM which code (in SVG)
     * the entity of the drawing represented by the calling AElementSVG.
     **/
    public Element getGenerator() {
	return(generator);
    }


    /**
     * method getDesc
     * @return the content of the calling object's generator childnode
     * whose name is 'desc'.
     * ie, it returns the description of the entity (in the SVG code, NOT in
     * the RDF code)
     * represented by the calling AElementSVG.
     **/
    public String getDesc() {
	Node elt = generator.getFirstChild();
	while(elt != null) {
	     if(elt.getNodeName().equalsIgnoreCase("desc")) {
		 return(((Text)elt.getFirstChild()).getData());
	     }
	     elt = elt.getNextSibling();
	}
	return("");
    }
}
	
