cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jos Snellings <>
Subject Re: Initialization of variables
Date Fri, 04 Dec 2009 05:50:14 GMT
Hi Johannes,

I must say, I do not completely understand your point. Talking about
such things as 'transactions': you could setup in the system what needs
to be setup once in a separate class.
Below is an example from the real world where database connections are
set up in a separate spring bean:

On Fri, 2009-12-04 at 02:06 +0100, Johannes Lichtenberger wrote:
> Hello,
> how do I initialize an object (a transaction), which I then have to
> access in a self written pipeline component (generator)?
> My concern is, that the session can only be bound once to a path/file,
> so subsequent requests throw errors.
> regards,
> Johannes
package org.herein.thesaurus.cocoon;

import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.apache.cocoon.pipeline.caching.CacheKey;
import org.apache.cocoon.pipeline.caching.SimpleCacheKey;
import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
import org.apache.cocoon.sax.AbstractSAXGenerator;
import org.apache.cocoon.xml.sax.AttributesImpl;
import org.apache.cocoon.sax.SAXConsumer;

import org.apache.cocoon.servlet.util.HttpContextHelper;

import org.xml.sax.SAXException;

import org.herein.thesaurus.ThesaurusBrowser;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ToptermsGenerator extends AbstractSAXGenerator  implements
CachingPipelineComponent, ApplicationContextAware {
	private ApplicationContext applicationContext;
    private String language;
    private String deep;  
    private String showClass;  
    private String id;
    private String editing;
// String language = "en";

public void setup(Map<String, Object> parameters)  {
     HttpServletRequest request =
     language = request.getParameter("language");
     deep = request.getParameter("all");     
     showClass = request.getParameter("class");
     id = request.getParameter("nr");
     editing = request.getParameter("edit");

public void execute() {
        SAXConsumer consumer = this.getSAXConsumer();
        try {

            consumer.startElement("", "page", "page", new
            if (deep == null) {
            	AttributesImpl attr = new AttributesImpl();
            	consumer.startElement("", "searchform", "searchform",
            	consumer.endElement("", "searchform", "searchform");      
            ThesaurusBrowser T;
            if (editing != null) T =  (ThesaurusBrowser)
            else T = (ThesaurusBrowser)
            if ((showClass != null) && showClass.equals("1")) {
            else if ((deep != null) && (deep.equals("1"))) {
            	T.listClassesDeep(consumer, language);
            else if (language != null) {
            	T.listClasses(consumer, language);
        } catch (SAXException e) {
            throw new RuntimeException(e);
public CacheKey constructCacheKey() {
	        return new SimpleCacheKey();
public void setApplicationContext(ApplicationContext applicationContext)
    this.applicationContext = applicationContext;


View raw message