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


Java FormatWriter类代码示例

本文整理汇总了Java中org.odata4j.format.FormatWriter的典型用法代码示例。如果您正苦于以下问题:Java FormatWriter类的具体用法?Java FormatWriter怎么用?Java FormatWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FormatWriter类属于org.odata4j.format包,在下文中一共展示了FormatWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: renderEntityResponse

import org.odata4j.format.FormatWriter; //导入依赖的package包/类
/**
 * レスポンスボディを作成する.
 * @param uriInfo UriInfo
 * @param resp レスポンス
 * @param format レスポンスボディのフォーマット
 * @param acceptableMediaTypes 許可するMediaTypeのリスト
 * @return レスポンスボディ
 */
protected String renderEntityResponse(
        final UriInfo uriInfo,
        final EntityResponse resp,
        final String format,
        final List<MediaType> acceptableMediaTypes) {
    StringWriter w = new StringWriter();
    try {
        FormatWriter<EntityResponse> fw = PersoniumFormatWriterFactory.getFormatWriter(EntityResponse.class,
                acceptableMediaTypes, format, null);
        // UriInfo uriInfo2 = PersoniumCoreUtils.createUriInfo(uriInfo, 1);
        fw.write(uriInfo, w, resp);
    } catch (UnsupportedOperationException e) {
        throw PersoniumCoreException.OData.FORMAT_INVALID_ERROR.params(format);
    }

    String responseStr = w.toString();

    return responseStr;

}
 
开发者ID:personium,项目名称:personium-core,代码行数:29,代码来源:AbstractODataResource.java

示例2: getRoot

import org.odata4j.format.FormatWriter; //导入依赖的package包/类
/**
     * サービスドキュメントを返す.
     * @param uriInfo UriInfo
     * @param format String
     * @param httpHeaders HttpHeaders
     * @return JAX-RS Response Object
     */
    @GET
//    @Path("")
    public Response getRoot(
            @Context final UriInfo uriInfo,
            @QueryParam("$format") final String format,
            @Context HttpHeaders httpHeaders) {
        // アクセス制御
        this.checkAccessContext(this.getAccessContext(), BoxPrivilege.READ);

        StringWriter w = new StringWriter();

        log.debug(format);
        List<MediaType> acceptableMediaTypes = null; // Enumerable.create(MediaType.APPLICATION_XML_TYPE).toList();

        FormatWriter<EdmDataServices> fw = FormatWriterFactory.getFormatWriter(EdmDataServices.class,
                acceptableMediaTypes, format, "");

        fw.write(PersoniumCoreUtils.createUriInfo(uriInfo, 0), w, this.metadata);

        return Response.ok(w.toString(), fw.getContentType())
                .header(ODataConstants.Headers.DATA_SERVICE_VERSION, ODataConstants.DATA_SERVICE_VERSION_HEADER)
                .build();
    }
 
开发者ID:personium,项目名称:personium-core,代码行数:31,代码来源:ODataResource.java

示例3: getServiceDocument

import org.odata4j.format.FormatWriter; //导入依赖的package包/类
@GET
@Produces({ ODataConstants.APPLICATION_XML_CHARSET_UTF8, ODataConstants.TEXT_JAVASCRIPT_CHARSET_UTF8, ODataConstants.APPLICATION_JAVASCRIPT_CHARSET_UTF8 })
public Response getServiceDocument(
    @Context HttpHeaders httpHeaders,
    @Context UriInfo uriInfo,
    @Context ContextResolver<ODataProducer> producerResolver,
    @QueryParam("$format") String format,
    @QueryParam("$callback") String callback) {

  ODataProducer producer = producerResolver.getContext(ODataProducer.class);

  EdmDataServices metadata = producer.getMetadata();

  StringWriter w = new StringWriter();
  FormatWriter<EdmDataServices> fw = FormatWriterFactory.getFormatWriter(EdmDataServices.class, httpHeaders.getAcceptableMediaTypes(), format, callback);
  fw.write(uriInfo, w, metadata);

  return Response.ok(w.toString(), fw.getContentType())
      .header(ODataConstants.Headers.DATA_SERVICE_VERSION, ODataConstants.DATA_SERVICE_VERSION_HEADER)
      .build();
}
 
开发者ID:teiid,项目名称:oreva,代码行数:22,代码来源:ServiceDocumentResource.java

示例4: toResponse

import org.odata4j.format.FormatWriter; //导入依赖的package包/类
public Response toResponse(RuntimeException e) {
  ODataProducerException exception;
  if (e instanceof ODataProducerException)
    exception = (ODataProducerException) e;
  else
    exception = new ServerErrorException(e);

  ErrorResponseExtension errorResponseExtension = producerResolver.getContext(ODataProducer.class).findExtension(ErrorResponseExtension.class);
  boolean includeInnerError = errorResponseExtension != null && errorResponseExtension.returnInnerError(httpHeaders, uriInfo, exception);

  FormatWriter<ErrorResponse> fw = FormatWriterFactory.getFormatWriter(ErrorResponse.class, httpHeaders.getAcceptableMediaTypes(),
      getFormatParameter(), getCallbackParameter());
  StringWriter sw = new StringWriter();
  fw.write(uriInfo, sw, getErrorResponse(exception, includeInnerError));

  return Response.status(exception.getHttpStatus())
      .type(fw.getContentType())
      .header(ODataConstants.Headers.DATA_SERVICE_VERSION, ODataConstants.DATA_SERVICE_VERSION_HEADER)
      .entity(sw.toString())
      .build();
}
 
开发者ID:teiid,项目名称:oreva,代码行数:22,代码来源:ExceptionMappingProvider.java

示例5: buildPayload

import org.odata4j.format.FormatWriter; //导入依赖的package包/类
private String buildPayload(String entitySet, final List<OProperty<?>> props, EdmDataServices edm) {
	final EdmEntitySet ees = edm.getEdmEntitySet(entitySet);
	
    Entry entry =  new Entry() {
        public String getUri() {
          return null;
        }
        public OEntity getEntity() {
          return OEntities.createRequest(ees, props, null);
        }
      };		
	
	StringWriter sw = new StringWriter();
	FormatWriter<Entry> fw = FormatWriterFactory.getFormatWriter(Entry.class, null, "ATOM", null); //$NON-NLS-1$
	fw.write(null, sw, entry);
	return sw.toString();
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:18,代码来源:ODataUpdateExecution.java

示例6: createEntity

import org.odata4j.format.FormatWriter; //导入依赖的package包/类
protected Response createEntity(
    HttpHeaders httpHeaders,
    UriInfo uriInfo,
    SecurityContext securityContext,
    ODataProducer producer,
    String entitySetName,
    OEntity entity,
    ODataContext odataContext, List<MediaType> mediaTypeList) throws Exception {

  EntityResponse response = producer.createEntity(odataContext, entitySetName, entity);
  FormatWriter<EntityResponse> writer = null;
  if (mediaTypeList != null) {
    writer = FormatWriterFactory.getFormatWriter(EntityResponse.class, mediaTypeList, null, null);
  }
  else {
    writer = FormatWriterFactory.getFormatWriter(EntityResponse.class, httpHeaders.getAcceptableMediaTypes(), null, null);
  }

  StringWriter sw = new StringWriter();
  writer.write(uriInfo, sw, response);

  String relid = InternalUtil.getEntityRelId(response.getEntity());
  String entryId = uriInfo.getBaseUri().toString() + relid;

  String responseEntity = sw.toString();

  return Response
      .ok(responseEntity, writer.getContentType())
      .status(Status.CREATED)
      .location(URI.create(entryId))
      .header(ODataConstants.Headers.DATA_SERVICE_VERSION,
          ODataConstants.DATA_SERVICE_VERSION_HEADER).build();
}
 
开发者ID:teiid,项目名称:oreva,代码行数:34,代码来源:EntitiesRequestResource.java

示例7: createResponseForBatch

import org.odata4j.format.FormatWriter; //导入依赖的package包/类
/**
 * Creates the response for batch.
 *
 * @param httpHeaders the http headers
 * @param uriInfo the uri info
 * @param producer the producer
 * @param entitySetName the entity set name
 * @param entity the entity
 * @param mediaTypeList 
 * @return the response
 * @throws Exception the exception
 */
protected Response createResponseForBatch(
    HttpHeaders httpHeaders,
    UriInfo uriInfo,
    ODataProducer producer,
    String entitySetName,
    OEntity entity, List<MediaType> mediaTypeList) throws Exception {

  EntityResponse response = producer.createResponseForBatchPostOperation(entitySetName, entity);
  FormatWriter<EntityResponse> writer = null;
  if (mediaTypeList != null) {
    writer = FormatWriterFactory
        .getFormatWriter(EntityResponse.class, mediaTypeList, null, null);
  } else {
    writer = FormatWriterFactory
        .getFormatWriter(EntityResponse.class, httpHeaders.getAcceptableMediaTypes(), null, null);
  }

  StringWriter sw = new StringWriter();
  writer.write(uriInfo, sw, response);

  String relid = InternalUtil.getEntityRelId(response.getEntity());
  String entryId = uriInfo.getBaseUri().toString() + relid;

  String responseEntity = sw.toString();

  return Response
      .ok(responseEntity, writer.getContentType())
      .status(Status.CREATED)
      .location(URI.create(entryId))
      .header(ODataConstants.Headers.DATA_SERVICE_VERSION,
          ODataConstants.DATA_SERVICE_VERSION_HEADER).build();
}
 
开发者ID:teiid,项目名称:oreva,代码行数:45,代码来源:BatchRequestResource.java

示例8: getNavProperty

import org.odata4j.format.FormatWriter; //导入依赖的package包/类
/**
 * NavPropに対するGETメソッドによる検索処理.
 * @param uriInfo UriInfo
 * @param accept Acceptヘッダ
 * @param callback ?? なんだこれは?JSONP?
 * @param skipToken ?? なんだこれは?
 * @param q 全文検索パラメタ
 * @return JAX-RS Response
 */
@GET
@Produces({ODataConstants.APPLICATION_ATOM_XML_CHARSET_UTF8, ODataConstants.TEXT_JAVASCRIPT_CHARSET_UTF8,
        ODataConstants.APPLICATION_JAVASCRIPT_CHARSET_UTF8 })
public final Response getNavProperty(
        @Context final UriInfo uriInfo,
        @HeaderParam(HttpHeaders.ACCEPT) final String accept,
        @QueryParam("$callback") final String callback,
        @QueryParam("$skiptoken") final String skipToken,
        @QueryParam("q") final String q) {
    // アクセス制御
    this.checkReadAccessContext();

    // queryのパース
    UriInfo uriInfo2 = PersoniumCoreUtils.createUriInfo(uriInfo, 2);
    QueryInfo queryInfo = ODataEntitiesResource.queryInfo(uriInfo);

    // NavigationProperty経由の一覧取得を実行する
    BaseResponse response = getOdataProducer().getNavProperty(
            this.sourceEntityId.getEntitySetName(),
            this.sourceEntityId.getEntityKey(),
            this.targetNavProp,
            queryInfo);

    StringWriter sw = new StringWriter();
    // TODO 制限事項でAcceptは無視してJSONで返却するため固定でJSONを指定する.
    List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
    acceptableMediaTypes.add(MediaType.APPLICATION_JSON_TYPE);
    // TODO 制限事項でQueryは無視するため固定でnullを指定する.
    FormatWriter<EntitiesResponse> fw = PersoniumFormatWriterFactory.getFormatWriter(EntitiesResponse.class,
            acceptableMediaTypes, null, callback);

    fw.write(uriInfo2, sw, (EntitiesResponse) response);

    String entity = sw.toString();
    // 制御コードのエスケープ処理
    entity = escapeResponsebody(entity);

    ODataVersion version = ODataVersion.V2;

    return Response.ok(entity, fw.getContentType())
            .header(ODataConstants.Headers.DATA_SERVICE_VERSION, version.asString).build();
}
 
开发者ID:personium,项目名称:personium-core,代码行数:52,代码来源:ODataPropertyResource.java

示例9: listEntities

import org.odata4j.format.FormatWriter; //导入依赖的package包/类
/**
 * @param uriInfo UriInfo
 * @param accept Acceptヘッダ
 * @param format $format パラメタ
 * @param callback コールバック
 * @param skipToken スキップトークン
 * @param q 全文検索パラメタ
 * @return JAX-RS Response
 */
@GET
public Response listEntities(
        @Context UriInfo uriInfo,
        @HeaderParam(HttpHeaders.ACCEPT) final String accept,
        @QueryParam("$format") String format,
        @QueryParam("$callback") final String callback,
        @QueryParam("$skiptoken") final String skipToken,
        @QueryParam("q") final String q) {

    // アクセス制御
    this.odataResource.checkAccessContext(this.accessContext,
            this.odataResource.getNecessaryReadPrivilege(getEntitySetName()));

    // リクエストの取得をProducerに依頼
    EntitiesResponse resp = getEntities(uriInfo, q);
    StringWriter sw = new StringWriter();

    // $formatとAcceptヘッダの値から出力形式を決定
    List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
    MediaType contentType = decideOutputFormat(accept, format);
    acceptableMediaTypes.add(contentType);

    FormatWriter<EntitiesResponse> fw = PersoniumFormatWriterFactory.getFormatWriter(EntitiesResponse.class,
            acceptableMediaTypes, null, callback);
    UriInfo uriInfo2 = PersoniumCoreUtils.createUriInfo(uriInfo, 1);

    fw.write(uriInfo2, sw, resp);
    String entity = null;
    entity = sw.toString();

    // 制御コードのエスケープ処理
    entity = escapeResponsebody(entity);

    // TODO remove this hack, check whether we are Version 2.0 compatible anyway
    ODataVersion version = null;
    version = ODataVersion.V2;

    return Response.ok(entity, fw.getContentType())
            .header(ODataConstants.Headers.DATA_SERVICE_VERSION, version.asString).build();
}
 
开发者ID:personium,项目名称:personium-core,代码行数:50,代码来源:ODataEntitiesResource.java

示例10: list

import org.odata4j.format.FormatWriter; //导入依赖的package包/类
/**
 * バッチリクエストの一覧取得処理.
 * @param uriInfo uriInfo
 * @param bodyPart BatchBodyPart
 * @return レスポンス
 */
private BatchResponse list(UriInfo uriInfo, BatchBodyPart bodyPart) {
    BatchResponse res = new BatchResponse();
    EntitiesResponse entitiesResp = null;
    try {
        // アクセス制御
        checkReadAccessContext(bodyPart);
        // NavigationProperty経由の一覧取得は 501
        if (bodyPart.hasNavigationProperty()) {
            throw PersoniumCoreException.Misc.METHOD_NOT_IMPLEMENTED;
        }
        ODataEntitiesResource entitiesResource = new ODataEntitiesResource(this.odataResource,
                bodyPart.getEntitySetName());

        // Entityの一覧取得
        String query = bodyPart.getRequestQuery();
        QueryInfo queryInfo = QueryParser.createQueryInfo(query);
        entitiesResp = entitiesResource.getEntities(queryInfo);

        // レスポンス作成
        res.setResponseCode(HttpStatus.SC_OK);
        // TODO 現状は、ContentTypeはJSON固定
        res.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
        res.setHeader(ODataConstants.Headers.DATA_SERVICE_VERSION, "2.0");
        // レスポンスボディ
        UriInfo resUriInfo = PersoniumCoreUtils.createUriInfo(uriInfo, 1);
        StringWriter sw = new StringWriter();
        // TODO 制限事項でAcceptは無視してJSONで返却するため固定でJSONを指定する.
        List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
        acceptableMediaTypes.add(MediaType.APPLICATION_JSON_TYPE);
        // TODO 制限事項でQueryは無視するため固定でnullを指定する.
        FormatWriter<EntitiesResponse> fw = PersoniumFormatWriterFactory.getFormatWriter(EntitiesResponse.class,
                acceptableMediaTypes, null, null);
        UriInfo uriInfo2 = PersoniumCoreUtils.createUriInfo(resUriInfo, 1);

        fw.write(uriInfo2, sw, entitiesResp);
        String entity = sw.toString();

        res.setBody(entity);

    } catch (Exception e) {
        res.setErrorResponse(e);
    }

    return res;
}
 
开发者ID:personium,项目名称:personium-core,代码行数:52,代码来源:ODataBatchResource.java

示例11: getServiceDocumentFormatWriter

import org.odata4j.format.FormatWriter; //导入依赖的package包/类
@Override
public FormatWriter<EdmDataServices> getServiceDocumentFormatWriter() {
    return new JsonServiceDocumentFormatWriter(callback);
}
 
开发者ID:personium,项目名称:personium-core,代码行数:5,代码来源:PersoniumFormatWriterFactory.java

示例12: getFeedFormatWriter

import org.odata4j.format.FormatWriter; //导入依赖的package包/类
@Override
public FormatWriter<EntitiesResponse> getFeedFormatWriter() {
    return new PersoniumJsonFeedFormatWriter(callback);
}
 
开发者ID:personium,项目名称:personium-core,代码行数:5,代码来源:PersoniumFormatWriterFactory.java

示例13: getEntryFormatWriter

import org.odata4j.format.FormatWriter; //导入依赖的package包/类
@Override
public FormatWriter<EntityResponse> getEntryFormatWriter() {
    return new PersoniumJsonEntryFormatWriter(callback);
}
 
开发者ID:personium,项目名称:personium-core,代码行数:5,代码来源:PersoniumFormatWriterFactory.java

示例14: getPropertyFormatWriter

import org.odata4j.format.FormatWriter; //导入依赖的package包/类
@Override
public FormatWriter<PropertyResponse> getPropertyFormatWriter() {
    return new JsonPropertyFormatWriter(callback);
}
 
开发者ID:personium,项目名称:personium-core,代码行数:5,代码来源:PersoniumFormatWriterFactory.java

示例15: getRequestEntryFormatWriter

import org.odata4j.format.FormatWriter; //导入依赖的package包/类
@Override
public FormatWriter<Entry> getRequestEntryFormatWriter() {
    return new JsonRequestEntryFormatWriter(callback);
}
 
开发者ID:personium,项目名称:personium-core,代码行数:5,代码来源:PersoniumFormatWriterFactory.java


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