public Document getDocumentById( String id ) {
File file = fileFor(id);
if (isExcluded(file) || !file.exists()) return null;
boolean isRoot = isRoot(id);
boolean isResource = isContentNode(id);
DocumentWriter writer = null;
File parentFile = file.getParentFile();
if (isResource) {
writer = newDocument(id);
BinaryValue binaryValue = binaryFor(file);
writer.setPrimaryType(NT_RESOURCE);
writer.addProperty(JCR_DATA, binaryValue);
if (addMimeTypeMixin) {
String mimeType = null;
try {
mimeType = binaryValue.getMimeType();
} catch (Throwable e) {
getLogger().error(e, JcrI18n.couldNotGetMimeType, getSourceName(), id, e.getMessage());
}
writer.addProperty(JCR_MIME_TYPE, mimeType);
}
writer.addProperty(JCR_LAST_MODIFIED, lastModifiedTimeFor(file));
writer.addProperty(JCR_LAST_MODIFIED_BY, ownerFor(file));
// // make these binary not queryable. If we really want to query them, we need to switch to external binaries
// writer.setNotQueryable();
if (!isQueryable()) writer.setNotQueryable();
parentFile = file;
} else if (file.isFile()) {
writer = newDocument(id);
writer.setPrimaryType(NT_FILE);
writer.addProperty(JCR_CREATED, createdTimeFor(file));
writer.addProperty(JCR_CREATED_BY, ownerFor(file));
String childId = contentChildId(id, isRoot);
writer.addChild(childId, JCR_CONTENT);
if (!isQueryable()) writer.setNotQueryable();
} else {
writer = newFolderWriter(id, file, 0);
}
if (!isRoot) {
// Set the reference to the parent ...
String parentId = idFor(parentFile);
writer.setParents(parentId);
}
// Add the extra properties (if there are any), overwriting any properties with the same names
// (e.g., jcr:primaryType, jcr:mixinTypes, jcr:mimeType, etc.) ...
writer.addProperties(extraPropertiesStore().getProperties(id));
// Add the 'mix:mixinType' mixin; if other mixins are stored in the extra properties, this will append ...
if (addMimeTypeMixin) {
writer.addMixinType(MIX_MIME_TYPE);
}
// Return the document ...
return writer.document();
}