@Override public long setContent( Node parentNode, String resourceName, InputStream newContent, String contentType, String characterEncoding ) throws RepositoryException, IOException { Node contentNode; if (parentNode.hasNode(CONTENT_NODE_NAME)) { contentNode = parentNode.getNode(CONTENT_NODE_NAME); } else { contentNode = parentNode.addNode(CONTENT_NODE_NAME, newContentPrimaryType); } // contentNode.setProperty(MIME_TYPE_PROP_NAME, contentType != null ? contentType : "application/octet-stream"); contentNode.setProperty(ENCODING_PROP_NAME, characterEncoding != null ? characterEncoding : "UTF-8"); org.modeshape.jcr.api.Binary binary = (org.modeshape.jcr.api.Binary)parentNode.getSession() .getValueFactory() .createBinary(newContent); contentNode.setProperty(DATA_PROP_NAME, binary); contentNode.setProperty(MODIFIED_PROP_NAME, Calendar.getInstance()); // Copy the content to the property, THEN re-read the content from the Binary value to avoid discarding the first // bytes of the stream if (contentType == null) { contentType = binary.getMimeType(resourceName); } if (contentType != null) { contentNode.setProperty(MIME_TYPE_PROP_NAME, contentType); } return contentNode.getProperty(DATA_PROP_NAME).getLength(); }
private void addFileContent( ZipInputStream zipInputStream, ZipEntry entry, Context context, Node zipFileNode ) throws RepositoryException, IOException { Node contentNode = zipFileNode.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE); // on session pre-save the appropriate properties should be set automatically contentNode.addMixin(JcrConstants.MIX_LAST_MODIFIED); // set the content bytes byte[] contentBytes = readContent(zipInputStream); org.modeshape.jcr.api.Binary contentBinary = context.valueFactory().createBinary(contentBytes); contentNode.setProperty(JcrConstants.JCR_DATA, contentBinary); // Figure out the mime type ... String mimeType = contentBinary.getMimeType(entry.getName()); if (mimeType != null) { contentNode.setProperty(JcrConstants.JCR_MIME_TYPE, mimeType); } }
/** * Returns the default mime-type of a given binary property. * * @param binaryProperty a non-null {@link Property} * @return a non-null String which represents the mime-type of the binary property. * @throws RepositoryException if any JCR related operation involving the binary property fail. */ public String getDefaultMimeType( Property binaryProperty ) throws RepositoryException { try { Binary binary = binaryProperty.getBinary(); return binary instanceof org.modeshape.jcr.api.Binary ? ((org.modeshape.jcr.api.Binary)binary) .getMimeType() : DEFAULT_MIME_TYPE; } catch (IOException e) { logger.warn("Cannot determine default mime-type", e); return DEFAULT_MIME_TYPE; } }
mimeType = ((org.modeshape.jcr.api.Binary)binary).getMimeType(parent.getName());
mimeType = ((org.modeshape.jcr.api.Binary)binary).getMimeType(parent.getName());
@Override public boolean execute( Property inputProperty, Node outputNode, Context context ) throws Exception { Binary binaryValue = (Binary) inputProperty.getBinary(); CheckArg.isNotNull(binaryValue, "binary"); String mimeType = binaryValue.getMimeType(); Node sequencedNode = getMetadataNode(outputNode); setPropertyIfMetadataPresent(sequencedNode, JcrConstants.JCR_MIME_TYPE, mimeType); return processBasicMetadata(sequencedNode, binaryValue); }
@Override public boolean execute( Property inputProperty, Node outputNode, Context context ) throws Exception { Binary binaryValue = (Binary) inputProperty.getBinary(); CheckArg.isNotNull(binaryValue, "binary"); String mimeType = binaryValue.getMimeType(); Node sequencedNode = getMetadataNode(outputNode); setPropertyIfMetadataPresent(sequencedNode, JcrConstants.JCR_MIME_TYPE, mimeType); return processBasicMetadata(sequencedNode, binaryValue); }
@Override public boolean execute( Property inputProperty, Node outputNode, Context context ) throws Exception { Binary binaryValue = (Binary) inputProperty.getBinary(); CheckArg.isNotNull(binaryValue, "binary"); String mimeType = binaryValue.getMimeType(); Node sequencedNode = getMetadataNode(outputNode); setPropertyIfMetadataPresent(sequencedNode, JcrConstants.JCR_MIME_TYPE, mimeType); return processBasicMetadata(sequencedNode, binaryValue); }
/** * Creates a new tika metadata object used by the parser. This will contain the mime-type of the content being parsed, if this * is available to the underlying context. If not, Tika's autodetection mechanism is used to try and get the mime-type. * * @param binary a <code>org.modeshape.jcr.api.Binary</code> instance of the content being parsed * @param context the extraction context; may not be null * @return a <code>Metadata</code> instance. * @throws java.io.IOException if auto-detecting the mime-type via Tika fails * @throws RepositoryException if error obtaining MIME-type of the binary parameter */ protected final Metadata prepareMetadata( final Binary binary, final Context context ) throws IOException, RepositoryException { Metadata metadata = new Metadata(); String mimeType = binary.getMimeType(); if (StringUtil.isBlank(mimeType)) { // Call the detector (we don't know the name) ... mimeType = context.mimeTypeOf(null, binary); } if (!StringUtil.isBlank(mimeType)) { metadata.set(Metadata.CONTENT_TYPE, mimeType); } return metadata; }
assertEquals("Invalid mime-type", "text/plain", file1Binary.getMimeType()); assertEquals("Invalid mime-type", "text/plain", file2Binary.getMimeType());
Binary binaryValue = (Binary) inputProperty.getBinary(); CheckArg.isNotNull(binaryValue, "binary"); final String mimeType = binaryValue.getMimeType(); boolean isValid = false; AudioMetadata metadata = null;
String mimeType = binaryValue.getMimeType(inputFileName);
String mimeType = binaryValue.getMimeType(inputFileName);
fileName = stringFactory().create(parentName); String mimeType = binaryValue.getMimeType(fileName); if (mimeType != null) { node.setProperty(cache, propertyFactory.create(JcrLexicon.MIMETYPE, mimeType));
fileName = stringFactory().create(parentName); String mimeType = binaryValue.getMimeType(fileName); if (mimeType != null) { node.setProperty(cache, propertyFactory.create(JcrLexicon.MIMETYPE, mimeType));