Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 12706 invoked from network); 3 May 2005 19:59:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 May 2005 19:59:46 -0000 Received: (qmail 85184 invoked by uid 500); 3 May 2005 19:58:02 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 85053 invoked by uid 500); 3 May 2005 19:57:59 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 84780 invoked by uid 99); 3 May 2005 19:57:57 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Tue, 03 May 2005 12:57:55 -0700 Received: (qmail 7385 invoked by uid 65534); 3 May 2005 19:49:25 -0000 Message-ID: <20050503194925.7384.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r167969 - in /cocoon/branches/BRANCH_2_1_X: ./ src/blocks/databases/java/org/apache/cocoon/transformation/ src/blocks/databases/samples/transform/ src/documentation/xdocs/userdocs/transformers/ Date: Tue, 03 May 2005 19:49:24 -0000 To: cvs@cocoon.apache.org From: vgritsenko@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: vgritsenko Date: Tue May 3 12:49:23 2005 New Revision: 167969 URL: http://svn.apache.org/viewcvs?rev=3D167969&view=3Drev Log: Cleanup namespace handling in the SQLTransformer (at least a bit). More samples are desperately needed for testing. Fixes bug #25203, #31634. Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/databases/java/org/apache/cocoo= n/transformation/SQLTransformer.java cocoon/branches/BRANCH_2_1_X/src/blocks/databases/samples/transform/sql= -page.xml cocoon/branches/BRANCH_2_1_X/src/documentation/xdocs/userdocs/transform= ers/sql-transformer.xml cocoon/branches/BRANCH_2_1_X/status.xml Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/databases/java/org/apache= /cocoon/transformation/SQLTransformer.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/= databases/java/org/apache/cocoon/transformation/SQLTransformer.java?rev=3D1= 67969&r1=3D167968&r2=3D167969&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- cocoon/branches/BRANCH_2_1_X/src/blocks/databases/java/org/apache/cocoo= n/transformation/SQLTransformer.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/databases/java/org/apache/cocoo= n/transformation/SQLTransformer.java Tue May 3 12:49:23 2005 @@ -145,30 +145,31 @@ /** Check if nr of rows need to be written out. **/ protected boolean showNrOfRows; =20 - /** Namespace prefix to output */ - protected String outPrefix; - - /** Namespace uri to output */ + /** The namespace uri of the XML output. Defaults to {@link #namespace= URI}. */ protected String outUri; =20 + /** The namespace prefix of the XML output. Defaults to 'sql'. */ + protected String outPrefix; + /** The database selector */ protected ServiceSelector dbSelector; =20 - protected XMLSerializer compiler; - protected XMLDeserializer interpreter; - protected SAXParser parser; - /** Encoding we use for CLOB field */ protected String clobEncoding; =20 /** The connection used by all top level queries */ protected Connection conn; =20 + // Used to parse XML from database. + protected XMLSerializer compiler; + protected XMLDeserializer interpreter; + protected SAXParser parser; + /** * Constructor */ public SQLTransformer() { - this.defaultNamespaceURI =3D NAMESPACE; + super.defaultNamespaceURI =3D NAMESPACE; } =20 /** @@ -250,6 +251,7 @@ =20 this.showNrOfRows =3D parameters.getParameterAsBoolean(SQLTransfor= mer.MAGIC_NR_OF_ROWS, false); this.clobEncoding =3D parameters.getParameter(SQLTransformer.CLOB_= ENCODING, ""); + if (getLogger().isDebugEnabled()) { if (this.parameters.getParameter(SQLTransformer.MAGIC_CONNECTI= ON, null) !=3D null) { getLogger().debug("CONNECTION: " + this.parameters.getPara= meter(SQLTransformer.MAGIC_CONNECTION, null)); @@ -259,11 +261,23 @@ } getLogger().debug("DOC-ELEMENT: " + parameters.getParameter(SQ= LTransformer.MAGIC_DOC_ELEMENT, "rowset")); getLogger().debug("ROW-ELEMENT: " + parameters.getParameter(SQ= LTransformer.MAGIC_ROW_ELEMENT, "row")); - getLogger().debug("NS-URI: " + parameters.getParameter(SQLTran= sformer.MAGIC_NS_URI_ELEMENT, NAMESPACE)); - getLogger().debug("NS-PREFIX: " + parameters.getParameter(SQLT= ransformer.MAGIC_NS_PREFIX_ELEMENT, "")); - getLogger().debug("CLOB_ENCODING: " + clobEncoding); + getLogger().debug("Using CLOB encoding: " + clobEncoding); + } + } + + /** + * Return attribute value. + * First try non-namespaced attribute, then try this transformer names= pace. + * @param name local attribute name + */ + private String getAttributeValue(Attributes attr, String name) { + String value =3D attr.getValue("", name); + if (value =3D=3D null) { + value =3D attr.getValue(this.namespaceURI, name); } - } + + return value; + } =20 /** * This will be the meat of SQLTransformer, where the query is run. @@ -274,10 +288,13 @@ getLogger().debug("Executing query nr " + index); } =20 - this.outUri =3D getCurrentQuery().properties.getParameter(SQLTrans= former.MAGIC_NS_URI_ELEMENT, NAMESPACE); - this.outPrefix =3D getCurrentQuery().properties.getParameter(SQLTr= ansformer.MAGIC_NS_PREFIX_ELEMENT, ""); + this.outUri =3D getCurrentQuery().properties.getParameter(SQLTrans= former.MAGIC_NS_URI_ELEMENT, namespaceURI); + this.outPrefix =3D getCurrentQuery().properties.getParameter(SQLTr= ansformer.MAGIC_NS_PREFIX_ELEMENT, "sql"); =20 - if (!"".equals(this.outUri)) { + // Start prefix mapping for output namespace + // only if its URI is not empty, and if it is not this transformer= namespace. + final boolean startPrefixMapping =3D !"".equals(this.outUri) && !n= amespaceURI.equals(this.outUri); + if (startPrefixMapping) { super.startPrefixMapping(this.outPrefix, this.outUri); } =20 @@ -314,13 +331,11 @@ if (!query_failure) { AttributesImpl attr =3D new AttributesImpl(); if (this.showNrOfRows) { - attr.addAttribute(NAMESPACE, query.nr_of_rows, query.n= r_of_rows, "CDATA", - String.valueOf(query.getNrOfRows())); + attr.addAttribute("", query.nr_of_rows, query.nr_of_ro= ws, "CDATA", String.valueOf(query.getNrOfRows())); } String name =3D query.getName(); if (name !=3D null) { - attr.addAttribute(NAMESPACE, query.name_attribute, que= ry.name_attribute, "CDATA", - name); + attr.addAttribute("", query.name_attribute, query.name= _attribute, "CDATA", name); } start(query.rowset_name, attr); =20 @@ -339,7 +354,6 @@ =20 end(query.rowset_name); } - } catch (SQLException e) { getLogger().debug("Exception in executeQuery()", e); throw new SAXException(e); @@ -355,7 +369,7 @@ } } =20 - if (!"".equals(this.outUri)) { + if (startPrefixMapping) { super.endPrefixMapping(this.outPrefix); } } @@ -483,15 +497,13 @@ case SQLTransformer.STATE_INSIDE_QUERY_ELEMENT: int level =3D 0; try { - level =3D Integer.parseInt(attributes.getValue(NAMESPA= CE, - SQLTransf= ormer.MAGIC_ANCESTOR_VALUE_LEVEL_ATTRIBUTE)); + level =3D Integer.parseInt(getAttributeValue(attribute= s, SQLTransformer.MAGIC_ANCESTOR_VALUE_LEVEL_ATTRIBUTE)); } catch (Exception e) { getLogger().debug("Exception in startAncestorValueElem= ent", e); throwIllegalStateException("Ancestor value elements mu= st have a " + SQLTransformer.MAGIC_ANCEST= OR_VALUE_LEVEL_ATTRIBUTE + " attribute"); } - String name =3D attributes.getValue(NAMESPACE, - SQLTransformer.MAGIC_ANC= ESTOR_VALUE_NAME_ATTRIBUTE); + String name =3D getAttributeValue(attributes, SQLTransform= er.MAGIC_ANCESTOR_VALUE_NAME_ATTRIBUTE); if (name =3D=3D null) { throwIllegalStateException("Ancestor value elements mu= st have a " + SQLTransformer.MAGIC_ANCEST= OR_VALUE_NAME_ATTRIBUTE + " attribute"); @@ -526,8 +538,7 @@ throws ProcessingException, SAXException { switch (current_state) { case SQLTransformer.STATE_INSIDE_QUERY_ELEMENT: - String name =3D attributes.getValue(NAMESPACE, - SQLTransformer.MAGIC_SUB= STITUTE_VALUE_NAME_ATTRIBUTE); + String name =3D getAttributeValue(attributes, SQLTransform= er.MAGIC_SUBSTITUTE_VALUE_NAME_ATTRIBUTE); if (name =3D=3D null) { throwIllegalStateException("Substitute value elements = must have a " + SQLTransformer.MAGIC_SUBSTI= TUTE_VALUE_NAME_ATTRIBUTE + " attribute"); @@ -607,10 +618,8 @@ protected void startInParameterElement(Attributes attributes) { switch (current_state) { case SQLTransformer.STATE_INSIDE_EXECUTE_QUERY_ELEMENT: - String nr =3D attributes.getValue(NAMESPACE, - SQLTransformer.MAGIC_IN_PA= RAMETER_NR_ATTRIBUTE); - String value =3D attributes.getValue(NAMESPACE, - SQLTransformer.MAGIC_IN= _PARAMETER_VALUE_ATTRIBUTE); + String nr =3D getAttributeValue(attributes, SQLTransformer= .MAGIC_IN_PARAMETER_NR_ATTRIBUTE); + String value =3D getAttributeValue(attributes, SQLTransfor= mer.MAGIC_IN_PARAMETER_VALUE_ATTRIBUTE); if (getLogger().isDebugEnabled()) { getLogger().debug("IN PARAMETER NR " + nr + "; VALUE "= + value); } @@ -632,12 +641,9 @@ protected void startOutParameterElement(Attributes attributes) { switch (current_state) { case SQLTransformer.STATE_INSIDE_EXECUTE_QUERY_ELEMENT: - String name =3D attributes.getValue(NAMESPACE, - SQLTransformer.MAGIC_OUT= _PARAMETER_NAME_ATTRIBUTE); - String nr =3D attributes.getValue(NAMESPACE, - SQLTransformer.MAGIC_OUT_P= ARAMETER_NR_ATTRIBUTE); - String type =3D attributes.getValue(NAMESPACE, - SQLTransformer.MAGIC_OUT= _PARAMETER_TYPE_ATTRIBUTE); + String name =3D getAttributeValue(attributes, SQLTransform= er.MAGIC_OUT_PARAMETER_NAME_ATTRIBUTE); + String nr =3D getAttributeValue(attributes, SQLTransformer= .MAGIC_OUT_PARAMETER_NR_ATTRIBUTE); + String type =3D getAttributeValue(attributes, SQLTransform= er.MAGIC_OUT_PARAMETER_TYPE_ATTRIBUTE); if (getLogger().isDebugEnabled()) { getLogger().debug("OUT PARAMETER NAME" + name + ";NR "= + nr + "; TYPE " + type); } Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/databases/samples/transfo= rm/sql-page.xml URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/= databases/samples/transform/sql-page.xml?rev=3D167969&r1=3D167968&r2=3D1679= 69&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- cocoon/branches/BRANCH_2_1_X/src/blocks/databases/samples/transform/sql= -page.xml (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/databases/samples/transform/sql= -page.xml Tue May 3 12:49:23 2005 @@ -32,7 +32,7 @@ - select id, name from employee where department_id =3D + select id, name from employee where department_id =3D Modified: cocoon/branches/BRANCH_2_1_X/src/documentation/xdocs/userdocs/tra= nsformers/sql-transformer.xml URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/documen= tation/xdocs/userdocs/transformers/sql-transformer.xml?rev=3D167969&r1=3D16= 7968&r2=3D167969&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- cocoon/branches/BRANCH_2_1_X/src/documentation/xdocs/userdocs/transform= ers/sql-transformer.xml (original) +++ cocoon/branches/BRANCH_2_1_X/src/documentation/xdocs/userdocs/transform= ers/sql-transformer.xml Tue May 3 12:49:23 2005 @@ -48,11 +48,11 @@ - =20 - + =20 + - - + + ]]>

@@ -72,7 +72,7 @@ query, you can use another transformer to check the name of the = rowset and to execute the necessary business logic on it.
- usage: <query name=3D"myName"> + usage: <sql:query name=3D"myName">

  • isstoredprocedure: @@ -80,7 +80,7 @@ this attribute to the query element. By default, the transformer assumes that you want to execute a SQL statement.
    - usage: <query isstoredprocedure=3D"true"> + usage: <sql:query isstoredprocedure=3D"true">
  • Here is an example of how the input XML might look like:

    @@ -90,11 +90,11 @@ Hello This is my first Cocoon page filled with sql data! - =20 - - select id,name from department_table=20 - - + =20 + + select id,name from department_table=20 + + ]]> @@ -136,17 +136,17 @@ Hello This is my first Cocoon page filled with sql data! - - - 1 - Programmers - - - 2 - Loungers - - + + + 1 + Programmers + + + 2 + Loungers + + ]]> @@ -179,13 +179,13 @@

    - - - select id,name from employee_table where name =3D - '' - - + + + + select id,name from employee_table where name =3D + '' + + ]]>

    @@ -211,13 +211,13 @@

    The output XML will be as follow:

    - - - 2 - Stefano Mazzocchi - - + + + + 2 + Stefano Mazzocchi + + ]]>

    @@ -230,18 +230,18 @@

    Take following input XML:

    - - - select id,name from department_table - - - - select id,name from employee_table where department_id =3D - - - - + + + + select id, name from department_table + + + + select id, name from employee_table where department_id =3D + + + + ]]>

    @@ -255,34 +255,34 @@

    - - - 1 - Programmers - - - 1 - Donald Ball - - - 2 - Stefano Mazzocchi - - - - - 2 - Loungers - - - 3 - Pierpaolo Fumagalli - - - - + + + + 1 + Programmers + + + 1 + Donald Ball + + + 2 + Stefano Mazzocchi + + + + + 2 + Loungers + + + 3 + Pierpaolo Fumagalli + + + + ]]> @@ -297,8 +297,9 @@

    + ]]>

    where:

      @@ -325,19 +326,19 @@

      - - - begin QUICK_SEARCH.FIND_NAME('',?,?,?); end; - - - - - + + + + begin QUICK_SEARCH.FIND_NAME('',?,?,?); end; + + + + + ]]>

      @@ -348,7 +349,7 @@ ResultSet, a rowset element will be cr= eated, containing all the data of the resultset. It is also possible to= use an in-parameter element, e.g. - <in-parameter sql:nr=3D"1" sql:value=3D"1"/>.= This + <sql:in-parameter nr=3D"1" value=3D"1"/>. This functionality is only provided to be complete, because it is ava= ilable in Java itself. You can also use the in-parameter in combination with a SQL statement. Used in combination with an @@ -358,7 +359,7 @@ - +

      When you query a database and it returns too many rows to proces= s at once, you might want to take a block of elements, process this b= lock @@ -376,21 +377,21 @@

      Output XML from the SQLTransformer:

      - + + - - + + - + =20 ... =20 - + - - + + ]]>

      By adding following lines to the sitemap, just under the @@ -408,25 +409,25 @@

      output XML:

      + - + - + =20 =20 - + - + - + ]]>

      To make it more dynamically, put something like Modified: cocoon/branches/BRANCH_2_1_X/status.xml URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?= rev=3D167969&r1=3D167968&r2=3D167969&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- cocoon/branches/BRANCH_2_1_X/status.xml (original) +++ cocoon/branches/BRANCH_2_1_X/status.xml Tue May 3 12:49:23 2005 @@ -196,6 +196,22 @@ =20 + + Databases: Changes in SQLTransformer: +

        +
      • By default, output resulting XML using 'sql' namespace prefix.=
      • +
      • Accept non-namespaced attributes in the input XML, + and prefer them over attributes in SQLTransformer namespace.
      • +
      • Support configured namespace, instead of hardcoded value.
      • +
      + + + Databases: SQLTransformer: Output attributes on rowset element with + empty namespace. + + + Databases: SQLTransformer: Avoid declaring duplicate namespaces. + Databases: Removed xml-encoding parameter from the SQLTransformer co= nfiguration. The latest SQLTransformer has no byte to character conversions.