public static void main(String[] args) throws CommandExecutionException, FileNotFoundException, IOException { DroidDetector dd = new DroidDetector(); // Can use a File or an InputStream: File inFile = new File("src/test/resources/lorem-ipsum.doc"); // If you use the InputStream, you need to add the resource name if you // want extension-based identification to work: Metadata metadata = new Metadata(); metadata.set(Metadata.RESOURCE_NAME_KEY, inFile.toURI().toString()); // To get the identification as an extended MIME type: MediaType mt = dd.detect(inFile); // Or: mt = dd.detect(new FileInputStream(inFile), metadata); // Giving: // MIME Type: application/msword; version=97-2003 System.out.println("MIME Type: " + mt); // Or, get the raw DROID results List<IdentificationResult> lir = dd.detectPUIDs(inFile); for (IdentificationResult ir : lir) { System.out.println("PUID: " + ir.getPuid() + " '" + ir.getName() + "' " + ir.getVersion() + " (" + ir.getMimeType() + ") via " + ir.getMethod() + " identification."); // PUID: fmt/40 'Microsoft Word Document' 97-2003 // (application/msword) via Container identification. // Which you can then turn into an extended MIME type if required: System.out.println("Extended MIME:" + DroidDetector.getMimeTypeFromResult(ir)); // Extended MIME:application/msword; version=97-2003 } }
/** * Removes a result. * * @param result The result to remove. */ public void removeResult(IdentificationResult result) { if (results.remove(result)) { final String puid = result.getPuid(); puidMap.remove(puid); } }
String puid = identResult.getPuid(); if (!container && JIP_ARCHIVE.equals(puid)) { puid = ZIP_ARCHIVE; .getFileFormat(identResult.getPuid()); IdentificationResultImpl resultImpl = new IdentificationResultImpl(); resultImpl.setMimeType(hit.getMimeType()); resultImpl.setName(hit.getName()); resultImpl.setVersion(hit.getVersion()); resultImpl.setPuid(identResult.getPuid()); resultImpl.setMethod(identResult.getMethod()); result = resultImpl;
for (IdentificationResult identificationResult : results.getResults()) { try { FileFormat fileFormat = retrieveSigFileDetails().getFileFormat(identificationResult.getPuid()); IdentificationResultImpl result = new IdentificationResultImpl(); result.setMimeType(fileFormat.getMimeType()); result.setPuid(fileFormat.getPUID()); result.setMethod(IdentificationMethod.CONTAINER); result.setRequestMetaData(identificationResult.getMetaData()); containerResults.removeResult(identificationResult); containerResults.addResult(result);
/** * {@inheritDoc} */ @Override public ResourceId handleDirectory(IdentificationResult result, ResourceId parentId, boolean restricted) { final URI uri = result.getIdentifier().getUri(); //log.debug(String.format("handling directory [%s]", uri)); ProfileResourceNode node = new ProfileResourceNode(uri); RequestMetaData requestMetaData = result.getMetaData(); NodeMetaData metaData = new NodeMetaData(); metaData.setName(requestMetaData.getName()); metaData.setSize(null); metaData.setLastModified(requestMetaData.getTime()); metaData.setIdentificationMethod(IdentificationMethod.NULL); metaData.setNodeStatus(restricted ? NodeStatus.ACCESS_DENIED : NodeStatus.DONE); metaData.setResourceType(ResourceType.FOLDER); node.setMetaData(metaData); node.setFinished(new Date()); node.addFormatIdentification(Format.NULL); resultHandlerDao.save(node, parentId); progressMonitor.stopJob(node); return new ResourceId(node.getId(), node.getPrefix()); }
/** * Removes a result. * * @param result The result to remove. */ public void removeResult(IdentificationResult result) { if (results.remove(result)) { final String puid = result.getPuid(); puidMap.remove(puid); } }
/** * {@inheritDoc} */ @Override public ResourceId handleDirectory(IdentificationResult result, ResourceId parentId, boolean restricted) { final URI uri = result.getIdentifier().getUri(); //log.debug(String.format("handling directory [%s]", uri)); ProfileResourceNode node = new ProfileResourceNode(uri); RequestMetaData requestMetaData = result.getMetaData(); NodeMetaData metaData = new NodeMetaData(); metaData.setName(requestMetaData.getName()); metaData.setSize(null); metaData.setLastModified(requestMetaData.getTime()); metaData.setIdentificationMethod(IdentificationMethod.NULL); metaData.setNodeStatus(restricted ? NodeStatus.ACCESS_DENIED : NodeStatus.DONE); metaData.setResourceType(ResourceType.FOLDER); node.setMetaData(metaData); node.setFinished(new Date()); node.addFormatIdentification(Format.NULL); resultHandlerDao.save(node, parentId); progressMonitor.stopJob(node); return new ResourceId(node.getId(), node.getPrefix()); }
String mimeTypeString = r.getMimeType(); if (mimeTypeString != null && !"".equals(mimeTypeString.trim())) { parameters = new HashMap<String, String>(mediaType.getParameters()); if (parameters.get("version") == null && r.getVersion() != null && (!"".equals(r.getVersion())) && parameters.put("version", r.getVersion()); String id = "puid-" + r.getPuid().replace("/", "-"); String name = r.getName().replace("\"", "'"); String version = r.getVersion(); if (version != null && !"".equals(version) && !"null".equals(version)) {
/** * Adds a result. * @param result the result to add */ public void addResult(IdentificationResult result) { // Don't add the same puid more than once to a result collection. final String puid = result.getPuid(); if (!puidMap.containsKey(puid)) { puidMap.put(puid, result); results.add(result); } }
DcsFormat dcsPronomFormat = new DcsFormat(); dcsPronomFormat.setSchemeUri(PRONOM_SCHEME_URI); dcsPronomFormat.setFormat(identificationResult.getPuid()); if(identificationResult.getName() != null){ dcsPronomFormat.setName(identificationResult.getName()); if(identificationResult.getVersion() != null){ dcsPronomFormat.setVersion(identificationResult.getVersion()); if(identificationResult.getMimeType() != null && !identificationResult.getMimeType().isEmpty()){ String[] types = identificationResult.getMimeType().split(",");
/** * Adds a result. * @param result the result to add */ public void addResult(IdentificationResult result) { // Don't add the same puid more than once to a result collection. final String puid = result.getPuid(); if (!puidMap.containsKey(puid)) { puidMap.put(puid, result); results.add(result); } }
private String getContainerFormat(IdentificationResultCollection results) { final List<IdentificationResult> theResults = results.getResults(); final int numResults = theResults.size(); // use an indexed loop to reduce garbage, don't allocate an iterator. for (int i = 0; i < numResults; i++) { final IdentificationResult result = theResults.get(i); final String format = containerFormatResolver.forPuid(result.getPuid()); if (format != null) { return format; } } return null; }
private String getContainerFormat(IdentificationResultCollection results) { final List<IdentificationResult> theResults = results.getResults(); final int numResults = theResults.size(); // use an indexed loop to reduce garbage, don't allocate an iterator. for (int i = 0; i < numResults; i++) { final IdentificationResult result = theResults.get(i); final String format = containerFormatResolver.forPuid(result.getPuid()); if (format != null) { return format; } } return null; }
/** * @param results A previous identification of an archival format. * @return format or null */ private String getArchiveFormat(IdentificationResultCollection results) { final List<IdentificationResult> theResults = results.getResults(); final int numResults = theResults.size(); // use an indexed loop to reduce garbage, don't allocate an iterator. for (int i = 0; i < numResults; i++) { final IdentificationResult result = theResults.get(i); String format = archiveFormatResolver.forPuid(result.getPuid()); if (format != null) { // exit on the first non-null format met if (processArchives && !processWebArchives && isWebArchiveFormat(format)) { format = null; } else if (!processArchives && processWebArchives && !isWebArchiveFormat(format)) { format = null; } return format; } } return null; }
for (int i = 0; i < numResults; i++) { final IdentificationResult result = theResults.get(i); final String resultPUID = result.getPuid(); final FileFormat format = allFormats.getFormatForPUID(resultPUID); lowerPriorityIDs.addAll(format.getFormatIdsHasPriorityOver()); for (int i = 0; i < numResults; i++) { final IdentificationResult result = theResults.get(i); final String resultPUID = result.getPuid(); final FileFormat format = allFormats.getFormatForPUID(resultPUID); if (lowerPriorityIDs.contains(format.getID())) {
/** * @param results A previous identification of an archival format. * @return format or null */ private String getArchiveFormat(IdentificationResultCollection results) { final List<IdentificationResult> theResults = results.getResults(); final int numResults = theResults.size(); // use an indexed loop to reduce garbage, don't allocate an iterator. for (int i = 0; i < numResults; i++) { final IdentificationResult result = theResults.get(i); String format = archiveFormatResolver.forPuid(result.getPuid()); if (format != null) { // exit on the first non-null format met if (processArchives && !processWebArchives && isWebArchiveFormat(format)) { format = null; } else if (!processArchives && processWebArchives && !isWebArchiveFormat(format)) { format = null; } return format; } } return null; }
for (int i = 0; i < numResults; i++) { final IdentificationResult result = theResults.get(i); final String resultPUID = result.getPuid(); final FileFormat format = allFormats.getFormatForPUID(resultPUID); if (format.getNumExtensions() > 0) { for (int i = 0; i < numResults; i++) { final IdentificationResult result = theResults.get(i); final String resultPUID = result.getPuid(); final FileFormat format = allFormats.getFormatForPUID(resultPUID); if (format.hasExtensionMismatch(fileExtension)) {
String puid = identResult.getPuid(); if (!container && JIP_ARCHIVE.equals(puid)) { puid = ZIP_ARCHIVE;