// Could not parse embedded XMP metadata. That's not a serious
// problem, so we'll just ignore the issue for now.
// TODO: Make error handling like this configurable.
public void parse(InputStream file) throws IOException, TikaException {
        ByteArrayOutputStream xmpraw = new ByteArrayOutputStream();
        if (!scanner.parse(file, xmpraw)) {
            return;
        }
        Reader decoded = new InputStreamReader(
                new ByteArrayInputStream(xmpraw.toByteArray()),
                DEFAULT_XMP_CHARSET);
        try {
            XMPMetadata xmp = XMPMetadata.load(new InputSource(decoded));
            XMPSchemaDublinCore dc = xmp.getDublinCoreSchema();
            if (dc != null) {
                if (dc.getTitle() != null) {
                    metadata.set(DublinCore.TITLE, dc.getTitle());
                }
                if (dc.getDescription() != null) {
                    metadata.set(DublinCore.DESCRIPTION, dc.getDescription());
                }
                if (dc.getCreators() != null && dc.getCreators().size() > 0) {
                    metadata.set(DublinCore.CREATOR, joinCreators(dc.getCreators()));
                }
                if (dc.getSubjects() != null && dc.getSubjects().size() > 0) {
                    Iterator<String> keywords = dc.getSubjects().iterator();
                    while (keywords.hasNext()) {
                        metadata.add(DublinCore.SUBJECT, keywords.next());
                    }
                    // TODO should we set KEYWORDS too?
                    // All tested photo managers set the same in Iptc.Application2.Keywords and Xmp.dc.subject
                }
            }
        } catch (IOException e) {
            // Could not parse embedded XMP metadata. That's not a serious
            // problem, so we'll just ignore the issue for now.
            // TODO: Make error handling like this configurable.
        }
    }
}
} catch (IOException e) {
// Could not parse embedded XMP metadata. That's not a serious
// problem, so we'll just ignore the issue for now.
// TODO: Make error handling like this configurable.
}
}
if (dc.getSubjects() != null && dc.getSubjects().size() > 0) {
Iterator<String> keywords = dc.getSubjects().iterator();
while (keywords.hasNext()) {
metadata.add(DublinCore.SUBJECT, keywords.next());
}
// TODO should we set KEYWORDS too?
// All tested photo managers set the same in Iptc.Application2.Keywords and Xmp.dc.subject
}
}
} catch (IOException e) {
// Could not parse embedded XMP metadata. That's not a serious
// problem, so we'll just ignore the issue for now.
// TODO: Make error handling like this configurable.
}
}
if (dc != null) {
if (dc.getTitle() != null) {
metadata.set(DublinCore.TITLE, dc.getTitle());
}
if (dc.getDescription() != null) {
metadata.set(DublinCore.DESCRIPTION, dc.getDescription());
}
if (dc.getCreators() != null && dc.getCreators().size() > 0) {
metadata.set(DublinCore.CREATOR, joinCreators(dc.getCreators()));
}
if (dc.getSubjects() != null && dc.getSubjects().size() > 0) {
Iterator<String> keywords = dc.getSubjects().iterator();
while (keywords.hasNext()) {
metadata.add(DublinCore.SUBJECT, keywords.next());
}
// TODO should we set KEYWORDS too?
// All tested photo managers set the same in Iptc.Application2.Keywords and Xmp.dc.subject
}
}
} catch (IOException e) {
// Could not parse embedded XMP metadata. That's not a serious
// problem, so we'll just ignore the issue for now.
// TODO: Make error handling like this configurable.
}
}