commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Luke Shannon" <lshan...@futurebrand.com>
Subject Re: Need a little help
Date Tue, 01 Feb 2005 15:58:59 GMT
Thank you Kishore;

Your suggestions make sense and work.

Now that things are working a little better a flaw has occurred to me. And I
am not married to this approach in anyway. If someone sees less complex way
of achieving my goal please let me know.

To review, the end result was to get a TreeMap containing all the name
attributes as keys and the contents of the item tags as values from a
directory of XML files containing the below schema.

<VERSION>
  <ITEM NAME="category" TYPE="text">Category 4</ITEM>
  <ITEM NAME="provider" TYPE="text">Provider</ITEM>
  <ITEM NAME="progress_ref" TYPE="text">11008</ITEM>
  <ITEM NAME="name" TYPE="text">Name</ITEM>
  <ITEM NAME="desc" TYPE="text">Description</ITEM>
  <ITEM NAME="poster" TYPE="text">Company Who Posted</ITEM>
  <ITEM NAME="sort" TYPE="text">8</ITEM>
  <ITEM DIR="x.ppt" HEIGHT="-1" NAME="kcfileupload" SIZE="9728" STYPE="file"
TYPE="upload" WIDTH="-1">x.ppt</ITEM>
</VERSION>

My plan was to have an Item class create a TreeMap for each item tag (key =
@NAME, value = contents of the tag).

At the close of each Item tag the TreeMap would be added to a TreeMap in the
Version class, which by the time the parser reaches the closing version tag
would contain entries for each of the item tags (it would get called for
each item tag).

Here are the methods below:

At the close of each item tag I need to call the method below in the Version
class. In the example above this method would be called 8 times resulting in
fieldsValues contain 8 key/value pairings.

 /**
  * @param items The iTEMS to set.
  */
 public void setItems(TreeMap map) {
  fieldsValues.putAll(map);
 }
}

This is the method in the Item class that supplies the argument for the
setITEMS above. For each item class it would be called once.

/**
  * @return Returns the iTEMS.
  */
 public TreeMap getMap() {
  return fieldsValues;

 }

Here is my parsing method. After set
digester.addCallMethod("DATA/VERSION/ITEM", "setContents", 0); I need to
call the setItems method in version with the getMap method of Item providing
the argument. I took a stab at it below, this doesn't even compile, but I
hope it illustrates what I mean. How can I do this? Is there a better way?

public Version digest() throws IOException, SAXException {
  digester = new Digester();
  digester.setValidating(false);
  digester.addObjectCreate("DATA/VERSION", Version.class);
  digester.addObjectCreate("DATA/VERSION/ITEM", Item.class);
  digester.addSetProperties("DATA/VERSION/ITEM", "Name", "name");
  digester.addCallMethod("DATA/VERSION/ITEM", "setContents", 0);
//how can i call the method of the version class with the item pattern,
using an item method for the arguement?
  digester.addCallMethod("DATA/VERSION/ITEM", "Version.setItems", "getMap");
    return (Version)digester.parse(parseMe);
 }

Thanks,

Luke


----- Original Message ----- 
From: "Kishore Senji" <ksenji@gmail.com>
To: "Jakarta Commons Users List" <commons-user@jakarta.apache.org>
Sent: Monday, January 31, 2005 7:18 PM
Subject: Re: Need a little help


> >
> > public Version digest() throws IOException, SAXException {
> >  digester = new Digester();
> >  digester.setValidating(false);
> >  digester.addObjectCreate("DATA/VERSION", Version.class);
> >  digester.addObjectCreate("DATA/VERSION/ITEM", Item.class);
> >  digester.addSetProperties("DATA/VERSION/ITEM", "name", "name");
>
> The above line should be
> digester.addSetProperties("DATA/VERSION/ITEM", "NAME", "name"); Since
> the NAME attribute is in capitals, where as the "name" property on
> Item is in small letters
>
> >  digester.addCallMethod("DATA/VERSION/ITEM", "setContents");
>
> Digester is not able to find setContents because the above tells
> digester to look for a method called setContents which takes no
> arguments. But the setContents on Item takes a String. Since you are
> looking to get the body content and set it to the contents of the
> Item, use
>
> digester.addCallMethod("DATA/VERSION/ITEM", "setContents", 0);
>
> You might also want to add the Item to the Version's map I believe.
> Since I don't see that call here, I would add it here
>
> digester.addSetNext("DATA/VERSION/ITEM", "addItem");
>
> Where "addItem" method will live on the Version class which takes an
> Item as an argument and add it to the TreeMap with the "name" of the
> "Item" as the key
>
> >  return (Version)digester.parse(parseMe);
> > }
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message