[opencms-dev] OpenCMS Access

Rodriguez, Adrian A.Rodriguez at comundus.com
Fri Oct 16 11:28:40 CEST 2009


Hello Markus,

we use the following code to trigger the template mechanism in OpenCms. In the example, myEmail.html is a resource of type XmlPage with a template assigned.

CmsObject cms=...;
HttpServletRequest request=...;
HttpServletResponse response=new DummyResponse();
CmsResource resource=cms.readResource("/myEmail.html");

I_CmsResourceLoader loader = OpenCms.getResourceManager().getLoader(resource);	    
cms.getRequestContext().setUri(cms.getSitePath(resource));
	    	    
byte[]result= loader.export(cms,resource,request,response);

public class DummyResponse implements HttpServletResponse {

    public ServletOutputStream getOutputStream() throws IOException {

	return new ServletOutputStream(){

	    public void write(int b) throws IOException {
		// Do nothing
		
	    }
	    public void write(byte[] b) throws IOException {
		//Do nothing
		
	    }
	    public void flush() throws IOException {
		//Do nothing
		
	    }    

	};
    }

   // ... Rest of the implemented methods of HttpServletResponse
}


The reason why response is of type DummyResponse, is because in the process of exporting, OpenCms tries to write to it. It can also be useful if in you don't have access to a real HttpServletRequest at all. Then you should use a kind of dummy HttpServletRequest. 

This is working, but the problem is that it is completely dependent of the use of the response that the OpenCms implementation does, so I will be very glad to know if there is a more elegant approach.

Kind regards,

Adrián Rodríguez
comundus GmbH

-----Original Message-----
From: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] On Behalf Of May, Markus
Sent: Friday, October 16, 2009 9:22 AM
To: 'bw at code-create.com'; 'The OpenCms mailing list'
Subject: Re: [opencms-dev] OpenCMS Access

Hello Bernd,

Thats exactly what I would like to do. The OpenCMS API call would my favourite. Could you just point me to the right Class?

R,

Markus

-----Ursprüngliche Nachricht-----
Von: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] Im Auftrag von ] Code Create [ Bernd Wolfsegger
Gesendet: Donnerstag, 15. Oktober 2009 19:21
An: 'The OpenCms mailing list'
Betreff: Re: [opencms-dev] OpenCMS Access

Hi Markus,

so what you like to implement is to have the structured content generated as usual but nor for the browser client but on the server itself to be able to send it via email?
One way would be to export the structured content and then use the generates file for whatever purpose.
But I think there may be also possibilities in the OpenCms API to get the generated content via a "dummy" Request programmatically.

Though, I would have to study the API to get the idea :-)

Kind regards, Bernd

-----Ursprüngliche Nachricht-----
Von: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] Im Auftrag von May, Markus
Gesendet: Donnerstag, 15. Oktober 2009 17:58
An: 'kuku at physik.rwth-aachen.de'; 'opencms-dev at opencms.org'
Betreff: Re: [opencms-dev] OpenCMS Access

 I think we misunderstood each other, probably I was using the word Template in the wrong context.

To clear this up. We are right now using HTML-Files in the OpenCMS without any Templates and/or schema behind. These Files do just contain plain HTML. This is what we are using for the eMail Stuff in our Module, and this is done in JAVA and not in JSPs.

What we are looking for, is basically a way to retrieve the full HTML-file after we migrated to using Templates for them.

R,

Markus

-----Ursprüngliche Nachricht-----
Von: Christoph P. Kukulies [mailto:kuku at physik.rwth-aachen.de]
Gesendet: Donnerstag, 15. Oktober 2009 17:36
An: May, Markus
Betreff: Re: [opencms-dev] OpenCMS Access

Maybe some of the CmsXml classes might do?
Don't know. Is the content of the Email in these XML files?
Would you have to parse the XML?

I'm using the CmsHtmlMail class in a jsp to send Email like this:
   CmsHtmlMail htmlmail= new CmsHtmlMail();

   htmlmail.addTo("kuku at somewhere.de","Company GmbH");
   htmlmail.addCc("meier at somewhere.de","Company GmbH");
   htmlmail.setFrom("Infoveranstaltung at company.de");
   htmlmail.setSubject("Anmeldung");
   htmlmail.setCharset("iso-8859-2");
   htmlmail.setHtmlMsg(
   "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
\"http://www.w3.org/TR/html4/loose.dtd\">\r"+
"<html>\r"+
"<head>\r"+
"<title>Registrierung</title>\r"+
"<style type=\"text/css\">\r"+
"body {\r"+
"    font-family: Tahoma, Helvetica, Arial, sans-serif;"+
"    font-size: 12px;"+
"    text-align: left;"+
"    background:#f0f2f4;"+
"    color: #11316c;"+
"}"+
"td {     text-align: left;\r     vertical-align: top;\r"+
"</style>\r"+
...


And the htmlmail.send();



--
Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de

On Thu, Oct 15, 2009 at 05:02:21PM +0200, May, Markus wrote:
> Hello,
>
> We are basically right now reading the Content of the XML-File and
> therefor we
are not able to construct the email from it, because the email should be "transformed" to an HTML-File. Like stated, right now the XML-File is read directly and this file contains a kind of static HTML-page.
>
> IMHO, this should be done in a more CMS like way and we are trying to
> avoid
the readFile() construct. What I would like to get is basically the "exported"
HTML-page from the template. Could this be done in a program?
>
> R,
>
> Markus
>
> -----Urspr?ngliche Nachricht-----
> Von: opencms-dev-bounces at opencms.org
> [mailto:opencms-dev-bounces at opencms.org] Im Auftrag von Christoph P.
> Kukulies
> Gesendet: Donnerstag, 15. Oktober 2009 16:51
> An: The OpenCms mailing list
> Betreff: Re: [opencms-dev] OpenCMS Access
>
> Markus,
>
> what are you intending to do with readFile()?
> Inclusion in templates is mostly done by constructs like
>
> <cms:template element="head" >
> <cms:include file="../elements/head" element="head"/> </cms:template>
>
> Or do I misunderstand something.
>
> On Thu, Oct 15, 2009 at 04:38:46PM +0200, May, Markus wrote:
> > Hello,
> >
> > We have now (finally) transferred our site to 7.5.1, thanks for the
> > great
help. We are now trying to do something really easy (at least I hope so).
> >
> > We have a couple of files, which are basically full HTML-Files
> > including the
Header and so on. These are mainly used for emailing. Now we would like to use some Templates there as well, so that it is easier to use for our Authors.
> >
> > Right now we are just using the CMSObject.readFile() Method, but
> > this will
not work, if we would like to use the Template variant. Any help?
> >
> > Mit freundlichen Gr??en
> >
> > Markus M. May
> --
> Chris Christoph P. U. Kukulies kukulies (at) rwth-aachen.de
>

_______________________________________________
This mail is sent to you from the opencms-dev mailing list To change your list options, or to unsubscribe from the list, please visit http://lists.opencms.org/mailman/listinfo/opencms-dev


_______________________________________________
This mail is sent to you from the opencms-dev mailing list To change your list options, or to unsubscribe from the list, please visit http://lists.opencms.org/mailman/listinfo/opencms-dev

_______________________________________________
This mail is sent to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://lists.opencms.org/mailman/listinfo/opencms-dev



More information about the opencms-dev mailing list