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


Java LinkHeader类代码示例

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


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

示例1: getAll

import com.sun.jersey.core.header.LinkHeader; //导入依赖的package包/类
/**
 * Goes over all GitHub pages and return all pages union.
 *
 * @param webResource of first page
 * @param entityType type of entities
 * @return union
 */
protected <T> List<T> getAll(WebResource webResource, Class<T[]> entityType, ClientFilter filter)
{
    List<T> result = new LinkedList<T>();

    WebResource cursor = webResource;
    do
    {
        if (filter != null)
        {
            cursor.addFilter(filter);
        }
        WebResource.Builder builder = cursor.accept(MediaType.APPLICATION_JSON_TYPE);

        ClientResponse clientResponse = builder.get(ClientResponse.class);

        if (clientResponse.getStatus() < 300)
        {
            result.addAll(Arrays.asList(clientResponse.getEntity(entityType)));

            LinkHeaders linkHeaders = getLinks(clientResponse);
            LinkHeader nextLink = linkHeaders.getLink("next");
            URI nextPage = nextLink != null ? nextLink.getUri() : null;
            cursor = nextPage != null ? client.resource(nextPage) : null;
        }
        else
        {
            throw new UniformInterfaceException(clientResponse);
        }
    }
    while (cursor != null);
    return result;
}
 
开发者ID:edgehosting,项目名称:jira-dvcs-connector,代码行数:40,代码来源:AbstractGitHubRESTClientImpl.java

示例2: loadLinks

import com.sun.jersey.core.header.LinkHeader; //导入依赖的package包/类
protected List<Link> loadLinks(ClientResponse response, E entity) {
  ArrayList<Link> links = new ArrayList<Link>();

  //if there's a location, we'll consider it a "self" link.
  if (response.getLocation() != null) {
    links.add(new Link(Rel.SELF, new org.gedcomx.common.URI(response.getLocation().toString())));
  }

  //initialize links with link headers
  List<String> linkHeaders = response.getHeaders().get("Link");
  if (linkHeaders != null) {
    for (String header : linkHeaders) {
      LinkHeader lh = LinkHeader.valueOf(header);
      for (String rel : lh.getRel()) {
        Link link = new Link(rel, lh.getUri() == null ? null : org.gedcomx.common.URI.create(lh.getUri().toString()));
        link.setTemplate(lh.getParams().getFirst("template"));
        link.setTitle(lh.getParams().getFirst("title"));
        link.setAccept(lh.getParams().getFirst("accept"));
        link.setAllow(lh.getParams().getFirst("allow"));
        link.setHreflang(lh.getParams().getFirst("hreflang"));
        link.setType(lh.getParams().getFirst("type"));
        links.add(link);
      }
    }
  }

  //load the links from the main data element
  SupportsLinks mainElement = getMainDataElement();
  if (mainElement != null && mainElement.getLinks() != null) {
    links.addAll(mainElement.getLinks());
  }

  //load links at the document level
  if(entity != mainElement && entity instanceof SupportsLinks && ((SupportsLinks) entity).getLinks() != null) {
    links.addAll(((SupportsLinks)entity).getLinks());
  }


  return links;
}
 
开发者ID:FamilySearch,项目名称:gedcomx-java,代码行数:41,代码来源:GedcomxApplicationState.java

示例3: addLink

import com.sun.jersey.core.header.LinkHeader; //导入依赖的package包/类
protected void addLink(String rel, Pagination p, ContainerRequest req,
                       ContainerResponse res) {
    if (p.getPage()>= 0 && p.getLimit() >= 0) {
        URI uri = req.getRequestUriBuilder()
                .replaceQueryParam(RESTConstants.LIMIT, p.getLimit())
                .replaceQueryParam(RESTConstants.PAGE, p.getPage())
                .build();
        MediaType type = res.getMediaType();
        LinkHeader header = LinkHeader.uri(uri).type(type).rel(rel).build();
        res.getHttpHeaders().add(LINK_HEADER, header.toString());
    }
}
 
开发者ID:enviroCar,项目名称:enviroCar-server,代码行数:13,代码来源:PaginationFilter.java


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