com.dotmarketing.viewtools.content
Class ContentTool

java.lang.Object
  extended by com.dotmarketing.viewtools.content.ContentTool
All Implemented Interfaces:
org.apache.velocity.tools.view.tools.ViewTool

public class ContentTool
extends java.lang.Object
implements org.apache.velocity.tools.view.tools.ViewTool

The purpose of this class is to provide a way to easily search and interact with content and dotcms objects surrounding content from the front end of dotCMS. Previously dotCMS relayed on many macros to do things like search for content but because of the overhead of Velocity this can cause load and performance issues in certain cases. This tool should provide a cleaner way to interact with content without needing to parse tons of objects in Velocity. The tool is mapped in Velocity as $dotcontent

Since:
1.9.3
Author:
Jason Tesser

Constructor Summary
ContentTool()
           
 
Method Summary
 long count(java.lang.String query)
          Use this method to return the number of contents which match a particular query.
 ContentMap find(java.lang.String inodeOrIdentifier)
          Will pull a single piece of content for you based on the inode or identifier.
 java.util.List<java.util.Map<java.lang.String,java.lang.String>> getMostViewedContent(java.lang.String structureVariableName, java.lang.String startDate, java.lang.String endDate)
          Gets the top viewed contents identifiers and numberOfViews for a particular structure for a specified date interval
 void init(java.lang.Object initData)
           
 PaginatedArrayList<ContentMap> pull(java.lang.String query, int offset, int limit, java.lang.String sort)
           
 java.util.List<ContentMap> pull(java.lang.String query, int limit, java.lang.String sort)
          Will return a ContentMap object which can be used on dotCMS front end.
 java.util.List<ContentMap> pull(java.lang.String query, java.lang.String limit, java.lang.String sort)
          Will return a ContentMap object which can be used on dotCMS front end.
 PaginatedArrayList<ContentMap> pullPagenated(java.lang.String query, int limit, int offset, java.lang.String sort)
          Will return a ContentMap object which can be used on dotCMS front end.
 PaginatedContentList<ContentMap> pullPerPage(java.lang.String query, int currentPage, int contentsPerPage, java.lang.String sort)
          Works just similar to the pullPagenated.
 java.util.List<ContentMap> pullRelated(java.lang.String relationshipName, java.lang.String contentletIdentifier, boolean pullParents, int limit)
          Will return a ContentMap object which can be used on dotCMS front end.
 java.util.List<ContentMap> pullRelated(java.lang.String relationshipName, java.lang.String contentletIdentifier, boolean pullParents, int limit, java.lang.String sort)
          Will return a ContentMap object which can be used on dotCMS front end.
 java.util.List<ContentMap> pullRelated(java.lang.String relationshipName, java.lang.String contentletIdentifier, java.lang.String condition, boolean pullParents, int limit, java.lang.String sort)
          Will return a ContentMap object which can be used on dotCMS front end.
 java.util.List<ContentletSearch> query(java.lang.String query, int limit)
          Will return a ContentSearch object which can be used on dotCMS front end.
 java.util.List<ContentletSearch> query(java.lang.String query, int limit, java.lang.String sort)
          Will return a ContentSearch object which can be used on dotCMS front end.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContentTool

public ContentTool()
Method Detail

init

public void init(java.lang.Object initData)
Specified by:
init in interface org.apache.velocity.tools.view.tools.ViewTool

find

public ContentMap find(java.lang.String inodeOrIdentifier)
Will pull a single piece of content for you based on the inode or identifier. It will always try to retrieve the live content unless in EDIT_MODE in the backend of dotCMS when passing in an identifier. If it is an inode this is ignored. Will return NULL if not found

Parameters:
inodeOrIdentifier - Can be either an Inode or Indentifier of content.
Returns:
NULL if not found

pull

public java.util.List<ContentMap> pull(java.lang.String query,
                                       java.lang.String limit,
                                       java.lang.String sort)
Will return a ContentMap object which can be used on dotCMS front end. This method is better then the old #pullcontent macro because it doesn't have to parse all the velocity content object that are returned. If you are building large pulls and depending on the types of fields on the content this can get expensive especially with large data sets.
EXAMPLE:
#foreach($con in $dotcontent.pull('+structureName:newsItem',5,'modDate desc'))
$con.headline
#end
Returns empty List if no results are found

Parameters:
query - - Lucene Query used to search for content - Will append live, working, deleted, and language if not passed
limit - 0 is the dotCMS max limit which is 10000. Becareful when searching for unlimited amount as all content will load into memory
sort - - Velocity variable name to sort by. this is a string and can contain multiple values "sort1 acs, sort2 desc"
Returns:
Returns empty List if no results are found

pull

public java.util.List<ContentMap> pull(java.lang.String query,
                                       int limit,
                                       java.lang.String sort)
Will return a ContentMap object which can be used on dotCMS front end. This method is better then the old #pullcontent macro because it doesn't have to parse all the velocity content object that are returned. If you are building large pulls and depending on the types of fields on the content this can get expensive especially with large data sets.
EXAMPLE:
#foreach($con in $dotcontent.pull('+structureName:newsItem',5,'modDate desc'))
$con.headline
#end
Returns empty List if no results are found

Parameters:
query - - Lucene Query used to search for content - Will append live, working, deleted, and language if not passed
limit - 0 is the dotCMS max limit which is 10000. Becareful when searching for unlimited amount as all content will load into memory
sort - - Velocity variable name to sort by. this is a string and can contain multiple values "sort1 acs, sort2 desc"
Returns:
Returns empty List if no results are found

pull

public PaginatedArrayList<ContentMap> pull(java.lang.String query,
                                           int offset,
                                           int limit,
                                           java.lang.String sort)

pullPagenated

public PaginatedArrayList<ContentMap> pullPagenated(java.lang.String query,
                                                    int limit,
                                                    int offset,
                                                    java.lang.String sort)
Will return a ContentMap object which can be used on dotCMS front end. This method is better then the old #pullcontent macro because it doesn't have to parse all the velocity content object that are returned. If you are building large pulls and depending on the types of fields on the content this can get expensive especially with large data sets.
EXAMPLE:
#foreach($con in $dotcontent.pullPagenated('+structureName:newsItem',20,20,'modDate desc'))
$con.headline
#end
Returns empty List if no results are found
there is a totalResults avialible to you on the returned list. $retList.totalResults

Parameters:
query - - Lucene Query used to search for content - Will append live, working, deleted, and language if not passed
limit - 0 is the dotCMS max limit which is 10000. Becareful when searching for unlimited amount as all content will load into memory
offset - offset to start the results from
sort - - Velocity variable name to sort by. this is a string and can contain multiple values "sort1 acs, sort2 desc"
Returns:
Returns empty List if no results are found

pullPerPage

public PaginatedContentList<ContentMap> pullPerPage(java.lang.String query,
                                                    int currentPage,
                                                    int contentsPerPage,
                                                    java.lang.String sort)
Works just similar to the pullPagenated. Will return a ContentMap object which can be used on dotCMS front end. This method is better then the old #pullcontent macro because it doesn't have to parse all the velocity content object that are returned. If you are building large pulls and depending on the types of fields on the content this can get expensive especially with large data sets.
EXAMPLE:
#set($pagedList = $dotcontent.pullPerPage("+structureName:webPageContent" ,20, 3, "modDate desc"))

$pagedList

$pagedList.previousPage


$pagedList.nextPage


$pagedList.totalPages


$pagedList.totalResults


#foreach($con in $pagedList)

$con.inode


$con.identifier


$con.title
#end
Returns empty List if no results are found The returned list is a PaginatedContentList which lets you get at the totalPages, nextPage, and previousPage, and totalResults as helpers ie.. $conlist.previousPage ...

Parameters:
query - - Lucene Query used to search for content - Will append live, working, deleted, and language if not passed
currentPage - Current page number for pagination the first page would be one.
contentsPerPage - Number of contentlets you are displaying per page
offset - offset to start the results from
sort - - Velocity variable name to sort by. this is a string and can contain multiple values "sort1 acs, sort2 desc"
Returns:
Returns empty List if no results are found

query

public java.util.List<ContentletSearch> query(java.lang.String query,
                                              int limit)
Will return a ContentSearch object which can be used on dotCMS front end. The method can be used to determine the inodes or identifiers which match a given query. It does NOT return actual content only the inodes and identifiers. An example use could be you need to know if a query matches at all. Lets say you want to know if a category is used at all within a given query this is the fastest way to figure it out as dotCMS doesn't have to put together the content itself.

Parameters:
query - - Lucene Query used to search for content - Will append live, working, deleted, and language if not passed
limit - 0 is the dotCMS max limit which is 10000.
Returns:

query

public java.util.List<ContentletSearch> query(java.lang.String query,
                                              int limit,
                                              java.lang.String sort)
Will return a ContentSearch object which can be used on dotCMS front end. The method can be used to determine the inodes or identifiers which match a given query. It does NOT return actual content only the inodes and identifiers. An example use could be you need to know if a query matches at all. Lets say you want to know if a category is used at all within a given query this is the fastest way to figure it out as dotCMS doesn't have to put together the content itself. Returns empty List if no results are found

Parameters:
query - - Lucene Query used to search for content - Will append live, working, deleted, and language if not passed
limit - 0 is the dotCMS max limit which is 10000.
sort - - Velocity variable name to sort by. this is a string and can contain multiple values "sort1 acs, sort2 desc"
Returns:
Returns empty List if no results are found

count

public long count(java.lang.String query)
Use this method to return the number of contents which match a particular query.

Parameters:
query - - Lucene Query used to search for content - Will append live, working, deleted, and language if not passed
Returns:

pullRelated

public java.util.List<ContentMap> pullRelated(java.lang.String relationshipName,
                                              java.lang.String contentletIdentifier,
                                              boolean pullParents,
                                              int limit)
Will return a ContentMap object which can be used on dotCMS front end. This method is better then the old #pullRelatedContent macro because it doesn't have to parse all the velocity content object that are returned. If you are building large pulls and depending on the types of fields on the content this can get expensive especially with large data sets.
EXAMPLE:
#foreach($con in $dotcontent.pullRelated('myRelationship','asbd-asd-asda-asd',false,5))
$con.title
#end
The method will figure out language, working and live for you. Returns empty List if no results are found

Parameters:
relationshipName - - Name of the relationship as defined in the structure.
contentletIdentifier - - Identifier of the contentlet
pullParents - Should the related pull be based on Parents or Children
limit - 0 is the dotCMS max limit which is 10000. Becareful when searching for unlimited amount as all content will load into memory
Returns:
Returns empty List if no results are found
Throws:
DotSecurityException
DotDataException

pullRelated

public java.util.List<ContentMap> pullRelated(java.lang.String relationshipName,
                                              java.lang.String contentletIdentifier,
                                              boolean pullParents,
                                              int limit,
                                              java.lang.String sort)
Will return a ContentMap object which can be used on dotCMS front end. This method is better then the old #pullRelatedContent macro because it doesn't have to parse all the velocity content object that are returned. If you are building large pulls and depending on the types of fields on the content this can get expensive especially with large data sets.
EXAMPLE:
#foreach($con in $dotcontent.pullRelated('myRelationship','asbd-asd-asda-asd',false,5,'modDate'))
$con.title
#end
The method will figure out language, working and live for you. Returns empty List if no results are found

Parameters:
relationshipName - - Name of the relationship as defined in the structure.
contentletIdentifier - - Identifier of the contentlet
pullParents - Should the related pull be based on Parents or Children
limit - 0 is the dotCMS max limit which is 10000. Becareful when searching for unlimited amount as all content will load into memory
sort - - Velocity variable name to sort by. this is a string and can contain multiple values "sort1 acs, sort2 desc". Can be Null
Returns:
Returns empty List if no results are found
Throws:
DotSecurityException
DotDataException

pullRelated

public java.util.List<ContentMap> pullRelated(java.lang.String relationshipName,
                                              java.lang.String contentletIdentifier,
                                              java.lang.String condition,
                                              boolean pullParents,
                                              int limit,
                                              java.lang.String sort)
Will return a ContentMap object which can be used on dotCMS front end. This method is better then the old #pullRelatedContent macro because it doesn't have to parse all the velocity content object that are returned. If you are building large pulls and depending on the types of fields on the content this can get expensive especially with large data sets.
EXAMPLE:
#foreach($con in $dotcontent.pullRelated('myRelationship','asbd-asd-asda-asd','+myField:someValue',false,5,'modDate desc'))
$con.title
#end
The method will figure out language, working and live for you if not passed in with the condition Returns empty List if no results are found

Parameters:
relationshipName - - Name of the relationship as defined in the structure.
contentletIdentifier - - Identifier of the contentlet
condition - - Extra conditions to add to the query. like +title:Some Title. Can be Null
pullParents - Should the related pull be based on Parents or Children
limit - 0 is the dotCMS max limit which is 10000. Becareful when searching for unlimited amount as all content will load into memory
sort - - Velocity variable name to sort by. this is a string and can contain multiple values "sort1 acs, sort2 desc". Can be Null
Returns:
Returns empty List if no results are found
Throws:
DotSecurityException
DotDataException

getMostViewedContent

public java.util.List<java.util.Map<java.lang.String,java.lang.String>> getMostViewedContent(java.lang.String structureVariableName,
                                                                                             java.lang.String startDate,
                                                                                             java.lang.String endDate)
Gets the top viewed contents identifiers and numberOfViews for a particular structure for a specified date interval

Parameters:
structureVariableName -
startDate -
endDate -
user -
Returns:


Copyright © 2013 dotCMS Inc. All Rights Reserved.