@Override public Object encode(final Object value, final MappedField optionalExtraInfo) { return ((MimeType) value).getBaseType(); } }
/** * Return the String representation of this object. */ public String toString() { return getBaseType() + parameters.toString(); }
/** * 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; }
/** * Return the String representation of this object. */ public String toString() { return getBaseType() + parameters.toString(); }
/** * 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; }
/** * Return the String representation of this object. */ public String toString() { return getBaseType() + parameters.toString(); }
/** * Return the String representation of this object. */ public String toString() { return getBaseType() + parameters.toString(); }
/** * Return the String representation of this object. */ public String toString() { return getBaseType() + parameters.toString(); }
/** * Return the String representation of this object. */ public String toString() { return getBaseType() + parameters.toString(); }
/** * Return the String representation of this object. */ public String toString() { return getBaseType() + parameters.toString(); }
private ContentType createContentType(String contentType) { try { MimeType mimeType = new MimeType(contentType); String mediaType = mimeType.getBaseType(); String charset = defaultString(mimeType.getParameter("charset"), DEFAULT_CONTENT_ENCODING); return ContentType.create(mediaType, charset); } catch (MimeTypeParseException e) { throw new IllegalArgumentException("Invalid content type: " + contentType, e); } }
private ContentType createContentType(String contentType) { try { MimeType mimeType = new MimeType(contentType); String mediaType = mimeType.getBaseType(); String charset = defaultString(mimeType.getParameter("charset"), DEFAULT_CONTENT_ENCODING); return ContentType.create(mediaType, charset); } catch (MimeTypeParseException e) { throw new IllegalArgumentException("Invalid content type: " + contentType, e); } }
public Object getValueForDatastoreMapping(NucleusContext nucleusCtx, int index, Object value) { Blob blob = ((Blob)value); switch (index) { case 0: return blob.getName(); case 1: return blob.getMimeType().getBaseType(); case 2: return blob.getBytes(); } throw new IndexOutOfBoundsException(); }
public Object getValueForDatastoreMapping(NucleusContext nucleusCtx, int index, Object value) { Clob clob = ((Clob)value); switch (index) { case 0: return clob.getName(); case 1: return clob.getMimeType().getBaseType(); case 2: return clob.getChars(); } throw new IndexOutOfBoundsException(); }
@Override public String toString() { return getName() + " [" + getMimeType().getBaseType() + "]: " + getChars().length() + " chars"; }
@Override public String toString() { return getName() + " [" + getMimeType().getBaseType() + "]: " + getBytes().length + " bytes"; }
AcceptHeaderEntry(MimeType mediaType) { MimeTypeParameterList parametersWithoutQ = mediaType.getParameters(); String qValue = parametersWithoutQ.get("q"); parametersWithoutQ.remove("q"); this.mediaType = mimeType(mediaType.getBaseType() + parametersWithoutQ.toString()); if (qValue == null) { quality = 1000; } else { quality = (int) (Float.parseFloat(qValue) * 1000); } }
public void setObject(ExecutionContext ec, PreparedStatement preparedStmt, int[] exprIndex, Object value) { Clob clob = ((Clob)value); if (clob == null) { getDatastoreMapping(0).setObject(preparedStmt, exprIndex[0], null); getDatastoreMapping(1).setObject(preparedStmt, exprIndex[1], null); getDatastoreMapping(2).setObject(preparedStmt, exprIndex[2], null); } else { getDatastoreMapping(0).setString(preparedStmt, exprIndex[0], clob.getName()); getDatastoreMapping(1).setString(preparedStmt, exprIndex[1], clob.getMimeType().getBaseType()); getDatastoreMapping(2).setObject(preparedStmt, exprIndex[2], clob.getChars().toString()); } }