/** * Simple parser to convert a link header containing a single link into an FcrepoLink object. * * @param link link header value. * @return FcrepoLink representing the link */ public static FcrepoLink valueOf(final String link) { return new FcrepoLink(link); }
/** * Parse the value of a link header */ private void parse(final String link) { final int paramIndex = link.indexOf(PARAM_DELIM); if (paramIndex == -1) { uri = getLinkPart(link); } else { uri = getLinkPart(link.substring(0, paramIndex)); // Parse the remainder of the header after the URI as parameters parseParams(link.substring(paramIndex + 1)); } }
/** * Retrieve the REL portion of the link * * @return the "rel" portion of a Link header */ public String getRel() { return getParam(META_REL); }
/** * Provide the URI to an ACL for this request * * @param aclUri URI to the ACL * @return this builder */ protected BodyRequestBuilder linkAcl(final String aclUri) { if (aclUri != null) { final FcrepoLink link = FcrepoLink.fromUri(aclUri) .rel(ACL_REL) .build(); request.addHeader(LINK, link.toString()); } return this; }
/** * Return true if the response represents a resource with the given type * * @param typeUri URI of the type * @return true if the type is present. */ public boolean hasType(final URI typeUri) { return getHeaderValues(LINK).stream() .map(FcrepoLink::new) .anyMatch(l -> l.getRel().equals(TYPE_REL) && l.getUri().equals(typeUri)); }
/** * Create a representation of a Link header. * * @param link the value for a Link header */ public FcrepoLink(final String link) { if (link == null) { throw new IllegalArgumentException("Link header did not contain a URI"); } this.params = new HashMap<>(); parse(link); }
/** * Retrieve link header values matching the given relationship * * @param relationship the relationship of links to return * @return list of link header URIs matching the given relationship */ public List<URI> getLinkHeaders(final String relationship) { return getHeaderValues(LINK).stream().map(FcrepoLink::new).filter(link -> link.getRel().equals(relationship)) .map(FcrepoLink::getUri).collect(toList()); }
/** * Add a link header to the request * * @param linkHeader link header value represented as a FcrepoLink * @return this builder */ protected RequestBuilder addLinkHeader(final FcrepoLink linkHeader) { request.addHeader(LINK, linkHeader.toString()); return this; } }
/** * Add an interaction model to the request * * @param interactionModelUri URI of the interaction model * @return this builder */ protected BodyRequestBuilder addInteractionModel(final String interactionModelUri) { if (interactionModelUri != null) { final FcrepoLink link = FcrepoLink.fromUri(interactionModelUri) .rel(TYPE_REL) .build(); request.addHeader(LINK, link.toString()); } return this; }
/** * Add the given URI to the request as the location a Non-RDF Source binary should use for external content. The * handling parameter must be supplied, and informs the server of how to process the request. * * @param contentURI URI of the external content. * @param contentType Mimetype to supply for the external content. * @param handling Name of the handling method, used by the server to determine how to process the external * content URI. Standard values can be found in {@link ExternalContentHandling}. * @return this builder */ protected BodyRequestBuilder externalContent(final URI contentURI, final String contentType, final String handling) { final Builder linkBuilder = FcrepoLink.fromUri(contentURI) .rel(EXTERNAL_CONTENT_REL) .param(EXTERNAL_CONTENT_HANDLING, handling); if (StringUtils.isNotBlank(contentType)) { linkBuilder.type(contentType); } request.addHeader(LINK, linkBuilder.build().toString()); return this; }
/** * Finish building this link. * * @return newly built link. */ public FcrepoLink build() { return new FcrepoLink(uri, params); } }
/** * Retrieve the type portion of the link * * @return the "type" parameter of the header */ public String getType() { return getParam(META_TYPE); }
links.add(new FcrepoLink(currentLink.toString().trim())); currentLink = new StringBuilder(); continue; links.add(new FcrepoLink(currentLink.toString().trim())); return links;