/** * Indicates if the searched entry is specified in the given media range. * * @param searchedEntry * The searched entry. * @param mediaRange * The media range to inspect. * @return True if the searched entry is specified in the given media range. */ public static boolean isEntryFound(FormData searchedEntry, MediaType mediaRange) { boolean result = false; for (Iterator<? extends NamedValue<String>> iter = mediaRange .getParameters().iterator(); !result && iter.hasNext();) { result = searchedEntry.equals(iter.next()); } return result; }
@Override public String toString() { final StringBuilder sb = new StringBuilder(); if (getName() != null) { sb.append(getName()); for (final Parameter param : getParameters()) { sb.append("; ").append(param.getName()).append('=').append( param.getValue()); } } return sb.toString(); } }
/** * Test the equality of two media types, with the possibility to ignore the * parameters. * * @param obj * The object to compare to. * @param ignoreParameters * Indicates if parameters should be ignored during comparison. * @return True if both media types are equal. */ public boolean equals(Object obj, boolean ignoreParameters) { boolean result = (obj == this); // if obj == this no need to go further if (!result) { // test for equality at Metadata level i.e. name and value. if (super.equals(obj)) { // if obj isn't a mediatype or is null don't evaluate further if (obj instanceof MediaType) { final MediaType that = (MediaType) obj; result = ignoreParameters || getParameters().equals(that.getParameters()); } } } return result; }
/** {@inheritDoc} */ @Override public int hashCode() { return Engine.hashCode(super.hashCode(), getParameters()); }
/** {@inheritDoc} */ @Override public int hashCode() { return SystemUtils.hashCode(super.hashCode(), getParameters()); }
/** {@inheritDoc} */ @Override public int hashCode() { return SystemUtils.hashCode(super.hashCode(), getParameters()); }
/** * Indicates if the searched parameter is specified in the given media * range. * * @param searchedParam * The searched parameter. * @param mediaRange * The media range to inspect. * @return True if the searched parameter is specified in the given media * range. */ public static boolean isParameterFound(Parameter searchedParam, MediaType mediaRange) { boolean result = false; for (Iterator<Parameter> iter = mediaRange.getParameters().iterator(); !result && iter.hasNext();) { result = searchedParam.equals(iter.next()); } return result; }
/** * Indicates if the searched parameter is specified in the given media * range. * * @param searchedParam * The searched parameter. * @param mediaRange * The media range to inspect. * @return True if the searched parameter is specified in the given media * range. */ public static boolean isParameterFound(Parameter searchedParam, MediaType mediaRange) { boolean result = false; for (Iterator<Parameter> iter = mediaRange.getParameters().iterator(); !result && iter.hasNext();) { result = searchedParam.equals(iter.next()); } return result; }
/** * Creates a MediaType without any parameters. * * @param mediaType * A MediaType, perhaps with parameters. * @return Creates a MediaType without any parameters. */ public static org.restlet.data.MediaType getMediaTypeWithoutParams( org.restlet.data.MediaType mediaType) { if (mediaType == null) { return null; } Series<Parameter> parameters = mediaType.getParameters(); if ((parameters == null) || parameters.isEmpty()) { return mediaType; } return mediaType.getParent(); }
/** * Test the equality of two media types, with the possibility to ignore the * parameters. * * @param obj * The object to compare to. * @param ignoreParameters * Indicates if parameters should be ignored during comparison. * @return True if both media types are equal. */ public boolean equals(Object obj, boolean ignoreParameters) { boolean result = (obj == this); // if obj == this no need to go further if (!result) { // if obj isn't a mediatype or is null don't evaluate further if (obj instanceof MediaType) { final MediaType that = (MediaType) obj; if (getMainType().equals(that.getMainType()) && getSubType().equals(that.getSubType())) { result = ignoreParameters || getParameters().equals(that.getParameters()); } } } return result; }
/** * 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; }
/** * Test the equality of two media types, with the possibility to ignore the * parameters. * * @param obj * The object to compare to. * @param ignoreParameters * Indicates if parameters should be ignored during comparison. * @return True if both media types are equal. */ public boolean equals(Object obj, boolean ignoreParameters) { boolean result = (obj == this); // if obj == this no need to go further if (!result) { // if obj isn't a mediatype or is null don't evaluate further if (obj instanceof MediaType) { final MediaType that = (MediaType) obj; if (getMainType().equals(that.getMainType()) && getSubType().equals(that.getSubType())) { result = ignoreParameters || getParameters().equals(that.getParameters()); } } } return result; }
/** * Convert a Restlet MediaType to a JAX-RS MediaType. * * @param restletMediaType * the MediaType to convert. * @param restletCharacterSet * the CharacterSet for the MediaType; may be null. * @return the converted MediaType */ public static MediaType toJaxRsMediaType( org.restlet.data.MediaType restletMediaType, org.restlet.data.CharacterSet restletCharacterSet) { if (restletMediaType == null) { return null; } final Map<String, String> parameters = toMap(restletMediaType .getParameters()); if (restletCharacterSet != null) { parameters.put(Converter.CHARSET_PARAM, restletCharacterSet.getName()); } return new MediaType(restletMediaType.getMainType(), restletMediaType.getSubType(), parameters); }
for (int i = 0; result && i < getParameters().size(); i++) { Parameter param = getParameters().get(i); Parameter includedParam = includedMediaType .getParameters().getFirst(param.getName());
for (int i = 0; result && i < getParameters().size(); i++) { Parameter param = getParameters().get(i); Parameter includedParam = includedMediaType .getParameters().getFirst(param.getName());
Series<Parameter> parameters = mediaType.getParameters(); for (Parameter parameter : parameters) { if (parameter.getName().equalsIgnoreCase(CHARSET)) {
/** * {@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; }
/** * {@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; }