[opencms-dev] how to acces cms object when writing a new class
bub habub
japorami at yahoo.com
Tue Jul 19 12:36:38 CEST 2005
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
More information about the opencms-dev
mailing list