Return-Path: Delivered-To: apmail-xml-cocoon-dev-archive@xml.apache.org Received: (qmail 23178 invoked by uid 500); 20 Feb 2003 09:05:09 -0000 Mailing-List: contact cocoon-dev-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: cocoon-dev@xml.apache.org Delivered-To: mailing list cocoon-dev@xml.apache.org Received: (qmail 23165 invoked from network); 20 Feb 2003 09:05:08 -0000 Message-ID: <018901c2d8be$ba19e400$22020a0a@hw0393> From: "Guido Casper" To: References: <20030220054318.32766.qmail@web21304.mail.yahoo.com> Subject: Re: [Q]Non-cacheable Generator Date: Thu, 20 Feb 2003 10:01:59 +0100 MIME-Version: 1.0 X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-MIMETrack: Itemize by SMTP Server on PBSN1/Systeme und Netzwerke(Release 5.0.8 |June 18, 2001) at 20.02.2003 10:05:10, Serialize by Router on PBSN1/Systeme und Netzwerke(Release 5.0.8 |June 18, 2001) at 20.02.2003 10:05:11, Serialize complete at 20.02.2003 10:05:11 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="iso-8859-1" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N > I just notice that the deprecated folder from cvs > contains XMLDBGenerator and XMLDBCollectionGenerator. > But I never tried out. Anyway, would you suggest how I > could fix my generator to non-cached? Are you sure your generator is cached?? I think extending AbstractGenerator is noncacheable by default. To be sure you can change your pipeline to noncaching This is 2.1 only, for 2.0 edit cocoon.xconf (just search for "caching"). BTW, you should have a look at: http://wiki.cocoondev.org/Wiki.jsp?page=EXistInCocoon HTH Guido > > Thanks. > > > --- Ken C wrote: > > Hi, > > Having read the "write a custom generator" > > tutorial, I am trying to write one that hooks up a > > connection to an xmldb -- eXist; and then get an xml > > back based on a request parameter. Everything seems > > to > > work fine for the first time the request is made. > > Different request parameters on subsequent request > > won't result a correct xml. I suspect that this > > generator may have been cached, which is not what I > > want. Following is the code, it's ugly but just a > > first try... > > > > ========================================== > > > > import > > org.apache.cocoon.generation.AbstractGenerator; > > import org.xml.sax.helpers.AttributesImpl; > > import org.xml.sax.SAXException; > > // for the setup() method > > import org.apache.cocoon.environment.SourceResolver; > > import java.util.Map; > > import > > org.apache.avalon.framework.parameters.Parameters; > > import org.apache.cocoon.ProcessingException; > > import java.io.IOException; > > // used to deal with the request parameters. > > import > > org.apache.cocoon.environment.ObjectModelHelper; > > import org.apache.cocoon.environment.Request; > > import java.util.Enumeration; > > import java.util.Date; > > > > //xmldb > > import org.xmldb.api.base.*; > > import org.xmldb.api.modules.*; > > import org.xmldb.api.*; > > > > public class ThreadGenerator extends > > AbstractGenerator > > > > { > > // Will be initialized in the setup() method and > > used in generate() > > Request request = null; > > String threadID = null; //the thread we are > > looking for > > //todo: set threadID as > > a > > static final variable > > > > //xmldb > > String driver = null; > > Database database = null; > > Collection col = null; > > String[] resources = null; > > XMLResource xmlres = null; > > String forumURI = > > "xmldb:exist:///db/cocoon/forum"; //db root > > > > > > public void setup(SourceResolver resolver, Map > > objectModel, > > String src, Parameters parameters) > > throws ProcessingException, SAXException, > > IOException > > { > > super.setup(resolver, objectModel, src, > > parameters); > > request = > > ObjectModelHelper.getRequest(objectModel); > > forumURI = forumURI + "/" + > > request.getParameter("groupID"); > > forumURI = forumURI + "/" + > > request.getParameter("forumID"); > > > > //xmldb > > try { > > driver = "org.exist.xmldb.DatabaseImpl"; > > //todo: parameters.getParameter("driver"); > > Class cl = Class.forName(driver); > > database = (Database)cl.newInstance(); > > DatabaseManager.registerDatabase(database); > > database.setProperty("create-database", > > "true"); > > > > > > col = > > DatabaseManager.getCollection(forumURI); > > > > col.setProperty("pretty", "true"); > > col.setProperty("encoding", "UTF-8"); > > > > this.getLogger().debug("getting threadID"); > > threadID = request.getParameter("threadID") > > + > > ".xml"; //todo: set threadID as a static final > > variable > > resources = col.listResources(); > > this.getLogger().debug("getting threadID > > done..."); > > > > } > > catch(Exception e){} > > } > > /** > > * Implement the generate() method from > > AbstractGenerator. > > */ > > public void generate() throws SAXException > > { > > > > if (threadID!=null) > > { > > try { > > > > xmlres = > > (XMLResource)col.getResource(threadID); > > if (xmlres==null) > > throw new SAXException("Resource not > > found:" + threadID + "doesn't not exist"); > > > > > > xmlres.getContentAsSAX(this.contentHandler); > > > > contentHandler.startDocument(); > > contentHandler.endDocument(); > > > > } > > > > catch (Exception e){} > > } > > } > > public void recycle() { > > super.recycle(); > > this.request = null; > > driver = null; > > > > try { > > col.close(); > > DatabaseManager.deregisterDatabase(database); > > } > > catch (Exception e){} > > database = null; > > resources = null; > > xmlres = null; > > forumURI = null; > > } > > } > > //end class > > > > __________________________________________________ > > Do you Yahoo!? > > Yahoo! Shopping - Send Flowers for Valentine's Day > > http://shopping.yahoo.com > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: > > cocoon-dev-unsubscribe@xml.apache.org > > For additional commands, email: > > cocoon-dev-help@xml.apache.org > > > > > __________________________________________________ > Do you Yahoo!? > Yahoo! Tax Center - forms, calculators, tips, more > http://taxes.yahoo.com/ > > --------------------------------------------------------------------- > To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org > For additional commands, email: cocoon-dev-help@xml.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org For additional commands, email: cocoon-dev-help@xml.apache.org