本文整理汇总了Java中org.apache.olingo.commons.api.format.ContentType.isCompatible方法的典型用法代码示例。如果您正苦于以下问题:Java ContentType.isCompatible方法的具体用法?Java ContentType.isCompatible怎么用?Java ContentType.isCompatible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.olingo.commons.api.format.ContentType
的用法示例。
在下文中一共展示了ContentType.isCompatible方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSerializer
import org.apache.olingo.commons.api.format.ContentType; //导入方法依赖的package包/类
@Override
public ODataSerializer createSerializer(ContentType contentType) throws SerializerException {
ODataSerializer serializer = null;
if (contentType.isCompatible(ContentType.APPLICATION_JSON)) {
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 ElasticODataJsonSerializer(contentType);
}
} else if (contentType.isCompatible(ContentType.APPLICATION_XML)
|| contentType.isCompatible(ContentType.APPLICATION_ATOM_XML)) {
serializer = new ElasticODataXmlSerializer();
}
if (serializer == null) {
throw new SerializerException(
"Unsupported format: " + contentType.toContentTypeString(),
SerializerException.MessageKeys.UNSUPPORTED_FORMAT,
contentType.toContentTypeString());
}
return serializer;
}
示例2: parseContentType
import org.apache.olingo.commons.api.format.ContentType; //导入方法依赖的package包/类
/**
* 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());
}
}
示例3: createSerializer
import org.apache.olingo.commons.api.format.ContentType; //导入方法依赖的package包/类
@Override
public ODataSerializer createSerializer(final ContentType contentType) throws SerializerException {
ODataSerializer serializer = null;
if (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.isCompatible(ContentType.APPLICATION_XML)
|| contentType.isCompatible(ContentType.APPLICATION_ATOM_XML)) {
serializer = new ODataXmlSerializer();
}
if (serializer == null) {
throw new SerializerException("Unsupported format: " + contentType.toContentTypeString(),
SerializerException.MessageKeys.UNSUPPORTED_FORMAT, contentType.toContentTypeString());
} else {
return serializer;
}
}
示例4: _enum
import org.apache.olingo.commons.api.format.ContentType; //导入方法依赖的package包/类
private void _enum(final ContentType contentType) throws ODataDeserializerException, ODataSerializerException {
final InputStream input = getClass().getResourceAsStream("Products_5_SkinColor." + getSuffix(contentType));
final ClientProperty property = client.getReader().readProperty(input, contentType);
assertNotNull(property);
assertTrue(property.hasEnumValue());
final ClientProperty written = client.getReader().readProperty(
client.getWriter().writeProperty(property, contentType), contentType);
// This is needed because type information gets lost with serialization
if (contentType.isCompatible(ContentType.APPLICATION_XML)) {
final ClientProperty comparable = client.getObjectFactory().newEnumProperty(property.getName(),
client.getObjectFactory().
newEnumValue(property.getEnumValue().getTypeName(), written.getEnumValue().getValue()));
assertEquals(property, comparable);
}
}
示例5: collection
import org.apache.olingo.commons.api.format.ContentType; //导入方法依赖的package包/类
private void collection(final ContentType contentType) throws ODataDeserializerException, ODataSerializerException {
final InputStream input = getClass().getResourceAsStream("Products_5_CoverColors." + getSuffix(contentType));
final ClientProperty property = client.getReader().readProperty(input, contentType);
assertNotNull(property);
assertTrue(property.hasCollectionValue());
assertEquals(3, property.getCollectionValue().size());
final ClientProperty written = client.getReader().readProperty(
client.getWriter().writeProperty(property, contentType), contentType);
// This is needed because type information gets lost with JSON serialization
if(contentType.isCompatible(ContentType.APPLICATION_XML)) {
final ClientCollectionValue<ClientValue> typedValue = client.getObjectFactory().
newCollectionValue(property.getCollectionValue().getTypeName());
for (final Iterator<ClientValue> itor = written.getCollectionValue().iterator(); itor.hasNext();) {
final ClientValue value = itor.next();
typedValue.add(value);
}
final ClientProperty comparable = client.getObjectFactory().
newCollectionProperty(property.getName(), typedValue);
assertEquals(property, comparable);
}
}
示例6: ClientEntitySetIterator
import org.apache.olingo.commons.api.format.ContentType; //导入方法依赖的package包/类
/**
* Constructor.
*
* @param odataClient client instance getting this request
* @param stream source stream.
* @param contentType OData format.
*/
public ClientEntitySetIterator(final ODataClient odataClient, final InputStream stream,
final ContentType contentType) {
this.odataClient = odataClient;
this.stream = stream;
this.contentType = contentType;
this.osEntitySet = new ByteArrayOutputStream();
if(contentType.isCompatible(ContentType.APPLICATION_ATOM_SVC)
|| contentType.isCompatible(ContentType.APPLICATION_ATOM_XML)) {
namespaces = getAllElementAttributes(stream, "feed", osEntitySet);
} else {
namespaces = null;
try {
if (consume(stream, "\"value\":", osEntitySet, true) >= 0) {
int c = 0;
while (c != '[' && (c = stream.read()) >= 0) {
osEntitySet.write(c);
}
}
} catch (IOException e) {
LOG.error("Error parsing entity set", e);
throw new IllegalStateException(e);
}
}
}
示例7: getCharset
import org.apache.olingo.commons.api.format.ContentType; //导入方法依赖的package包/类
private Charset getCharset(final BatchQueryOperation operation) {
final ContentType contentType = ContentType.parse(operation.getHeaders().getHeader(HttpHeader.CONTENT_TYPE));
if (contentType != null) {
final String charsetValue = contentType.getParameter(ContentType.PARAMETER_CHARSET);
if (charsetValue == null) {
if (contentType.isCompatible(ContentType.APPLICATION_JSON) || contentType.getSubtype().contains("xml")) {
return Charset.forName("UTF-8");
}
} else {
return Charset.forName(charsetValue);
}
}
return Charset.forName("ISO-8859-1");
}
示例8: createEdmAssistedSerializer
import org.apache.olingo.commons.api.format.ContentType; //导入方法依赖的package包/类
@Override
public EdmAssistedSerializer createEdmAssistedSerializer(final ContentType contentType) throws SerializerException {
if (contentType.isCompatible(ContentType.APPLICATION_JSON)) {
return new EdmAssistedJsonSerializer(contentType);
}
throw new SerializerException("Unsupported format: " + contentType.toContentTypeString(),
SerializerException.MessageKeys.UNSUPPORTED_FORMAT, contentType.toContentTypeString());
}
示例9: createEdmDeltaSerializer
import org.apache.olingo.commons.api.format.ContentType; //导入方法依赖的package包/类
@Override
public EdmDeltaSerializer createEdmDeltaSerializer(final ContentType contentType, final List<String> versions)
throws SerializerException {
if (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.toContentTypeString(),
SerializerException.MessageKeys.UNSUPPORTED_FORMAT, contentType.toContentTypeString());
}
示例10: createDeserializer
import org.apache.olingo.commons.api.format.ContentType; //导入方法依赖的package包/类
@Override
public ODataDeserializer createDeserializer(final ContentType contentType) throws DeserializerException {
if (contentType.isCompatible(ContentType.JSON)) {
return new ODataJsonDeserializer(contentType);
} else if (contentType.isCompatible(ContentType.APPLICATION_XML)
|| contentType.isCompatible(ContentType.APPLICATION_ATOM_XML)) {
return new ODataXmlDeserializer();
} else {
throw new DeserializerException("Unsupported format: " + contentType.toContentTypeString(),
DeserializerException.MessageKeys.UNSUPPORTED_FORMAT, contentType.toContentTypeString());
}
}
示例11: validateContentType
import org.apache.olingo.commons.api.format.ContentType; //导入方法依赖的package包/类
private void validateContentType() throws ODataApplicationException {
final ContentType contentType = getRequestContentType();
if (contentType == null || !contentType.isCompatible(ContentType.MULTIPART_MIXED)) {
throw new ODataApplicationException("Invalid content type",
HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.getDefault());
}
}
示例12: ClientODataDeserializerImpl
import org.apache.olingo.commons.api.format.ContentType; //导入方法依赖的package包/类
public ClientODataDeserializerImpl(final boolean serverMode, final ContentType contentType) {
this.contentType = contentType;
if (contentType.isCompatible(ContentType.APPLICATION_ATOM_SVC)
|| contentType.isCompatible(ContentType.APPLICATION_ATOM_XML)
|| contentType.isCompatible(ContentType.APPLICATION_XML)) {
deserializer = new AtomDeserializer();
} else {
deserializer = new JsonDeserializer(serverMode);
}
}
示例13: getSerializer
import org.apache.olingo.commons.api.format.ContentType; //导入方法依赖的package包/类
@Override
public ODataSerializer getSerializer(final ContentType contentType) {
return contentType.isCompatible(ContentType.APPLICATION_ATOM_SVC)
|| contentType.isCompatible(ContentType.APPLICATION_ATOM_XML)
|| contentType.isCompatible(ContentType.APPLICATION_XML) ?
new AtomSerializer() : new JsonSerializer(false, contentType);
}
示例14: isODataMetadataNone
import org.apache.olingo.commons.api.format.ContentType; //导入方法依赖的package包/类
protected boolean isODataMetadataNone(final ContentType contentType) {
return contentType.isCompatible(ContentType.APPLICATION_JSON)
&& ContentType.VALUE_ODATA_METADATA_NONE.equalsIgnoreCase(
contentType.getParameter(ContentType.PARAMETER_ODATA_METADATA));
}
示例15: isODataMetadataNone
import org.apache.olingo.commons.api.format.ContentType; //导入方法依赖的package包/类
public static boolean isODataMetadataNone(final ContentType contentType) {
return contentType.isCompatible(ContentType.APPLICATION_JSON)
&& ContentType.VALUE_ODATA_METADATA_NONE.equalsIgnoreCase(
contentType.getParameter(ContentType.PARAMETER_ODATA_METADATA));
}