[opencms-dev] CmsTimeFrameCategoryCollector not filtering properly

Paul-Inge Flakstad flakstad at npolar.no
Fri Feb 5 15:24:54 CET 2010


Hi

I'm using org.opencms.file.collectors.CmsTimeFrameCategoryCollector for the first time, and I don't know if there's a bug in this file, or if I'm just doing something terribly wrong. No matter what time range I define, all resources in the given folder is returned by the collector. Basically, I can just as well leave out the timeStart and timeEnd parts of the collector parameter, as they do not influence the result in any way(!).

Any ideas why this is happening?

My development system is the 7.5.1 release version. To avoid misunderstandings, and so you'll be able to test for yourselves, I'm attaching my JSP test code (in order for this particular JSP to work, place it in the same folder as your timestamped resources):

<%@ page import="org.opencms.jsp.*,
java.util.*,
java.text.SimpleDateFormat,
org.opencms.file.*,
org.opencms.file.collectors.*,
org.opencms.relations.*" session="false"
%><%
CmsJspXmlContentBean cms = new CmsJspActionElement(pageContext, request, response);

// Make the appropriate adjustments to the variables below
String start = "2010-02-07 12:00:00";
String end = "2010-02-09 12:00:00";
String timeProp = "collector.date";
String resType  = "my_event";
String listFolder = cms.getRequestContext().getFolderUri(); // default setting: look inside this JSP's parent folder
// No need to change anything below this line


SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date startDate = df.parse(start);
Date endDate = df.parse(end);

out.println("<h2>Time range parameters:</h2>");
out.println("<p>Start set to: " + df.format(startDate) + "<br/>");
out.println("End set to: " + df.format(endDate) + "<br/>");
out.println("Time property set to: " + timeProp + "<br/>");
out.println("List folder set to: " + listFolder + "<br/>");
out.println("Resource type set to: " + resType + "</p>");

String collectorParam = "resource=" + listFolder;
collectorParam += "|resourceType=np_event";
collectorParam += "|timeStart=" + start;
collectorParam += "|timeEnd=" + end;
collectorParam += "|collectorTime=" + timeProp;
collectorParam += "|sortDescending=true";
collectorParam += "|resultLimit=100";

I_CmsXmlContentContainer xmlEvents = cms.contentload("timeFrameAndCategories", collectorParam, false);
out.println("<h2>Resources collected for this time range:</h2>");
out.println("<ul>");
while (xmlEvents.hasMoreContent()) {
    String filename = cms.contentshow(xmlEvents, "%(opencms.filename)");
    String timePropValue = cms.getCmsObject().readPropertyObject(filename, timeProp, false).getValue();
    Date timestamp = new Date(Long.valueOf(timePropValue).longValue());
    out.print("<li><code>" + filename + "</code>: timestamp is <strong>" + df.format(timestamp) + "</strong> – ");
    out.print("this is <em>" + (timestamp.after(startDate) ? "after" : "before") + "</em> the time range start");
    //out.print(" [" + timestamp.getTime() + (timestamp.getTime() > startDate.getTime() ? " > " : " < ") + startDate.getTime() + "]"); // Remove comment to print timestamp long comparisons
    out.print(" and <em>" + (timestamp.after(endDate) ? "after" : "before") + "</em> the time range end");
    //out.print(" [" + timestamp.getTime() + (timestamp.getTime() > endDate.getTime() ? " > " : " < ") + endDate.getTime() + "]"); // Remove comment to print timestamp long comparisons
    out.print("</li>");
}
out.println("</ul>");
%>

Best regards,
Paul


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20100205/2778773e/attachment.htm>


More information about the opencms-dev mailing list