1 /* 2 * Copyright 2013 smartics, Kronseder & Reiner GmbH 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package de.smartics.resteasy.hypermedia.renderer; 17 18 import javax.ws.rs.core.Link; 19 20 import org.apache.commons.lang3.StringUtils; 21 22 /** 23 * Provides information on a single link. 24 */ 25 public final class LinkDescriptorJaxrs extends LinkDescriptor 26 { 27 // ********************************* Fields ********************************* 28 29 // --- constants ------------------------------------------------------------ 30 31 // --- members -------------------------------------------------------------- 32 33 /** 34 * The URI to the resource the link points to. 35 */ 36 private String href; 37 38 /** 39 * The media type of the resource the link points to. 40 */ 41 private String type; 42 43 /** 44 * The content that describes the language of the resource pointed to by the 45 * link. When used together with the rel="alternate", it implies a translated 46 * version of the entry. Link elements MAY have an hreflang attribute, whose 47 * value MUST be a language tag [RFC3066]. 48 */ 49 private String hrefLang; 50 51 /** 52 * The advisory length of the linked content in octets; it is a hint about the 53 * content length of the representation returned when the IRI in the href 54 * attribute is mapped to a URI and dereferenced. Note that the length 55 * attribute does not override the actual content length of the representation 56 * as reported by the underlying protocol. Link elements MAY have a length 57 * attribute. 58 */ 59 private String length; 60 61 // ****************************** Initializer ******************************* 62 63 // ****************************** Constructors ****************************** 64 65 /** 66 * Default constructor. 67 * 68 * @param link the basic link information provided by RESTEasy. 69 * @param metadata the additional link metadata about the link. 70 */ 71 public LinkDescriptorJaxrs(final Link link, final LinkMetadata metadata) 72 { 73 super(metadata, link.getParams(), splitRel(link.getRel())); 74 75 final String title = link.getTitle(); 76 if (StringUtils.isNotBlank(title)) 77 { 78 setTitle(title); 79 } 80 this.type = link.getType(); 81 this.params.putAll(link.getParams()); 82 this.href = link.getUri().toString(); 83 } 84 85 // ****************************** Inner Classes ***************************** 86 87 // ********************************* Methods ******************************** 88 89 // --- init ----------------------------------------------------------------- 90 91 // --- get&set -------------------------------------------------------------- 92 93 @Override 94 public String getHref() 95 { 96 return href; 97 } 98 99 @Override 100 public void setHref(final String href) 101 { 102 this.href = href; 103 } 104 105 @Override 106 public String getType() 107 { 108 return type; 109 } 110 111 @Override 112 public void setType(final String type) 113 { 114 this.type = type; 115 } 116 117 @Override 118 public String getHrefLang() 119 { 120 return hrefLang; 121 } 122 123 @Override 124 public void setHrefLang(final String hrefLang) 125 { 126 this.hrefLang = hrefLang; 127 } 128 129 @Override 130 public String getLength() 131 { 132 return length; 133 } 134 135 @Override 136 public void setLength(final String length) 137 { 138 this.length = length; 139 } 140 141 @Override 142 public String getTitle() 143 { 144 final String title = metadata.getTitle(); 145 return title; 146 } 147 148 // --- business ------------------------------------------------------------- 149 150 // --- object basics -------------------------------------------------------- 151 152 }