Class Link

java.lang.Object
org.apache.juneau.bean.atom.Common
org.apache.juneau.bean.atom.Link

@Bean(typeName="link") public class Link extends Common
Represents a reference from an entry or feed to a Web resource.

Atom links define references to related resources such as alternate representations, related documents, enclosures (for podcasts), and navigation links. Links are one of the fundamental components of Atom and enable rich hypermedia relationships between resources.

The link's rel attribute defines the relationship type, while href provides the target URI. Common relationship types include:

  • alternate - An alternate representation (e.g., HTML version of entry)
  • self - The feed/entry itself
  • related - A related resource
  • enclosure - A related resource to be downloaded (e.g., podcast audio)
  • via - The source of the information
Schema

atomLink = element atom:link { atomCommonAttributes, attribute href { atomUri }, attribute rel { atomNCName | atomUri }?, attribute type { atomMediaType }?, attribute hreflang { atomLanguageTag }?, attribute title { text }?, attribute length { text }?, undefinedContent }

Example:

// Create links for an entry Entry entry = new Entry(...) .setLinks( // Link to HTML version new Link("alternate", "text/html", "http://example.org/post1.html") .setHreflang("en"), // Podcast enclosure new Link("enclosure", "audio/mpeg", "http://example.org/episode1.mp3") .setLength(24986239) );

Specification:

Represents an atomLink construct in the RFC 4287 - Section 4.2.7 specification.

See Also:
  • Constructor Details

    • Link

      public Link(String rel, String type, String href)
      Normal constructor.
      Parameters:
      rel - The rel of the link.
      type - The type of the link.
      href - The URI of the link.
    • Link

      public Link()
      Bean constructor.
  • Method Details

    • getHref

      Bean property getter: href.

      Returns the URI of the referenced resource.

      This is the target address of the link and is a required attribute for all Atom links.

      Returns:
      The property value, or null if it is not set.
    • setHref

      public Link setHref(String value)
      Bean property setter: href.

      Sets the URI of the referenced resource (required).

      Example:

      Link link = new Link() .setHref("http://example.org/posts/1");

      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object.
    • getRel

      Bean property getter: rel.

      Returns the link relation type.

      The rel attribute indicates the type of relationship between the entry/feed and the linked resource. When not specified, the default is "alternate".

      Returns:
      The property value, or null if it is not set.
    • setRel

      public Link setRel(String value)
      Bean property setter: rel.

      Sets the link relation type.

      Common values include "alternate", "self", "related", "enclosure", "via", "first", "last", "previous", "next".

      Example:

      Link link = new Link() .setRel("alternate") .setHref("http://example.org/post1.html");

      Parameters:
      value - The new value for this property.
      Can be null to unset the property (defaults to "alternate").
      Returns:
      This object.
    • getType

      Bean property getter: type.

      The content type of the target of this link.

      Returns:
      The property value, or null if it is not set.
    • setType

      public Link setType(String value)
      Bean property setter: type.

      The content type of the target of this link.

      This should be a valid MIME media type as defined by RFC 4287.

      Examples:
      • "text/html"
      • "application/pdf"
      • "image/jpeg"
      • "application/atom+xml"
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object
    • getHreflang

      Bean property getter: hreflang.

      Returns the language of the resource pointed to by the link.

      The value should be a language tag as defined by RFC 3066.

      Returns:
      The property value, or null if it is not set.
    • setHreflang

      public Link setHreflang(String value)
      Bean property setter: hreflang.

      Sets the language of the resource pointed to by the link.

      Example:

      Link link = new Link("alternate", "text/html", "http://example.org/post1.html") .setHreflang("en-US");

      Parameters:
      value - The new value for this property (e.g., "en", "fr", "de", "en-US").
      Can be null to unset the property.
      Returns:
      This object.
    • getTitle

      Bean property getter: title.

      Returns human-readable information about the link.

      The title provides advisory information about the link, typically for display to users.

      Returns:
      The property value, or null if it is not set.
    • setTitle

      public Link setTitle(String value)
      Bean property setter: title.

      Sets human-readable information about the link.

      Example:

      Link link = new Link("related", "text/html", "http://example.org/related") .setTitle("Related Article");

      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object.
    • getLength

      Bean property getter: length.

      Returns an advisory size in bytes of the linked resource.

      This is particularly useful for enclosures (podcast episodes, video files, etc.) to help clients decide whether to download the resource.

      Returns:
      The property value, or null if it is not set.
    • setLength

      public Link setLength(Integer value)
      Bean property setter: length.

      Sets an advisory size in bytes of the linked resource.

      Example:

      // Podcast episode with file size Link link = new Link("enclosure", "audio/mpeg", "http://example.org/episode1.mp3") .setLength(24986239); // ~24 MB

      Parameters:
      value - The new value for this property in bytes.
      Can be null to unset the property.
      Returns:
      This object.
    • setBase

      public Link setBase(Object value)
      Description copied from class: Common
      Bean property setter: base.

      Sets the base URI for resolving relative URI references (xml:base attribute).

      The value can be of any of the following types: URI, URL, String. Strings must be valid URIs.

      Example:

      Feed feed = new Feed(...) .setBase("http://example.org/");

      Overrides:
      setBase in class Common
      Parameters:
      value - The new value for this property.
      Can be null to unset the property.
      Returns:
      This object.
    • setLang

      public Link setLang(String value)
      Description copied from class: Common
      Bean property setter: lang.

      Sets the natural language of the element's content (xml:lang attribute).

      Example:

      Text title = new Text("text") .setText("Mon Blog") .setLang("fr");

      Overrides:
      setLang in class Common
      Parameters:
      value - The new value for this property (e.g., "en", "fr", "de", "en-US").
      Can be null to unset the property.
      Returns:
      This object.