Search in sources :

Example 1 with XMPPacketScanner

use of org.apache.tika.parser.image.xmp.XMPPacketScanner in project stanbol by apache.

the class XmpExtractorEngine method computeEnhancements.

@Override
public void computeEnhancements(ContentItem ci) throws EngineException {
    InputStream in = ci.getBlob().getStream();
    XMPPacketScanner scanner = new XMPPacketScanner();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        scanner.parse(in, baos);
    } catch (IOException e) {
        throw new EngineException(e);
    }
    byte[] bytes = baos.toByteArray();
    if (bytes.length > 0) {
        Graph model = new IndexedGraph();
        parser.parse(model, new ByteArrayInputStream(bytes), "application/rdf+xml");
        GraphNode gn = new GraphNode(new IRI("http://relative-uri.fake/"), model);
        gn.replaceWith(ci.getUri());
        ci.getLock().writeLock().lock();
        try {
            LOG.info("Model: {}", model);
            ci.getMetadata().addAll(model);
        } finally {
            ci.getLock().writeLock().unlock();
        }
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) ImmutableGraph(org.apache.clerezza.commons.rdf.ImmutableGraph) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) SimpleGraph(org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph) Graph(org.apache.clerezza.commons.rdf.Graph) XMPPacketScanner(org.apache.tika.parser.image.xmp.XMPPacketScanner) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EngineException(org.apache.stanbol.enhancer.servicesapi.EngineException) GraphNode(org.apache.clerezza.rdf.utils.GraphNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Graph (org.apache.clerezza.commons.rdf.Graph)1 IRI (org.apache.clerezza.commons.rdf.IRI)1 ImmutableGraph (org.apache.clerezza.commons.rdf.ImmutableGraph)1 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)1 GraphNode (org.apache.clerezza.rdf.utils.GraphNode)1 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)1 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)1 XMPPacketScanner (org.apache.tika.parser.image.xmp.XMPPacketScanner)1