You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-users@xml.apache.org by Lisa McCabe <lm...@myeastern.com> on 2005/07/25 15:19:58 UTC

JSP, JavaBeans and Xindice

Hi,

I am trying to call Xindice from a JavaBean and serve the results to a JSP page. My Xindice code works as a standalone java program but does not return any results in the bean. There is no runtime error, just returns with no results.

Any ideas why this does not work? Is it sending the results to somewhere else?

Thanks,
Lisa McCabe

Re: JSP, JavaBeans and Xindice

Posted by Lisa McCabe <lm...@myeastern.com>.
Hi,

I have run my query with this URI on my standalone java prog so I am confident that they are correct. I have added print statements all over the code and once the line Class c = Class.forName(driver); is called, all print stmts stop. Its like System.out gets redirected. Very strange. Should I be using embed.DatabaseImpl?

Thanks for helping,
Lisa

  ----- Original Message ----- 
  From: Marcin Goldyn 
  To: xindice-users@xml.apache.org 
  Sent: Monday, July 25, 2005 4:57 PM
  Subject: Re: JSP, JavaBeans and Xindice


  it looks ok
  did u check if URI is ok?
  or in this loop
  while (resourceIterator.hasMoreResources()) {

  Resource resource = resourceIterator.nextResource();

  myResult.append((String) resource.getContent());

  }

  try to put System.out.println((String) resource.getContent()); there and check if it print something. It can be also a wrong XPath Query. Try very simple query at the first time. 



  Marcin Goldyn

Re: JSP, JavaBeans and Xindice

Posted by Marcin Goldyn <Ma...@poczta.onet.pl>.
it looks ok
did u check if URI is ok?
or in this loop
while (resourceIterator.hasMoreResources()) {

Resource resource = resourceIterator.nextResource();

myResult.append((String) resource.getContent());

}

try to put System.out.println((String) resource.getContent()); there and check if it print something. It can be also a wrong XPath Query. Try very simple query at the first time. 



Marcin Goldyn

Re: JSP, JavaBeans and Xindice

Posted by Lisa McCabe <lm...@myeastern.com>.
Hi Marcin,

Here is my code:

package org.isetools;

import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;
import org.xmldb.api.*;
import java.io.*;
public class XindiceBean {


public String callDB(String xpath) throws Exception {

Collection collection = null;

StringBuffer myResult = new StringBuffer();

try {

String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";

Class c = Class.forName(driver);

Database database = (Database) c.newInstance();

database.setProperty("false", "true");

DatabaseManager.registerDatabase(database);

String uri = "xmldb:xindice-embed://localhost:8080/db/xml/metadata"; 

collection = DatabaseManager.getCollection(uri);


XPathQueryService service = (XPathQueryService) collection.getService("XPathQueryService", "1.0");


ResourceSet resourceSet = service.query(xpath);

ResourceIterator resourceIterator = resourceSet.getIterator();

while (resourceIterator.hasMoreResources()) {

Resource resource = resourceIterator.nextResource();

myResult.append((String) resource.getContent());

}

} catch (Exception e) {

System.err.println("XML:DB Exception occured ");

} finally {

if (collection != null) {

collection.close();

}

}

String text = myResult.toString();

return text;

}

}

Thanks for taking a look! My JSP page calls this bean, sending it the xpath query. I hope to manipulate the results with JSTL.

-Lisa McCabe



  ----- Original Message ----- 
  From: Marcin Goldyn 
  To: xindice-users@xml.apache.org 
  Sent: Monday, July 25, 2005 9:53 AM
  Subject: Re: JSP, JavaBeans and Xindice


  there can be a plenty of reasons 
  show us the code 
  Marcin Goldyn

Re: JSP, JavaBeans and Xindice

Posted by Marcin Goldyn <Ma...@poczta.onet.pl>.
there can be a plenty of reasons 
show us the code 
Marcin Goldyn