@Override public String[] getExtensionsAndMimetypes() { List<String> extensionsAndMimetypes = new ArrayList<String>(); for (String mimetype: mimetypeService.getMimetypes(null)) { String extension = mimetypeService.getExtension(mimetype); extensionsAndMimetypes.add(extension+" - "+mimetype); } return extensionsAndMimetypes.toArray(new String[extensionsAndMimetypes.size()]); }
private String stdMimetype(String mimetype) { return mimetypeService.getMimetype(mimetypeService.getExtension(mimetype)); } }
private void doGuessMimetype(String filename) { String mimetype; if (filename != null && filename.startsWith(MimetypeMap.MACOS_RESOURCE_FORK_FILE_NAME_PREFIX)) { mimetype = MimetypeMap.MIMETYPE_APPLEFILE; } else { mimetype = mimetypeService.guessMimetype(filename, getReader()); } setMimetype(mimetype); }
/** * Mock up the responses from the mimetypeService so that it: * a) returns all the supplied mimetypes * b) returns the extension given the mimetype * c) returns the mimetype given the extension. * @param mimetypeService mimetype service * @param mimetypesAndExtensions sequence of mimetypes and extenstions. * @throws IllegalStateException if there is not an extension for every mimetype */ public static void mockMimetypes(MimetypeService mimetypeService, String... mimetypesAndExtensions) { if (mimetypesAndExtensions.length % 2 != 0) { // Not using IllegalArgumentException as this is thrown by classes under test throw new java.lang.IllegalStateException("There should be an extension for every mimetype"); } final Set<String> allMimetypes = new HashSet<String>(); for (int i=0; i < mimetypesAndExtensions.length; i+=2) { allMimetypes.add(mimetypesAndExtensions[i]); when(mimetypeService.getExtension(mimetypesAndExtensions[i])).thenReturn(mimetypesAndExtensions[i+1]); when(mimetypeService.getMimetype(mimetypesAndExtensions[i+1])).thenReturn(mimetypesAndExtensions[i]); } when(mimetypeService.getMimetypes()).thenReturn(new ArrayList<String>(allMimetypes)); }
@Override public String getSourceExt() { return ANY.equals(sourceMimetype) ? ANY : mimetypeService.getExtension(sourceMimetype); }
/** * Returns a collection of mimetypes ordered by extension, but unlike the version in MimetypeService * throws an exception if the sourceExtension is supplied but does not match a mimetype. * @param sourceExtension to restrict the collection to one entry * @throws IllegalArgumentException if there is no match. The message indicates this. */ public Collection<String> getSourceMimetypes(String sourceExtension) { Collection<String> sourceMimetypes = mimetypeService.getMimetypes(sourceExtension); if (sourceMimetypes.isEmpty()) { throw new IllegalArgumentException("Unknown source extension "+sourceExtension); } return sourceMimetypes; }
String actualExtensionMimetype = mimetypeService.guessMimetype(fileName); assertEquals("The "+quickname+" extension indicates a mimetype of "+actualExtensionMimetype+ " rather than "+extensionMimetype, extensionMimetype, actualExtensionMimetype); String outputFileExtension = mimetypeService.getExtension(targetMimeType); ContentReader contentReader = AuthenticationUtil.runAs(createTargetWork, AuthenticationUtil.getSystemUserName()); contentReader.setMimetype(declaredMimetype); String actualDetectedMimetype = mimetypeService.getMimetypeIfNotMatches(contentReader); if (actualDetectedMimetype != null)
private void strictMimetypeCheck(ContentReader reader, TransformationOptions options, String sourceMimetype) throws UnsupportedTransformationException { if (strictMimeTypeCheck && depth.get() == 1) { String differentType = getMimetypeService().getMimetypeIfNotMatches(reader.getReader()); if (!transformerConfig.strictMimetypeCheck(sourceMimetype, differentType)) { String fileName = transformerDebug.getFileName(options, true, 0); String readerSourceMimetype = reader.getMimetype(); String message = "Transformation of ("+fileName+ ") has not taken place because the declared mimetype ("+ readerSourceMimetype+") does not match the detected mimetype ("+ differentType+")."; logger.warn(message); throw new UnsupportedTransformationException(message); } } }
public TransformerSourceTargetSuffixValue(String transformerName, String sourceExt, String targetExt, String suffix, String use, String value, MimetypeService mimetypeService) { super(transformerName, sourceExt, targetExt, suffix, use); this.value = value; this.sourceMimetype = ANY.equals(sourceExt) ? ANY : mimetypeService.getMimetype(sourceExt); this.targetMimetype = ANY.equals(targetExt) ? ANY : mimetypeService.getMimetype(targetExt); }
mimetypeService.getMimetypesByExtension(); for (String bit: bits) sourceMimetype = bit.equals("*") ? bit : mimetypeService.getMimetype(bit); if (sourceMimetype == null) targetMimetype = bit.equals("*") ? bit : mimetypeService.getMimetype(bit); if (targetMimetype == null)
String mimetype = mimetypeService.guessMimetype(tempFile.getFullName(), new FileContentReader(tempFile.getFile())); logger.debug("guesssed mimetype:" + mimetype); try ContentCharsetFinder charsetFinder = mimetypeService.getContentCharsetFinder(); Charset charset = charsetFinder.getCharset(is, mimetype); encoding = charset.name();
return defaultEncoding; // not necessary to guess folder encoding InputStream is = null; ContentCharsetFinder charsetFinder = mimetypeService.getContentCharsetFinder();
if (mimetypeService.isText(mimetype)) ContentCharsetFinder charsetFinder = mimetypeService.getContentCharsetFinder(); encoding = charsetFinder.getCharset(bis, mimetype).name();
@Override public FacetLabel getDisplayLabel(String value) { Map<String, String> mimetypes = serviceRegistry.getMimetypeService().getDisplaysByMimetype(); String displayName = mimetypes.get(value); return new FacetLabel(value, displayName == null ? value : displayName.trim(), -1); } }
Map<String, String> extensionsByMimetype = serviceRegistry.getMimetypeService().getExtensionsByMimetype();
@Override public String getSourceExt() { return ANY.equals(sourceMimetype) ? ANY : mimetypeService.getExtension(sourceMimetype); }
/** * Returns a collection of mimetypes ordered by extension, but unlike the version in MimetypeService * throws an exception if the sourceExtension is supplied but does not match a mimetype. * @param sourceExtension to restrict the collection to one entry * @throws IllegalArgumentException if there is no match. The message indicates this. */ public Collection<String> getSourceMimetypes(String sourceExtension) { Collection<String> sourceMimetypes = mimetypeService.getMimetypes(sourceExtension); if (sourceMimetypes.isEmpty()) { throw new IllegalArgumentException("Unknown source extension "+sourceExtension); } return sourceMimetypes; }
differentType = mimetypeService.getMimetypeIfNotMatches(writer.getReader());
public TransformerSourceTargetSuffixValue(String transformerName, String sourceExt, String targetExt, String suffix, String use, String value, MimetypeService mimetypeService) { super(transformerName, sourceExt, targetExt, suffix, use); this.value = value; this.sourceMimetype = ANY.equals(sourceExt) ? ANY : mimetypeService.getMimetype(sourceExt); this.targetMimetype = ANY.equals(targetExt) ? ANY : mimetypeService.getMimetype(targetExt); }
mimetypeService.getMimetypesByExtension(); for (String bit: bits) sourceMimetype = bit.equals("*") ? bit : mimetypeService.getMimetype(bit); if (sourceMimetype == null) targetMimetype = bit.equals("*") ? bit : mimetypeService.getMimetype(bit); if (targetMimetype == null)