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();