/** * Determine if the primary and sub type of this object is * the same as the content type described in rawdata. * * @param rawdata the MIME type string to compare with * @return true if they match */ public boolean match(String rawdata) throws MimeTypeParseException { return match(new MimeType(rawdata)); }
/** * Is the string representation of the MIME type passed in equivalent * to the MIME type of this DataFlavor. <p> * * ActivationDataFlavor delegates the comparison of MIME types to * the MimeType class included as part of the JavaBeans Activation * Framework. This provides a more robust comparison than is normally * available in the DataFlavor class. * * @param mimeType the MIME type * @return true if the same MIME type */ public boolean isMimeTypeEqual(String mimeType) { MimeType mt = null; try { if (mimeObject == null) mimeObject = new MimeType(this.mimeType); mt = new MimeType(mimeType); } catch (MimeTypeParseException e) { // something didn't parse, do a crude comparison return this.mimeType.equalsIgnoreCase(mimeType); } return mimeObject.match(mt); }
public DataSourceSource(DataSource source) throws MimeTypeParseException { this.source = source; String ct = source.getContentType(); if(ct==null) { charset = null; } else { MimeType mimeType = new MimeType(ct); this.charset = mimeType.getParameter("charset"); } }
/** * Use the MimeType class to extract the MIME type/subtype, * ignoring the parameters. The type is cached. */ private synchronized String getBaseType() { if (shortType == null) { String ct = getContentType(); try { MimeType mt = new MimeType(ct); shortType = mt.getBaseType(); } catch (MimeTypeParseException e) { shortType = ct; } } return shortType; }
if(contentType!=null) try { mt = new MimeType(contentType); } catch (MimeTypeParseException e) { xs.handleError(e);
static MimeType calcExpectedMediaType(AnnotationSource primarySource, ModelBuilder builder ) { XmlMimeType xmt = primarySource.readAnnotation(XmlMimeType.class); if(xmt==null) return null; try { return new MimeType(xmt.value()); } catch (MimeTypeParseException e) { builder.reportError(new IllegalAnnotationException( Messages.ILLEGAL_MIME_TYPE.format(xmt.value(),e.getMessage()), xmt )); return null; } } }
/** * Is the string representation of the MIME type passed in equivalent * to the MIME type of this DataFlavor. <p> * * ActivationDataFlavor delegates the comparison of MIME types to * the MimeType class included as part of the JavaBeans Activation * Framework. This provides a more robust comparison than is normally * available in the DataFlavor class. * * @param mimeType the MIME type * @return true if the same MIME type */ public boolean isMimeTypeEqual(String mimeType) { MimeType mt = null; try { if (mimeObject == null) mimeObject = new MimeType(this.mimeType); mt = new MimeType(mimeType); } catch (MimeTypeParseException e) {} return mimeObject.match(mt); }
/** * Determine if the primary and sub type of this object is * the same as the content type described in rawdata. * * @param rawdata the MIME type string to compare with * @return true if they match */ public boolean match(String rawdata) throws MimeTypeParseException { return match(new MimeType(rawdata)); }
@Test public void mimeType() throws MimeTypeParseException { getMorphia().map(MimeTyped.class); getDs().ensureIndexes(); MimeTyped entity = new MimeTyped(); entity.name = "test name"; entity.mimeType = new MimeType("text/plain"); //MimeTypeParseException final DBObject dbObject = getMorphia().toDBObject(entity); assertEquals("text/plain", dbObject.get("mimeType")); getDs().save(entity); // FAILS WITH ERROR HERE }
public DataSourceSource(DataSource source) throws MimeTypeParseException { this.source = source; String ct = source.getContentType(); if(ct==null) { charset = null; } else { MimeType mimeType = new MimeType(ct); this.charset = mimeType.getParameter("charset"); } }
/** * Use the MimeType class to extract the MIME type/subtype, * ignoring the parameters. The type is cached. */ private synchronized String getBaseType() { if (shortType == null) { String ct = getContentType(); try { MimeType mt = new MimeType(ct); shortType = mt.getBaseType(); } catch (MimeTypeParseException e) { shortType = ct; } } return shortType; }
public static VariableValueDto fromFormPart(String type, FormPart binaryDataFormPart) { VariableValueDto dto = new VariableValueDto(); dto.type = type; dto.value = binaryDataFormPart.getBinaryContent(); if (ValueType.FILE.getName().equals(fromRestApiTypeName(type))) { String contentType = binaryDataFormPart.getContentType(); if (contentType == null) { contentType = MediaType.APPLICATION_OCTET_STREAM; } dto.valueInfo = new HashMap<String, Object>(); dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_NAME, binaryDataFormPart.getFileName()); MimeType mimeType = null; try { mimeType = new MimeType(contentType); } catch (MimeTypeParseException e) { throw new RestException(Status.BAD_REQUEST, "Invalid mime type given"); } dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_MIME_TYPE, mimeType.getBaseType()); String encoding = mimeType.getParameter("encoding"); if (encoding != null) { dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_ENCODING, encoding); } String transientString = mimeType.getParameter("transient"); boolean isTransient = Boolean.parseBoolean(transientString); if (isTransient) { dto.valueInfo.put(AbstractValueTypeImpl.VALUE_INFO_TRANSIENT, isTransient); } } return dto; }
public static VariableValueDto fromFormPart(String type, FormPart binaryDataFormPart) { VariableValueDto dto = new VariableValueDto(); dto.type = type; dto.value = binaryDataFormPart.getBinaryContent(); if (ValueType.FILE.getName().equals(fromRestApiTypeName(type))) { String contentType = binaryDataFormPart.getContentType(); if (contentType == null) { contentType = MediaType.APPLICATION_OCTET_STREAM; } dto.valueInfo = new HashMap<String, Object>(); dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_NAME, binaryDataFormPart.getFileName()); MimeType mimeType = null; try { mimeType = new MimeType(contentType); } catch (MimeTypeParseException e) { throw new RestException(Status.BAD_REQUEST, "Invalid mime type given"); } dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_MIME_TYPE, mimeType.getBaseType()); String encoding = mimeType.getParameter("encoding"); if (encoding != null) { dto.valueInfo.put(FileValueType.VALUE_INFO_FILE_ENCODING, encoding); } String transientString = mimeType.getParameter("transient"); boolean isTransient = Boolean.parseBoolean(transientString); if (isTransient) { dto.valueInfo.put(AbstractValueTypeImpl.VALUE_INFO_TRANSIENT, isTransient); } } return dto; }
if(contentType!=null) try { mt = new MimeType(contentType); } catch (MimeTypeParseException e) { xs.handleError(e);
static MimeType calcExpectedMediaType(AnnotationSource primarySource, ModelBuilder builder ) { XmlMimeType xmt = primarySource.readAnnotation(XmlMimeType.class); if(xmt==null) return null; try { return new MimeType(xmt.value()); } catch (MimeTypeParseException e) { builder.reportError(new IllegalAnnotationException( Messages.ILLEGAL_MIME_TYPE.format(xmt.value(),e.getMessage()), xmt )); return null; } } }
static Optional<MimeType> parse(final String mimeType) { try { return Optional.of(new MimeType(mimeType)); } catch (final MimeTypeParseException e) { return Optional.empty(); } }