application programming interface METS API application programming interface

  • Slides: 47
Download presentation
application programming interface METS - API application programming interface METS Implementors Meeting, May 8

application programming interface METS - API application programming interface METS Implementors Meeting, May 8 th, 2007 Markus Enders, SUB Göttingen Jens Ludwig, SUB Göttingen

application programming interface Why? necessity of an API

application programming interface Why? necessity of an API

application programming interface Why? METS has a complex data model: the most common instantiation

application programming interface Why? METS has a complex data model: the most common instantiation of METS is its XML form an API should be based on the data model and is (theoretically) independent of its XML representation

application programming interface Why? API should be focused on METS elements and their appropriate

application programming interface Why? API should be focused on METS elements and their appropriate attributes and relationships API should support creation of METS as well: creation of invalid data should not be possible (e. g. wrong order of elements. . . ) 100% valid METS data

application programming interface Why? Multi-Tier Applications: API connects application with serialization level. API as

application programming interface Why? Multi-Tier Applications: API connects application with serialization level. API as a framework for METS creation / parsing

application programming interface Why? Applikation METS API XML Repository Database

application programming interface Why? Applikation METS API XML Repository Database

application programming interface Implementation Issues: Maintainance: Changes in METS-schema must be reflected by API

application programming interface Implementation Issues: Maintainance: Changes in METS-schema must be reflected by API Programming language: more than one language should be supported multi-level access: • Granularity of access

application programming interface Implementation Issues: Maintainance: Changes in METS-schema must be reflected by API

application programming interface Implementation Issues: Maintainance: Changes in METS-schema must be reflected by API Derive classes from xml-schema: Programming e. g. language: more than one language should Apache xmlbeans or be supported SUN JAXB multi-level access: provides java classes for • Granularity of access xml-schema

application programming interface Implementation Issues: Maintainance: Changes in METS-schema must be reflected by API

application programming interface Implementation Issues: Maintainance: Changes in METS-schema must be reflected by API Programming language: more than one language should be supported multi-levelphp-java access: bridge: http: //php-java-bridge. sourceforge. net • Granularity of access Inline-Java perl module: http: //search. cpan. org/~patl/Inline-Java/

application programming interface Implementation Issues: Maintainance: Changes in METS-schema must be reflected by API

application programming interface Implementation Issues: Maintainance: Changes in METS-schema must be reflected by API • access to single elements / attributes Programming language: • higher level for more thanwidespread one language should be supported functionality multi-level access: • Granularity of access

application programming interface Implementation Issues: Apache xmlbeans based API for java Creates an interface

application programming interface Implementation Issues: Apache xmlbeans based API for java Creates an interface for each schema object and an implementation to read / write this object to XML Other implementations possible (repository) Can create DOM tree at any time, e. g. if non-schema based xml-data needs to be stored.

application programming interface Implementation Issues: level one: METSbeans allows acces to single METS elements,

application programming interface Implementation Issues: level one: METSbeans allows acces to single METS elements, attributes and their relationships xmlbeans based API for java level two: more complex functions which are based on the METSbeans

application programming interface METSbeans every type from schema becomes one classes are generated automatically

application programming interface METSbeans every type from schema becomes one classes are generated automatically from the XML-schema additional APIs can be generated and integrated for any xml-schema based data format (e. g. MODS, premis etc. )

application programming interface METSbeans internal architecture: for every type in the xml schema, an

application programming interface METSbeans internal architecture: for every type in the xml schema, an appropriate java interface exists every interface is implemented during automatic generation process additional implementations of an interface are possible – high flexibility to access mets-data outside a file system

application programming interface METSbeans internal architecture: <xsd: complex. Type name="div. Type"> interface: class: Div.

application programming interface METSbeans internal architecture: <xsd: complex. Type name="div. Type"> interface: class: Div. Type. Impl

application programming interface METSbeans internal architecture: xmlbeans has a set of native data types:

application programming interface METSbeans internal architecture: xmlbeans has a set of native data types: XMLObject, XMLString XMLShort, XMLTime etc. . .

application programming interface METSbeans internal architecture: METSDocument as topmost class instantiates the document. All

application programming interface METSbeans internal architecture: METSDocument as topmost class instantiates the document. All other objects cannot be created without this object Instance can be created by: • parsing a file • using a factory class to create new document

application programming interface METSbeans snippet: Mets. Document example factory class: Mets. Document mets=Mets. Document.

application programming interface METSbeans snippet: Mets. Document example factory class: Mets. Document mets=Mets. Document. Factory. new. Instance(); example parsing a file: try { xml = Xml. Object. Factory. parse(f); } catch (Xml. Exception e) { e. print. Stack. Trace(); return false; } Mets. Document mets. Doc=(Mets. Document) xml;

application programming interface METSbeans Div. Type: methods for accessing <mprtr> element get. Mptr. Array(),

application programming interface METSbeans Div. Type: methods for accessing <mprtr> element get. Mptr. Array(), get. Mptr. Array(int i), size. Of. Mptr. Array(), set. Mptr. Array(Mptr[] mptr. Array), set. Mptr. Array(int i, Mptr mptr), insert. New. Mptr(int i), add. New. Mptr(); remove. Mptr(int i)

application programming interface METSbeans Div. Type: methods for accessing <div> element get. Div. Array()

application programming interface METSbeans Div. Type: methods for accessing <div> element get. Div. Array() get. Div. Array(int i) size. Of. Div. Array() set. Div. Array(Div. Type[] div. Array) set. Div. Array(int i, Div. Type div) insert. New. Div(int i) add. New. Div() remove. Div(int i)

application programming interface METSbeans Div. Type: very similar methods for handling file pointers (<fptr>

application programming interface METSbeans Div. Type: very similar methods for handling file pointers (<fptr> elements)

application programming interface METSbeans Div. Type: methods to set attributes (id attribute) get. ID();

application programming interface METSbeans Div. Type: methods to set attributes (id attribute) get. ID(); is. Set. ID(); set. ID(String id); unset. ID(); xset. ID(org. apache. xmlbeans. Xml. ID id); xget. ID();

application programming interface METSbeans snippet: create a new <div> element Mets. Document mets=Mets. Document.

application programming interface METSbeans snippet: create a new <div> element Mets. Document mets=Mets. Document. Factory. new. Instance(); Mets. Type my. Mets=mets. add. New. Mets(); Struct. Map. Type sm=my. Mets. add. New. Struct. Map(); Div. Type div=sm. add. New. Div(); div. set. TYPE("Monograph"); Div. Type firstchild=div. add. New. Div(); firstchild. set. TYPE("Title. Page");

application programming interface METSbeans snippet: saving a METS document Hash. Map suggested. Prefixes =

application programming interface METSbeans snippet: saving a METS document Hash. Map suggested. Prefixes = new Hash. Map(); suggested. Prefixes. put("http: //www. loc. gov/METS/", "mets"); suggested. Prefixes. put("http: //www. w 3. org/1999/xlink", "xlink"); Xml. Options opts = new Xml. Options(); opts. set. Save. Suggested. Prefixes(suggested. Prefixes); File output. File=new File(filename); mets. save(output. File, opts);

application programming interface METSbeans Md. Sec. Type represents the METS elements <dmd. Sec> <tech.

application programming interface METSbeans Md. Sec. Type represents the METS elements <dmd. Sec> <tech. Md> <digiprov. Md> <rights. Md> <source. Md> but not: <amd. Sec> may contain: Md. Ref or Md. Wrap object

application programming interface METSbeans snippet: create an Md. Sec. Type object Mets. Document mets=Mets.

application programming interface METSbeans snippet: create an Md. Sec. Type object Mets. Document mets=Mets. Document. Factory. new. Instance(); Mets. Type my. Mets=mets. add. New. Mets(); Md. Sec. Type dmd. Sec= my. Mets. add. New. Dmd. Sec(); dmd. Sec. set. ID("DMDID 01"); Md. Sec. Type. Md. Wrap mdwrap=dmd. Sec. add. New. Md. Wrap(); Md. Sec. Type. Md. Wrap. Xml. Data xmldata=mdwrap. add. New. Xml. Data(); xmldata. set(mods. Object); any XMLObject: e. g XMLString

application programming interface METSbeans snippet: create an Md. Sec. Type object String: Xml. String

application programming interface METSbeans snippet: create an Md. Sec. Type object String: Xml. String xs=Xml. String. Factory. new. Value("<mydata/>"); xmldata. set(xs); Document: Mods. Document mods. Object=Mods. Document. Factory. new. Instance(); Mods. Type my. Mods=mods. add. New. Mods(); Identifier. Type identifier=my. Mods. add. New. Identifier(); . . xmldata. set(mods. Object);

application programming interface METSbeans parse mets data: the API provides some parse-methods: parse(java. lang.

application programming interface METSbeans parse mets data: the API provides some parse-methods: parse(java. lang. String xml. As. String) parse(java. io. File file) parse(java. net. URL u) parse(java. io. Input. Stream is) parse(org. w 3 c. dom. Node node) if the parsed data is NOT valid METS a Xml. Exception is thrown.

application programming interface METSbeans snippet: parse mets data File f=new File(filename); Xml. Object xml;

application programming interface METSbeans snippet: parse mets data File f=new File(filename); Xml. Object xml; try { xml = Xml. Object. Factory. parse(f); } catch (Xml. Exception e) { e. print. Stack. Trace(); } catch (IOException e) { e. print. Stack. Trace(); } Mets. Document mets. Doc=(Mets. Document) xml;

application programming interface METSbeans snippet: get a Div. Type Mets. Document mets. Doc=(Mets. Document)

application programming interface METSbeans snippet: get a Div. Type Mets. Document mets. Doc=(Mets. Document) xml; Mets. Type mets=in. Doc. get. Mets(); Struct. Map. Type structs[]=mets. get. Struct. Map. Array(); for (int i=0; i<structs. length; i++){ Struct. Map. Type struct=structs[i]; String structtype=structs[i]. get. TYPE(); if ((structtype!=null)&&( structtype. equals("LOGICAL"))){ Div. Type div= struct. get. Div(); String divtype=div. get. TYPE(); return divtype; } }

application programming interface METSbeans easy to create and parse valid METS data (much easier

application programming interface METSbeans easy to create and parse valid METS data (much easier than parsing DOM trees) easy to combine with other xml data quite fast compared to DOM Drawback: as based on xmlbeans it is only available for java; php-java / inline: : java modul needed for php/perl

application programming interface Helper-class Functions: Need for additional high-level functions: Though the METSbeans allow

application programming interface Helper-class Functions: Need for additional high-level functions: Though the METSbeans allow access to every single METS element, it is still a complex task to do simple things e. g. adding metadata to a <div> Helper-class needed, which sits on top of Mets. Beans

application programming interface Helper-class Functions: Following examples are from experiences working with METSbeans (based

application programming interface Helper-class Functions: Following examples are from experiences working with METSbeans (based on METSbeans) No official implementation, just an excerpt of functions which a level 2 API could provide

application programming interface Helper-class Functions: Create DMDSec for common METSobjects: create. DMDSec(XMLObject in. Metadata,

application programming interface Helper-class Functions: Create DMDSec for common METSobjects: create. DMDSec(XMLObject in. Metadata, Div. Type in. Div) create. DMDSec(XMLObject in. Metadata, File. Type in. File). . .

application programming interface Helper-class Functions: Create adminsitrative metadata for common METS-objects: e. g. create.

application programming interface Helper-class Functions: Create adminsitrative metadata for common METS-objects: e. g. create. MDSection. In. AMDSec( XMLObject in. Metadata, String type, Div. Type in. Div, Amd. Sec. Type in. Amd. Sec). . .

application programming interface Helper-class Functions: function to retrieve special metadata sections by ID or

application programming interface Helper-class Functions: function to retrieve special metadata sections by ID or TYPE: get. MDSec. Type. By. ID( String in. ID) get. MDSec. Type. By. Type( String in. Type). . .

application programming interface Helper-class Functions: functions to get related files (to a <div> element):

application programming interface Helper-class Functions: functions to get related files (to a <div> element): get. All. Files. For. Div. Type( Div. Type in. Div) get. All. Files. For. File. Group( File. Grp. Type in. Grp). . .

application programming interface Extension schema Integration of extension schema: Export Mets. Beans-objects as DOM

application programming interface Extension schema Integration of extension schema: Export Mets. Beans-objects as DOM tree. Create Beans for extensions schema as well: Premis, MODS, MIX - Beans.

application programming interface Extension schema Example: create MODS data Md. Sec. Type dmd. Sec=mets.

application programming interface Extension schema Example: create MODS data Md. Sec. Type dmd. Sec=mets. add. New. Dmd. Sec(); dmd. Sec. set. ID(dmdid_string); Md. Sec. Type. Md. Wrap mdwrap=dmd. Sec. add. New. Md. Wrap(); Md. Sec. Type. Md. Wrap. Xml. Data xml=mdwrap. add. New. Xml. Data(); Mods. Document mods=Mods. Document. Factory. new. Instance(); Mods. Type my. Mods=mods. add. New. Mods(); xml. set(mods);

application programming interface Extension schema Example: create <premis: object> data Md. Sec. Type. Md.

application programming interface Extension schema Example: create <premis: object> data Md. Sec. Type. Md. Wrap mdwrap=dmd. Sec. add. New. Md. Wrap(); Md. Sec. Type. Md. Wrap. Xml. Data xml=mdwrap. add. New. Xml. Data(); Object. Document objdoc=Object. Document. Factory. new. Instance(); Object. Document. Object premis_object=objdoc. add. New. Object(); xml. set(objdoc);

application programming interface Extension schema Example: parse MODS data Md. Sec. Type dmd. Sec;

application programming interface Extension schema Example: parse MODS data Md. Sec. Type dmd. Sec; . . Md. Sec. Type. Md. Wrap mdw= dmd. Sec. get. Md. Wrap(); Md. Sec. Type. Md. Wrap. Xml. Data xml_data=mdw. get. Xml. Data(); String result=xml_data. xml. Text(); Mods. Document mods=Mods. Document. Factory. parse(result);

application programming interface Problems? ! Quality of the API depends on XML-schema; quality of

application programming interface Problems? ! Quality of the API depends on XML-schema; quality of API depends on quality of schema. Mets. Type Div. Type Md. Sec. Type fpr <mets> for <div> for <dmd. Sec>, . . but not type for METS-Header <mets. Hdr> as it is defined inline

application programming interface Problems? ! Integration of extension schema Problematic, if extension schema do

application programming interface Problems? ! Integration of extension schema Problematic, if extension schema do not have a top -level element; especially parsing is difficult: String result=xml_data. xml. Text(); Mods. Document mods=Mods. Document. Factory. parse(result); result must always contain a valid XML- document! e. g Dublin. Core simple

application programming interface How to continue Work with METSbeans everybody can create METSbeans by

application programming interface How to continue Work with METSbeans everybody can create METSbeans by him/herself -> see Apache xmlbeans Downloadable from GDZ website Will provide a primer as a noncomplete documention for METSbeans.

application programming interface How to continue Identify necessary functions for helper-class Over time we

application programming interface How to continue Identify necessary functions for helper-class Over time we will identify additional methods which might be useful and should be integrated in the "helperclass".

application programming interface Application Layer can be build on top of METSbeans Profile specific

application programming interface Application Layer can be build on top of METSbeans Profile specific implementations can be build on top of METSbeans and provide an API to the underlying document/content model.

application programming interface Application Layer can be build on top of METSbeans Applikation API

application programming interface Application Layer can be build on top of METSbeans Applikation API for content model helper class XML serialization METS API