public final class Link extends Object
This is how it is supposed to be used, for example:
@Path("/alpha")
public class MainRs {
@GET
@Produces(MediaTypes.APPLICATION_XML)
public BasePage front() {
return new PageBuilder()
.stylesheet("/xsl/front.xsl")
.build(BasePage.class)
.link(new Link("search", "./s"))
.link(new Link("start", "/start"));
}
}
That is how an XML will look like (if the site is deployed to
http://example.com/foo/):
<?xml version="1.0" ?>
<?xml-stylesheet type='text/xsl' href='/xsl/front.xsl'?>
<page>
<links>
<link rel="search" href="http://example.com/foo/alpha/s"
type="application/xml"/>
<link rel="start" href="http://example.com/foo/start"
type="application/xml"/>
</links>
</page>
Sometimes it's necessary to add more information to the link, besides the
the mandatory rel, href, and type attributes. That's
how you can specify more:
return new PageBuilder()
.build(BasePage.class)
.link(
new Link("search", "./s")
.with(new JaxbBundle("name", "John Doe"))
)
The result XML will look like:
<?xml version="1.0" ?>
<?xml-stylesheet type='text/xsl' href='/xsl/front.xsl'?>
<page>
<links>
<link rel="search" href="http://example.com/foo/alpha/s"
type="application/xml"/>
<name>John Doe</name>
</link>
</links>
</page>
URI provided as a second parameter of any constructor of this class
may be absolute or relative. It is relative if it starts with a slash
("/") or a dot ("."). URIs started with a slash are related
to the absolute path of the deployed application. URIs started with a dot
are related to the path of the currently rendered page. To get the
information about current context attachTo(Resource) method
is used. It is being called by BasePage.init(Resource).
The class is mutable and thread-safe.
| Constructor and Description |
|---|
Link()
Public ctor for JAXB (always throws a runtime exception).
|
Link(String rname,
String link)
Public ctor.
|
Link(String rname,
URI uri)
Public ctor.
|
Link(String rname,
javax.ws.rs.core.UriBuilder builder)
Public ctor.
|
Link(String rname,
URI uri,
String tpe)
Public ctor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
attachTo(Resource res)
Attach to this resource and make
HREF attribute
absolute, using the URI information of the resource. |
List<Object> |
getElements()
Get all elements.
|
URI |
getHref()
HREF attribute of the link.
|
String |
getRel()
REL attribute of the link.
|
String |
getType()
Type of destination resource.
|
void |
setHref(String uri)
Set HREF attribute of the link.
|
void |
setHref(URI uri)
Set HREF attribute of the link.
|
Link |
with(JaxbBundle bundle)
Add new JAXB bundle.
|
Link |
with(Object element)
Add new sub-element.
|
public Link()
You're not supposed to use this ctor (it is here just for compliance with JAXB implementations). Use other ctors instead.
public Link(@NotNull
String rname,
@NotNull
String link)
rname - The "rel" of itlink - The hrefpublic Link(@NotNull
String rname,
@NotNull
URI uri)
rname - The "rel" of ituri - The hrefpublic Link(@NotNull
String rname,
@NotNull
javax.ws.rs.core.UriBuilder builder)
rname - The "rel" of itbuilder - URI builder@NotNull public String getRel()
@NotNull public URI getHref()
@NotNull public String getType()
@NotNull public List<Object> getElements()
@NotNull public Link with(@NotNull Object element)
element - The sub-element to add@NotNull public Link with(@NotNull JaxbBundle bundle)
bundle - The bundle to addpublic void setHref(@NotNull
URI uri)
uri - The value of itpublic void setHref(@NotNull
String uri)
uri - The value of itpublic void attachTo(@NotNull
Resource res)
HREF attribute
absolute, using the URI information of the resource.res - The resource to attach toCopyright © 2011–2014 ReXSL.com. All rights reserved.