@Override public List<DcsFormat> detectFormats(File file) { List<DcsFormat> detectedFormats = droidDriver.detectFormats(file); //according to the contract, must return this format if none is detected if(detectedFormats.size() == 0){ String unknownType = "application/octet-stream"; DcsFormat unknownFormat = new DcsFormat(); unknownFormat.setSchemeUri(MIME_TYPE_SCHEME_URI); unknownFormat.setFormat(unknownType); unknownFormat.setName(unknownType); detectedFormats.add(unknownFormat); } return detectedFormats; }
/** * Copy constructor for a DcsFormat. The state of <code>toCopy</code> is copied * to this. * * @param toCopy the dcs format to copy */ public DcsFormat(DcsFormat toCopy) { this.format = toCopy.getFormat(); this.version = toCopy.getVersion(); this.name = toCopy.getName(); this.schemeUri = toCopy.getSchemeUri(); }
protected String extract_format(String value) { try { DcsFormat format = DcsFormat.parseDcsFormat(value); if (format.getSchemeUri() != null && format.getSchemeUri().equals(PRONOM_URI)) { return PRONOM_FORMAT_PREFIX + format.getFormat(); } else { return format.getFormat(); } } catch (IllegalArgumentException e) { return null; } }
/** * Converts format id from the DcsFormat objects into formatURI string with qualifying namespace. Only applicable * to pronom format identifier at this point. * @param dcsFormat * @return */ private String createFormatURIString(DcsFormat dcsFormat) { if (dcsFormat.getSchemeUri().equals(pronomSchemaUri)) { return "info:pronom/" + dcsFormat.getFormat(); } else { log.info("Format URI conversion is not supported for: " + dcsFormat.getSchemeUri() + ". Format URI conversion is supported for " + pronomSchemaUri + ". Returning format string as format URI"); return dcsFormat.getFormat(); } }
DcsFormat format = new DcsFormat(); format.setSchemeUri("http://www.iana.org/assignments/media-types/"); format.setFormat(mime); file.addFormat(format);
private Map<String, Integer> getFileCountByFormat(Set<AttributeSet> fileAttributeSets) { //TODO: map keyed by format's name. keyed by DcsFormat object would be more reliable. Report consumer can //decide what field of DcsFormat to use. But IngestReport doesn't current support mapping keyed on DcsFormat type. Map<String, Integer> fileCountByFormat = new HashMap<String, Integer>(); for (AttributeSet fileAttributeSet : fileAttributeSets) { //extract file-formats java.util.Collection<Attribute> matchingAttributes = fileAttributeSet.getAttributesByName(Metadata.FILE_FORMAT); for (Attribute attribute : matchingAttributes) { if (attribute.getType().equals(AttributeValueType.DCS_FORMAT)) { DcsFormat format = DcsFormat.parseDcsFormat(attribute.getValue()); // Only add the Pronom format to the report to be displayed or the unknown mime-type // (application/octet-stream) if (format.getSchemeUri().contains("PRONOM") || format.getName().equalsIgnoreCase("application/octet-stream")) { // if an entry for this format does not exist yet if (!fileCountByFormat.containsKey(format.getName())) { // create the new entry fileCountByFormat.put(format.getName(), 0); } // increase count for the format entry. fileCountByFormat.put(format.getName(), fileCountByFormat.get(format.getName()) + 1); } } } } return fileCountByFormat; } /**
Attribute formatAttribute = new AttributeImpl(Metadata.FILE_FORMAT, AttributeValueType.DCS_FORMAT, format.toString()); attributes.add(formatAttribute); event.setOutcome(format.getSchemeUri() + " " + format.getFormat()); DcsEntityReference ref = new DcsEntityReference(file.getPath()); List<DcsEntityReference> refs = new ArrayList<DcsEntityReference>();
file.setId(UUID.randomUUID().toString()); final DcsFormat format = new DcsFormat(); try { file.setExtant(true); file.setName("java-format-serialization"); format.setFormat("application/xml"); format.setSchemeUri("http://www.iana.org/assignments/media-types/"); file.addFormat(format);
if (formatEntry.getSchemeUri().equals(ianaURI)) { fileMIME = formatEntry.getFormat(); if (formatEntry.getSchemeUri().equals(registryURI)) { fileFormatURI = formatEntry.getFormat();
private Set<DcsFormat> createFormatSet(int size) { Set<DcsFormat> set = new HashSet<DcsFormat>(); for (int i = 0; i < size; i++) { DcsFormat fmt = new DcsFormat(); fmt.setFormat(randomString(10, false)); fmt.setName(randomString(10, false)); fmt.setSchemeUri(randomString(10, false)); fmt.setVersion(randomString(10, false)); set.add(fmt); } return set; }
file.setId(UUID.randomUUID().toString()); final DcsFormat format = new DcsFormat(); try { file.setExtant(true); file.setName("java-format-serialization"); format.setFormat("application/xml"); format.setSchemeUri("http://www.iana.org/assignments/media-types/"); file.addFormat(format);
private static void addFormatSet(SolrInputDocument doc, Collection<DcsFormat> set) { if (set == null || set.size() == 0) { return; } for (DcsFormat fmt : set) { setadd(doc, FormatField.NAME, fmt.getName()); setadd(doc, FormatField.FORMAT, fmt.getFormat()); setadd(doc, FormatField.SCHEMA, fmt.getSchemeUri()); setadd(doc, FormatField.VERSION, fmt.getVersion()); } }
IdentificationResultCollection identificationResultCollection = droidIdentifier.detectFormat(file); for (IdentificationResult identificationResult : identificationResultCollection.getResults()){ DcsFormat dcsPronomFormat = new DcsFormat(); dcsPronomFormat.setSchemeUri(PRONOM_SCHEME_URI); dcsPronomFormat.setFormat(identificationResult.getPuid()); if(identificationResult.getName() != null){ dcsPronomFormat.setName(identificationResult.getName()); dcsPronomFormat.setVersion(identificationResult.getVersion()); DcsFormat dcsMimeType = new DcsFormat(); dcsMimeType.setSchemeUri(MIME_TYPE_SCHEME_URI); dcsMimeType.setFormat(mimeType); dcsMimeType.setName(mimeType);
man.setType(REGISTRY_ENTRY_MAN_TYPE); final DcsManifestationFile mf = new DcsManifestationFile(); final DcsFormat format = new DcsFormat(); DcsFile entry_file = new DcsFile(); entry_file.setExtant(true); entry_file.setName("java-entry-serialization"); format.setFormat("application/xml"); format.setSchemeUri("http://www.iana.org/assignments/media-types/"); entry_file.addFormat(format);
@Override public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { super.marshal(source, writer, context); final DcsFormat format = (DcsFormat) source; writer.startNode(E_ID); if (format.getSchemeUri() != null) { writer.addAttribute(A_SCHEME, format.getSchemeUri()); } if (format.getFormat() != null) { writer.setValue(format.getFormat()); } writer.endNode(); if (format.getName() != null) { writer.startNode(E_NAME); writer.setValue(format.getName()); writer.endNode(); } if (format.getVersion() != null) { writer.startNode(E_VERSION); writer.setValue(format.getVersion()); writer.endNode(); } }
private static Set<DcsFormat> getFormatSet(SolrDocument doc) { Set<DcsFormat> set = new HashSet<DcsFormat>(); String[] names = setgetAll(doc, FormatField.NAME); String[] schemas = setgetAll(doc, FormatField.SCHEMA); String[] versions = setgetAll(doc, FormatField.VERSION); String[] formats = setgetAll(doc, FormatField.FORMAT); for (int i = 0; i < formats.length; i++) { DcsFormat fmt = new DcsFormat(); if (!Util.isEmptyOrNull(formats[i])) { fmt.setFormat(formats[i]); } if (!Util.isEmptyOrNull(names[i])) { fmt.setName(names[i]); } if (!Util.isEmptyOrNull(schemas[i])) { fmt.setSchemeUri(schemas[i]); } if (!Util.isEmptyOrNull(versions[i])) { fmt.setVersion(versions[i]); } set.add(fmt); } return set; }
state_file.setId(nextId()); final DcsFormat format = new DcsFormat(); try { File outfile = null; state_file.setExtant(true); state_file.setName("java-scheme-serialization"); format.setFormat("application/xml"); format.setSchemeUri("http://www.iana.org/assignments/media-types/"); state_file.addFormat(format);
@Override public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { super.marshal(source, writer, context); final DcsFormat format = (DcsFormat) source; writer.startNode(E_ID); if (format.getSchemeUri() != null) { writer.addAttribute(A_SCHEME, format.getSchemeUri()); } if (format.getFormat() != null) { writer.setValue(format.getFormat()); } writer.endNode(); if (format.getName() != null) { writer.startNode(E_NAME); writer.setValue(format.getName()); writer.endNode(); } if (format.getVersion() != null) { writer.startNode(E_VERSION); writer.setValue(format.getVersion()); writer.endNode(); } }