Java Code Examples for org.apache.olingo.commons.api.format.ContentType#toContentTypeString()
The following examples show how to use
org.apache.olingo.commons.api.format.ContentType#toContentTypeString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BatchParserCommon.java From olingo-odata4 with Apache License 2.0 | 6 votes |
/** * Get the content type based on <code>contentType</code> parameter. * If this content type is not compatible to the expected ContentType a * BatchDeserializerException is thrown. * * @param contentType content type string which is parsed * @param expected content type to which the parsed must be compatible * @param line parsed line * @return the parsed content type or if not compatible or parseable an exception is thrown (never returns null) * @throws BatchDeserializerException */ public static ContentType parseContentType(final String contentType, final ContentType expected, final int line) throws BatchDeserializerException { if (contentType == null) { throw new BatchDeserializerException("Missing content type", BatchDeserializerException.MessageKeys.MISSING_CONTENT_TYPE, Integer.toString(line)); } ContentType type; try { type = ContentType.create(contentType); } catch (final IllegalArgumentException e) { throw new BatchDeserializerException("Invalid content type.", e, BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE, Integer.toString(line)); } if (type.isCompatible(expected)) { return type; } else { throw new BatchDeserializerException("Content type is not the expected content type", BatchDeserializerException.MessageKeys.UNEXPECTED_CONTENT_TYPE, Integer.toString(line), expected.toContentTypeString(), type.toContentTypeString()); } }
Example 2
Source File: ODataImpl.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override public ODataSerializer createSerializer(final ContentType contentType) throws SerializerException { ODataSerializer serializer = null; if (contentType != null && contentType.isCompatible(ContentType.APPLICATION_JSON)) { final String metadata = contentType.getParameter(ContentType.PARAMETER_ODATA_METADATA); if (metadata == null || ContentType.VALUE_ODATA_METADATA_MINIMAL.equalsIgnoreCase(metadata) || ContentType.VALUE_ODATA_METADATA_NONE.equalsIgnoreCase(metadata) || ContentType.VALUE_ODATA_METADATA_FULL.equalsIgnoreCase(metadata)) { serializer = new ODataJsonSerializer(contentType, new Constantsv00()); } } else if (contentType != null && (contentType.isCompatible(ContentType.APPLICATION_XML) || contentType.isCompatible(ContentType.APPLICATION_ATOM_XML))) { serializer = new ODataXmlSerializer(); } if (serializer == null) { throw new SerializerException("Unsupported format: " + ((contentType != null) ? contentType.toContentTypeString() : null), SerializerException.MessageKeys.UNSUPPORTED_FORMAT, ((contentType != null) ? contentType.toContentTypeString() : null)); } else { return serializer; } }
Example 3
Source File: ODataImpl.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override public ODataDeserializer createDeserializer(ContentType contentType, List<String> versions) throws DeserializerException { IConstants constants = new Constantsv00(); if(versions!=null && !versions.isEmpty() && getMaxVersion(versions)>4){ constants = new Constantsv01() ; } if (contentType != null && contentType.isCompatible(ContentType.JSON)) { return new ODataJsonDeserializer(contentType, constants); } else if (contentType != null && (contentType.isCompatible(ContentType.APPLICATION_XML) || contentType.isCompatible(ContentType.APPLICATION_ATOM_XML))) { return new ODataXmlDeserializer(); } else { throw new DeserializerException("Unsupported format: " + ((contentType != null) ? contentType.toContentTypeString() : null), DeserializerException.MessageKeys.UNSUPPORTED_FORMAT, ((contentType != null) ? contentType.toContentTypeString() : null)); } }
Example 4
Source File: ODataImpl.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override public ODataDeserializer createDeserializer(ContentType contentType, ServiceMetadata metadata, List<String> versions) throws DeserializerException { IConstants constants = new Constantsv00(); if(versions!=null && !versions.isEmpty() && getMaxVersion(versions)>4){ constants = new Constantsv01() ; } if (contentType != null && contentType.isCompatible(ContentType.JSON)) { return new ODataJsonDeserializer(contentType, metadata, constants); } else if (contentType != null && (contentType.isCompatible(ContentType.APPLICATION_XML) || contentType.isCompatible(ContentType.APPLICATION_ATOM_XML))) { return new ODataXmlDeserializer(metadata); } else { throw new DeserializerException("Unsupported format: " + ((contentType != null) ? contentType.toContentTypeString() : null), DeserializerException.MessageKeys.UNSUPPORTED_FORMAT, ((contentType != null) ? contentType.toContentTypeString() : null)); } }
Example 5
Source File: ContentNegotiator.java From olingo-odata4 with Apache License 2.0 | 5 votes |
public static void checkSupport(final ContentType contentType, final CustomContentTypeSupport customContentTypeSupport, final RepresentationType representationType) throws ContentNegotiatorException { for (ContentType supportedContentType : getSupportedContentTypes(customContentTypeSupport, representationType)) { if (AcceptType.fromContentType(supportedContentType).get(0).matches(contentType)) { return; } } throw new ContentNegotiatorException("unsupported content type: " + contentType, ContentNegotiatorException.MessageKeys.UNSUPPORTED_CONTENT_TYPE, contentType.toContentTypeString()); }
Example 6
Source File: ODataImpl.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public ODataSerializer createSerializer(final ContentType contentType, final List<String> versions) throws SerializerException { ODataSerializer serializer = null; IConstants constants = new Constantsv00(); if(versions!=null && !versions.isEmpty() && getMaxVersion(versions) > 4){ constants = new Constantsv01() ; } if (contentType != null && contentType.isCompatible(ContentType.APPLICATION_JSON)) { final String metadata = contentType.getParameter(ContentType.PARAMETER_ODATA_METADATA); if (metadata == null || ContentType.VALUE_ODATA_METADATA_MINIMAL.equalsIgnoreCase(metadata) || ContentType.VALUE_ODATA_METADATA_NONE.equalsIgnoreCase(metadata) || ContentType.VALUE_ODATA_METADATA_FULL.equalsIgnoreCase(metadata)) { serializer = new ODataJsonSerializer(contentType, constants); } } else if (contentType != null && (contentType.isCompatible(ContentType.APPLICATION_XML) || contentType.isCompatible(ContentType.APPLICATION_ATOM_XML))) { serializer = new ODataXmlSerializer(); } if (serializer == null) { throw new SerializerException("Unsupported format: " + ((contentType != null) ? contentType.toContentTypeString() : null), SerializerException.MessageKeys.UNSUPPORTED_FORMAT, ((contentType != null) ? contentType.toContentTypeString() : null)); } else { return serializer; } }
Example 7
Source File: ODataImpl.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public EdmAssistedSerializer createEdmAssistedSerializer(final ContentType contentType) throws SerializerException { if (contentType != null && contentType.isCompatible(ContentType.APPLICATION_JSON)) { return new EdmAssistedJsonSerializer(contentType); } throw new SerializerException("Unsupported format: " + ((contentType != null) ? contentType.toContentTypeString() : null), SerializerException.MessageKeys.UNSUPPORTED_FORMAT, ((contentType != null) ? contentType.toContentTypeString() : null)); }
Example 8
Source File: ODataImpl.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public EdmDeltaSerializer createEdmDeltaSerializer(final ContentType contentType, final List<String> versions) throws SerializerException { if (contentType != null && contentType.isCompatible(ContentType.APPLICATION_JSON)) { if(versions!=null && !versions.isEmpty()){ return getMaxVersion(versions)>4 ? new JsonDeltaSerializerWithNavigations(contentType): new JsonDeltaSerializer(contentType); } return new JsonDeltaSerializerWithNavigations(contentType); } throw new SerializerException("Unsupported format: " + ((contentType != null) ? contentType.toContentTypeString() : null), SerializerException.MessageKeys.UNSUPPORTED_FORMAT, ((contentType != null) ? contentType.toContentTypeString() : null)); }
Example 9
Source File: ODataImpl.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public ODataDeserializer createDeserializer(final ContentType contentType) throws DeserializerException { if (contentType != null && contentType.isCompatible(ContentType.JSON)) { return new ODataJsonDeserializer(contentType); } else if (contentType != null && (contentType.isCompatible(ContentType.APPLICATION_XML) || contentType.isCompatible(ContentType.APPLICATION_ATOM_XML))) { return new ODataXmlDeserializer(); } else { throw new DeserializerException("Unsupported format: " + ((contentType != null) ? contentType.toContentTypeString() : null), DeserializerException.MessageKeys.UNSUPPORTED_FORMAT, ((contentType != null) ? contentType.toContentTypeString() : null)); } }
Example 10
Source File: ODataImpl.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public ODataDeserializer createDeserializer(final ContentType contentType, ServiceMetadata metadata) throws DeserializerException { if (contentType != null && contentType.isCompatible(ContentType.JSON)) { return new ODataJsonDeserializer(contentType, metadata); } else if (contentType != null && (contentType.isCompatible(ContentType.APPLICATION_XML) || contentType.isCompatible(ContentType.APPLICATION_ATOM_XML))) { return new ODataXmlDeserializer(metadata); } else { throw new DeserializerException("Unsupported format: " + ((contentType != null) ? contentType.toContentTypeString() : null), DeserializerException.MessageKeys.UNSUPPORTED_FORMAT, ((contentType != null) ? contentType.toContentTypeString() : null)); } }
Example 11
Source File: AbstractODataBasicRequest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Override public void setFormat(final ContentType contentType) { if (contentType != null) { final String formatString = contentType.toContentTypeString(); setAccept(formatString); setContentType(formatString); } }