public class AbstractListServlet extends AbstractPredicateServlet
AbstractListServlet provides base functionality such as
sorting and paging for servlets that feed Ext grids (like in the SiteAdmin)
with JSON.
Normally, the list of children of the addressed resource are returned.
Alternatively, the paging index of an item can be requested.| Modifier and Type | Class and Description |
|---|---|
static interface |
AbstractListServlet.ListItem
The
ListItem interface defines a sortable item of the list. |
class |
AbstractListServlet.ListItemComparator
The
ListItemComparator compares public fields of
AbstractListServlet.ListItems. |
| Modifier and Type | Field and Description |
|---|---|
protected Session |
admin |
protected static java.lang.String |
CONTENT_TYPE |
protected static java.lang.String |
DEFAULT_SORT_DIR |
protected static java.lang.String |
DEFAULT_SORT_KEY |
protected static java.lang.String |
DEFAULT_TIDY |
protected static java.lang.String |
ENCODING |
protected ListInfoProvider |
listInfoProvider |
static java.lang.String |
PAGE_INDEX
Parameter to use in conjunction with
PATH to determine the
paging index of an item. |
static java.lang.String |
PAGE_LIMIT
Parameter to specify the limit of items per page when using paging.
|
static java.lang.String |
PAGE_START
Parameter to specify the start index with when using paging.
|
static java.lang.String |
PATH
Parameter to use in conjunction with
PAGE_INDEX to determine the
paging index of an item. |
static java.lang.String |
PROP
Parameter to use to specify the name(s) of custom properties that should be
returned for each item in the list.
|
protected SlingRepository |
repository |
protected static long |
serialVersionUID |
static java.lang.String |
SORT_ASCENDING
Value to use for
SORT_DIR to use ascending order (default). |
static java.lang.String |
SORT_DESCENDING
Value to use for
SORT_DIR to use descending order. |
static java.lang.String |
SORT_DIR
Parameter to specify the direction to use for sorting.
|
static java.lang.String |
SORT_KEY
Parameter to specify which property use for sorting.
|
static java.lang.String |
TIDY
Parameter to use for tidy JSON.
|
FILTER_PARAM, PATH_PARAM, PREDICATE_PARAM| Constructor and Description |
|---|
AbstractListServlet() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
activate(ComponentContext context) |
protected java.util.List<AbstractListServlet.ListItem> |
applyPaging(SlingHttpServletRequest request,
java.util.List<AbstractListServlet.ListItem> items,
int total)
Applies paging to the list items if specified in the request.
|
protected java.util.List<AbstractListServlet.ListItem> |
applySorting(SlingHttpServletRequest request,
java.util.List<AbstractListServlet.ListItem> items)
Applies sorting to the list items if specified in the request.
|
protected void |
bindListInfoProvider(ServiceReference ref) |
protected void |
deactivate(ComponentContext context) |
protected void |
doGet(SlingHttpServletRequest request,
SlingHttpServletResponse response,
Predicate predicate)
Handles the HTTP GET method
|
protected java.text.Collator |
getCollator() |
protected java.util.List<AbstractListServlet.ListItem> |
getItems(SlingHttpServletRequest request,
Predicate predicate)
Returns the list items based on the specified request and predicate.
|
protected long |
getPagingIndex(SlingHttpServletRequest request,
java.util.List<AbstractListServlet.ListItem> items,
java.lang.String path)
Returns the paging index of the item with the specified path or
-1 if item not part of the specified items. |
protected java.util.List<AbstractListServlet.ListItem> |
processItems(SlingHttpServletRequest request,
java.util.List<AbstractListServlet.ListItem> items,
int total)
Processes the specified list items based on the request parameters.
|
protected void |
registerProvider(ServiceReference ref) |
protected void |
unbindListInfoProvider(ServiceReference ref) |
protected void |
write(SlingHttpServletRequest request,
SlingHttpServletResponse response,
java.util.List<AbstractListServlet.ListItem> listItems,
java.lang.String[] customProps,
int total)
Writes the list to a JSON writer.
|
protected void |
writeCustomProperties(JSONWriter out,
Resource resource,
java.lang.String[] customProps)
Writes the specified properties of the resource to the JSON writer.
|
protected void |
writeKey(JSONWriter out,
java.lang.String key,
java.lang.Object value)
Writes a key and its value to the specified JSON writer.
|
protected void |
writeOptionalDateKey(JSONWriter out,
java.lang.String key,
java.util.Calendar value)
Writes a key and its date value to the specified JSON writer.
|
protected void |
writeOptionalKey(JSONWriter out,
java.lang.String key,
java.lang.Object value)
Writes a key and its value to the specified JSON writer.
|
protected void |
writePagingIndex(SlingHttpServletRequest request,
SlingHttpServletResponse response,
java.util.List<AbstractListServlet.ListItem> listItems,
java.lang.String path)
Writes the paging index of the item with the specified path to a JSON writer.
|
doGet, getPredicate, selectorPredicateStartdoDelete, doPost, doPut, getAllowedRequestMethods, isMethodValid, mayServicedoGeneric, doHead, doOptions, doTrace, getServletInfo, handleMethodNotImplemented, service, serviceprotected static final long serialVersionUID
public static final java.lang.String TIDY
public static final java.lang.String PAGE_START
PAGE_LIMIT.
For the items of the page n, use a start index of
limit + (n - 1).public static final java.lang.String PAGE_LIMIT
PAGE_START.public static final java.lang.String SORT_KEY
public static final java.lang.String SORT_DIR
SORT_ASCENDING.public static final java.lang.String SORT_ASCENDING
SORT_DIR to use ascending order (default).public static final java.lang.String SORT_DESCENDING
SORT_DIR to use descending order.public static final java.lang.String PATH
PAGE_INDEX to determine the
paging index of an item. If both parameters are present, the paging
index of the item with the specified path will be returned instead of the
list of children.public static final java.lang.String PAGE_INDEX
PATH to determine the
paging index of an item. If this parameter is present, the paging
index of the item with the path specified in PATH will be returned
instead of the list of children.public static final java.lang.String PROP
protected static final java.lang.String DEFAULT_TIDY
protected static final java.lang.String DEFAULT_SORT_KEY
protected static final java.lang.String DEFAULT_SORT_DIR
protected static final java.lang.String CONTENT_TYPE
protected static final java.lang.String ENCODING
protected SlingRepository repository
protected ListInfoProvider listInfoProvider
protected Session admin
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response, Predicate predicate) throws ServletException, java.io.IOException
doGet in class AbstractPredicateServletrequest - The HTTP requestresponse - The HTTP responsepredicate - the predicate retrieved from the requestServletException - if a servlet error occursjava.io.IOException - if an I/O error occursprotected java.util.List<AbstractListServlet.ListItem> getItems(SlingHttpServletRequest request, Predicate predicate) throws java.lang.Exception
Resource provided by the request. The optional predicate
can be used for evaluation.request - The requestpredicate - The predicate (optional)java.lang.Exception - if unable to retrieve itemsprotected java.util.List<AbstractListServlet.ListItem> processItems(SlingHttpServletRequest request, java.util.List<AbstractListServlet.ListItem> items, int total)
request - The requestitems - The list itemstotal - The total number of list itemsapplySorting(SlingHttpServletRequest, List),
applyPaging(SlingHttpServletRequest, List, int)protected java.util.List<AbstractListServlet.ListItem> applySorting(SlingHttpServletRequest request, java.util.List<AbstractListServlet.ListItem> items)
request - The requestitems - The list itemsprotected java.util.List<AbstractListServlet.ListItem> applyPaging(SlingHttpServletRequest request, java.util.List<AbstractListServlet.ListItem> items, int total)
request - The requestitems - The list itemstotal - The total number of list itemsprotected long getPagingIndex(SlingHttpServletRequest request, java.util.List<AbstractListServlet.ListItem> items, java.lang.String path)
-1 if item not part of the specified items.request - The requestitems - The list itemspath - The path of the itemprotected void write(SlingHttpServletRequest request, SlingHttpServletResponse response, java.util.List<AbstractListServlet.ListItem> listItems, java.lang.String[] customProps, int total) throws java.lang.Exception
request - The requestresponse - The responselistItems - The list itemscustomProps - The names of the custom properties to includetotal - The total number of list itemsjava.lang.Exception - if unable to write the listprotected void writeKey(JSONWriter out, java.lang.String key, java.lang.Object value) throws JSONException
out - The JSONkey - The name of the keyvalue - The value of the keyJSONException - if unable to write the keyprotected void writeOptionalKey(JSONWriter out, java.lang.String key, java.lang.Object value) throws JSONException
null, the key is omitted.out - The JSONkey - The name of the keyvalue - The value of the keyJSONException - if unable to write the keyprotected void writeOptionalDateKey(JSONWriter out, java.lang.String key, java.util.Calendar value) throws JSONException
null, the key is omitted.out - The JSONkey - The name of the keyvalue - The date value of the keyJSONException - if unable to write the keyprotected void writeCustomProperties(JSONWriter out, Resource resource, java.lang.String[] customProps) throws JSONException
null, the key is omitted.out - The JSONresource - The resourcecustomProps - The propertiesJSONException - if unable to write the propertiesprotected void writePagingIndex(SlingHttpServletRequest request, SlingHttpServletResponse response, java.util.List<AbstractListServlet.ListItem> listItems, java.lang.String path) throws java.lang.Exception
request - The requestresponse - The responselistItems - The list itemspath - The path of the itemjava.lang.Exception - if unable to write the indexprotected void activate(ComponentContext context)
throws java.lang.Exception
java.lang.Exceptionprotected void deactivate(ComponentContext context)
protected void bindListInfoProvider(ServiceReference ref)
protected void unbindListInfoProvider(ServiceReference ref)
protected void registerProvider(ServiceReference ref)
protected java.text.Collator getCollator()