Create a Custom Scheduled Job

(Difference between revisions)
Jump to: navigation, search
Line 2: Line 2:
  
 
Then you add your Java class to OpenCms. You can either create a jar file, or a class file.  Then you add them to your OpenCms installation - your options are on the [[Adding_Jar_Files]] page.
 
Then you add your Java class to OpenCms. You can either create a jar file, or a class file.  Then you add them to your OpenCms installation - your options are on the [[Adding_Jar_Files]] page.
 +
 +
Follows an example (that gets parameters from request), found at this thread at Nabble:
 +
 +
<code lang="java">
 +
 +
<%@page import="org.opencms.main.CmsContextInfo,
 +
                        org.opencms.scheduler.CmsScheduledJobInfo,
 +
                        org.opencms.scheduler.CmsScheduleManager,
 +
                        org.opencms.file.CmsObject,
 +
                        org.opencms.jsp.CmsJspBean,
 +
                        java.util.SortedMap,
 +
                        java.util.TreeMap"%>
 +
 +
<%
 +
 +
CmsScheduledJobInfo csji = new CmsScheduledJobInfo();
 +
CmsScheduleManager csm = new CmsScheduleManager();
 +
CmsJspBean cjb = new CmsJspBean();
 +
 +
cjb.init(pageContext,request,response);
 +
 +
CmsObject cmsObj = cjb.getCmsObject();
 +
CmsContextInfo cci = new CmsContextInfo(cjb.getRequestContext());
 +
 +
csji.setCronExpression("0 0/1 * * * ?");
 +
csji.setClassName("org.opencms.business.services.NewsLetterCmsScheduledJob");
 +
 +
csji.setActive(true);
 +
csji.setContextInfo(cci);
 +
csji.setJobName("boletin");
 +
 +
SortedMap parametros = new TreeMap();
 +
parametros.put("request",request);
 +
parametros.put("response",response);
 +
 +
csji.setParameters(parametros);
 +
csm.initialize(cmsObj);
 +
 +
csm.scheduleJob(cmsObj,csji);
 +
 +
%>
 +
 +
</code>
  
 
[[Category:Extending OpenCms]]
 
[[Category:Extending OpenCms]]

Revision as of 19:39, 14 December 2007

A scheduled job is a bit of code that is run on a regular basis by OpenCms. You can create custom scheduled jobs by creating a java class that implements I_CmsScheduledJob.

Then you add your Java class to OpenCms. You can either create a jar file, or a class file. Then you add them to your OpenCms installation - your options are on the Adding_Jar_Files page.

Follows an example (that gets parameters from request), found at this thread at Nabble:

<%@page import="org.opencms.main.CmsContextInfo,
                        org.opencms.scheduler.CmsScheduledJobInfo,
                        org.opencms.scheduler.CmsScheduleManager,
                        org.opencms.file.CmsObject,
                        org.opencms.jsp.CmsJspBean,
                        java.util.SortedMap,
                        java.util.TreeMap"%>
 
<%
 
CmsScheduledJobInfo csji = new CmsScheduledJobInfo();
CmsScheduleManager csm = new CmsScheduleManager();
CmsJspBean cjb = new CmsJspBean();
 
cjb.init(pageContext,request,response);
 
CmsObject cmsObj = cjb.getCmsObject();
CmsContextInfo cci = new CmsContextInfo(cjb.getRequestContext());
 
csji.setCronExpression("0 0/1 * * * ?");
csji.setClassName("org.opencms.business.services.NewsLetterCmsScheduledJob");
 
csji.setActive(true);
csji.setContextInfo(cci);
csji.setJobName("boletin");
 
SortedMap parametros = new TreeMap();
parametros.put("request",request);
parametros.put("response",response);
 
csji.setParameters(parametros);
csm.initialize(cmsObj);
 
csm.scheduleJob(cmsObj,csji);
 
%>
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox