www.pudn.com > Caliph_v0.9.13+Emirv0.8.5-src.zip > Mpeg7AnnotationInfo.java


/* 
 * This file is part of Caliph & Emir. 
 * 
 * Caliph & Emir is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 2 of the License, or 
 * (at your option) any later version. 
 * 
 * Caliph & Emir is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 * GNU General Public License for more details. 
 * 
 * You should have received a copy of the GNU General Public License 
 * along with Caliph & Emir; if not, write to the Free Software 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 * 
 * Copyright statement: 
 * -------------------- 
 * (c) 2002-2004 by Mathias Lux (mathias@juggle.at) and the Know-Center Graz 
 * Inffeldgasse 21a, 8010 Graz, Austria 
 * http://www.know-center.at 
 */ 
package at.know.center.wv_wr.imb.objectcatalog.mpeg7tools; 
 
import org.jdom.Element; 
import org.jdom.Namespace; 
import org.jdom.output.XMLOutputter; 
import org.jdom.output.Format; 
 
import java.io.IOException; 
import java.util.Iterator; 
import java.util.Vector; 
 
/** 
 * Date: 02.09.2002 
 * Time: 14:48:12 
 * @author Mathias Lux, mathias@juggle.at 
 */ 
public class Mpeg7AnnotationInfo { 
    Element root; 
    Namespace mpeg7, xsi; 
 
    /** 
     * creates a new MPEG-7 DescriptionMetadata element + subelements 
     * @param version gives the version of the description, e.g. "1.0" 
     * @param givenName first name of the person who annotates, e.g. John 
     * @param familyName familyname of the person who annotates, e.g. Smith. Can be null 
     * @param organization name of the organization, e.g. W3C. Can be null 
     * @param addressLines Vector of Strings, lines of the postal address of the annotator. Can be null 
     * @param phone telephone number of the annotator. Can be null 
     * @param fax fax number of the annotator. Can be null 
     * @param email email address of the annotator. Can be null 
     * @param url homnepage url of the annotator. Can be null 
     * @param creationLocationAddressLines Vector of Strings, lines of the postal address of the creation location. Can be null 
     * @param toolName name of the instrument used to create the annotation. Can be null 
     * @param freeText additional comment. Can be null 
     */ 
    public Mpeg7AnnotationInfo(String version, String givenName, String familyName, 
                               String organization, Vector addressLines, String phone, 
                               String fax, String email, String url, Vector creationLocationAddressLines, 
                               String toolName, String freeText) { 
 
        mpeg7 = Namespace.getNamespace("", "urn:mpeg:mpeg7:schema:2001"); 
        xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); 
 
        root = new Element("DescriptionMetadata", mpeg7); 
        root.addContent(new Element("Version", mpeg7).addContent(version)); 
        if (freeText != null) 
            root.addContent(new Element("Comment", mpeg7).addContent(new Element("FreeTextAnnotation", mpeg7).addContent(freeText))); 
        // creator 
        Element creator = new Element("Creator", mpeg7); 
        root.addContent(creator); 
        creator.addContent(new Element("Role", mpeg7).setAttribute("href", "creatorCS").addContent(new Element("Name", mpeg7).addContent("Creator"))); 
        Element agent = new Element("Agent", mpeg7).setAttribute("type", "PersonType", xsi); 
        root.addContent(agent); 
        agent.addContent(new Element("Name", mpeg7).addContent(new Element("GivenName", mpeg7).addContent(givenName))); 
        if (familyName != null) agent.addContent(new Element("FamiliyName", mpeg7).addContent(familyName)); 
        if (organization != null) agent.addContent(new Element("Affiliation", mpeg7).addContent(new Element("Organization", mpeg7).addContent(new Element("Name", mpeg7).addContent(organization)))); 
        if (addressLines != null) { 
            Element paddress = new Element("PostalAddress", mpeg7); 
            for (Iterator i = addressLines.iterator(); i.hasNext();) { 
                String s = (String) i.next(); 
                paddress.addContent(new Element("AddressLine", mpeg7).addContent(s)); 
            } 
            agent.addContent(new Element("Address", mpeg7).addContent(paddress)); 
        } 
        Element eaddress = new Element("ElectronicAddress", mpeg7); 
        if ((phone != null) || (fax != null) || (email != null) || (url != null)) 
            agent.addContent(eaddress); 
        if (phone != null) eaddress.addContent(new Element("Telephone", mpeg7).addContent(phone)); 
        if (fax != null) eaddress.addContent(new Element("Fax", mpeg7).addContent(fax)); 
        if (email != null) eaddress.addContent(new Element("Email", mpeg7).addContent(email)); 
        if (url != null) eaddress.addContent(new Element("Url", mpeg7).addContent(url)); 
        // creationlocation 
        if (creationLocationAddressLines != null) { 
            Element paddress = new Element("PostalAddress", mpeg7); 
            for (Iterator i = creationLocationAddressLines.iterator(); i.hasNext();) { 
                String s = (String) i.next(); 
                paddress.addContent(new Element("AddressLine", mpeg7).addContent(s)); 
            } 
            root.addContent(new Element("CreationLocation", mpeg7).addContent(paddress)); 
        } 
        // creationtool 
        if (toolName != null) { 
            root.addContent(new Element("Instrument", mpeg7).addContent((new Element("Tool", mpeg7).addContent((new Element("Name", mpeg7).addContent(toolName)))))); 
        } 
 
        try { 
            new XMLOutputter(Format.getPrettyFormat()).output(root, System.out); 
        } catch (IOException e) { 
            e.printStackTrace(); 
        } 
    } 
 
    /** 
     * returns the filled in description 
     * @return the Element DescriptionMetadata 
     */ 
    public Element getDescriptionMetadata() { 
        return root; 
    } 
 
    /** 
     * returns string representation of the content 
     * @return the annotaion infa as formatted XML string 
     */ 
    public String toString() { 
        return new XMLOutputter(Format.getPrettyFormat()).outputString(root); 
    } 
 
//    public static void main(String[] args) { 
//        Vector al = new Vector(); 
//        al.add("Inffeldgasse 16c"); 
//        al.add("8010 Graz"); 
//        Mpeg7AnnotationInfo i = new Mpeg7AnnotationInfo("1.0", "Mathias", "Lux", "Know-Center", al, "+43 (316) 873 5669", null, 
//                "mathias@juggle.at", "http://www.at.know-center.at", al, "IMB prototype", "Description"); 
//    } 
/* SAMPLE DESCRIPTION: 
     
		1.0 
		 
			Description of the Annotation 
		 
		 
			 
				Creator 
			 
			 
				 
					Mathias 
					Lux 
				 
				 
					 
						Know Center 
					 
				 
				
Know-Center z.H. Mathias Lux Inffeldgasse 16c 8010 Graz Austria
+43 (316) 873 - 5669 +43 (316) 873 - 5688 mathias@juggle.at http://www.at.know-center.at
Know-Center z.H. Mathias Lux Inffeldgasse 16c 8010 Graz Austria IMB Prototype
*/ }