com.rexsl.page
Class PageBuilder

java.lang.Object
  extended by com.rexsl.page.PageBuilder

public final class PageBuilder
extends Object

Page builder.

First, you should create a base class, which will be used by all pages. (they all will inherit it). The base class should be JAXB annotated, for example:

 @XmlRootElement(name = "page")
 public class MyPage extends BasePage {
   public String title;
   public BasePage title(String text) {
     this.title = text;
   }
   @XmlElement
   public String getTitle() {
     return this.title;
   }
 }
 

Then, in JAX-RS resource you instantiate and extend this class with application/request specific content (we think that suffix Rs is a good notation for all JAX-RS resources):

 @Path("/")
 public class MainRs {
   @GET
   @Produces(MediaTypes.APPLICATION_XML)
   public MyPage front() {
     return new PageBuilder()
       .stylesheet("/xsl/front.xsl")
       .build(MyPage.class)
       .append(new JaxbBundle("score", 2))
       .title("Hello, world!");
   }
 }
 

That's it. The XML produced by JAX-RS and JAXB will look like:

 <?xml version="1.0" ?>
 <?xml-stylesheet type='text/xsl' href='/xsl/front.xsl'?>
 <page>
   <score>2</score>
   <title>Hello, world!</title>
 </page>
 

We recommend to extend BasePage, since it already implements a few most popular and necessary methods and properties.

The class is mutable and thread-safe.

Since:
0.3.7
Version:
$Id: PageBuilder.java 1758 2012-05-28 14:51:16Z guard $
Author:
Yegor Bugayenko (yegor@rexsl.com)
See Also:
BasePage, JaxbGroup, JaxbBundle

Constructor Summary
PageBuilder()
           
 
Method Summary
<T> T
build(Class<T> base)
          Create new class.
 PageBuilder schema(String name)
          Configure the schema to be used.
 PageBuilder stylesheet(String uri)
          Configure the stylesheet to be used.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PageBuilder

public PageBuilder()
Method Detail

stylesheet

public PageBuilder stylesheet(@NotNull
                              String uri)
Configure the stylesheet to be used.

Parameters:
uri - The URI of the stylesheet
Returns:
This object

schema

public PageBuilder schema(@NotNull
                          String name)
Configure the schema to be used.

Parameters:
name - Name of schema
Returns:
This object

build

public <T> T build(@NotNull
                   Class<T> base)
Create new class.

Type Parameters:
T - The type of result expected
Parameters:
base - Parent class, which will be inherited
Returns:
The instance of the class just created


Copyright © 2011-2012 ReXSL.com. All Rights Reserved.