« Return to Thread: Create a scheduled job from jsp

RE: [opencms] Create a scheduled job from jsp

by Luis Rodriguez Fernandez :: Rate this Message:

| View in Thread

Good morning Jorge. At first thanks for your answer.

I´m using jsp`s for making the news because I think is the most useful and comfortable way to separate the presentation (the view) of the content. I mean that I could have a few jsp pages for making the head of the newsletter, another few for making the body, maybe another few for the foot (if it was required).

I know that I can use CmsResource to get structured contents, even I had a pair of classes that did it in this way:

public List getContenidosEstructurados() throws BusinessException,
                        CmsDataAccessException, CmsException {
                       
// now collect the resources
I_CmsResourceCollector collector = OpenCms.getResourceManager()
                                .getContentCollector(nombreCollector);

List m_collectorResult = collector.getResults(cms, nombreCollector,
                                carpeta);
Iterator iter = m_collectorResult.iterator();
CmsResource e = null;
CmsFile f = null;
List delete = new ArrayList();
while (iter.hasNext()) {
        e = (CmsResource) iter.next();
        f = CmsFile.upgrade(e, cms);

        A_CmsXmlDocument contenidoEstructurado = CmsXmlContentFactory
                        .unmarshal(cms, f);

        if (!contentDateCheckValue(contenidoEstructurado)) {
                delete.add(e);
        }
}
m_collectorResult.removeAll(delete);
CmsContentInfoBean contentInfoBean = new CmsContentInfoBean();
contentInfoBean.setResultSize(m_collectorResult.size());
contentInfoBean.initResultIndex();
contentInfoBean.initPageNavIndexes();
return m_collectorResult;
}

/**
* @return
*/
private boolean contentDateCheckValue(A_CmsXmlDocument content) {
        String stringDate = content.getStringValue(cms, discriminante, locale);
Long l = new Long(stringDate);
Date dPublicacion = new Date(l.longValue());
Date d = new Date();

if (periodicidad.equals(NewsLetterOpenCmsService.PERIODICIDAD_DIARIA)) {
        if ((d.getDate() == dPublicacion.getDate())
                && (d.getMonth() == dPublicacion.getMonth())
                && (d.getYear() == dPublicacion.getYear())) {
                return true;
        } else {
                return false;
        }
}
if (periodicidad.equals(NewsLetterOpenCmsService.PERIODICIDAD_SEMANAL)) {
        long diferenciaEnMilisegundos = 7 * 1000 * 60 * 60 * 24;
        if ((d.getTime() - dPublicacion.getTime()) <= diferenciaEnMilisegundos)
                return true;
        else {
                return false;
        }
}
return false;
}


private String tratarContenidosEstructurados(CmsObject cms, String locale, List contenidosEstructurados) throws CmsException {
       
CmsFile f = null;
StringBuffer sb = new StringBuffer();
               
for (Iterator iter = contenidosEstructurados.iterator(); iter.hasNext();) {
        CmsResource element = (CmsResource) iter.next();
        String nombre = element.getName();
        f = CmsFile.upgrade(element, cms);
        A_CmsXmlDocument content = CmsXmlContentFactory.unmarshal(cms, f);
        String address = cms.getRequestContext().getRemoteAddress();
        String uri = cms.getRequestContext().getUri();
        String titulo = content.getStringValue(cms, "Title", new Locale(locale));
        sb.append(nombre + " " + titulo + " " + address + " " + uri + "\n");
}
return sb.toString();
}


Ok, that's great, but you must realize that I have to give format to the mail (the newsletter), I have to put css, images, links to the news... So I think the better way to do this is launching jsp pages, even I have done a custom tag for getting the structured contents (in this case news). I could do all of this from the same java class, but in that case I was mixing the view with the logic bussines.

Thanks again. Luis.

Ps: it could be great to continue talking about this topic.  



 
-----Mensaje original-----
De: opencms-dev-bounces@... [mailto:opencms-dev-bounces@...] En nombre de Jorge González
Enviado el: martes, 06 de septiembre de 2005 13:38
Para: 'The OpenCms mailing list'
Asunto: RE: [opencms] [opencms-dev] Create a scheduled job from jsp

Hi Luis:

Why are you trying to launch a jsp page to build the contents of the newsletter ?

You could use the CmsResource directly to pick the title and content of all the news matching the criteria and store it into a (file/buffer/whatever) after that, you could send this to the mailing list.

Do you need to execute a jsp to do this for another reasons ?



_______________________________________________
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

 « Return to Thread: Create a scheduled job from jsp