
package uk.co.wingpath.gpx;

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

// Information about the copyright holder and any license
// governing use of this file. By linking to an appropriate license, you
// may place your data into the public domain or grant additional usage rights.

public class Copyright
    implements Xml.Savable, Xml.Loader
{
    private String author;      // Copyright holder (TopoSoft, Inc.)
    private int year;           // Year of copyright.
    private boolean hasYear;
    private String license;     // Link to external file containing license text

	public Copyright ()
    {
        author = null;
        hasYear = false;
        license = null;
    }

    public Xml.Loader startChild (String tag)
    {
        if (tag.equalsIgnoreCase ("year"))
        {
            return new Xml.IntegerLoader (new Xml.Receiver<Integer> ()
            {
                public void receive (Integer value)
                {
                    year = value;
                    hasYear = true;
                }
            });
        }
        if (tag.equalsIgnoreCase ("license"))
        {
            return new Xml.StringLoader (new Xml.Receiver<String> ()
            {
                public void receive (String value)
                {
                    license = value;
                }
            });
        }
        return null;
    }

    public void end (String value)
        throws ValueException
    {
        if (!value.equals (""))
            throw new ValueException ("Value not allowed");
    }

    public void cleanup ()
    {
    }

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

    public void save (Xml.Saver saver)
        throws IOException
    {
        if (author != null)
            saver.saveAttribute ("author", author);
        if (hasYear)
            saver.saveValue ("year", "" + year);
        if (license != null)
            saver.saveValue ("license", license);
    }
}

