Mercurial > hg > mpdl-group
diff software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/escidoc/Item.java @ 0:408254cf2f1d
Erstellung
author | Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 24 Nov 2010 17:24:23 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/escidoc/Item.java Wed Nov 24 17:24:23 2010 +0100 @@ -0,0 +1,103 @@ +package de.mpg.mpiwg.berlin.mpdl.escidoc; + +import java.util.ArrayList; +import java.util.Date; + +import de.mpg.mpiwg.berlin.mpdl.util.XmlUtil; + +public class Item { + private String id; + private String contextId; // e.g. "/ir/context/escidoc:23002" + private String contentModelId; + private String pid; + private MetadataRecord mdRecord; + private ArrayList<Component> components; + private Date lastModificationDate; + + public Item(String id, Date lastModificationDate) { + this.id = id; + this.lastModificationDate = lastModificationDate; + } + + public Item(String contextId, String pid, MetadataRecord mdRecord, String contentModelId, ArrayList<Component> components) { + this.contextId = contextId; + this.pid = pid; + this.mdRecord = mdRecord; + this.contentModelId = contentModelId; + this.components = components; + } + + public void addComponent(Component component) { + if (components == null) + components = new ArrayList<Component>(); + components.add(component); + } + + public String getId() { + return id; + } + + public Date getLastModificationDate() { + return lastModificationDate; + } + + public void setLastModificationDate(Date lastModificationDate) { + this.lastModificationDate = lastModificationDate; + } + + public String toXmlString() { + StringBuilder str = new StringBuilder(); + str.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); + str.append("<escidocItem:item\n"); + str.append(" xmlns:escidocItem=\"http://www.escidoc.de/schemas/item/0.9\"\n"); + str.append(" xmlns:escidocMetadataRecords=\"http://www.escidoc.de/schemas/metadatarecords/0.5\"\n"); + str.append(" xmlns:escidocComponents=\"http://www.escidoc.de/schemas/components/0.9\"\n"); + str.append(" xmlns:prop=\"http://escidoc.de/core/01/properties/\"\n"); + str.append(" xmlns:srel=\"http://escidoc.de/core/01/structural-relations/\"\n"); + str.append(" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"); + str.append(" xmlns:mpiwg=\"http://www.mpiwg-berlin.mpg.de/ns/mpiwg\"\n"); + str.append(" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\""); + if (lastModificationDate != null) { + XmlUtil xmlUtil = XmlUtil.getInstance(); + String xsDateStr = xmlUtil.toXsDate(lastModificationDate); + str.append(" last-modification-date=\"" + xsDateStr + "\""); + } + str.append(">\n"); + str.append(" <escidocItem:properties>\n"); + str.append(" <srel:context xlink:href=\"" + contextId + "\"/>\n"); + str.append(" <srel:content-model xlink:href=\"" + contentModelId + "\"/>\n"); + if (pid != null) { + str.append(" <prop:pid>" + pid + "</prop:pid>\n"); + } + str.append(" <prop:content-model-specific>\n"); + str.append(" <my-content-model-value-structure />\n"); + str.append(" </prop:content-model-specific>\n"); + str.append(" </escidocItem:properties>\n"); + + str.append(" <!-- A Container could have multiple meta data records. -->\n"); + str.append(" <escidocMetadataRecords:md-records>\n"); + str.append(" <escidocMetadataRecords:md-record name=\"escidoc\">\n"); + if (mdRecord != null) { + str.append(mdRecord.toXmlString()); + } else { + str.append(" <metadata xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n"); + str.append(" </metadata>\n"); + } + str.append(" </escidocMetadataRecords:md-record>\n"); + + str.append(" </escidocMetadataRecords:md-records>\n"); + + if (components != null) { + str.append(" <escidocComponents:components>\n"); + for (int i=0; i<components.size(); i++) { + Component component = components.get(i); + str.append(component.toXmlString()); + } + str.append(" </escidocComponents:components>\n"); + } + + str.append("</escidocItem:item>\n"); + return str.toString(); + } + +}