
package uk.co.wingpath.gpx;

import java.io.*;
import java.util.*;
import uk.co.wingpath.xml.*;

// A link to an external resource (Web page, digital photo,
// video clip, etc) with additional information.

public class Link
    implements Xml.Savable, Xml.Loader
{
    private String href;                // URL of hyperlink.
    private String text;                // Text of hyperlink.
    private String type;                // Mime type of content (image/jpeg)

    public Xml.Loader startChild (String tag)
    {
        href = null;
        text = null;
        type = null;
        if (tag.equalsIgnoreCase ("text"))
        {
            return new Xml.StringLoader (new Xml.Receiver<String> ()
            {
                public void receive (String value)
                {
                    text = value;
                }
            });
        }
        if (tag.equalsIgnoreCase ("type"))
        {
            return new Xml.StringLoader (new Xml.Receiver<String> ()
            {
                public void receive (String value)
                {
                    type = value;
                }
            });
        }
        return null;
    }

    public void end (String value)
    {
    }

    public void cleanup ()
    {
    }

    public void attribute (String attr, String value)
    {
        if (attr.equals ("href"))
            href = value;
    }

    public void save (Xml.Saver saver)
        throws IOException
    {
        if (href != null)
            saver.saveAttribute ("href", href);
        if (text != null)
            saver.saveValue ("text", text);
        if (type != null)
            saver.saveValue ("type", type);
    }
}

