reader.set(factory.createXMLStreamReader(is));
// expect xpacket processing instruction
expectNext(XMLStreamReader.PROCESSING_INSTRUCTION,
"Did not find initial xpacket processing instruction");
XMPMetadata metadata = parseInitialXpacket(reader.get().getPIData());
// expect x:xmpmeta
expectNextTag(XMLStreamReader.START_ELEMENT,
"Did not find initial x:xmpmeta");
expectName("adobe:ns:meta/", "xmpmeta");
// expect rdf:RDF
expectNextTag(XMLStreamReader.START_ELEMENT,
"Did not find initial rdf:RDF");
expectName("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "RDF");
nsMap.resetComplexBasicTypesDeclarationInEntireXMPLevel();
// add all namespaces which could declare nsURI of a basicValueType
// all others declarations are ignored
int nsCount = reader.get().getNamespaceCount();
for (int i = 0; i < nsCount; i++) {
if (nsMap.isComplexBasicTypes(reader.get().getNamespaceURI(i))) {
nsMap.setComplexBasicTypesDeclarationForLevelXMP(
reader.get().getNamespaceURI(i),
reader.get().getNamespacePrefix(i));
}
}
// now work on each rdf:Description
int type = reader.get().nextTag();
while (type == XMLStreamReader.START_ELEMENT) {
parseDescription(metadata);
type = reader.get().nextTag();
}
// all description are finished
// expect end of rdf:RDF
expectType(XMLStreamReader.END_ELEMENT,
"Expected end of descriptions");
expectName("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "RDF");
// expect ending xmpmeta
expectNextTag(XMLStreamReader.END_ELEMENT,
"Did not find initial x:xmpmeta");
expectName("adobe:ns:meta/", "xmpmeta");
// expect final processing instruction
expectNext(XMLStreamReader.PROCESSING_INSTRUCTION,
"Did not find final xpacket processing instruction");
// treats xpacket end
if (!reader.get().getPITarget().equals("xpacket")) {
throw new XmpXpacketEndException("Excepted PI xpacket");
}
String xpackData = reader.get().getPIData();
// end attribute must be present and placed in first
// xmp spec says Other unrecognized attributes can follow, but
// should be ignored
if (xpackData.startsWith("end=")) {
// check value (5 for end='X')
if (xpackData.charAt(5)!='r' && xpackData.charAt(5)!='w') {
throw new XmpXpacketEndException(
"Excepted xpacket 'end' attribute with value 'r' or 'w' ");
}
} else {
// should find end='r/w'
throw new XmpXpacketEndException(
"Excepted xpacket 'end' attribute (must be present and placed in first)");
}
metadata.setEndXPacket(xpackData);
// return constructed object
return metadata;
} catch (XMLStreamException e) {
throw new XmpParsingException("An error has occured when processing the underlying XMP source", e);
} finally {