public MetsObject getMetsObject(String oid) throws DAOException {
metsObj = new MetsObject();
metsObj.setId(oid);
try {
Mets mets = unmarshallMets(oid);
metsObj.setObjId(mets.getOBJID());
metsObj.setMetsId(mets.getID());
DmdSec[] dmdSecs = mets.getDmdSec();
DmdSec fullLinkDmd = null;
Map<String, DescriptiveMetadata> dmdMap = new HashMap<String, DescriptiveMetadata>();
for (int i = 0; i < dmdSecs.length; i++) {
if ("dmdSec_fullRecordLink".equals(dmdSecs[i].getID())) {
fullLinkDmd = dmdSecs[i];
} else {
if (dmdSecs[i].getMdWrap().getXmlData().getAnyObjectCount() == 1) {
AnyNode anyNode = (AnyNode) dmdSecs[i].getMdWrap().getXmlData()
.getAnyObject(0);
int type = dmdSecs[i].getMdWrap().getMDTYPE().getType();
DescriptiveMetadata dmd = new DescriptiveMetadata(anyNode, type);
String id = dmdSecs[i].getID();
dmdMap.put(id, dmd);
}
}
}
metsObj.setDmdMap(dmdMap);
if (fullLinkDmd != null) {
metsObj.setLinkBackUrl((String) fullLinkDmd.getMdRef().getHref());
}
StructMap[] maps = mets.getStructMap();
// Always build the physicalStrcut first
for (int i = 0; i < maps.length; i++) {
StructMap structMap = maps[i];
Div div = structMap.getDiv();
String type = structMap.getTYPE();
if (MetsConstants.PHYSICAL.equals(type)) {
List<AtomicItem> list = parsePhysicalStruct(div);
metsObj.setPhysicalStruct(list);
Map<String, Integer> aimap = new HashMap<String, Integer>();
for (int j = 0; j < list.size(); j++) {
aimap.put(list.get(j).getId(), j);
}
metsObj.setAtomicItemIDIndexMap(aimap);
metsObj.setDescription(div.getLABEL());
Fptr[] fptrs = div.getFptr();
ParameterMap dataStream = config.getDataStream();
if (dataStream != null) {
Map<String, Map<String, String>> valueMap = dataStream.getValueMap();
for (Map.Entry<String, Map<String, String>> entry : valueMap.entrySet()) {
Map<String, String> stream = new HashMap<String, String>();
for (Fptr fptr2: fptrs) {
File file = (File)fptr2.getFILEID();
String use = file.getUSE();
if (entry.getValue().get(use) != null) {
stream.put(use, file.getFLocat(0).getHref());
}
}
metsObj.getDataStreamsMap().put(entry.getKey(), stream);
}
}
}
}
// Now we can process logicalStruct
for (int i = 0; i < maps.length; i++) {
StructMap structMap = maps[i];
Div div = structMap.getDiv();
String type = structMap.getTYPE();
if (MetsConstants.LOGICAL.equals(type)) {
Map<String, CompositeItem> cimap = new HashMap<String, CompositeItem>();
metsObj.setCompositeItemMap(cimap);
metsObj.setDescription(div.getLABEL());
Fptr[] fptrs = div.getFptr();
ParameterMap dataStream = config.getDataStream();
if (dataStream != null) {
Map<String, Map<String, String>> valueMap = dataStream.getValueMap();
for (Map.Entry<String, Map<String, String>> entry : valueMap.entrySet()) {
Map<String, String> stream = new HashMap<String, String>();
for (Fptr fptr2: fptrs) {
File file = (File)fptr2.getFILEID();
String use = file.getUSE();
if (entry.getValue().get(use) != null) {
stream.put(use, file.getFLocat(0).getHref());
}
}
metsObj.getDataStreamsMap().put(entry.getKey(), stream);
}
}
metsObj.setLogicalStruct((CompositeItem) parseLogicalStruct(oid, div, null));
} else if (MetsConstants.RELATED.equals(type)) {
Map<String, Related> rmap = new HashMap<String, Related>();
metsObj.setRelatedMap(rmap);
Div[] divs = div.getDiv();
for (Div div2 : divs) {
Related related = new Related();
related.setType(div2.getTYPE());
related.setLabel(div2.getLABEL());
Mptr[] mptrs = div2.getMptr();
if (mptrs.length == 1) {
related.setPurl(mptrs[0].getHref());
rmap.put(div2.getTYPE(), related);
}
}
}
}
if (mets.getFileSec() != null) {
FileGrp[] filegrp = mets.getFileSec().getFileGrp(0).getFileGrp();
for (int i = 0; i < filegrp.length; i++) {
if (StringUtils.equals(filegrp[i].getUSE(), "printable")) {
String url = (String) filegrp[i].getFile(0).getFLocat(0).getHref();
metsObj.setPrintableUrl(url);
}