com.day.cq.wcm.core.contentfinder
Class DefaultViewHandler

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by org.apache.sling.api.servlets.SlingSafeMethodsServlet
          extended by org.apache.sling.api.servlets.SlingAllMethodsServlet
              extended by com.day.cq.commons.servlets.AbstractPredicateServlet
                  extended by com.day.cq.wcm.core.contentfinder.DefaultViewHandler
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class DefaultViewHandler
extends AbstractPredicateServlet

Servlet that returns search results for a given gql statement.

example statement:'path:/content About'

or url params:/bin/wcm/search/gql.json?query='path:/content type:"cq:Page" About'&pathPrefix=jcr:content

See Also:
Serialized Form

Nested Class Summary
protected  class DefaultViewHandler.GQLViewQuery
           
 class DefaultViewHandler.Hit
           
protected  class DefaultViewHandler.NodeIndexerViewQuery
           
static interface DefaultViewHandler.ViewQuery
           
 
Field Summary
static String COMMON_PATH_PREFIX
          Common path prefix
static String DEFAULT_NODE_TYPE
          Default node type
static String DEFAULT_START_PATH
          default start path
static String MIME
          mimeType clause
static String MIX_DAM_RESOURCE
          dam:Resource mixin nodetype
static String QUERY
          Query clause
protected  String startPath
          start path
 
Fields inherited from class com.day.cq.commons.servlets.AbstractPredicateServlet
FILTER_PARAM, PATH_PARAM, PREDICATE_PARAM
 
Constructor Summary
DefaultViewHandler()
           
 
Method Summary
protected  boolean doAdd(Node node, String type)
          Checks if a "result entry" has to be added to the final result set
protected  void doGet(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response, org.apache.commons.collections.Predicate predicate)
          Handles the HTTP GET method
protected  boolean isPageContent(Node node)
           
protected  List<DefaultViewHandler.Hit> order(Map<String,DefaultViewHandler.Hit> hits)
          It may happen that files/pages have the same modification date.
protected  long search(Session session, org.apache.sling.commons.json.io.JSONWriter writer, String queryString, List<String> searchAttr, String commonPathPrefix, String lastModified, boolean returnParent, int limit, String type)
          This method analyzes/prepares the passed gql statement and executes the search than.
 
Methods inherited from class com.day.cq.commons.servlets.AbstractPredicateServlet
doGet, getPredicate, selectorPredicateStart
 
Methods inherited from class org.apache.sling.api.servlets.SlingAllMethodsServlet
doDelete, doPost, doPut, getAllowedRequestMethods, isMethodValid, mayService
 
Methods inherited from class org.apache.sling.api.servlets.SlingSafeMethodsServlet
doGeneric, doHead, doOptions, doTrace, getServletInfo, handleMethodNotImplemented, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

QUERY

public static final String QUERY
Query clause

See Also:
Constant Field Values

MIME

public static final String MIME
mimeType clause

See Also:
Constant Field Values

COMMON_PATH_PREFIX

public static final String COMMON_PATH_PREFIX
Common path prefix

See Also:
Constant Field Values

DEFAULT_NODE_TYPE

public static final String DEFAULT_NODE_TYPE
Default node type

See Also:
Constant Field Values

MIX_DAM_RESOURCE

public static final String MIX_DAM_RESOURCE
dam:Resource mixin nodetype

See Also:
Constant Field Values

DEFAULT_START_PATH

public static final String DEFAULT_START_PATH
default start path

See Also:
Constant Field Values

startPath

protected String startPath
start path

Constructor Detail

DefaultViewHandler

public DefaultViewHandler()
Method Detail

doGet

protected void doGet(org.apache.sling.api.SlingHttpServletRequest request,
                     org.apache.sling.api.SlingHttpServletResponse response,
                     org.apache.commons.collections.Predicate predicate)
              throws javax.servlet.ServletException,
                     IOException
Description copied from class: AbstractPredicateServlet
Handles the HTTP GET method

Overrides:
doGet in class AbstractPredicateServlet
Parameters:
request - The HTTP request
response - The HTTP response
predicate - the predicate retrieved from the request
Throws:
javax.servlet.ServletException - if a servlet error occurs
IOException - if an I/O error occurs

search

protected long search(Session session,
                      org.apache.sling.commons.json.io.JSONWriter writer,
                      String queryString,
                      List<String> searchAttr,
                      String commonPathPrefix,
                      String lastModified,
                      boolean returnParent,
                      int limit,
                      String type)
               throws IOException,
                      org.apache.sling.commons.json.JSONException,
                      RepositoryException
This method analyzes/prepares the passed gql statement and executes the search than. the search results will be post processsed (filtered by node type, ordered) and finally written to the output.

Parameters:
session - jcr session
writer - writer used to output results
queryString - query string received from client
searchAttr - additional search attributes
commonPathPrefix - common path prefix
lastModified - name of last modified property
returnParent - specifies if the parent node has to be returned of each hit
limit - 0 means no limit
type - nodetype to filter
Returns:
number of hits
Throws:
IOException
org.apache.sling.commons.json.JSONException
RepositoryException

doAdd

protected boolean doAdd(Node node,
                        String type)
Checks if a "result entry" has to be added to the final result set

Parameters:
node - node to check
type - nodetype to match
Returns:
true if the node should be added to the result set

order

protected List<DefaultViewHandler.Hit> order(Map<String,DefaultViewHandler.Hit> hits)
                                      throws RepositoryException
It may happen that files/pages have the same modification date. if this is the case than it makes sense to order these results by path. that's what this method is supposed to do (at least needed for davids demo ;-)).

Parameters:
hits - "unordered" result list
Returns:
"ordered" list
Throws:
RepositoryException

isPageContent

protected boolean isPageContent(Node node)


Copyright © 2008 Day Management AG. All Rights Reserved.