Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2013-2014 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.springframework.hateoas.client;
 
 
Helper class to find org.springframework.hateoas.Link instances in representations.

Author(s):
Oliver Gierke
Since:
0.11
 
 class Rels {

Creates a new Rels.Rel for the given relation name and org.springframework.hateoas.LinkDiscoverers.

Parameters:
rel must not be null or empty.
discoverers must not be null.
Returns:
 
 	public static Rel getRelFor(String relLinkDiscoverers discoverers) {
 
 		Assert.hasText(rel"Relation name must not be null!");
 		Assert.notNull(discoverers"LinkDiscoverers must not be null!");
 
 		if (rel.startsWith("$")) {
 			return new JsonPathRel(rel);
 		}
 
 		return new LinkDiscovererRel(reldiscoverers);
 	}
 
 	public interface Rel {

Returns the link contained in the given representation of the given org.springframework.http.MediaType.

Parameters:
representation
mediaType
Returns:
 
 		Link findInResponse(String representationMediaType mediaType);
 	}

Rels.Rel to using a org.springframework.hateoas.LinkDiscoverer based on the given org.springframework.http.MediaType.

Author(s):
Oliver Gierke
 
 	private static class LinkDiscovererRel implements Rel {
 
 		private final String rel;
 		private final LinkDiscoverers discoverers;

Creates a new Rels.LinkDiscovererRel for the given relation name and org.springframework.hateoas.LinkDiscoverers.

Parameters:
rel must not be null or empty.
discoverers must not be null.
 
 		private LinkDiscovererRel(String relLinkDiscoverers discoverers) {
 
 			Assert.hasText(rel"Rel must not be null or empty!");
 			Assert.notNull(discoverers"LinkDiscoverers must not be null!");
 
 			this. = rel;
 			this. = discoverers;
 		}
 
 		/* 
 		 * (non-Javadoc)
 		 * @see org.springframework.hateoas.client.Rels.Rel#findInResponse(java.lang.String, org.springframework.http.MediaType)
 		 */
 		public Link findInResponse(String responseMediaType mediaType) {
 
 			LinkDiscoverer discoverer = .getLinkDiscovererFor(mediaType);
 
 			if (discoverer == null) {
				throw new IllegalStateException(String.format("Did not find LinkDiscoverer supporting media type %s!",
						mediaType));
			}
			return discoverer.findLinkWithRel(response);
		}
	}

A relation that's being looked up by a JSONPath expression.

Author(s):
Oliver Gierke
	private static class JsonPathRel implements Rel {
		private final String jsonPath;
		private final String rel;

Creates a new Rels.JsonPathRel for the given JSON path.

Parameters:
jsonPath must not be null or empty.
		private JsonPathRel(String jsonPath) {
			Assert.hasText(jsonPath"JSON path must not be null or empty!");
			this. = jsonPath;
			String lastSegment = jsonPath.substring(jsonPath.lastIndexOf('.'));
			this. = lastSegment.contains("[") ? lastSegment.substring(0, lastSegment.indexOf("[")) : lastSegment;
		}
		/* 
		 * (non-Javadoc)
		 * @see org.springframework.hateoas.client.Rels.Rel#findInResponse(java.lang.String, org.springframework.http.MediaType)
		 */
		public Link findInResponse(String representationMediaType mediaType) {
			return new Link(JsonPath.<Objectread(representation).toString(), );
		}
	}
New to GrepCode? Check out our FAQ X