highestQuality = Math.max(highestQuality, mediaTypeDescriptor.getQualityOfSourceFactor()); while (iterator.hasNext()) { MediaTypeDescriptor mediaTypeDescriptor = iterator.next(); if (mediaTypeDescriptor.getQualityOfSourceFactor() < highestQuality) { iterator.remove(); if (mediaTypeDescriptor.getSyntax() != null && mediaTypeDescriptor.getSyntax().toLowerCase().contains("json")) { return mediaTypeDescriptor.getDataType(); String mt = mediaTypeDescriptor.getMediaType(); if (mt != null) { mt = mt.toLowerCase(); if (mt.startsWith("text") || mt.endsWith("json") || mt.endsWith("xml")) { DataTypeReference dataType = mediaTypeDescriptor.getDataType(); return dataType == null || dataType.getValue() == null ? GENERIC_STRING_BASED_DATATYPE_REFERENCE : dataType; if (mediaTypeDescriptor.getDataType() != null) { return mediaTypeDescriptor.getDataType();
@Override public String getResponseLang() { if (this.responseDescriptor == null) { return null; } String lang = "txt"; com.webcohesion.enunciate.api.datatype.Example example = this.responseDescriptor.getExample(); if (example != null) { lang = example.getLang(); } return lang; }
public Object exec(List list) throws TemplateModelException { if (list.size() < 1) { throw new TemplateModelException("The uniqueMediaTypesFor method must have a parameter."); } TemplateModel from = (TemplateModel) list.get(0); Object unwrapped = new BeansWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS).build().unwrap(from); HashMap<String, MediaTypeDescriptor> uniqueMediaTypes = new HashMap<String, MediaTypeDescriptor>(); if (unwrapped instanceof Entity) { Entity entity = (Entity) unwrapped; List<? extends MediaTypeDescriptor> mts = entity.getMediaTypes(); if (mts != null) { for (MediaTypeDescriptor mt : mts) { uniqueMediaTypes.put(mt.getMediaType(), mt); } } } ArrayList<MediaTypeDescriptor> orderedTypes = new ArrayList<>(uniqueMediaTypes.values()); Collections.sort(orderedTypes, (m1, m2) -> { String syntax1 = m1.getSyntax() == null ? "" : m1.getSyntax(); String syntax2 = m2.getSyntax() == null ? "" : m2.getSyntax(); return syntax1.compareTo(syntax2); }); return orderedTypes; } }
@Override public String convertUnwrappedObject(Object unwrapped) throws TemplateModelException { if (unwrapped instanceof Entity) { List<? extends MediaTypeDescriptor> mediaTypes = ((Entity) unwrapped).getMediaTypes(); for (MediaTypeDescriptor mediaType : mediaTypes) { if (SyntaxImpl.SYNTAX_LABEL.equals(mediaType.getSyntax())) { DataTypeReference dataType = mediaType.getDataType(); return super.convertUnwrappedObject(this.jsonContext.findType(dataType)); } } return "byte[]"; } return super.convertUnwrappedObject(unwrapped); }
@Override public String getSyntax() { return delegate.getSyntax(); }
if (mts != null) { for (MediaTypeDescriptor mt : mts) { if (mt.getMediaType().endsWith("json")) { DataTypeReference dataType = mt.getDataType(); if (dataType != null && dataType.getBaseType() == BaseType.object) { DataType value = dataType.getValue(); String body = example.getBody(); if (body != null) { uniqueMediaTypes.put(mt.getMediaType(), body);
@Override public DataTypeReference getDataType() { return delegate.getDataType(); }
@Override public String getMediaType() { return delegate.getMediaType(); }
@Override public float getQualityOfSourceFactor() { return delegate.getQualityOfSourceFactor(); }
@Override public String convertUnwrappedObject(Object unwrapped) throws TemplateModelException { if (unwrapped instanceof Entity) { List<? extends MediaTypeDescriptor> mediaTypes = ((Entity) unwrapped).getMediaTypes(); for (MediaTypeDescriptor mediaType : mediaTypes) { if (SyntaxImpl.SYNTAX_LABEL.equals(mediaType.getSyntax())) { DataTypeReference dataType = mediaType.getDataType(); return super.convertUnwrappedObject(this.jsonContext.findType(dataType)); } } return "byte[]"; } return super.convertUnwrappedObject(unwrapped); }
@Override public String getSyntax() { return delegate.getSyntax(); }
if (unwrapped instanceof MediaTypeDescriptor) { MediaTypeDescriptor mt = (MediaTypeDescriptor) unwrapped; DataTypeReference typeReference = mt.getDataType(); if (typeReference != null) { if (typeReference instanceof DataTypeReferenceImpl) { return ((DataTypeReferenceImpl) typeReference).getElementQName(); } else if (associateJsonWithXml && mt.getMediaType().endsWith("json")) { DataType dataType = typeReference.getValue(); if (dataType != null) {
@Override public DataTypeReference getDataType() { return delegate.getDataType(); }
@Override public String getMediaType() { return delegate.getMediaType(); }
@Override public int compare(MediaTypeDescriptor d1, MediaTypeDescriptor d2) { return new Float(d2.getQualityOfSourceFactor()).compareTo(d1.getQualityOfSourceFactor()); } });
@Override public String simpleNameFor(Object unwrapped, boolean noParams) throws TemplateModelException { if (unwrapped instanceof Entity) { List<? extends MediaTypeDescriptor> mediaTypes = ((Entity) unwrapped).getMediaTypes(); for (MediaTypeDescriptor mediaType : mediaTypes) { if (this.jsonContext.getLabel().equals(mediaType.getSyntax())) { DataTypeReference dataType = mediaType.getDataType(); unwrapped = this.jsonContext.findType(dataType); if (unwrapped == null) { return "Object"; } } } } if (unwrapped instanceof Entity) { return "Object"; } return super.simpleNameFor(unwrapped, noParams); } }
private boolean hasXmlResponseEntity(Method method) { if (method.getResponseEntity() != null) { for (MediaTypeDescriptor mediaTypeDescriptor : method.getResponseEntity().getMediaTypes()) { String syntax = mediaTypeDescriptor.getSyntax(); if (com.webcohesion.enunciate.modules.jackson.api.impl.SyntaxImpl.SYNTAX_LABEL.equals(syntax) || SyntaxImpl.SYNTAX_LABEL.equals(syntax)) { return true; } } } return false; }
if (unwrapped instanceof MediaTypeDescriptor) { MediaTypeDescriptor mt = (MediaTypeDescriptor) unwrapped; DataTypeReference typeReference = mt.getDataType(); if (typeReference != null) { if (typeReference instanceof DataTypeReferenceImpl) { return ((DataTypeReferenceImpl) typeReference).getElementQName(); } else if (associateJsonWithXml && mt.getMediaType().endsWith("json")) { DataType dataType = typeReference.getValue(); if (dataType != null) {
/** * Returns the qname of the element that has the first parameter as the namespace, the second as the element. * * @param list The arguments. * @return The qname. */ public Object exec(List list) throws TemplateModelException { if (list.size() < 1) { throw new TemplateModelException("The MediaTypeForMethod must have a entity as a parameter."); } TemplateModel from = (TemplateModel) list.get(0); Object unwrapped = DeepUnwrap.unwrap(from); if (unwrapped instanceof Entity) { List<? extends MediaTypeDescriptor> mediaTypes = ((Entity) unwrapped).getMediaTypes(); if (mediaTypes != null && !mediaTypes.isEmpty()) { for (MediaTypeDescriptor mediaType : mediaTypes) { if (mediaType.getMediaType().contains("json")) { return mediaType.getMediaType(); } } } } return "application/json"; }
@Override public String getRequestLang() { if (this.requestDescriptor == null) { return null; } String lang = "txt"; com.webcohesion.enunciate.api.datatype.Example example = this.requestDescriptor.getExample(); if (example != null) { lang = example.getLang(); } return lang; }