cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jos Snellings <Jos.Snelli...@pandora.be>
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.rest.controller.annotation.SitemapParameter;
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;
	
    @SitemapParameter
    private String language;
    
    @SitemapParameter
    private String deep;  
    
    private String showClass;  
    private String id;
    private String editing;
    
// String language = "en";

public void setup(Map<String, Object> parameters)  {
     HttpServletRequest request =
HttpContextHelper.getRequest(parameters);
     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.startDocument();

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


}



Mime
View raw message