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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to