StringBuffer sb = new StringBuffer();
for (Iterator mi = mdc.iterator(); mi.hasNext();)
{
sb.append(", ").append(((Content)mi.next()).toString());
}
throw new MetadataValidationException("Cannot parse METS with "+mdSec.getQualifiedName()+" element that contains more than one child, size="+String.valueOf(mdc.size())+", ID="+id+"Kids="+sb.toString());
}
Element mdRef = null;
Element mdWrap = mdSec.getChild("mdWrap", metsNS);
if (mdWrap != null)
{
Element xmlData = mdWrap.getChild("xmlData", metsNS);
if (xmlData == null)
{
Element bin = mdWrap.getChild("binData", metsNS);
if (bin == null)
{
throw new MetadataValidationException("Invalid METS Manifest: mdWrap element with neither xmlData nor binData child.");
}
// if binData is actually XML, return it; otherwise ignore.
else
{
String mimeType = mdWrap.getAttributeValue("MIMETYPE");
if (mimeType != null && mimeType.equalsIgnoreCase("text/xml"))
{
byte value[] = Base64.decodeBase64(bin.getText().getBytes());
Document mdd = parser.build(new ByteArrayInputStream(value));
List<Element> result = new ArrayList<Element>(1);
result.add(mdd.getRootElement());
return result;
}
else
{
log.warn("Ignoring binData section because MIMETYPE is not XML, but: "+mimeType);
return new ArrayList<Element>(0);
}
}
}
else
{
return xmlData.getChildren();
}
}
else
{
mdRef = mdSec.getChild("mdRef", metsNS);
if (mdRef != null)
{
String mimeType = mdRef.getAttributeValue("MIMETYPE");
if (mimeType != null && mimeType.equalsIgnoreCase("text/xml"))
{
Document mdd = parser.build(callback.getInputStream(mdRef));
List<Element> result = new ArrayList<Element>(1);
result.add(mdd.getRootElement());
return result;
}
else
{
log.warn("Ignoring mdRef section because MIMETYPE is not XML, but: "+mimeType);
return new ArrayList<Element>(0);
}
}
else
{
throw new MetadataValidationException("Invalid METS Manifest: ?mdSec element with neither mdRef nor mdWrap child.");
}
}
}
catch (JDOMException je)
{
throw new MetadataValidationException("Error parsing or validating metadata section in mdRef or binData within "+mdSec.toString(), je);
}
}