RepositoryDocument rd = new RepositoryDocument();
if (Logging.connectors.isDebugEnabled()) {
Logging.connectors.debug("GridFS: Processing document _id = " + _id);
}
GridFSDBFile document = gfs.findOne(new ObjectId(_id));
if (document == null) {
activities.deleteDocument(_id);
i++;
continue;
}
DBObject metadata = document.getMetaData();
if (metadata == null) {
Logging.connectors.warn("GridFS: Document " + _id + " has a null metadata - skipping.");
i++;
continue;
}
String urlValue = document.getMetaData().get(this.url) == null
? StringUtils.EMPTY
: document.getMetaData().get(this.url).toString();
if (!StringUtils.isEmpty(urlValue)) {
if (!scanOnly[i]) {
boolean validURL;
try {
new java.net.URI(urlValue);
validURL = true;
} catch (java.net.URISyntaxException e) {
validURL = false;
}
if (validURL) {
long fileLenght = document.getLength();
InputStream is = document.getInputStream();
try {
Date indexingDate = new Date();
rd.setBinary(is, fileLenght);
rd.setCreatedDate(document.getUploadDate());
rd.setFileName(document.getFilename());
rd.setIndexingDate(indexingDate);
rd.setMimeType(document.getContentType());
String[] aclsArray = null;
String[] denyAclsArray = null;
if (acl != null) {
try {
Object aclObject = document.getMetaData().get(acl);
if (aclObject != null) {
List<String> acls = (List<String>) aclObject;
aclsArray = (String[]) acls.toArray();
}
} catch (ClassCastException e) {
// This is bad because security will fail
Logging.connectors.warn("GridFS: Document " + _id + " metadata ACL field doesn't contain List<String> type.");
throw new ManifoldCFException("Security decoding error: "+e.getMessage(),e);
}
}
if (denyAcl != null) {
try {
Object denyAclObject = document.getMetaData().get(denyAcl);
if (denyAclObject != null) {
List<String> denyAcls = (List<String>) denyAclObject;
denyAcls.add(GLOBAL_DENY_TOKEN);
denyAclsArray = (String[]) denyAcls.toArray();
}