当前位置: 首页>>代码示例>>Java>>正文


Java ContentType.isCompatible方法代码示例

本文整理汇总了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;
}
 
开发者ID:Hevelian,项目名称:hevelian-olastic,代码行数:24,代码来源:ElasticOData.java

示例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());
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:33,代码来源:BatchParserCommon.java

示例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;
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:25,代码来源:ODataImpl.java

示例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);
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:18,代码来源:PropertyTest.java

示例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);
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:24,代码来源:PropertyTest.java

示例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);
    }
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:34,代码来源:ClientEntitySetIterator.java

示例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");
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:15,代码来源:BatchRequestTransformator.java

示例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());
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:9,代码来源:ODataImpl.java

示例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());
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:14,代码来源:ODataImpl.java

示例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());
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:13,代码来源:ODataImpl.java

示例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());
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:8,代码来源:BatchRequest.java

示例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);
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:11,代码来源:ClientODataDeserializerImpl.java

示例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);
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:8,代码来源:ODataClientImpl.java

示例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));
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:6,代码来源:TechnicalProcessor.java

示例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));
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:6,代码来源:CarsProcessor.java


注:本文中的org.apache.olingo.commons.api.format.ContentType.isCompatible方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。