use of org.springframework.http.MediaType in project service-proxy by membrane.
the class Header method getBestAcceptedType.
/**
* Tries to determines the index of the best content type.
*/
public int getBestAcceptedType(MediaType[] supported) {
String accept = getFirstValue(ACCEPT);
if (accept == null)
return -1;
List<MediaType> m;
try {
m = MediaType.parseMediaTypes(accept);
} catch (IllegalArgumentException e) {
return -1;
}
MediaType.sortByQualityValue(m);
for (MediaType t : m) for (int i = 0; i < supported.length; i++) if (t.includes(supported[i]))
return i;
return -1;
}
use of org.springframework.http.MediaType in project com.revolsys.open by revolsys.
the class AbstractHttpMessageConverter method getMediaTypes.
public static List<MediaType> getMediaTypes(final Collection<?> contentTypes) {
final List<MediaType> mediaTypes = new ArrayList<>();
if (contentTypes != null) {
for (final Object mediaTypeObject : contentTypes) {
if (mediaTypeObject instanceof MediaType) {
final MediaType mediaType = (MediaType) mediaTypeObject;
mediaTypes.add(mediaType);
} else if (mediaTypeObject != null) {
mediaTypes.add(MediaType.parseMediaType(mediaTypeObject.toString()));
}
}
}
return mediaTypes;
}
use of org.springframework.http.MediaType in project com.revolsys.open by revolsys.
the class PageInfoHttpMessageConverter method writeMethod.
private void writeMethod(final XmlWriter writer, final String url, final PageInfo pageInfo, final String method, final Map<String, Object> values) {
final Collection<ParameterInfo> parameters = pageInfo.getParameters();
final boolean hasParameters = !parameters.isEmpty();
if (hasParameters) {
if (hasParameters) {
writer.startTag(HtmlElem.DIV);
writer.attribute(HtmlAttr.CLASS, "form");
writer.startTag(HtmlElem.FORM);
writer.attribute(HtmlAttr.ACTION, url);
writer.attribute(HtmlAttr.TARGET, "_top");
if (method.equals("post")) {
boolean isFormData = false;
for (final MediaType mediaType : pageInfo.getInputContentTypes()) {
if (MediaType.MULTIPART_FORM_DATA.isCompatibleWith(mediaType)) {
isFormData = true;
}
}
if (isFormData) {
writer.attribute(HtmlAttr.ENCTYPE, MediaType.MULTIPART_FORM_DATA.toString());
}
}
writer.attribute(HtmlAttr.METHOD, method);
writer.startTag(HtmlElem.DIV);
writer.attribute(HtmlAttr.CLASS, "objectView");
writer.startTag(HtmlElem.TABLE);
writer.attribute(HtmlAttr.CLASS, "data");
writer.startTag(HtmlElem.TBODY);
for (final ParameterInfo parameter : parameters) {
final Map<Object, Object> options = parameter.getAllowedValues();
if (options.isEmpty()) {
if (parameter.getType().equals(DataTypes.BASE64_BINARY)) {
writeHtmlFileField(writer, parameter, values);
} else {
writeHtmlField(writer, parameter, values);
}
} else {
writeHtmlSelect(writer, parameter, values, options);
}
}
}
final List<MediaType> mediaTypes = pageInfo.getMediaTypes();
if (!mediaTypes.isEmpty()) {
final ParameterInfo parameter = new ParameterInfo("format", true, DataTypes.STRING, "Select the file format to return the result data in.", mediaTypes);
writeHtmlSelect(writer, parameter, values, mediaTypes);
}
writer.endTag(HtmlElem.TBODY);
writer.endTag(HtmlElem.TABLE);
writer.endTag(HtmlElem.DIV);
writer.startTag(HtmlElem.DIV);
writer.attribute(HtmlAttr.CLASS, "actionMenu");
HtmlUtil.serializeSubmitInput(writer, "Submit", "submit");
writer.endTag(HtmlElem.DIV);
writer.endTag(HtmlElem.FORM);
writer.endTag(HtmlElem.DIV);
}
}
use of org.springframework.http.MediaType in project com.revolsys.open by revolsys.
the class PageInfo method setInputContentTypes.
public void setInputContentTypes(final MediaType... inputContentTypes) {
final ArrayList<MediaType> mediaTypes = new ArrayList<>();
for (final MediaType mediaType : inputContentTypes) {
mediaTypes.add(mediaType);
}
setInputContentTypes(mediaTypes);
}
use of org.springframework.http.MediaType in project com.revolsys.open by revolsys.
the class GeometryHttpMessageConverter method write.
@Override
public void write(final Geometry geometry, final MediaType mediaType, final HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
if (!HttpServletUtils.getResponse().isCommitted()) {
MediaType actualMediaType;
if (mediaType == null) {
actualMediaType = getDefaultMediaType();
} else {
actualMediaType = mediaType;
}
if (actualMediaType != null) {
final Charset charset = HttpServletUtils.setContentTypeWithCharset(outputMessage, actualMediaType);
final OutputStream body = outputMessage.getBody();
final String mediaTypeString = actualMediaType.getType() + "/" + actualMediaType.getSubtype();
final GeometryWriterFactory writerFactory = IoFactory.factoryByMediaType(GeometryWriterFactory.class, mediaTypeString);
if (writerFactory == null) {
throw new IllegalArgumentException("Media type " + actualMediaType + " not supported");
} else {
final String baseName = HttpServletUtils.getRequestBaseFileName();
final GeometryWriter writer = writerFactory.newGeometryWriter(baseName, body, charset);
writer.write(geometry);
writer.close();
}
}
}
}
Aggregations