/********************************************************************** * METS Java Toolkit * Copyright (c) 2002 by the President and Fellows of Harvard College * * The METS specification was developed as an initiative of the * Digital Library Federation and is * maintained by the Network Development and MARC Standards Office of * the Library of Congress . * The toolkit is compliant with the JAXB API specification, copyright * (c) 2001 Sun Microsystems, Inc. . * The toolkit uses the XP parser, copyright (c) 1997,1998 James Clark * . **********************************************************************/ import java.util.*; import org.mets.xml.bind.*; import org.mets.xml.mets.*; /** * Test procedural construction, validation, and marshalling of a * METS file using the METS Java toolkit, based on the JAXB binding * framework API. * * @author Stephen Abrams * @version 1.0 (alpha) 12/03/15 */ public class Marshal { /****************************************************************** * APPLICATION MAIN ENTRY POINT. ******************************************************************/ public static void main (String [] args) { try { Mets mets = new Mets (); mets.setOBJID ("1234-5678(2002)9:1<>1.0.CO;9-X"); mets.setLABEL ("METS Java toolkit"); mets.setTYPE ("Article"); MetsHdr metsHdr = new MetsHdr (); metsHdr.setCREATEDATE (new Date ()); metsHdr.setRECORDSTATUS ("DRAFT"); Agent agent = new Agent (); agent.setROLE (Role.CREATOR); Name name = new Name (); name.getContent ().add (new PCData ("S. L. Abrams")); agent.getContent ().add (name); Note note = new Note (); note.getContent ().add (new PCData ("HUL/OIS")); agent.getContent ().add (note); note = new Note (); note.getContent ().add (new PCData ("Special order, 2002/02/25")); agent.getContent ().add (note); metsHdr.getContent ().add (agent); AltRecordID doi = new AltRecordID (); doi.setTYPE ("DOI"); doi.getContent ().add (new PCData ("10.1234/56789")); AltRecordID nrs = new AltRecordID (); nrs.setTYPE ("NRS"); nrs.getContent ().add (new PCData ("nrs:hul.ois:10203")); metsHdr.getContent ().add (doi); metsHdr.getContent ().add (nrs); mets.getContent ().add (metsHdr); DmdSec dmdSec = new DmdSec (); dmdSec.setID ("xyz-123"); MdRef mdRef = new MdRef (); mdRef.setLOCTYPE (Loctype.DOI); mdRef.setMDTYPE (Mdtype.DC); mdRef.setMIMETYPE ("text/xml"); mdRef.setXlinkHref ("10.9876/54321"); dmdSec.getContent ().add (mdRef); MdWrap mdWrap = new MdWrap (); mdWrap.setMDTYPE (Mdtype.MARC); BinData binData = new BinData (); binData.getContent ().add (new PCData ("AbCdEfGhIjKlMnOpQrStUvWxYz0123456789")); mdWrap.getContent ().add (binData); dmdSec.getContent ().add (mdWrap); mets.getContent ().add (dmdSec); AmdSec amdSec = new AmdSec (); TechMD techMD = new TechMD (); techMD.setID ("t-1234"); mdWrap = new MdWrap (); mdWrap.setMDTYPE (Mdtype.OTHER); mdWrap.setOTHERMDTYPE ("MyTechMD"); XmlData xmlData = new XmlData (); Any any = new Any ("my", "techMD"); any.getAttributes ().add (new Attribute ("ID", "AB123")); any.getAttributes ().add (new Attribute ("my", "type", "TIFF")); any.getContent ().add (new PCData ("...technical MD...")); xmlData.getContent ().add (any); mdWrap.getContent ().add (xmlData); techMD.getContent ().add (mdWrap); amdSec.getContent ().add (techMD); RightsMD rightsMD = new RightsMD (); rightsMD.setID ("r-5678"); mdWrap = new MdWrap (); mdWrap.setMDTYPE (Mdtype.OTHER); mdWrap.setOTHERMDTYPE ("MyRightsMD"); xmlData = new XmlData (); any = new Any ("my", "rightsMD"); any.getContent ().add (new PCData ("...rights MD...")); xmlData.getContent ().add (any); any = new Any ("your", "rightsMD"); any.getContent ().add (new PCData ("...rights MD...")); xmlData.getContent ().add (any); any = new Any ("their", "rightsMD"); any.getContent ().add (new PCData ("...rights MD...")); xmlData.getContent ().add (any); mdWrap.getContent ().add (xmlData); rightsMD.getContent ().add (mdWrap); amdSec.getContent ().add (rightsMD); SourceMD sourceMD = new SourceMD (); sourceMD.setID ("s-9012"); mdWrap = new MdWrap (); mdWrap.setMDTYPE (Mdtype.OTHER); mdWrap.setOTHERMDTYPE ("MySourceMD"); xmlData = new XmlData (); any = new Any ("my", "sourceMD"); any.getAttributes ().add (new Attribute ("aat", "type", new Integer (178684))); any.getContent ().add (new PCData ("...source MD...")); xmlData.getContent ().add (any); mdWrap.getContent ().add (xmlData); sourceMD.getContent ().add (mdWrap); amdSec.getContent ().add (sourceMD); DigiprovMD digiprovMD = new DigiprovMD (); digiprovMD.setID ("d-3456"); mdWrap = new MdWrap (); mdWrap.setMDTYPE (Mdtype.OTHER); mdWrap.setOTHERMDTYPE ("MyDigiprovMD"); xmlData = new XmlData (); any = new Any ("my", "digiprovMD"); any.getContent ().add (new PCData ("...provenance MD...")); xmlData.getContent ().add (any); mdWrap.getContent ().add (xmlData); digiprovMD.getContent ().add (mdWrap); amdSec.getContent ().add (digiprovMD); mets.getContent ().add (amdSec); FileSec fileSec = new FileSec (); FileGrp fileGrp = new FileGrp (); fileGrp.getADMID ().add ("t-1234"); fileGrp.getADMID ().add ("s-9012"); File file = new File (); file.setID ("a1b2c3"); FLocat flocat = new FLocat (); flocat.setLOCTYPE (Loctype.URN); flocat.setXlinkHref ("urn:nid:nss"); file.getContent (). add (flocat); FContent fcontent = new FContent (); fcontent.getContent ().add (new PCData ("MS0yLTM=")); file.getContent ().add (fcontent); fileGrp.getContent ().add (file); fileSec.getContent ().add (fileGrp); mets.getContent ().add (fileSec); StructMap structMap = new StructMap (); structMap.setID ("A125"); structMap.setLABEL ("Individual volumes"); Div div = new Div (); div.setORDER (25); div.setORDERLABEL ("xxv"); div.setTYPE ("Chapter"); Div sec = new Div (); sec.setTYPE ("Section"); Div sub = new Div (); sub.setTYPE ("Sub-section"); Fptr fptr = new Fptr (); fptr.setFILEID ("a1b2c3"); sub.getContent ().add (fptr); sec.getContent ().add (sub); div.getContent ().add (sec); sec = new Div (); sec.setTYPE ("Section"); Mptr mptr = new Mptr (); mptr.setID ("123-45-6789"); mptr.setLOCTYPE (Loctype.OTHER); mptr.setOTHERLOCTYPE ("filepath"); mptr.setXlinkHref ("dir/file.xml"); sec.getContent ().add (mptr); div.getContent ().add (sec); structMap.getContent ().add (div); mets.getContent ().add (structMap); BehaviorSec behavior = new BehaviorSec (); behavior.setID ("killerapp"); behavior.getSTRUCTID ().add ("A125"); behavior.getSTRUCTID ().add ("s-9012"); Mechanism mechanism = new Mechanism (); mechanism.setLOCTYPE (Loctype.URL); mechanism.setXlinkHref ("http://host/path"); behavior.getContent ().add (mechanism); mets.getContent ().add (behavior); mets.validate (); mets.marshal (System.out); } catch (Exception e) { System.err.println ("Exception: " + e.getMessage ()); e.printStackTrace (); } } }