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 java.io.Serializable; 19 20 import org.apache.commons.lang3.builder.ToStringBuilder; 21 22 /** 23 * Provides link metadata that describes the link. 24 * 25 * @see <a href="http://dev.w3.org/html5/markup/a.html">a – hyperlink</a> 26 * @see <a 27 * href="http://dev.w3.org/html5/markup/aria/common-attributes.html">Common 28 * Attributes</a> 29 */ 30 public class LinkMetadata implements Serializable, Cloneable 31 { 32 // ********************************* Fields ********************************* 33 34 // --- constants ------------------------------------------------------------ 35 36 /** 37 * The class version identifier. 38 * <p> 39 * The value of this constant is {@value}. 40 */ 41 private static final long serialVersionUID = 1L; 42 43 // --- members -------------------------------------------------------------- 44 45 /** 46 * The identifier of the link. 47 * 48 * @see <a 49 * href="http://dev.w3.org/html5/markup/aria/common-attributes.html#common.attrs.id">id</a> 50 */ 51 private String id; 52 53 /** 54 * The CSS class information to the link. 55 */ 56 private String cssClass; 57 58 /** 59 * The key label or list of key labels with which to associate the element; 60 * each key label represents a keyboard shortcut which UAs can use to activate 61 * the element or give focus to the element. 62 * <p> 63 * An ordered set of unique space-separated tokens, each of which must be 64 * exactly one Unicode code point in length. 65 * </p> 66 * 67 * @see <a href="http://dev.w3.org/html5/markup/global-attributes.html">global 68 * attributes</a> 69 */ 70 private String accessKey; 71 72 /** 73 * The tab index. 74 * <p> 75 * Specifies whether the element represents an element that is is focusable 76 * (that is, an element which is part of the sequence of focusable elements in 77 * the document), and the relative order of the element in the sequence of 78 * focusable elements in the document. 79 * </p> 80 * 81 * @see <a href="http://dev.w3.org/html5/markup/global-attributes.html">global 82 * attributes</a> 83 */ 84 private Integer tabIndex; 85 86 /** 87 * The advisory information associated with the element. 88 * 89 * @see <a href="http://dev.w3.org/html5/markup/global-attributes.html">global 90 * attributes</a> 91 */ 92 private String title; 93 94 /** 95 * The element’s text directionality. 96 * 97 * @see <a href="http://dev.w3.org/html5/markup/global-attributes.html">global 98 * attributes</a> 99 */ 100 private String dir; 101 102 /** 103 * The hidden flag to specify that the element represents an element that is 104 * not yet, or is no longer, relevant. 105 * 106 * @see <a href="http://dev.w3.org/html5/markup/global-attributes.html">global 107 * attributes</a> 108 */ 109 private Boolean hidden; 110 111 /** 112 * The standard label to be rendered as the visible part of the link. 113 */ 114 private String label; 115 116 /** 117 * A short version of the label to be rendered in confined space. 118 */ 119 private String shortLabel; 120 121 /** 122 * The detailed help information on the link. 123 */ 124 private String help; 125 126 /** 127 * The name or keyword giving a browsing context for UAs to use when following 128 * the hyperlink. 129 * 130 * @see <a 131 * href="http://dev.w3.org/html5/markup/a.html#a.attrs.target">target</a> 132 */ 133 private String target; 134 135 /** 136 * The media for which the destination of the hyperlink was designed. 137 * <p> 138 * Values are according to <a 139 * href="http://www.w3.org/TR/2009/CR-css3-mediaqueries-20090915/">Media 140 * Queries</a>. 141 * </p> 142 * 143 * @see <a 144 * href="http://dev.w3.org/html5/markup/a.html#a.attrs.media">media</a> 145 */ 146 private String media; 147 148 /** 149 * The identifier of a menu with which to associate the element as a context 150 * menu. 151 * 152 * @see <a 153 * href="http://dev.w3.org/html5/markup/aria/common-attributes.html#common.attrs.contextmenu">contextmenu</a> 154 */ 155 private String contextMenu; 156 157 // ****************************** Initializer ******************************* 158 159 // ****************************** Constructors ****************************** 160 161 /** 162 * Default constructor. 163 */ 164 public LinkMetadata() 165 { 166 } 167 168 // ****************************** Inner Classes ***************************** 169 170 // ********************************* Methods ******************************** 171 172 // --- init ----------------------------------------------------------------- 173 174 // --- get&set -------------------------------------------------------------- 175 176 /** 177 * Returns the identifier of the link. 178 * 179 * @return the identifier of the link. 180 */ 181 public String getId() 182 { 183 return id; 184 } 185 186 /** 187 * Sets the identifier of the link. 188 * 189 * @param id the identifier of the link. 190 */ 191 public void setId(final String id) 192 { 193 this.id = id; 194 } 195 196 /** 197 * Returns the CSS class information to the link. 198 * 199 * @return the CSS class information to the link. 200 */ 201 public String getCssClass() 202 { 203 return cssClass; 204 } 205 206 /** 207 * Sets the CSS class information to the link. 208 * 209 * @param cssClass the CSS class information to the link. 210 */ 211 public void setCssClass(final String cssClass) 212 { 213 this.cssClass = cssClass; 214 } 215 216 /** 217 * Returns the key label or list of key labels with which to associate the 218 * element; each key label represents a keyboard shortcut which UAs can use to 219 * activate the element or give focus to the element. 220 * <p> 221 * An ordered set of unique space-separated tokens, each of which must be 222 * exactly one Unicode code point in length. 223 * </p> 224 * 225 * @return the key label or list of key labels with which to associate the 226 * element; each key label represents a keyboard shortcut which UAs 227 * can use to activate the element or give focus to the element. 228 */ 229 public String getAccessKey() 230 { 231 return accessKey; 232 } 233 234 /** 235 * Sets the key label or list of key labels with which to associate the 236 * element; each key label represents a keyboard shortcut which UAs can use to 237 * activate the element or give focus to the element. 238 * <p> 239 * An ordered set of unique space-separated tokens, each of which must be 240 * exactly one Unicode code point in length. 241 * </p> 242 * 243 * @param accessKey the key label or list of key labels with which to 244 * associate the element; each key label represents a keyboard 245 * shortcut which UAs can use to activate the element or give focus 246 * to the element. 247 */ 248 public void setAccessKey(final String accessKey) 249 { 250 this.accessKey = accessKey; 251 } 252 253 /** 254 * Returns the tab index. 255 * <p> 256 * Specifies whether the element represents an element that is is focusable 257 * (that is, an element which is part of the sequence of focusable elements in 258 * the document), and the relative order of the element in the sequence of 259 * focusable elements in the document. 260 * </p> 261 * 262 * @return the tab index. 263 */ 264 public Integer getTabIndex() 265 { 266 return tabIndex; 267 } 268 269 /** 270 * Sets the tab index. 271 * <p> 272 * Specifies whether the element represents an element that is is focusable 273 * (that is, an element which is part of the sequence of focusable elements in 274 * the document), and the relative order of the element in the sequence of 275 * focusable elements in the document. 276 * </p> 277 * 278 * @param tabIndex the tab index. 279 */ 280 public void setTabIndex(final Integer tabIndex) 281 { 282 this.tabIndex = tabIndex; 283 } 284 285 /** 286 * Returns the advisory information associated with the element. 287 * 288 * @return the advisory information associated with the element. 289 */ 290 public String getTitle() 291 { 292 return title; 293 } 294 295 /** 296 * Sets the advisory information associated with the element. 297 * 298 * @param title the advisory information associated with the element. 299 */ 300 public void setTitle(final String title) 301 { 302 this.title = title; 303 } 304 305 /** 306 * Returns the element’s text directionality. 307 * 308 * @return the element’s text directionality. 309 */ 310 public String getDir() 311 { 312 return dir; 313 } 314 315 /** 316 * Sets the element’s text directionality. 317 * 318 * @param dir the element’s text directionality. 319 */ 320 public void setDir(final String dir) 321 { 322 this.dir = dir; 323 } 324 325 /** 326 * Returns the hidden flag to specify that the element represents an element 327 * that is not yet, or is no longer, relevant. 328 * 329 * @return the hidden flag to specify that the element represents an element 330 * that is not yet, or is no longer, relevant. 331 */ 332 public Boolean isHidden() 333 { 334 return hidden; 335 } 336 337 /** 338 * Sets the hidden flag to specify that the element represents an element that 339 * is not yet, or is no longer, relevant. 340 * 341 * @param hidden the hidden flag to specify that the element represents an 342 * element that is not yet, or is no longer, relevant. 343 */ 344 public void setHidden(final Boolean hidden) 345 { 346 this.hidden = hidden; 347 } 348 349 /** 350 * Returns the standard label to be rendered as the visible part of the link. 351 * 352 * @return the standard label to be rendered as the visible part of the link. 353 */ 354 public String getLabel() 355 { 356 return label; 357 } 358 359 /** 360 * Sets the standard label to be rendered as the visible part of the link. 361 * 362 * @param label the standard label to be rendered as the visible part of the 363 * link. 364 */ 365 public void setLabel(final String label) 366 { 367 this.label = label; 368 } 369 370 /** 371 * Returns a short version of the label to be rendered in confined space. 372 * 373 * @return a short version of the label to be rendered in confined space. 374 */ 375 public String getShortLabel() 376 { 377 return shortLabel; 378 } 379 380 /** 381 * Sets a short version of the label to be rendered in confined space. 382 * 383 * @param shortLabel a short version of the label to be rendered in confined 384 * space. 385 */ 386 public void setShortLabel(final String shortLabel) 387 { 388 this.shortLabel = shortLabel; 389 } 390 391 /** 392 * Returns the detailed help information on the link. 393 * 394 * @return the detailed help information on the link. 395 */ 396 public String getHelp() 397 { 398 return help; 399 } 400 401 /** 402 * Sets the detailed help information on the link. 403 * 404 * @param help the detailed help information on the link. 405 */ 406 public void setHelp(final String help) 407 { 408 this.help = help; 409 } 410 411 /** 412 * Returns the name or keyword giving a browsing context for UAs to use when 413 * following the hyperlink. 414 * 415 * @return the name or keyword giving a browsing context for UAs to use when 416 * following the hyperlink. 417 */ 418 public String getTarget() 419 { 420 return target; 421 } 422 423 /** 424 * Sets the name or keyword giving a browsing context for UAs to use when 425 * following the hyperlink. 426 * 427 * @param target the name or keyword giving a browsing context for UAs to use 428 * when following the hyperlink. 429 */ 430 public void setTarget(final String target) 431 { 432 this.target = target; 433 } 434 435 /** 436 * Returns the media for which the destination of the hyperlink was designed. 437 * <p> 438 * Values are according to <a 439 * href="http://www.w3.org/TR/2009/CR-css3-mediaqueries-20090915/">Media 440 * Queries</a>. 441 * </p> 442 * 443 * @return the media for which the destination of the hyperlink was designed. 444 */ 445 public String getMedia() 446 { 447 return media; 448 } 449 450 /** 451 * Sets the media for which the destination of the hyperlink was designed. 452 * <p> 453 * Values are according to <a 454 * href="http://www.w3.org/TR/2009/CR-css3-mediaqueries-20090915/">Media 455 * Queries</a>. 456 * </p> 457 * 458 * @param media the media for which the destination of the hyperlink was 459 * designed. 460 */ 461 public void setMedia(final String media) 462 { 463 this.media = media; 464 } 465 466 /** 467 * Returns the identifier of a menu with which to associate the element as a 468 * context menu. 469 * 470 * @return the identifier of a menu with which to associate the element as a 471 * context menu. 472 */ 473 public String getContextMenu() 474 { 475 return contextMenu; 476 } 477 478 /** 479 * Sets the identifier of a menu with which to associate the element as a 480 * context menu. 481 * 482 * @param contextMenu the identifier of a menu with which to associate the 483 * element as a context menu. 484 */ 485 public void setContextMenu(final String contextMenu) 486 { 487 this.contextMenu = contextMenu; 488 } 489 490 // --- business ------------------------------------------------------------- 491 492 // --- object basics -------------------------------------------------------- 493 494 /** 495 * Returns a shallow copy of the object. 496 * 497 * @return a shallow copy. 498 */ 499 @Override 500 public Object clone() 501 { 502 try 503 { 504 return super.clone(); 505 } 506 catch (final CloneNotSupportedException e) 507 { 508 throw new AssertionError(); // cannot happen! 509 } 510 } 511 512 /** 513 * {@inheritDoc} 514 * <p> 515 * Provides the properties via reflection for displaying debug information. 516 * </p> 517 * 518 * @see java.lang.Object#toString() 519 */ 520 @Override 521 public String toString() 522 { 523 return ToStringBuilder.reflectionToString(this); 524 } 525 }