}
} else {
node = node.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
}
Artifact a = info.artifacts.get(0);
// Keep track of whether this file got modified
boolean modified = false;
// Set the jcr:data property
ValueFactory factory = node.getSession().getValueFactory();
Value value = factory.createValue(a.getInputStream());
if (node.hasProperty(JcrConstants.JCR_DATA)) {
Property data = node.getProperty(JcrConstants.JCR_DATA);
if (!value.equals(data.getValue())) {
data.setValue(value);
// mark jcr:data as modified.
importInfo.onModified(data.getPath());
modified = true;
}
} else {
Property data = node.setProperty(JcrConstants.JCR_DATA, value);
// mark jcr:data as created
importInfo.onCreated(data.getPath());
modified = true;
}
// always update last modified if binary was modified (bug #22969)
if (!node.hasProperty(JcrConstants.JCR_LASTMODIFIED) || modified) {
Calendar lastModified = Calendar.getInstance();
node.setProperty(JcrConstants.JCR_LASTMODIFIED, lastModified);
modified = true;
}
// do not overwrite mimetype
if (!node.hasProperty(JcrConstants.JCR_MIMETYPE)) {
String mimeType = a.getContentType();
if (mimeType == null) {
mimeType = Text.getName(a.getRelativePath(), '.');
mimeType = MimeTypes.getMimeType(mimeType, MimeTypes.APPLICATION_OCTET_STREAM);
}
node.setProperty(JcrConstants.JCR_MIMETYPE, mimeType);
modified = true;
}