@Override public int canEnhance(ContentItem ci) throws EngineException { // check if content is present try { if ((ContentItemHelper.getText(ci.getBlob()) == null) || (ContentItemHelper.getText(ci.getBlob()).trim().isEmpty())) { return CANNOT_ENHANCE; } } catch (IOException e) { log.error("Failed to get the text for " + "enhancement of content: " + ci.getUri(), e); throw new InvalidContentException(this, ci, e); } // default enhancement is synchronous enhancement return ENHANCE_SYNCHRONOUS; }
Blob blob; if(mimeTypes == null || mimeTypes.isEmpty()){ blob = ci.getBlob(); } else { Entry<IRI,Blob> entry = ContentItemHelper.getBlob(ci, mimeTypes);
this.textContent = ContentItemHelper.getText(plainTextContentPart.getValue()); if (ci.getBlob().getMimeType().startsWith("image/")) { this.imageSrc = rawURI;
this.textContent = ContentItemHelper.getText(plainTextContentPart.getValue()); if (ci.getBlob().getMimeType().startsWith("image/")) { this.imageSrc = rawURI;
@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(); } } }
/** * Getter for the contentType. If not set or {@link MediaType#OCTET_STREAM} * than the media type is detected.<p> * This method returns the MediaType and the Stream used to detect the * MimeType. This allows to reuse the stream and the mediaType * @param ci * @param mediaTypeArray * @return */ private MediaTypeAndStream extractMediaType(ContentItem ci) { MediaTypeAndStream mtas = new MediaTypeAndStream(); mtas.mediaType = getMediaType(ci.getBlob()); mtas.uri = ci.getUri().getUnicodeString(); if(mtas.mediaType == null || mtas.mediaType.equals(MediaType.OCTET_STREAM)){ mtas.in = new BufferedInputStream(ci.getStream()); Metadata m = new Metadata(); m.add(Metadata.RESOURCE_NAME_KEY, mtas.uri); try { mtas.mediaType = detector.detect(mtas.in, m); } catch (IOException e) { log.warn("Exception while detection the MediaType of the" + "parsed ContentItem "+ci.getUri(),e); IOUtils.closeQuietly(mtas.in); mtas.in = null; } } return mtas; }