T - Type of pageR - Type of JAX-RS resource@Loggable(value=1) public class BasePage<T extends BasePage<?,?>,R extends Resource> extends Object
Use it as a base class for your own page, for example:
public class MyBasePage extends BasePage<MyPage> {
@XmlAnyElement(lax = true)
@XmlElement
public String getUser() {
return "John Doe";
}
}
However, it is recommended to use append(Object) and
JaxbGroup/JaxbBundle instead of defining own methods
annotated with @XmlElement.
Don't forget to call init(Resource) right after the page is
built by PageBuilder, for example:
@Path("/")
public class MainRs extends BaseResource {
@GET
@Produces(MediaTypes.APPLICATION_XML)
public BasePage front() {
return new PageBuilder()
.stylesheet("/xsl/front.xsl")
.build(BasePage.class)
.init(this);
}
}
JAX-RS resource classes should implement Resource or even
extend BaseResource, which is preferred.
This class adds date and ip attributes to the page, and
links and millis element. Thus, an empty page (if you don't
append(Object) anything to it) will look like:
<?xml version="1.0" ?> <page date="2012-04-15T07:07Z" ip="127.0.0.1"> <links /> <millis>234</millis> </page>
This functionality is not changeable. If this is not what you need in your page - just don't use this class and create your own. However, we believe that the majority of web applications need this information in their XML pages.
The class is mutable and thread-safe.
PageBuilder,
Resource,
BaseResource| Constructor and Description |
|---|
BasePage() |
| Modifier and Type | Method and Description |
|---|---|
T |
append(Element element)
Append new DOM element.
|
T |
append(JaxbBundle bundle)
Add new element.
|
T |
append(Object element)
Append new element.
|
Date |
getDate()
Get date and time when this page is generated.
|
Collection<Object> |
getElements()
Get all elements.
|
String |
getIp()
Get IP address of the server.
|
Collection<Link> |
getLinks()
List of links.
|
long |
getMillis()
Get page generation time, in milliseconds.
|
R |
home()
Get home.
|
T |
init(R res)
Init it with Resource.
|
boolean |
isSsl()
Get SSL or non-SSL flag.
|
T |
link(Link link)
Add new HATEOAS link.
|
javax.ws.rs.core.Response.ResponseBuilder |
render()
Render it.
|
@NotNull public final T init(@NotNull R res)
res - The resource@NotNull public final javax.ws.rs.core.Response.ResponseBuilder render()
@NotNull public final T append(@NotNull Object element)
element - The element to append@NotNull public final T append(@NotNull Element element)
element - The element to append@NotNull public final T append(@NotNull JaxbBundle bundle)
bundle - The element@NotNull public final R home()
@NotNull public final T link(@NotNull Link link)
link - The link to add@NotNull public final Collection<Object> getElements()
public final Collection<Link> getLinks()
@NotNull public final String getIp()
@NotNull public final Date getDate()
public final boolean isSsl()
public final long getMillis()
Copyright © 2011–2014 ReXSL.com. All rights reserved.