cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eliza.Khosr...@tminus10.com
Subject Robin? Re: How to Call Servlets, CGIs on your server and other servers; Servlet Chaining
Date Mon, 18 Sep 2000 20:13:10 GMT

Robin,

Thanks for your response.  I just had one more question that I was
wondering if you can help me.

My servlet is outputting an XML tree as a big XML string.  Specifically, it
will return a string containing the following:
          <Category>
                <Name>...</Name>
                <Description>...</Description>
         </Category>
          <Category>
                 <Name>...</Name>
                 <Description>...</Description>
          </Category>
           ....
I would like to embed the above XML tree in my XSP page where I called the
servlet.

Is there a way I can convert the XML string to XML node in my XSP page
after getting it from my servlet?
I am assuming another way would be to have my servlet dump XML node and not
string. If so, are there some documentation or sample codes
on how to create and build the above node in my servlet?  Also, if my
servlet output the XML node,  then after calling
               Object content = new URL
("http://...../myservlet:).getContent()
in my XSP page,
can I treat the content as a node and simply call
               xspCurrentNode.appendChild(document.importNode(node, true));
in my XSP page.

Thanks in advance for your help.

Below is my XSP page and my servlet.


sample.xml
===========
<?xml version="1.0"?>

<?cocoon-process type="xsp"?>

<?cocoon-process type="xslt"?>
<?xml-stylesheet href="sample.xsl" type="text/xsl"?>

<xsp:page
  language="java"
  xmlns:xsp="http://www.apache.org/1999/XSP/Core"
>

<Page>

     <!-- begin static data -->
     <Title>My HomePage</Title>
     <NavigationBar>
        <Item>
           <Name>Help</Name>
           <URL>help.xml</URL>
        </Item>
        <Item>
           <Name>About</Name>
           <URL>about.xml</URL>
        </Item>
        <Item>
           <Name>Login</Name>
           <URL>login.xml</URL>
        </Item>
        <Item>
           <Name>Register</Name>
           <URL>register.xml</URL>
        </Item>
      </NavigationBar>
      <!-- end static data -->

     <!-- start of dynamic data, so call servlet -->
     <GetCategories>
         <xsp:logic>


        URL junk = new URL("http://localhost/servlets/GetCategories");
     BufferedReader in = new BufferedReader(
                    new InputStreamReader(
                    junk.openStream()));

     String inputLine = null;

     while ((inputLine = in.readLine()) != null)
        {
         <xsp:content>
                   <xsp:expr>inputLine</xsp:expr>
            </xsp:content>
        }
     in.close();


      </xsp:logic>
  </GetCategories>

</Page>
</xsp:page>




GetCategories.java servlet
=======================

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class GetCategories extends HttpServlet
{
     public String getServletInfo()
     {
          return "Servlet to report a set of categories";
     }



     public void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException
     {

            PrintWriter out;


          resp.setContentType("text/xml");

            out = resp.getWriter();

          out.println("<Category>");
          out.println("<Name>Music</Name>");
          out.println("<Description>contains music-related
videos</Description>");
          out.println("</Category>");
          out.println("<Category>");
          out.println("<Name>Wedding</Name>");
          out.println("<Description>contains wedding-related
videos</Description>");
          out.println("</Category>");
          out.println("<Category>");
          out.println("<Name>Humor</Name>");
          out.println("<Description>contains humorous
videos</Description>");
          out.println("</Category>");
          out.println("<Category>");
          out.println("<Name>Animals</Name>");
          out.println("<Description>contains animals
videos</Description>");
          out.println("</Category>");
          out.println("<Category>");
          out.println("<Name>Children</Name>");
          out.println("<Description>contains children
videos</Description>");
          out.println("</Category>");
          out.println("<Category>");
          out.println("<Name>Sports</Name>");
          out.println("<Description>contains sports-related
videos</Description>");
          out.println("</Category>");

          out.close();

     }

}


Mime
View raw message