/** * Determines if the specified media type represents a zip stream. */ public static boolean isZipMediaType( MediaType mediaType ) { return ZIP_MIME_TYPES.contains( mediaType.toString() ); }
protected final void addAcceptJsonHeader( HttpMessage httpMessage ) { httpMessage.addHeader( "Accept", MediaType.APPLICATION_JSON.toString() ); }
/** * Convert the supplied value to a String. * * @param value * the value of type <code>T</code> * @return a String representation of the value * @throws IllegalArgumentException * if the supplied object cannot be serialized * @see javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate#toString(java.lang.Object) */ public String toString(MediaType jaxRsMediaType) { return Converter.toRestletMediaType(jaxRsMediaType).toString(); } }
public Header getContentType() { return new BasicHeader( HeaderConstants.HEADER_CONTENT_TYPE, (entity .getMediaType() != null) ? entity .getMediaType().toString() : null); }
@Override public Header getContentType() { final String contentType = (entity.getMediaType() != null) ? entity .getMediaType().toString() : null; if (contentType != null) { return new BasicHeader("Content-Type", contentType); } else { return null; } }
public int compare(org.restlet.data.MediaType mediaType1, org.restlet.data.MediaType mediaType2) { if (mediaType1 == null) { return mediaType2 == null ? 0 : 1; } if (mediaType2 == null) { return -1; } if (mediaType1.equals(mediaType2, false)) { return 0; } final int specNess1 = specificness(mediaType1); final int specNess2 = specificness(mediaType2); final int rt = specNess1 - specNess2; if (rt != 0) { return rt; } return mediaType1.toString().compareToIgnoreCase(mediaType2.toString()); } };
public String getContentType() { return (entity.getMediaType() != null) ? entity .getMediaType().toString() : null; }
/** * Constructor reading the object from a serialized representation. This * representation must have the proper media type: * "application/x-java-serialized-object". * * @param serializedRepresentation * The serialized representation. * @throws IOException * @throws ClassNotFoundException * @throws IllegalArgumentException */ @SuppressWarnings("unchecked") public ObjectRepresentation(Representation serializedRepresentation) throws IOException, ClassNotFoundException, IllegalArgumentException { super(MediaType.APPLICATION_JAVA_OBJECT); if (serializedRepresentation.getMediaType().equals( MediaType.APPLICATION_JAVA_OBJECT)) { final ObjectInputStream ois = new ObjectInputStream( serializedRepresentation.getStream()); this.object = (T) ois.readObject(); ois.close(); } else { throw new IllegalArgumentException( "The serialized representation must have this media type: " + MediaType.APPLICATION_JAVA_OBJECT.toString()); } }
protected SyndContent buildDescription(NexusArtifactEvent event) { SyndContent content = new SyndContentImpl(); content.setType(MediaType.TEXT_PLAIN.toString()); StringBuilder msg = new StringBuilder(); if (event.getMessage() != null) { msg.append(event.getMessage()); msg.append(' '); } msg.append(buildDescriptionMsgItem(event)); msg.append(buildDescriptionMsgAction(event)); msg.append(buildDescriptionMsgAuthor(event)); msg.append(buildDescriptionMsgAddress(event)); content.setValue(msg.toString()); return content; }
/** * Writes the HTTP "Content-Type" header. * * @param mediaType * The representation media type. * @param characterSet * The representation character set. * @return The HTTP "Content-Type" header. */ public static String writeHeader(MediaType mediaType, CharacterSet characterSet) { String result = mediaType.toString(); // Specify the character set parameter if required if ((mediaType.getParameters().getFirstValue("charset") == null) && (characterSet != null)) { result = result + "; charset=" + characterSet.getName(); } return result; }
protected void encodeAlternateAtomLink( String link, HierarchicalStreamWriter writer, DataFormat format ) { writer.startNode( "atom:link"); writer.addAttribute("xmlns:atom", "http://www.w3.org/2005/Atom"); writer.addAttribute( "rel", "alternate" ); writer.addAttribute( "href", href(link,format) ); if ( format != null ) { writer.addAttribute( "type", format.getMediaType().toString() ); } writer.endNode(); }
pipe = new ReadableDocument(runtime, doc, null, null, null); } else { pipe = new ReadableData(runtime, XProcConstants.c_data, entity.getStream(), entity.getMediaType().toString());
pipe = new ReadableDocument(runtime, doc, null, null, null); } else { pipe = new ReadableData(runtime, XProcConstants.c_data, entity.getStream(), entity.getMediaType().toString());
pipe = new ReadableDocument(runtime, doc, null, null, null); } else { pipe = new ReadableData(runtime, XProcConstants.c_data, entity.getStream(), entity.getMediaType().toString());
pipe = new ReadableDocument(runtime, doc, null, null, null); } else { pipe = new ReadableData(runtime, XProcConstants.c_data, entity.getStream(), entity.getMediaType().toString());
} else { ReadablePipe pipe = null; pipe = new ReadableData(runtime, XProcConstants.c_data, entity.getStream(), entity.getMediaType().toString()); doc = pipe.read();
content.setType(MediaType.TEXT_PLAIN.toString());
@Override public Object upload(Context context, Request request, Response response, List<FileItem> files) throws ResourceException { // NEXUS-4151: Do not accept upload/deploy requests with media type (Content-Type) of // "application/x-www-form-urlencoded", since ad 1, it's wrong, ad 2, we do know // Jetty's Request object "eats" up it's body to parse request parameters, invoked // way earlier in security filters if (request.isEntityAvailable()) { MediaType mt = request.getEntity().getMediaType(); if (mt != null && MediaType.APPLICATION_WWW_FORM.isCompatible(mt)) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Content-type of \"" + mt.toString() + "\" is not acceptable for uploads!"); } } try { final ResourceStoreRequest req = getResourceStoreRequest(request); for (FileItem fileItem : files) { getResourceStore(request).storeItem(req, fileItem.getInputStream(), null); } } catch (Exception t) { handleException(request, response, t); } return null; }
throw new ResourceException( Status.CLIENT_ERROR_BAD_REQUEST, "Content-type of \"" + mt.toString() + "\" is not acceptable for uploads!" );
/** * @see com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object, * com.thoughtworks.xstream.io.HierarchicalStreamWriter, * com.thoughtworks.xstream.converters.MarshallingContext) */ public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { @SuppressWarnings("unchecked") List<String> layers = (List<String>) source; for (String name : layers) { writer.startNode("layer"); writer.startNode("name"); writer.setValue(name); writer.endNode(); // name writer.startNode("atom:link"); writer.addAttribute("xmlns:atom", "http://www.w3.org/2005/Atom"); writer.addAttribute("rel", "alternate"); String href = restRoot + "/layers/" + ServletUtils.URLEncode(name) + ".xml"; writer.addAttribute("href", href); writer.addAttribute("type", MediaType.TEXT_XML.toString()); writer.endNode(); writer.endNode();// layer } }