[opencms-dev] how to acces cms object when writing a new class

Michael Emmerich m.emmerich at alkacon.com
Tue Jul 19 12:47:48 CEST 2005


Jap,

to write a class fpr the scheduler, you must implement the Interface 
I_CmsScheduledJob.

Take a look at the class CmsPublishJob in the org.opencms.scheduler.jobs 
package, it should show you how to implment a class for the scheduler 
(which cannot be made as a JSP), and how to access the CmsObject there.

Regards,
Michael Emmerich

Alkacon Software - The OpenCms Experts
http://www.alkacon.com



bub habub schrieb:
> hi,
> 
> i want to write a java class to use for the scheduler.
> for that i need to use the CmsObejct but i don't know
> how i can get one since it is not allowed to create a
> new one and i cannot use the jspActionElement to get
> the object. furthermore i cannot access the
> org.opencms.mail package correctly. when i try to
> compile my file it gives these errors: cannot access
> org.apache.commons.mail.html .
> 
> my program works as an .jsp file but i understood one
> cannot use an jsp file to run as a scheduled job.
> or am i wrong with this assumption.
> 
> thank you already in advance
> 
> jap
> 
> this is my attempted java class
> 
> package org.opencms.project.update;
> 
> import org.opencms.file.*;
> import org.opencms.file.collectors.*;
> import org.opencms.mail.*;
> import org.opencms.flex.*;
> import org.opencms.flex.*;
> import org.opencms.jsp.*;
> import org.opencms.util.CmsUUID;
> import org.opencms.scheduler.*;
> import java.io.*;
> import java.util.*;
> 
> public class ProjectUpdateReminder //implements
> Scheduler
> {
> 
> 	public void checkProjects()
> 	{
> 	
> 		
> 		String folder = "/sites/default/release/";
> 		System.out.println("Current folder=" + folder);
> 
> 		//CmsJspActionElement cms = new CmsJspActionElement(
> pageContext,request,	response );
> 
> 		CmsObject cmsobject =  cms.getCmsObject();
> 		List listfiles =
> cmsobject.getResourcesInFolder(folder,
> CmsResourceFilter.DEFAULT_FILES);
> 
> 		Iterator iterator = listfiles.iterator();
> 		System.out.println("Items in this folder: list:");
> 		long lastdate, time;
> 		Date today = new Date();
> 
> 
> 		while (iterator.hasNext())
> 		{
> 			CmsFile temp = (CmsFile)iterator.next();
> 			//out.println(temp);
> 			lastdate = temp.getDateLastModified();
> 			//out.println(date);
> 	
> 			time = today.getTime();
> 			//out.println(time);
> 			if(time-lastdate > 111840950)
> 			{
> 				CmsUUID userid = temp.getUserLastModified();
> 				CmsUser projectleader =
> cmsobject.readUser(userid);
> 		
> 				//out.println(userid);
> 				String emailofuser = projectleader.getEmail();
> 				String lastname = projectleader.getLastname();
> 				System.out.println(emailofuser);
> 		
> 				String url = temp.getRootPath();
> 				String filename = temp.getName();
> 				//out.println(url);
> 				System.out.println(filename);				//muss noch
> genauer aufgebaut werden
> 				String forwardUri = "mail.jsp";
>  		
> 				//response.sendRedirect(cms.link(forwardUri));
> 				//response.sendRedirect("mail.jsp"); 
> 
> 		
> 				org.opencms.mail.CmsHtmlMail amail = new
> org.opencms.mail.CmsHtmlMail();
> 
> 
> 				amail.addTo(emailofuser);
> 
> 				//Set From
> 
> 				String from = "onkel puenktlich";
> 
> 				//amail.setFrom("japorami at yahoo.com", "jap");
> 
> 				// Set Subject
> 
> 				amail.setSubject("Please update project"); //
> better with a variable for multiple use
> 
> 				String htmlcontent =
> cms.getContent("user_entry.html");
> 				System.out.println(htmlcontent);
> 
> 				amail.setHtmlMsg(htmlcontent);
> 
> 				// Sending the Email
> 				amail.send();
> 
> 			}
> 		}
> 	}
> }
> 
> 
> 
> 
> 		
> ____________________________________________________
> Start your day with Yahoo! - make it your home page 
> http://www.yahoo.com/r/hs 
>  
> 
> 
> _______________________________________________
> This mail is send to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://mail.opencms.org/mailman/listinfo/opencms-dev

-- 
Alkacon Software
An der Wachsfabrik 13
50996 Koeln, DE
Tel: +49 (0)2236 382614
Fax: +49 (0)2236 382620
Email m.emmerich at alkacon.com



More information about the opencms-dev mailing list