You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Mike LaRocca <la...@spinnakernet.com> on 2000/12/01 14:58:01 UTC

Re: cocoon2 bug in XSPObjectHelper.java

> > Found a usage bug with XSPObjectHelper.addAttribute()  where
attribute names
> > are not  making it into the SAX stream.  If the qualified attribute
name is
> > not set to the local attribute name then the attribute name will be
absent in
> > the output document.
> >   protected static void addAttribute(
> >     AttributesImpl attr,
> >     String name,
> >     String value
> >   )
> >     throws SAXException
> >   {
> >     // before fix
> >     //attr.addAttribute("", name, "", "CDATA", value);
>
> I havn't found that in the current CVS. It's already uncommented.

This line contains the bug which I've commented out (in my copy)
for documentation purposes.

> >     // after fix
> >     attr.addAttribute("", name, name, "CDATA", value);
>
> Using this signature dosn't compile!

I'm suggesting that this is a fix.  Also, see line 137 of the enclosed
listing for
clarity (note it compiles!).  Compare to line 137 in CVS.
http://xml.apache.org/websrc/index.cgi/xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/Attic/XSPObjectHelper.java?rev=1.1.2.4&content-type=text/vnd.viewcvs-markup

> > I found this with a logicsheet helper object that I'm working on but

> > you can reproduce the problem by running the simple.xsp exmple for
> > cocoon2. eg.
http://localhost:8080/cocoon/xsp/simple?name=bush&name=gore
> >
> > Output before fix (NOTE the missing attribute name 'name'):
> >      Parameter Values for "":
> >         bush
> >         gore
> >
> > Output after fix:
> >      Parameter Values for "name":
> >         bush
> >         gore
>
> I can't get the on nor the other. I have *no* values at all (no "bush"

> and no "gore").

I tried again and was able to reproduce the same result with and without

the fix to line 137.  I'm working with a snapshot from Nov23.

--Mike
larocca@spinnakernet.com

/local/xml-cocoon>javac
./src/org/apache/cocoon/components/language/markup/xsp/XSPObjectHelper.java

/local/xml-cocoon> pr -n
./src/org/apache/cocoon/components/language/markup/xsp/XSPObjectHelper.java

    1
/*****************************************************************************

    2    * Copyright (C) The Apache Software Foundation. All rights
reserved.        *
    3    * ---------------------------------------------------- *
    4    * This software is published under the terms of the Apache
Software License *
    5    * version 1.1, a copy of which has been included  with this
distribution in *
    6    * the LICENSE
file.                                                         *
    7
*****************************************************************************/

    8   package org.apache.cocoon.components.language.markup.xsp;
    9
   10   import org.xml.sax.ContentHandler;
   11   import org.xml.sax.helpers.AttributesImpl;
   12
   13   import org.xml.sax.SAXException;
   14
   15   /**
   16    * Base class for XSP's object model manipulation logicsheets
   17    *
   18    * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>

   19    * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/08/31 16:41:58
$
   20    */
   21   public class XSPObjectHelper {
   22     /**
   23      * Empty attributes used for contentHandler.startElement()
   24      */
   25     protected static final AttributesImpl emptyAttr = new
AttributesImpl();
   26
   27     /**
   28      * Uri and prefix associated with object helper. Derived
classes must assign
   29      * these variables to their proper values
   30      */
   31     protected static String URI;
   32     protected static String PREFIX;
   33
   34     /**
   35      * Output an element containing text only and no attributes
   36      *
   37      * @param contentHandler The SAX content handler
   38      * @param name The element name
   39      * @param data The data contained by the element
   40      */
   41     protected static void elementData(
   42       ContentHandler contentHandler,
   43       String name,
   44       String data
   45     )
   46       throws SAXException
   47     {
   48       start(contentHandler, name);
   49       data(contentHandler, data);
   50       end(contentHandler, name);
   51     }
   52
   53     /**
   54      * Output an element containing text only and attributes
   55      *
   56      * @param contentHandler The SAX content handler
   57      * @param name The element name
   58      * @param data The data contained by the element
   59      * @param attr The element attributes
   60      */
   61     protected static void elementData(
   62       ContentHandler contentHandler,
   63       String name,
   64       String data,
   65       AttributesImpl attr
   66     )
   67       throws SAXException
   68     {
   69       start(contentHandler, name, attr);
   70       data(contentHandler, data);
   71       end(contentHandler, name);
   72     }
   73
   74     /**
   75      * Start an element with the proper object's uri and prefix
and no
   76      * attributes
   77      *
   78      * @param contentHandler The SAX content handler
   79      * @param name The element name
   80      */
   81     protected static void start(
   82       ContentHandler contentHandler,
   83       String name
   84     )
   85       throws SAXException
   86     {
   87       contentHandler.startElement(URI, name, PREFIX + ":" + name,
emptyAttr);
   88     }
   89
   90     /**
   91      * Start an element with the proper object's uri and prefix
and with
   92      * attributes
   93      *
   94      * @param contentHandler The SAX content handler
   95      * @param name The element name
   96      * @param attr The element attributes
   97      */
   98     protected static void start(
   99       ContentHandler contentHandler,
  100       String name,
  101       AttributesImpl attr
  102     )
  103       throws SAXException
  104     {
  105       contentHandler.startElement(URI, name, PREFIX + ":" + name,
attr);
  106     }
  107
  108     /**
  109      * End an element with the proper object's uri and prefix
  110      *
  111      * @param contentHandler The SAX content handler
  112      * @param name The element name
  113      */
  114     protected static void end(
  115       ContentHandler contentHandler,
  116       String name
  117     )
  118       throws SAXException
  119     {
  120       contentHandler.endElement(URI, name, PREFIX + ":" + name);
  121     }
  122
  123     /**
  124      * Add an attribute
  125      *
  126      * @param attr The attribute list
  127      * @param name The attribute name
  128      * @param value The attribute value
  129      */
  130     protected static void addAttribute(
  131       AttributesImpl attr,
  132       String name,
  133       String value
  134     )
  135       throws SAXException
  136     {
  137       attr.addAttribute("", name, name, "CDATA", value);
  138     }
  139
  140     /**
  141      * Add string data
  142      *
  143      * @param contentHandler The SAX content handler
  144      * @param data The string data
  145      */
  146     protected static void data(
  147       ContentHandler contentHandler,
  148       String data
  149     )
  150       throws SAXException
  151     {
  152       contentHandler.characters(data.toCharArray(), 0,
data.length());
  153     }
  154   }