cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jin, Juping" <Juping....@ca.com>
Subject Help: How to create sql element for dynamic queries?
Date Tue, 10 Jun 2003 14:37:11 GMT
I am new to Apache Cocoon 2 and try to generate dynamic queries based on
user's parameters. My idea looks like this:

In sitemap.xmap, my pipeline will be:

  <map:pipeline match="cocoon/myquery">
	<map:generate type="mygenerator"/>
	<map:transform type="sql"/>
	<map:serialize type="xml"/>
  </map:pipeline>

mygenerator is a Java class following the examples in Cocoon 2:

public class SQLGenerator extends AbstractGenerator 
  implements Disposable, Configurable {

    ...
    public void generate() throws SAXException
    {

      contentHandler.startDocument();
      
      contentHandler.startElement("", "document", "document",
emptyAttr);

      contentHandler.startPrefixMapping("sql",
"http://apache.org/cocoon/SQL/2.0");
      contentHandler.startElement("sql", "execute-query",
"sql:execute-query", emptyAttr);
      contentHandler.startElement("sql", "use-connection",
"sql:use-connection", emptyAttr);
      contentHandler.characters("mycon".toCharArray(), 0,
"mycon".length());
      contentHandler.endElement("sql", "use-connection",
"sql:use-connection");
      contentHandler.startElement("sql", "query", "sql:query",
emptyAttr);
      contentHandler.characters("SELECT * FROM
Products".toCharArray(),0,
		 "SELECT * FROM Products".length());
      contentHandler.endElement("sql", "query", "sql:query");
      contentHandler.endElement("sql", "execute-query",
"sql:execute-query");
      contentHandler.endPrefixMapping("sql");
      ...
   }
   ...
}


Open IE, point it to http://localhost:8080/cocoon/myquery, I got the
following:

  <?xml version="1.0" encoding="UTF-8" ?> 
- <document>
- <sql:execute-query xmlns:sql="http://apache.org/cocoon/SQL/2.0">
     <sql:use-connection>mycon</sql:use-connection> 
     <sql:query>SELECT * FROM Product</sql:query> 
   </sql:execute-query>
  </document>

My question is: Why SQL tranformer is not invoked? However, if I create
a separate pipeline for above xml file, sql tranform is invoked and
executed.

The thing I am not sure is about startElement. The way I use is:

contentHandler.startElement("sql", "execute-query", "sql:execute-query",
emptyAttr);

Is this the correct way to start an element?

Thank you for reading and your suggestion will be highly appreciated.

Juping

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Mime
View raw message