/** Determines if this is a property that should be analyzed by text processing tools. */ protected boolean isTextProperty(Property property) { if (property == null) { return false; } if (property.getName().equals(LumifyProperties.RAW.getPropertyName())) { return false; } String mimeType = (String) property.getMetadata().get(LumifyProperties.MIME_TYPE.getPropertyName()); return !(mimeType == null || !mimeType.startsWith("text")); }
@Override public void handle(HttpServletRequest request, HttpServletResponse response, HandlerChain chain) throws Exception { boolean download = getOptionalParameter(request, "download") != null; boolean playback = getOptionalParameter(request, "playback") != null; User user = getUser(request); Authorizations authorizations = getAuthorizations(request, user); String graphVertexId = UrlUtils.urlDecode(getAttributeString(request, "graphVertexId")); Vertex artifactVertex = graph.getVertex(graphVertexId, authorizations); if (artifactVertex == null) { respondWithNotFound(response); return; } String fileName = LumifyProperties.FILE_NAME.getPropertyValue(artifactVertex); if (fileName == null) { fileName = LumifyProperties.TITLE.getPropertyValue(artifactVertex); } if (playback) { handlePartialPlayback(request, response, artifactVertex, fileName, user); } else { String mimeType = getMimeType(artifactVertex); response.setContentType(mimeType); setMaxAge(response, EXPIRES_1_HOUR); if (download) { response.addHeader("Content-Disposition", "attachment; filename=" + fileName); } else { response.addHeader("Content-Disposition", "inline; filename=" + fileName); } StreamingPropertyValue rawValue = LumifyProperties.RAW.getPropertyValue(artifactVertex); if (rawValue == null) { LOGGER.warn("Could not find raw on artifact: %s", artifactVertex.getId().toString()); respondWithNotFound(response); return; } InputStream in = rawValue.getInputStream(); try { IOUtils.copy(in, response.getOutputStream()); } finally { in.close(); } } chain.next(request, response); }
@Override public boolean isHandled(Element element, Property property) { if (property == null) { return false; } if (property.getName().equals(LumifyProperties.RAW.getPropertyName())) { return false; } String mimeType = (String) property.getMetadata().get(LumifyProperties.MIME_TYPE.getPropertyName()); return !(mimeType == null || !mimeType.startsWith("text")); }