Refine search
@Override public List<Class<?>> getObjectClasses(Variant variant) { List<Class<?>> result = null; if (variant.getMediaType() != null) { MediaType mediaType = variant.getMediaType(); if (MediaType.APPLICATION_ALL_XML.equals(mediaType) || MediaType.TEXT_XML.equals(mediaType) || MediaType.APPLICATION_ATOMPUB_SERVICE.equals(mediaType) || MediaType.APPLICATION_ATOM.equals(mediaType) || MediaType.APPLICATION_RDF_XML.equals(mediaType) || MediaType.APPLICATION_WADL.equals(mediaType) || MediaType.APPLICATION_XHTML.equals(mediaType)) { result = addObjectClass(result, Document.class); result = addObjectClass(result, XmlRepresentation.class); } } return result; }
public String getContentType() { return (entity.getMediaType() != null) ? entity .getMediaType().toString() : null; }
@Override public <T> float score(Representation source, Class<T> target, Resource resource) { for (Variant v : variants) { if (v.getMediaType().isCompatible(source.getMediaType())) { return .5F; } } return -1F; }
/** * If client can accept text/html, always prefer it. WebKit-based browsers * claim to want application/xml, but we don't want to give it to them. See * <a href="https://webarchive.jira.com/browse/HER-1603">https://webarchive.jira.com/browse/HER-1603</a> */ public Variant getPreferredVariant() { boolean addExplicitTextHtmlPreference = false; for (Preference<MediaType> mediaTypePreference: getRequest().getClientInfo().getAcceptedMediaTypes()) { if (mediaTypePreference.getMetadata().equals(MediaType.TEXT_HTML)) { mediaTypePreference.setQuality(Float.MAX_VALUE); addExplicitTextHtmlPreference = false; break; } else if (mediaTypePreference.getMetadata().includes(MediaType.TEXT_HTML)) { addExplicitTextHtmlPreference = true; } } if (addExplicitTextHtmlPreference) { List<Preference<MediaType>> acceptedMediaTypes = getRequest().getClientInfo().getAcceptedMediaTypes(); acceptedMediaTypes.add(new Preference<MediaType>(MediaType.TEXT_HTML, Float.MAX_VALUE)); getRequest().getClientInfo().setAcceptedMediaTypes(acceptedMediaTypes); } return super.getPreferredVariant(); }
protected boolean isXml(MediaType type) { String isxml = type.getSubType(); return MediaType.APPLICATION_XML.equals(type) || isxml.endsWith("+xml"); }
/** * {@inheritDoc}<br> * In case the media type has parameters, this method returns the * concatenation of the main type and the subtype. If the subtype is not * equal to "*", it returns the concatenation of the main type and "*". * Otherwise, it returns either the {@link #ALL} media type if it is already * the {@link #ALL} media type, or null. */ @Override public MediaType getParent() { MediaType result = null; if (getParameters().size() > 0) { result = MediaType.valueOf(getMainType() + "/" + getSubType()); } else { if (getSubType().equals("*")) { result = equals(ALL) ? null : ALL; } else { result = MediaType.valueOf(getMainType() + "/*"); } } return result; }
private boolean isMediaType(Representation entity, MediaType desiredType) { if (entity == null) { return false; } return desiredType.equals(entity.getMediaType(), true); }
/** * Tests whether the RDF/JSON page when there are no annotations is correct. */ @Test public void testAnnotationListEmptyJson() throws Exception { final ClientResource getResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_BULK_FETCH_ANNOTATION_PATH, OasProps.DEF_BULK_FETCH_ANNOTATION_PATH))); final Representation results = getResource.get(RestletUtilMediaType.APPLICATION_RDF_JSON); // Expecting HTTP 200 OK response Assert.assertEquals(200, getResource.getResponse().getStatus().getCode()); // Expecting application/json MIME type for response Assert.assertEquals(RestletUtilMediaType.APPLICATION_RDF_JSON.getName(), results.getMediaType().getName()); this.assertRdf(results.getStream(), RDFFormat.RDFJSON, 0); }
@Override public long getSize() { long result = wrappedRepresentation.getSize(); if (result > 0 && MediaType.APPLICATION_JSON.equals(wrappedRepresentation .getMediaType())) { try { java.io.StringWriter sw = new java.io.StringWriter(); write(sw); sw.flush(); return sw.toString().length(); } catch (IOException e) { return UNKNOWN_SIZE; } } return UNKNOWN_SIZE; }
boolean result = equals(ALL) || equals(included); if (getMainType().equals(includedMediaType.getMainType())) { if (getSubType().equals(includedMediaType.getSubType())) { if (ignoreParameters) { result = true; for (int i = 0; result && i < getParameters().size(); i++) { Parameter param = getParameters().get(i); Parameter includedParam = includedMediaType .getParameters().getFirst(param.getName()); } else if (getSubType().equals("*")) { result = true; } else if (getSubType().startsWith("*+") && includedMediaType.getSubType().endsWith( getSubType().substring(2))) { result = true;
variant.setMediaType((MediaType) current); } else if (current instanceof CharacterSet) { variant.setCharacterSet((CharacterSet) current); } else if (current instanceof Encoding) { && i < variant.getEncodings().size(); i++) { found = current.includes(variant.getEncodings() .get(i)); && !defaultMediaType.equals(MediaType.ALL)) { variant.setMediaType(defaultMediaType); && !defaultCharacterSet.equals(CharacterSet.ALL)) { variant.setCharacterSet(defaultCharacterSet);
@Override public float score(Object source, Variant target, Resource resource) { float result = -1.0F; if ((source instanceof JSONArray) || (source instanceof JSONObject) || (source instanceof JSONTokener)) { if (target == null) { result = 0.5F; } else if (MediaType.APPLICATION_JSON.isCompatible(target .getMediaType())) { result = 1.0F; } else { result = 0.5F; } } return result; }
return DateUtils.format(new Date(), FORMAT_RFC_1123.get(0)); case "ecs": return (entity != null && entity.getCharacterSet() != null) ? entity.getCharacterSet().getName() : null; case "ee": return getEncodingsAsString(entity); return getModificationDateAsString(entity); case "emt": return (entity != null && entity.getMediaType() != null) ? entity.getMediaType().getName() : null; case "es": return (entity != null && entity.getSize() != -1) ? Long.toString(entity.getSize()) : null; return (entity != null && entity.getCharacterSet() != null) ? entity.getCharacterSet().getName() : null; case "EE": return getEncodingsAsString(entity); return getModificationDateAsString(entity); case "EMT": return (entity != null && entity.getMediaType() != null) ? entity.getMediaType().getName() : null; case "ES": return (entity != null && entity.getSize() != -1) ? Long.toString(entity.getSize()) : null;
/** * Creates the media type of a multipart form which must include the used * boundary. * * @param boundary * The multipart boundary. * @return The multipart media type. */ private static MediaType createMultipartMediaType(String boundary) { Series<Parameter> params = new Series<Parameter>(Parameter.class); params.add("boundary", boundary); MediaType result = new MediaType( MediaType.MULTIPART_FORM_DATA.getName(), params); return result; }
result = ((getCharacterSet() == null) && (otherVariant.getCharacterSet() == null) || (getCharacterSet() != null) && getCharacterSet().equals( otherVariant.getCharacterSet())); result = ((getMediaType() == null) && (otherVariant.getMediaType() == null) || (getMediaType() != null) && getMediaType().equals(otherVariant.getMediaType()));
/** {@inheritDoc} */ @Override public boolean equals(Object obj) { return equals(obj, false); }
/** * 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; }
/** * Determines if the specified media type represents a zip stream. */ public static boolean isZipMediaType( MediaType mediaType ) { return ZIP_MIME_TYPES.contains( mediaType.toString() ); }
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()); } };
/** * Checks that the desired MediaType is compatible with the one present in the request. * * @param expectedType The expected type. * @param request The request whose MediaType is being checked. * @return true, if the MediaTypes match. --- OR false, if the MediaTypes do not match, or the * request is null. */ private boolean checkMediaType(MediaType expectedType, Representation request) { if (request == null) { return false; } return expectedType.isCompatible(request.getMediaType()); } }