commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Luke Shannon" <lshan...@hypermedia.com>
Subject Re: More Digester Help
Date Tue, 09 Nov 2004 18:48:17 GMT
Hi Marco;

Here is the XML:

<?xml version="1.0" encoding="UTF-8"?>
<DATA>
   <DEF>
      <TYPE>138</TYPE>
      <TYPES/>
   </DEF>
   <VERSION>
      <ITEM NAME="provider" TYPE="text">me</ITEM>
      <ITEM NAME="progress_ref" TYPE="text">1098818760440</ITEM>
      <ITEM NAME="name" TYPE="text">file1folder1</ITEM>
      <ITEM NAME="desc" TYPE="text">rg</ITEM>
      <ITEM NAME="select" TYPE="text">Please Select...</ITEM>
      <ITEM NAME="poster" TYPE="text">hypermedia</ITEM>
      <ITEM NAME="sort" TYPE="text">3</ITEM>
      <ITEM DIR="apache_config_command.txt" HEIGHT="-1" NAME="kcfileupload"
SIZE="942" STYPE="file" TYPE="upload"
WIDTH="-1">apache_config_command.txt</ITEM>
   </VERSION>
</DATA>

Here is the XMLParser (uses Digester) and the Item class that I use to store
the data:

public class XMLParser {

 public Vector items;
 private Digester digester;
 private File parseMe;

 public XMLParser(File file) {
  parseMe = file;
  items = new Vector();
 }

 public XMLParser digest() throws IOException, SAXException {
  digester = new Digester();
  digester.push(this);
  digester.setValidating(false);
  digester.addObjectCreate("DATA/VERSION/ITEM", Item.class);
  digester.addCallMethod("DATA/VERSION/ITEM", "setItem", 0);
  digester.addSetNext("DATA/VERSION/ITEM", "addItems");
  return (XMLParser)digester.parse(parseMe);
 }

 public void addItems(Item i) {
  System.out.println("Adding: " + i.toString());
  items.add(i);
 }
}

public class Item {
 String item;

 public Item() { }

 /**
  * @param content The content to set.
  */
 public void setItem(String _item) {
  System.out.println("Adding to item object " + _item);
  item = _item;
 }

 public String toString() {
  return "This item contains: " + item.toString();
 }
}



----- Original Message ----- 
From: "Marco Mistroni" <mmistroni@waersystems.com>
To: "'Jakarta Commons Users List'" <commons-user@jakarta.apache.org>
Sent: Tuesday, November 09, 2004 1:12 PM
Subject: RE: More Digester Help


> Hello,
> It will be useful If you can post the xml file and
> The code that you are putting in digester..
> If you got a null , it probably means that some path defined in your
> Rules are not correct....
>
> Regards
> marco
>
> -----Original Message-----
> From: Luke Shannon [mailto:lshannon@hypermedia.com]
> Sent: 09 November 2004 18:09
> To: commons-user@jakarta.apache.org
> Subject: More Digester Help
>
> Hi All;
>
> Sorry about the double post earlier. Mail client is a little wacky.
>
> I am trying to parse my XML document and am getting the error below.
>
> Underneath the error you will find my XML doc and my Digester class and
> Bean
> Class.
>
> Basically I want to put all the contents of the INPUT tags into a
> StringBuffer I can use in the creation of a Lucene document.
>
> It was parsing correctly before, but the addItems method was getting a
> NULL
> each time it was called.
>
> I have been playing with the code to fix this problem and now end up
> with
> the error below. I am lost.
>
> Any tips would be greatly appreciated.
>
> Thanks,
>
> Luke
>
>
>
> 13:00:29,732java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at
> org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:2
> 16)
> at org.apache.commons.digester.SetNextRule.end(SetNextRule.java:208)
> at org.apache.commons.digester.Rule.end(Rule.java:228)
> at org.apache.commons.digester.Digester.endElement(Digester.java:1067)
> at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unk
> nown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDis
> patc
> her.dispatch(Unknown Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unkno
> wn
> Source)
> at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
> at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
> at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
> at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
> at org.apache.commons.digester.Digester.parse(Digester.java:1556)
> at model.XMLParser.digest(XMLParser.java:40)
> at model.XMLDocument.Document(XMLDocument.java:69)
> at servlets.Update.indexDocs(Update.java:124)
> at servlets.Update.indexDocs(Update.java:108)
> at servlets.Update.doGet(Update.java:81)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
> at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
> tion
> FilterChain.java:237)
> at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
> erCh
> ain.java:157)
> at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
> e.ja
> va:214)
> at
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo
> ntex
> t.java:104)
> at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5
> 20)
> at
> org.apache.catalina.core.StandardContextValve.invokeInternal(StandardCon
> text
> Valve.java:198)
> at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
> e.ja
> va:152)
> at
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo
> ntex
> t.java:104)
> at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5
> 20)
> at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
> :137
> )
> at
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo
> ntex
> t.java:104)
> at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
> :118
> )
> at
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo
> ntex
> t.java:102)
> at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5
> 20)
> at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
> java
> :109)
> at
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo
> ntex
> t.java:104)
> at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5
> 20)
> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
> at
> org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
> at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:79
> 9)
> at
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processC
> onne
> ction(Http11Protocol.java:705)
> at
> org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:57
> 7)
> at
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool
> .jav
> a:683)
> at java.lang.Thread.run(Unknown Source)
> Caused by: java.lang.NullPointerException
> at model.Item.toString(Item.java:29)
> at model.XMLParser.addItems(XMLParser.java:44)
> ... 48 more
> java.lang.NullPointerException
> at
> org.apache.commons.digester.Digester.createSAXException(Digester.java:27
> 92)
> at
> org.apache.commons.digester.Digester.createSAXException(Digester.java:28
> 18)
> at org.apache.commons.digester.Digester.endElement(Digester.java:1070)
> at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unk
> nown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDis
> patc
> her.dispatch(Unknown Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unkno
> wn
> Source)
> at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
> at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
> at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
> at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
> at org.apache.commons.digester.Digester.parse(Digester.java:1556)
> at model.XMLParser.digest(XMLParser.java:40)
> at model.XMLDocument.Document(XMLDocument.java:69)
> at servlets.Update.indexDocs(Update.java:124)
> at servlets.Update.indexDocs(Update.java:108)
> at servlets.Update.doGet(Update.java:81)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
> at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
> tion
> FilterChain.java:237)
> at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
> erCh
> ain.java:157)
> at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
> e.ja
> va:214)
> at
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo
> ntex
> t.java:104)
> at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5
> 20)
> at
> org.apache.catalina.core.StandardContextValve.invokeInternal(StandardCon
> text
> Valve.java:198)
> at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
> e.ja
> va:152)
> at
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo
> ntex
> t.java:104)
> at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5
> 20)
> at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
> :137
> )
> at
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo
> ntex
> t.java:104)
> at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
> :118
> )
> at
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo
> ntex
> t.java:102)
> at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5
> 20)
> at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
> java
> :109)
> at
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo
> ntex
> t.java:104)
> at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5
> 20)
> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
> at
> org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
> at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:79
> 9)
> at
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processC
> onne
> ction(Http11Protocol.java:705)
> at
> org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:57
> 7)
> at
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool
> .jav
> a:683)
> at java.lang.Thread.run(Unknown Source)
>
> public class XMLParser {
>
>  public Vector items;
>  private Digester digester;
>  private File parseMe;
>
>  public XMLParser(File file) {
>   parseMe = file;
>   items = new Vector();
>  }
>
>  public XMLParser digest() throws IOException, SAXException {
>   digester = new Digester();
>   digester.push(this);
>   digester.setValidating(false);
>   digester.addObjectCreate("DATA/VERSION/ITEM", Item.class);
>   digester.addCallMethod("DATA/VERSION/ITEM", "setItem", 0);
>   digester.addSetNext("DATA/VERSION/ITEM", "addItems");
>   return (XMLParser)digester.parse(parseMe);
>  }
>
>  public void addItems(Item i) {
>   System.out.println("Adding: " + i.toString());
>   items.add(i);
>  }
> }
>
> public class Item {
>  String item;
>
>  public Item() { }
>
>  /**
>   * @param content The content to set.
>   */
>  public void setItem(String _item) {
>   System.out.println("Adding to item object " + _item);
>   item = _item;
>  }
>
>  public String toString() {
>   return "This item contains: " + item.toString();
>  }
> }
>
> <?xml version="1.0" encoding="UTF-8"?>
> <DATA>
>    <DEF>
>       <TYPE>138</TYPE>
>       <TYPES/>
>    </DEF>
>    <VERSION>
>       <ITEM NAME="provider" TYPE="text">me</ITEM>
>       <ITEM NAME="progress_ref" TYPE="text">1098818760440</ITEM>
>       <ITEM NAME="name" TYPE="text">file1folder1</ITEM>
>       <ITEM NAME="desc" TYPE="text">rg</ITEM>
>       <ITEM NAME="select" TYPE="text">Please Select...</ITEM>
>       <ITEM NAME="poster" TYPE="text">hypermedia</ITEM>
>       <ITEM NAME="sort" TYPE="text">3</ITEM>
>       <ITEM DIR="apache_config_command.txt" HEIGHT="-1"
> NAME="kcfileupload"
> SIZE="942" STYPE="file" TYPE="upload"
> WIDTH="-1">apache_config_command.txt</ITEM>
>    </VERSION>
> </DATA>
>
>
>
> ---------------------------------------------------------------------
> 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
>
>



---------------------------------------------------------------------
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