I need some basic DIGESTER help!  I think I'm trying to do something simple,
but it's not working for me and I've tried several things, etc,etc,etc...  I
just want to parse  an XML string that looks like:
<loginerr>
<errnum>18</errnum>
<errdesc>Your smallcorp site login has expired!!</errdesc>
</loginerr>

My ErrResp.java bean that should result in the parse looks like:

package com.oaktree.struts.common;

import java.io.Serializable;

public class ErrResp implements Serializable {
   private int errnum = 0;
   private String errdesc = null;

    // -- integer code for the error
   public int getErrnum() {
      return errnum;
   }

   public void setErrnum(int errnum) {
      this.errnum = errnum;
   }

   // -- description of error
   public String getErrdesc() {
      return errdesc;
   }

   public void setgetErrdesc(String errdesc) {
      this.errdesc = errdesc;
   }

   // -- Utils
   public String toString()  {
      StringBuffer sb = new StringBuffer("ErrResp is:\n");


      sb.append("Errnum=" + errnum + ".\n");
      sb.append("Errdesc=" + errdesc + ".\n");
      return sb.toString();
   }


}

AND my code (in the LoginAction.java ) looks like:

     // simulate XML string return for an error.
      StringBuffer xmlerr = new StringBuffer("");
      xmlerr.append("<loginerr>\n");

      xmlerr.append("<errnum>18</errnum>\n");
      xmlerr.append("<errdesc>Your smallcorp site login has
expired!!</errdesc>\n");

      xmlerr.append("</loginerr>\n");

      // Use Apache digester util to parse that xml string.
      // LoginResp bean : it contains: Away, Buddy, Group beans
      String xrsp = xmlerr.toString();
      System.out.println("XML is:\n" + xrsp);
      Digester digester = new Digester();
      digester.push(this);
      digester.setDebug(10);
      digester.setValidating(false);
      digester.addObjectCreate("loginerr",
          "com.oaktree.struts.common.ErrResp");
      digester.addSetProperties("loginerr");
      digester.addSetNext("loginerr", "gotErr",
          "com.oaktree.struts.common.ErrResp");

      try {
          digester.parse(new org.xml.sax.InputSource(new
StringReader(xrsp)));
      } catch (IOException e){
          e.printStackTrace();
      } catch (SAXException e) {
          e.printStackTrace();
      }




The 'gotErr ' that's referred to above is in the LoginAction.java class and
is simply:

    // Method called after parsing a Loginerr XML Response:
    public void gotErr(ErrResp er)
    {
        System.out.println("ErrResp bean:\n" + er.toString());
    }




When it runs, the debug output I see in my window is:

New com.oaktree.struts.common.ErrResp
Set com.oaktree.struts.common.ErrResp properties
Call com.oaktree.struts.logon.LogonAction.gotErr(ErrResp is:
Errnum=0.
Errdesc=null.
)
ErrResp bean:
ErrResp is:
Errnum=0.
Errdesc=null.

Pop com.oaktree.struts.common.ErrResp

... I see the ErrResp object gets created, then properties set, but when
gotErr is called, the bean is empty.  I'm not understanding why this
straightforward case isn't working!  Otherwise, I think the Digester utility
is pretty slick, and I'd also be interested in the reverse-digester utility,
if any, question in "tiles / portal / digester" message subject post.

Paula Young

winmail.dat

Reply via email to