mcardle 2005/06/01 19:20:19 CEST
Modified files:
src/view/jsp/include box_newslast5.inc
Added files:
src/view/jsp/include box_newslast5_cached.inc
Log:
Support for site wide caching of news5last views using jakarta caching tags
Revision Changes Path
1.2 +98 -323
corporate_portal_templates/src/view/jsp/include/box_newslast5.inc
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/corporate_portal_templates/src/view/jsp/include/box_newslast5.inc.diff?r1=1.1&r2=1.2&f=h
1.1 +337 -0
corporate_portal_templates/src/view/jsp/include/box_newslast5_cached.inc (new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/corporate_portal_templates/src/view/jsp/include/box_newslast5_cached.inc?rev=1.1&content-type=text/plain
Index: box_newslast5_cached.inc
====================================================================
<br>
<%
//Note: the variable 'id' is the current column number where this code is
executed i.e. 1, 2 or 3
//Containers Definitions over which to search/filter/sort over
String[] newsContainerDefNames = new
String[]{"newsContainer1","newsContainer2","newsContainer3","newsContainerLast5"+id};
//The (optional) search string to search for entered by the user
String userQueryString =
request.getParameter(JahiaSearchConstant.CLIST_SEARCHQUERY_INPUT_PREFIX +
"newsContainerLast5"+id); //i.e. clistsquery_newsContainerLast5
//Toggle to search using Jahia only or the Lucene search index
boolean useLucene = false;
//Get current time
TimeZone tz = TimeZone.getTimeZone("UTC");
Calendar cal = Calendar.getInstance(tz);
Date nowDate = cal.getTime();
long nowLong = nowDate.getTime();
//----------------------------------------------------------------------------------
//BEGIN - DO FILTERING
//----------------------------------------------------------------------------------
//list of container filter beans
Vector cFilterBeans = new Vector();
//holds logically combined filter beans
ContainerChainedFilter allfilters = null;
//In live mode, create filters to return news entries without empty titles
//These correspond to news entries in other languages.
//Even if we don't include these filters, these entries in the current
locale still won't be displayed
//but the pagination includes them and this distorts item numbering.
//so for the pagination not to be messed up, we include the following
filters
if (! jData.gui().isEditMode()) {
//Get rid of news entries with blank titles in Normal Mode
//These will correspond to entries not translated for the user's
locale
ContainerFilterBean containerFilter1 = new
ContainerFilterBean("newsTitle", jParams.getEntryLoadRequest());
containerFilter1.addClause(ContainerFilterBean.COMP_NOT_EQUAL,"");
allfilters = new ContainerChainedFilter(
new ContainerFilterInterface[]{containerFilter1},
new int[]{});
//Check the news has valid dates
containerFilter1 = new ContainerFilterBean("newsStartDate",true,
jParams.getEntryLoadRequest());
containerFilter1.addClause(ContainerFilterBean.COMP_SMALLER_OR_EQUAL,String.valueOf(nowLong));
//IF the date isn't in the range, then it might also be because there
is no date declared
//in which case we don't want to filter out news entries with empty
dates
ContainerFilterBean containerFilter2 = new
ContainerFilterBean("newsStartDate", jParams.getEntryLoadRequest());
containerFilter2.addClause(ContainerFilterBean.COMP_EQUAL,"");
ContainerChainedFilter allNewsStartDateFilters = new
ContainerChainedFilter(
new ContainerFilterInterface[]{containerFilter1,containerFilter2},
new int[]{ContainerChainedFilter.OR} );
allfilters = new ContainerChainedFilter(
new ContainerFilterInterface[]{allfilters,allNewsStartDateFilters},
new int[]{ContainerChainedFilter.AND} );
containerFilter1 = new ContainerFilterBean("newsEndDate",true,
jParams.getEntryLoadRequest());
containerFilter1.addClause(ContainerFilterBean.COMP_BIGGER_OR_EQUAL,String.valueOf(nowLong));
//IF the date isn't in the range, then it might also be because there
is no date declared
//in which case we don't want to filter out news entries with empty
dates
containerFilter2 = new ContainerFilterBean("newsEndDate",
jParams.getEntryLoadRequest());
containerFilter2.addClause(ContainerFilterBean.COMP_EQUAL,"");
ContainerChainedFilter allNewsEndDateFilters = new
ContainerChainedFilter(
new ContainerFilterInterface[]{containerFilter1,containerFilter2},
new int[]{ContainerChainedFilter.OR} );
allfilters = new ContainerChainedFilter(
new ContainerFilterInterface[]{allfilters,allNewsEndDateFilters},
new int[]{ContainerChainedFilter.AND} );
}
//Use Jahia for the search (i.e. a database query) instead of Lucene
//Note userQueryString text searches are not supported here
if (!useLucene) {
//search for all containers of any definition name defined in
'newsContainerDefNames'
ContainerFilterByContainerDefinitions defFilter = new
ContainerFilterByContainerDefinitions(
newsContainerDefNames,jParams.getEntryLoadRequest());
if (allfilters!=null)
allfilters = new ContainerChainedFilter(new
ContainerFilterInterface[]{allfilters,defFilter},new
int[]{ContainerChainedFilter.AND});
else
allfilters = new ContainerChainedFilter(new
ContainerFilterInterface[]{defFilter},
new int[]{});
//ContainerChainedFilter.OR);
}
if (allfilters!=null) {
Vector filterBeans = new Vector();
filterBeans.add(allfilters);
ContainerFilters containerFilters = new ContainerFilters(filterBeans,
searchScopeVal, null);//null means it searches over all container lists
// Store the list of filters in the request object.
// It will be used later by the container list loader.
request.setAttribute("newsContainerLast5"+id+"_filter_handler",containerFilters);
}
//----------------------------------------------------------------------------------
//END - DO FILTERING
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
//BEGIN - DO LUCENE SEARCH
//----------------------------------------------------------------------------------
if (useLucene) {
StringBuffer luceneSearchString = new StringBuffer("");
//include the user's search string if any
if (userQueryString!=null && !"".equals(userQueryString.trim())) {
luceneSearchString.append( "( ");
luceneSearchString.append(userQueryString);
luceneSearchString.append(" AND ");
}
//manually limit the search to news containers only
luceneSearchString.append("(container_definition_name:newsContainer1
OR container_definition_name:newsContainer2"+
" OR container_definition_name:newsContainer3 OR
container_definition_name:newsContainerLast5"+id+" )");
if (userQueryString!=null && !"".equals(userQueryString.trim())) {
luceneSearchString.append(" ) ");
}
//we use null for the second 'String containerDefinitionName'
argument since we have already manually
//specified above, not one but a SERIES of container definitionS to
search over.
ContainerSearcher containerTaglibSearcher = new
ContainerSearcher(searchScopeVal,
null,luceneSearchString.toString(),jParams.getEntryLoadRequest());
// Store the list of filters in the lucene search handler.
// It will be used later by the container list loader.
request.setAttribute("newsContainerLast5"+id+"_search_handler",containerTaglibSearcher);
}
//----------------------------------------------------------------------------------
//END - DO LUCENE SEARCH
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
//BEGIN - DO SORTING
//----------------------------------------------------------------------------------
//initialize multi-fieldname sorter
ContainerSorterByContainerDefinition newsContainerLast5_sort_handler =
new ContainerSorterByContainerDefinition(searchScopeVal,newsSort,
newsContainerDefNames
,numberSort, null, jParams.getEntryLoadRequest());
if ( "desc".equals(newsSortOrder) )
newsContainerLast5_sort_handler.setDescOrdering();
// Store the sort handler in the request object.
// It will be used later by the container list loader.
request.setAttribute("newsContainerLast5"+id+"_sort_handler",newsContainerLast5_sort_handler);
//----------------------------------------------------------------------------------
//END - DO SORTING
//----------------------------------------------------------------------------------
JahiaContainerList newsContainerList =
jData.containers().getContainerList( "newsContainerLast5"+id );
newsContainerList.setIsContainersLoaded(false);
//Make sure newsContainerList is initialized
if ( newsContainerList !=null && newsContainerList.getID()==0 ) {
ContainerListBean newsContainerListBean = new
ContainerListBean(newsContainerList,jParams);
org.jahia.registries.ServicesRegistry.getInstance().getJahiaContainersService().
saveContainerListInfo(newsContainerList,
jParams.getContentPage().getAclID());
newsContainerList = newsContainerListBean.getJahiaContainerList();
}
%>
<jahia:jahiaPageForm name="jahiapageform">
<%-- content:containerList name='<%="newsContainerLast5"+id%>'
id='newsContainerListTaglib' windowSize="<%=selWindowSize%>" --%>
<jahia:containerList name='<%="newsContainerLast5"+id%>'
title='newsContainerListTaglib' windowSize="<%=selWindowSize%>" >
<%//----------------------------------------------------------------------------------------------------------------------
%>
<%// START - PAGINATION
INFO %>
<%//----------------------------------------------------------------------------------------------------------------------
%>
<jahia:cListPaginationCurrentPageScrollingValue valueOnly="false" />
<table border="0">
<%
//text search is only available when using Lucene
if (useLucene) { %>
<tr>
<td nowrap="nowrap" valign="top" align="left"><b><jahia:resourceBundle
resourceBundle="jahiatemplates.Corporate_portal_templates"
resourceName="search"/> : </b></td>
<td valign="top" align="left">
<input type="text" name="<jahia:ctnListSQueryInputName/>"
value="<jahia:ctnListSQueryInputValue/>" size="25"/> <a
href="javascript:document.jahiapageform.submit()"><img
src="<jahia:contextURL/>/images/search.gif" alt="" width="15" height="15"
border="0" align="middle"/></a>
</td>
</tr>
<% } %>
<tr>
<td nowrap="nowrap" align="left" valign="top"><b><jahia:resourceBundle
resourceBundle="jahiatemplates.Corporate_portal_templates"
resourceName="result"/> : </b></td>
<td width="100%" align="left" valign="top">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top" style="white-space: nowrap;">
<select class="text"
name='<%="newsContainerLast5"+id%>_windowsize'
onChange="javascript:document.jahiapageform.submit()">
<option value="5" <% if
(selWindowSize.equals("5")){%>selected<% }%>>5</option>
<option value="10" <% if
(selWindowSize.equals("10")){%>selected<% }%>>10</option>
<option value="20" <% if
(selWindowSize.equals("20")){%>selected<% }%>>20</option>
</select> Items/Page
<br/><font size="2">[<jahia:cListPaginationFirstItemIndex />
- <jahia:cListPaginationLastItemIndex />] <jahia:resourceBundle
resourceBundle="jahiatemplates.Corporate_portal_templates" resourceName="of"/>
<jahia:cListPaginationTotalSize /></font>
</td>
<td align="right" valign="top" width="100%">
<jahia:previousWindowButton title='<%="<<" +
getResourceBundle("previousResults","previousResults",jData)%>' method="post"
formName="jahiapageform" />
<jahia:cListPagination nbStepPerPage="10"
><jahia:cListPaginationPreviousRangeOfPages method="post"
formName="jahiapageform" title=" .. "/>
<jahia:ifCListPaginationCurrentPage><b></jahia:ifCListPaginationCurrentPage>
<jahia:cListPaginationPageUrl method="post"
formName="jahiapageform" />
<jahia:ifCListPaginationCurrentPage></b>
</jahia:ifCListPaginationCurrentPage>
<jahia:cListPaginationNextRangeOfPages method="post"
formName="jahiapageform" title=" .. "/></jahia:cListPagination>
<jahia:nextWindowButton
title='<%=getResourceBundle("nextResults","nextResults",jData) + ">>"%>'
method="post" formName="jahiapageform" />
</td>
</tr>
</table>
</td>
</tr>
<%//----------------------------------------------------------------------------------------------------------------------
%>
<%// END - PAGINATION INFO
%>
<%//----------------------------------------------------------------------------------------------------------------------
%>
<tr>
<td nowrap="nowrap" valign="top" align="left"><b>Scope : </b></td>
<td valign="top" align="left">
<input type="radio" name="searchScope" value="currentSite" <%
if ( searchScopeVal!=-1 ){%>checked<% }%>
onchange="javascript:document.jahiapageform.submit()" >
Current site only
<br/>
<input type="radio" name="searchScope" value="allSites" <% if
( searchScopeVal==-1 ){%>checked<% }%>
onchange="javascript:document.jahiapageform.submit()"> All sites
</td>
</tr>
<%//----------------------------------------------------------------------------------------------------------------------
%>
<%// START - SORT ORDER
%>
<%//----------------------------------------------------------------------------------------------------------------------
%>
<% if (jData.gui().isEditMode()) { %>
<tr align="center"> ---> <b>Filtering Disabled</b> <--- </tr>
<% } %>
<tr>
<td nowrap="nowrap" align="left" valign="top"><b>Sort by :</b></td>
<td width="100%" align="left" valign="top">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<a href="javascript:<%
%>document.jahiapageform.<%="newsContainerLast5"+id%>_sort.value='newsStartDate';<%
%>document.jahiapageform.<%="newsContainerLast5"+id%>_sort_order.value=<%
if (newsSortOrder.equals("asc")){%>'desc'<%} else
{%>'asc'<%}
%>;document.jahiapageform.submit();" title="Select or
toggle Start Date sort order">
<%if (newsSortReq.equals("newsStartDate")) {%><b>Start
Date</b><%} else {%>Start Date<%}%>
<img
src="<%=theURL%>/images/sort_desc.gif" alt="sort"
border="0" width="5" height="7"/><img
src="<%=theURL%>/images/sort_asc.gif" alt=""
border="0" width="5" height="7"/></a>
<a href="javascript:<%
%>document.jahiapageform.<%="newsContainerLast5"+id%>_sort.value='newsEndDate';<%
%>document.jahiapageform.<%="newsContainerLast5"+id%>_sort_order.value=<%
if (newsSortOrder.equals("asc")){%>'desc'<%} else
{%>'asc'<%}
%>;document.jahiapageform.submit();" title="Select or
toggle End Date sort order">
<%if (newsSortReq.equals("newsEndDate")) {%><b>End
Date</b><%} else {%>End Date<%}%>
<img
src="<%=theURL%>/images/sort_desc.gif" alt="sort"
border="0" width="5" height="7"/><img
src="<%=theURL%>/images/sort_asc.gif" alt=""
border="0" width="5" height="7"/></a>
<a href="javascript:<%
%>document.jahiapageform.<%="newsContainerLast5"+id%>_sort.value='newsTitle';<%
%>document.jahiapageform.<%="newsContainerLast5"+id%>_sort_order.value=<%
if (newsSortOrder.equals("asc")){%>'desc'<%} else
{%>'asc'<%}
%>;document.jahiapageform.submit();" title="Select or
toggle Title sort order">
<%if (newsSortReq.equals("newsTitle")) {%><b>Title</b><%}
else {%>Title<%}%>
<img
src="<%=theURL%>/images/sort_desc.gif" alt="sort"
border="0" width="5" height="7"/><img
src="<%=theURL%>/images/sort_asc.gif" alt=""
border="0" width="5" height="7"/></a>
</table>
</tr>
<%//----------------------------------------------------------------------------------------------------------------------
%>
<%// END - SORT ORDER
%>
<%//----------------------------------------------------------------------------------------------------------------------
%>
</table>
<input type="hidden" name='<%="newsContainerLast5"+id%>_sort'
value="<%=newsSortReq%>"/>
<input type="hidden" name='<%="newsContainerLast5"+id%>_sort_order'
value="<%=newsSortOrder%>"/>
</jahia:containerList>
</jahia:jahiaPageForm>
<%
//----------------------------------------------------------------------------------------------------------------------
// START - DISPLAY NEWS
ENTRIES
//----------------------------------------------------------------------------------------------------------------------
Enumeration newsEnumeration = newsContainerList.getContainers();
int newsCount=0;
long cacheExpirationDelay = Long.MAX_VALUE;
while (newsEnumeration.hasMoreElements()) {
newsCount++;
if (newsCount == 1){
%><table border="0" cellpadding="0" cellspacing="0"><%
}
JahiaContainer newsContainer =
(JahiaContainer)newsEnumeration.nextElement();
//Retrieve the current fieldname postfix for the current container
String newsTitle = newsContainer.getFieldValue("newsTitle" , "", true ,
jData.params());
String newsDesc = newsContainer.getFieldValue("newsDesc" , "", true ,
jData.params());
JahiaPage myNewsLink = (JahiaPage)
newsContainer.getFieldObject("newsLink" );
String newsDate = (String) newsContainer.getFieldValue("newsStartDate"
,"");
String newsValidDate = (String) newsContainer.getFieldValue("newsEndDate"
,"");
String newsStartDateStr = (String)
newsContainer.getFieldObject("newsStartDate");
String newsEndDateStr = (String)
newsContainer.getFieldObject("newsEndDate" );
ContainerBean newsContainerBean = new
ContainerBean(newsContainer,jData.params());
jData.gui().html().drawBeginActionMenu(newsContainerBean , null, null,
true, "", "jahiatemplates.Corporate_portal_templates", null, out);
%><span class="bold"><%=newsTitle%></span><br><%
if (! "".equals(newsDate)){
%><i>Posted on the <%=newsDate%></i><br/><%
}
if (! "".equals(newsValidDate)){
%><i>Valid until the <%=newsValidDate%></i><br/><%
}
%><%=newsDesc%><br/><%
if (myNewsLink != null){
%><a
href="<%=myNewsLink.getUrl(jData.params())%>"><%=myNewsLink.getTitle()%></a><br><%
}
%><br/><br/><%
jData.gui().html().drawEndActionMenu(newsContainerBean , null, null,
true, "", "jahiatemplates.Corporate_portal_templates", null, out);
}
if (newsCount >0){
%></table><%
} else {
%><content:resourceBundle
resourceBundle="jahiatemplates.Corporate_portal_templates"
resourceName="noNews"/><br/><%
}
ContainerListBean newsContainerListBean = new
ContainerListBean(newsContainerList,jData.params());
jData.gui().html().drawBeginActionMenu(newsContainerListBean , null, theURL +
"/images/add.gif", false, "", "jahiatemplates.Corporate_portal_templates",
"addNew", out);
//----------------------------------------------------------------------------------------------------------------------
// END - DISPLAY NEWS
ENTRIES
//----------------------------------------------------------------------------------------------------------------------
%>
Index: box_newslast5.inc
===================================================================
RCS file:
/home/cvs/repository/corporate_portal_templates/src/view/jsp/include/box_newslast5.inc,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- box_newslast5.inc 31 May 2005 16:22:02 -0000 1.1
+++ box_newslast5.inc 1 Jun 2005 17:20:18 -0000 1.2
@@ -1,20 +1,33 @@
-<br>
- <%
- //Note: the variable 'id' is the current column number where this code
is executed i.e. 1, 2 or 3
-
- //Containers Definitions over which to search/filter/sort over
- String[] newsContainerDefNames = new
String[]{"newsContainer1","newsContainer2","newsContainer3","newsContainerLast5"+id};
- //The (optional) search string to search for entered by the user
- String userQueryString =
request.getParameter(JahiaSearchConstant.CLIST_SEARCHQUERY_INPUT_PREFIX +
"newsContainerLast5"+id); //i.e. clistsquery_newsContainerLast5
-
- //Toggle to search using Jahia only or the Lucene search index
- boolean useLucene = false;
-
- //Get current time
- TimeZone tz = TimeZone.getTimeZone("UTC");
- Calendar cal = Calendar.getInstance(tz);
- Date nowDate = cal.getTime();
- long nowLong = nowDate.getTime();
+<%
//------------------------------------------------------------------------ %>
+<% // Caches newslast5 box in Edit Mode using Apache Cache Taglib
%>
+<% // (http://jakarta.apache.org/taglibs/doc/cache-doc/)
%>
+<%
//------------------------------------------------------------------------ %>
+
+<% /*------------------------------------------------------------------------
+The box is cached into the "newslast5" cache where each cache entry is saved
+under its own keys. This key is formed of all the current viewing settings
for
+the current box such as the sort order, or the current pagination position.
+Since the cache is set to an application wide scope, it will allow cache
entries
+to be shared between users and news5last boxes across the site with the same
+box_news5last viewing settings across the whole site.
+
+Although the cache has an application wide scope, it won't share entries
across
+sites since we include the siteID in the cache entry key. This behaviour can
be
+changed by removing the siteID.
+
+You can change the size of the cache from the default 64Kb using the
+CacheUtil.setCacheSize() method. Please refer to
+(http://jakarta.apache.org/taglibs/doc/cache-doc/) for more details.
+ ------------------------------------------------------------------------
*/
+%>
+
+
+<%@ taglib uri="http://jakarta.apache.org/taglibs/cache-1.0" prefix="cache"
%>
+<%@ page import="org.apache.taglibs.cache.*" %>
+
+<%
+ //We first need to retrieve all elements forming the cache entry key
+ //(which are also used in box_newslast5.inc)
//----------------------------------------------------------------------------------
//BEGIN - SEARCH SCOPE
@@ -61,124 +74,10 @@
//END - SEARCH SCOPE
//----------------------------------------------------------------------------------
-
//----------------------------------------------------------------------------------
- //BEGIN - DO FILTERING
-
//----------------------------------------------------------------------------------
- //list of container filter beans
- Vector cFilterBeans = new Vector();
- //holds logically combined filter beans
- ContainerChainedFilter allfilters = null;
-
- //In live mode, create filters to return news entries without empty
titles
- //These correspond to news entries in other languages.
- //Even if we don't include these filters, these entries in the current
locale still won't be displayed
- //but the pagination includes them and this distorts item numbering.
- //so for the pagination not to be messed up, we include the following
filters
- if (! jData.gui().isEditMode()) {
- //Get rid of news entries with blank titles in Normal Mode
- //These will correspond to entries not translated for the user's
locale
- ContainerFilterBean containerFilter1 = new
ContainerFilterBean("newsTitle", jParams.getEntryLoadRequest());
- containerFilter1.addClause(ContainerFilterBean.COMP_NOT_EQUAL,"");
-
- allfilters = new ContainerChainedFilter(
- new ContainerFilterInterface[]{containerFilter1},
- new int[]{});
-
- //Check the news has valid dates
- containerFilter1 = new ContainerFilterBean("newsStartDate",true,
jParams.getEntryLoadRequest());
-
containerFilter1.addClause(ContainerFilterBean.COMP_SMALLER_OR_EQUAL,String.valueOf(nowLong));
-
- //IF the date isn't in the range, then it might also be because
there is no date declared
- //in which case we don't want to filter out news entries with empty
dates
- ContainerFilterBean containerFilter2 = new
ContainerFilterBean("newsStartDate", jParams.getEntryLoadRequest());
- containerFilter2.addClause(ContainerFilterBean.COMP_EQUAL,"");
-
- ContainerChainedFilter allNewsStartDateFilters = new
ContainerChainedFilter(
- new ContainerFilterInterface[]{containerFilter1,containerFilter2},
- new int[]{ContainerChainedFilter.OR} );
-
- allfilters = new ContainerChainedFilter(
- new ContainerFilterInterface[]{allfilters,allNewsStartDateFilters},
- new int[]{ContainerChainedFilter.AND} );
-
- containerFilter1 = new ContainerFilterBean("newsEndDate",true,
jParams.getEntryLoadRequest());
-
containerFilter1.addClause(ContainerFilterBean.COMP_BIGGER_OR_EQUAL,String.valueOf(nowLong));
-
- //IF the date isn't in the range, then it might also be because
there is no date declared
- //in which case we don't want to filter out news entries with empty
dates
- containerFilter2 = new ContainerFilterBean("newsEndDate",
jParams.getEntryLoadRequest());
- containerFilter2.addClause(ContainerFilterBean.COMP_EQUAL,"");
-
- ContainerChainedFilter allNewsEndDateFilters = new
ContainerChainedFilter(
- new ContainerFilterInterface[]{containerFilter1,containerFilter2},
- new int[]{ContainerChainedFilter.OR} );
-
- allfilters = new ContainerChainedFilter(
- new ContainerFilterInterface[]{allfilters,allNewsEndDateFilters},
- new int[]{ContainerChainedFilter.AND} );
- }
- //Use Jahia for the search (i.e. a database query) instead of Lucene
- //Note userQueryString text searches are not supported here
- if (!useLucene) {
- //search for all containers of any definition name defined in
'newsContainerDefNames'
- ContainerFilterByContainerDefinitions defFilter = new
ContainerFilterByContainerDefinitions(
- newsContainerDefNames,jParams.getEntryLoadRequest());
-
- if (allfilters!=null)
- allfilters = new ContainerChainedFilter(new
ContainerFilterInterface[]{allfilters,defFilter},new
int[]{ContainerChainedFilter.AND});
- else
- allfilters = new ContainerChainedFilter(new
ContainerFilterInterface[]{defFilter},
- new int[]{});
- //ContainerChainedFilter.OR);
- }
- if (allfilters!=null) {
- Vector filterBeans = new Vector();
- filterBeans.add(allfilters);
- ContainerFilters containerFilters = new
ContainerFilters(filterBeans, searchScopeVal, null);//null means it searches
over all container lists
-
- // Store the list of filters in the request object.
- // It will be used later by the container list loader.
-
request.setAttribute("newsContainerLast5"+id+"_filter_handler",containerFilters);
- }
-
//----------------------------------------------------------------------------------
- //END - DO FILTERING
-
//----------------------------------------------------------------------------------
-
-
//----------------------------------------------------------------------------------
- //BEGIN - DO LUCENE SEARCH
-
//----------------------------------------------------------------------------------
- if (useLucene) {
- StringBuffer luceneSearchString = new StringBuffer("");
-
- //include the user's search string if any
- if (userQueryString!=null && !"".equals(userQueryString.trim())) {
- luceneSearchString.append( "( ");
- luceneSearchString.append(userQueryString);
- luceneSearchString.append(" AND ");
- }
- //manually limit the search to news containers only
- luceneSearchString.append("(container_definition_name:newsContainer1
OR container_definition_name:newsContainer2"+
- " OR container_definition_name:newsContainer3 OR
container_definition_name:newsContainerLast5"+id+" )");
- if (userQueryString!=null && !"".equals(userQueryString.trim())) {
- luceneSearchString.append(" ) ");
- }
- //we use null for the second 'String containerDefinitionName'
argument since we have already manually
- //specified above, not one but a SERIES of container definitionS to
search over.
- ContainerSearcher containerTaglibSearcher = new
ContainerSearcher(searchScopeVal,
- null,luceneSearchString.toString(),jParams.getEntryLoadRequest());
-
- // Store the list of filters in the lucene search handler.
- // It will be used later by the container list loader.
-
request.setAttribute("newsContainerLast5"+id+"_search_handler",containerTaglibSearcher);
- }
-
//----------------------------------------------------------------------------------
- //END - DO LUCENE SEARCH
-
//----------------------------------------------------------------------------------
-
-
//----------------------------------------------------------------------------------
- //BEGIN - DO SORTING
+
//----------------------------------------------------------------------------------
+ //BEGIN - SORTING
//----------------------------------------------------------------------------------
//holds field names to sort over
String newsSort[] = null;
@@ -204,26 +103,17 @@
}
else logger.error("Unexpected value of newsSortReq :" + newsSortReq);
- //initialize multi-fieldname sorter
- ContainerSorterByContainerDefinition newsContainerLast5_sort_handler =
- new ContainerSorterByContainerDefinition(searchScopeVal,newsSort,
newsContainerDefNames
- ,numberSort, null, jParams.getEntryLoadRequest());
-
- //retrieve the sort order i.e. descending or ascending
+ //retrieve the sort order i.e. descending or ascending
String newsSortOrder =
request.getParameter("newsContainerLast5"+id+"_sort_order");
if (newsSortOrder==null || newsSortOrder.trim().equals("") )
newsSortOrder = "desc";
- if ( "desc".equals(newsSortOrder) )
- newsContainerLast5_sort_handler.setDescOrdering();
- // Store the sort handler in the request object.
- // It will be used later by the container list loader.
-
request.setAttribute("newsContainerLast5"+id+"_sort_handler",newsContainerLast5_sort_handler);
//----------------------------------------------------------------------------------
- //END - DO SORTING
+ //END - SORTING
//----------------------------------------------------------------------------------
-
//----------------------------------------------------------------------------------
+
+
//----------------------------------------------------------------------------------
//BEGIN - PAGINATION
//----------------------------------------------------------------------------------
//Selected pagination window size
@@ -258,192 +148,77 @@
jParams.getUser().setProperty (key, selWindowSize);
}
}
-
//----------------------------------------------------------------------------------
//END - PAGINATION
//----------------------------------------------------------------------------------
- JahiaContainerList newsContainerList =
jData.containers().getContainerList( "newsContainerLast5"+id );
-
- newsContainerList.setIsContainersLoaded(false);
- //Make sure newsContainerList is initialized
- if ( newsContainerList !=null && newsContainerList.getID()==0 ) {
- ContainerListBean newsContainerListBean = new
ContainerListBean(newsContainerList,jParams);
-
org.jahia.registries.ServicesRegistry.getInstance().getJahiaContainersService().
- saveContainerListInfo(newsContainerList,
jParams.getContentPage().getAclID());
- newsContainerList = newsContainerListBean.getJahiaContainerList();
- }
- %>
-<jahia:jahiaPageForm name="jahiapageform">
+ //retrieve the current pagination position
+ String ctnscroll =
jParams.getParameter("ctnscroll_newsContainerLast5"+id);
-<%-- content:containerList name='<%="newsContainerLast5"+id%>'
id='newsContainerListTaglib' windowSize="<%=selWindowSize%>" --%>
-<jahia:containerList name='<%="newsContainerLast5"+id%>'
title='newsContainerListTaglib' windowSize="<%=selWindowSize%>" >
-<%//----------------------------------------------------------------------------------------------------------------------
%>
-<%// START - PAGINATION
INFO %>
-<%//----------------------------------------------------------------------------------------------------------------------
%>
-
-<jahia:cListPaginationCurrentPageScrollingValue valueOnly="false" />
-<table border="0">
-<%
-//text search is only available when using Lucene
-if (useLucene) { %>
-<tr>
- <td nowrap="nowrap" valign="top" align="left"><b><jahia:resourceBundle
resourceBundle="jahiatemplates.Corporate_portal_templates"
resourceName="search"/> : </b></td>
- <td valign="top" align="left">
- <input type="text" name="<jahia:ctnListSQueryInputName/>"
value="<jahia:ctnListSQueryInputValue/>" size="25"/> <a
href="javascript:document.jahiapageform.submit()"><img
src="<jahia:contextURL/>/images/search.gif" alt="" width="15" height="15"
border="0" align="middle"/></a>
- </td>
-</tr>
-<% } %>
-
-<tr>
- <td nowrap="nowrap" align="left" valign="top"><b><jahia:resourceBundle
resourceBundle="jahiatemplates.Corporate_portal_templates"
resourceName="result"/> : </b></td>
- <td width="100%" align="left" valign="top">
- <table border="0" cellpadding="0" cellspacing="0">
- <tr>
- <td align="left" valign="top" style="white-space: nowrap;">
- <select class="text"
name='<%="newsContainerLast5"+id%>_windowsize'
onChange="javascript:document.jahiapageform.submit()">
- <option value="5" <% if
(selWindowSize.equals("5")){%>selected<% }%>>5</option>
- <option value="10" <% if
(selWindowSize.equals("10")){%>selected<% }%>>10</option>
- <option value="20" <% if
(selWindowSize.equals("20")){%>selected<% }%>>20</option>
- </select> Items/Page
- <br/><font size="2">[<jahia:cListPaginationFirstItemIndex />
- <jahia:cListPaginationLastItemIndex />] <jahia:resourceBundle
resourceBundle="jahiatemplates.Corporate_portal_templates" resourceName="of"/>
<jahia:cListPaginationTotalSize /></font>
- </td>
- <td align="right" valign="top" width="100%">
- <jahia:previousWindowButton title='<%="<<" +
getResourceBundle("previousResults","previousResults",jData)%>' method="post"
formName="jahiapageform" />
- <jahia:cListPagination nbStepPerPage="10"
><jahia:cListPaginationPreviousRangeOfPages method="post"
formName="jahiapageform" title=" .. "/>
-
<jahia:ifCListPaginationCurrentPage><b></jahia:ifCListPaginationCurrentPage>
- <jahia:cListPaginationPageUrl method="post"
formName="jahiapageform" />
- <jahia:ifCListPaginationCurrentPage></b>
- </jahia:ifCListPaginationCurrentPage>
- <jahia:cListPaginationNextRangeOfPages method="post"
formName="jahiapageform" title=" .. "/></jahia:cListPagination>
- <jahia:nextWindowButton
title='<%=getResourceBundle("nextResults","nextResults",jData) + ">>"%>'
method="post" formName="jahiapageform" />
- </td>
- </tr>
- </table>
- </td>
-</tr>
-<%//----------------------------------------------------------------------------------------------------------------------
%>
-<%// END - PAGINATION
INFO %>
-<%//----------------------------------------------------------------------------------------------------------------------
%>
-<tr>
- <td nowrap="nowrap" valign="top" align="left"><b>Scope : </b></td>
- <td valign="top" align="left">
- <input type="radio" name="searchScope" value="currentSite" <%
if ( searchScopeVal!=-1 ){%>checked<% }%>
- onchange="javascript:document.jahiapageform.submit()" >
Current site only
- <br/>
- <input type="radio" name="searchScope" value="allSites" <% if
( searchScopeVal==-1 ){%>checked<% }%>
- onchange="javascript:document.jahiapageform.submit()"> All sites
- </td>
-</tr>
-
-<%//----------------------------------------------------------------------------------------------------------------------
%>
-<%// START - SORT ORDER
%>
-<%//----------------------------------------------------------------------------------------------------------------------
%>
-
-<% if (jData.gui().isEditMode()) { %>
- <tr align="center"> ---> <b>Filtering Disabled</b> <--- </tr>
-<% } %>
-
-<tr>
-<td nowrap="nowrap" align="left" valign="top"><b>Sort by :</b></td>
- <td width="100%" align="left" valign="top">
- <table border="0" cellpadding="0" cellspacing="0">
- <tr>
- <a href="javascript:<%
-
%>document.jahiapageform.<%="newsContainerLast5"+id%>_sort.value='newsStartDate';<%
-
%>document.jahiapageform.<%="newsContainerLast5"+id%>_sort_order.value=<%
- if (newsSortOrder.equals("asc")){%>'desc'<%} else
{%>'asc'<%}
- %>;document.jahiapageform.submit();" title="Select or
toggle Start Date sort order">
- <%if (newsSortReq.equals("newsStartDate")) {%><b>Start
Date</b><%} else {%>Start Date<%}%>
- <img
- src="<%=theURL%>/images/sort_desc.gif" alt="sort"
border="0" width="5" height="7"/><img
- src="<%=theURL%>/images/sort_asc.gif" alt=""
border="0" width="5" height="7"/></a>
- <a href="javascript:<%
-
%>document.jahiapageform.<%="newsContainerLast5"+id%>_sort.value='newsEndDate';<%
-
%>document.jahiapageform.<%="newsContainerLast5"+id%>_sort_order.value=<%
- if (newsSortOrder.equals("asc")){%>'desc'<%} else
{%>'asc'<%}
- %>;document.jahiapageform.submit();" title="Select or
toggle End Date sort order">
- <%if (newsSortReq.equals("newsEndDate")) {%><b>End
Date</b><%} else {%>End Date<%}%>
- <img
- src="<%=theURL%>/images/sort_desc.gif" alt="sort"
border="0" width="5" height="7"/><img
- src="<%=theURL%>/images/sort_asc.gif" alt=""
border="0" width="5" height="7"/></a>
- <a href="javascript:<%
-
%>document.jahiapageform.<%="newsContainerLast5"+id%>_sort.value='newsTitle';<%
-
%>document.jahiapageform.<%="newsContainerLast5"+id%>_sort_order.value=<%
- if (newsSortOrder.equals("asc")){%>'desc'<%} else
{%>'asc'<%}
- %>;document.jahiapageform.submit();" title="Select or
toggle Title sort order">
- <%if (newsSortReq.equals("newsTitle"))
{%><b>Title</b><%} else {%>Title<%}%>
- <img
- src="<%=theURL%>/images/sort_desc.gif" alt="sort"
border="0" width="5" height="7"/><img
- src="<%=theURL%>/images/sort_asc.gif" alt=""
border="0" width="5" height="7"/></a>
-
- </table>
- </tr>
-<%//----------------------------------------------------------------------------------------------------------------------
%>
-<%// END - SORT ORDER
%>
-<%//----------------------------------------------------------------------------------------------------------------------
%>
-</table>
+ //build up the cache entry key for the current newslast5 box user
viewing settings
+ String cachekey = selWindowSize + "_" + newsSortReq+ "_" +
newsSortOrder+ "_" + numberSort+ "_" + searchScope+ "_" + ctnscroll
+ + "_" + jParams.getSiteID();
+ //System.err.println("cachekey : "+ cachekey);
+ request.setAttribute("cachekey",cachekey);
+%>
-<input type="hidden" name='<%="newsContainerLast5"+id%>_sort'
value="<%=newsSortReq%>"/>
-<input type="hidden" name='<%="newsContainerLast5"+id%>_sort_order'
value="<%=newsSortOrder%>"/>
-</jahia:containerList>
-</jahia:jahiaPageForm>
+ <%
+ //only use the cache when in Edit Mode
+ if ( !jData.gui().isEditMode() ) {
+ %>
+ <%
+ //This set the cache lifetime in seconds
+ int cacheLifeTimeInSeconds = 350;//i.e. 5 mins
+ if ( CacheUtil.getCacheLifetime(PageContext.APPLICATION_SCOPE,
pageContext)!=cacheLifeTimeInSeconds ) {
+ CacheUtil.setCacheLifetime(cacheLifeTimeInSeconds,
PageContext.APPLICATION_SCOPE, pageContext);
+ }
+ %>
+ <cache:cache scope="application" name="newslast5"
key="${cachekey}">
+ <%@ include file="box_newslast5_cached.inc"%>
+ <%
+ Date now = new Date();
+ logger.debug("box_newslast5_cached.inc generated at : "+
DateFormat.getTimeInstance().format(now));
+ %>
+ </cache:cache>
+ <% } else { %>
+ <%@ include file="box_newslast5_cached.inc"%>
+ <%
+ Date now = new Date();
+ logger.debug("box_newslast5_cached.inc generated at : "+
DateFormat.getTimeInstance().format(now));
+ %>
+ <% } %>
<%
-//----------------------------------------------------------------------------------------------------------------------
-// START - DISPLAY NEWS
ENTRIES
-//----------------------------------------------------------------------------------------------------------------------
-Enumeration newsEnumeration = newsContainerList.getContainers();
-
-int newsCount=0;
-long cacheExpirationDelay = Long.MAX_VALUE;
-
-while (newsEnumeration.hasMoreElements()) {
- newsCount++;
- if (newsCount == 1){
- %><table border="0" cellpadding="0" cellspacing="0"><%
- }
- JahiaContainer newsContainer =
(JahiaContainer)newsEnumeration.nextElement();
-
- //Retrieve the current fieldname postfix for the current container
- String newsTitle = newsContainer.getFieldValue("newsTitle" , "", true ,
jData.params());
- String newsDesc = newsContainer.getFieldValue("newsDesc" , "", true ,
jData.params());
- JahiaPage myNewsLink = (JahiaPage)
newsContainer.getFieldObject("newsLink" );
- String newsDate = (String) newsContainer.getFieldValue("newsStartDate"
,"");
- String newsValidDate = (String)
newsContainer.getFieldValue("newsEndDate" ,"");
- String newsStartDateStr = (String)
newsContainer.getFieldObject("newsStartDate");
- String newsEndDateStr = (String)
newsContainer.getFieldObject("newsEndDate" );
-
- ContainerBean newsContainerBean = new
ContainerBean(newsContainer,jData.params());
- jData.gui().html().drawBeginActionMenu(newsContainerBean , null, null,
true, "", "jahiatemplates.Corporate_portal_templates", null, out);
- %><span class="bold"><%=newsTitle%></span><br><%
- if (! "".equals(newsDate)){
- %><i>Posted on the <%=newsDate%></i><br/><%
- }
- if (! "".equals(newsValidDate)){
- %><i>Valid until the <%=newsValidDate%></i><br/><%
- }
- %><%=newsDesc%><br/><%
- if (myNewsLink != null){
- %><a
href="<%=myNewsLink.getUrl(jData.params())%>"><%=myNewsLink.getTitle()%></a><br><%
- }
- %><br/><br/><%
- jData.gui().html().drawEndActionMenu(newsContainerBean , null, null,
true, "", "jahiatemplates.Corporate_portal_templates", null, out);
-}
-if (newsCount >0){
- %></table><%
-} else {
- %><content:resourceBundle
resourceBundle="jahiatemplates.Corporate_portal_templates"
resourceName="noNews"/><br/><%
-}
-ContainerListBean newsContainerListBean = new
ContainerListBean(newsContainerList,jData.params());
-jData.gui().html().drawBeginActionMenu(newsContainerListBean , null, theURL
+ "/images/add.gif", false, "", "jahiatemplates.Corporate_portal_templates",
"addNew", out);
-
-//----------------------------------------------------------------------------------------------------------------------
-// END - DISPLAY NEWS
ENTRIES
-//----------------------------------------------------------------------------------------------------------------------
-%>
-
+ Date now = new Date();
+ logger.debug("box.JSP generated at : "+
DateFormat.getTimeInstance().format(now));
+/*
+ //For debugging purposes:
+ System.err.println("-------- Display Cache --------------");
+ LRUCache cachedObjs =
CacheUtil.getCache(PageContext.APPLICATION_SCOPE,"newslast5", pageContext);
+ Iterator i = cachedObjs.keySet().iterator();
+ System.err.println("Cache size = " + cachedObjs.getCurrentSize());
+ while(i.hasNext())
+ System.err.println(" -> " + i.next());
+
+Typical output:
+
+--------getCache--------------
+Cache size = 57558
+ -> 5_newsEndDate_asc_true_allSites_5_0
+ -> 5_newsStartDate_asc_true_allSites_5_0
+ -> 5_newsTitle_desc_false_currentSite_5_0
+ -> 5_newsEndDate_asc_true_currentSite_5_0
+ -> 5_newsStartDate_desc_true_currentSite_20_0
+ -> 5_newsStartDate_desc_true_currentSite_5_0
+ -> 5_newsStartDate_asc_true_currentSite_5_0
+ -> 20_newsEndDate_asc_true_currentSite_20_0
+ -> 5_newsStartDate_desc_true_allSites_5_0
+ -> 5_newsStartDate_desc_true_currentSite_null
+ -> 5_newsEndDate_desc_true_currentSite_5_0
+ -> 20_newsStartDate_desc_true_currentSite_20_0
+*/
+%>