You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Jon Williams <jo...@ulanguzi.com> on 2002/05/08 18:18:20 UTC

data from url into java String

I've made a great deal of progress on this problem already, but i seem to
have hit a snag.
 
i have this line in my XSP:
 
<cinclude:include
src="http://localhost:8080/exist/modify_rank/includeXmlTest.xsp" />
 
which causes the include of data that looks like:
 
<xsp:logic>
String xml="&lt;/content&gt;";
</xsp:logic>
 
alas, cincludes appear to be processed *after* the XSP page is compiled
and so i end up with the above XML in my output stream, rather than it
being executed along with the rest of the XSP page.
 
just fyi, what i'm going for is to get "entity-fied" XML (via
xml-to-string.xsl)
into a java variable, so i can pass it to a taglib that saves it into an XML
repository.
 
So what i really need, is to get dynamic text (XML in this case) into a Java
string at runtime... 
and here i thought i almost had it... isn't there a load_String_from_URL
method somewhere???
 
i've been reading the archives for months -- thanks for the kickin' resource
 
:j

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


Re: data from url into java String

Posted by Christoph Gaffga <cg...@triplemind.com>.
> So what i really need, is to get dynamic text (XML in this case) into a
Java
> string at runtime...
> and here i thought i almost had it... isn't there a load_String_from_URL
> method somewhere???

That's easy, but has nothing to do with Cocoon:

      import java.io.InputStream;
      import java.net.URL;

      String s = "";

      try {
        InputStream in = new
URL("http://www.someurl.com/somepage.xml").openStream();
        int c;
        while( (c=in.read()) != -1) {
          s += (char) c;
        }
        in.close();
      } catch ( Exception e) {
        e.printStackTrace();
      }

Yout page from someurl is in String s!

yours
Christoph


----- Original Message -----
From: "Jon Williams" <jo...@ulanguzi.com>
To: <co...@xml.apache.org>
Sent: Wednesday, May 08, 2002 6:18 PM
Subject: data from url into java String


> I've made a great deal of progress on this problem already, but i seem to
> have hit a snag.
>
> i have this line in my XSP:
>
> <cinclude:include
> src="http://localhost:8080/exist/modify_rank/includeXmlTest.xsp" />
>
> which causes the include of data that looks like:
>
> <xsp:logic>
> String xml="&lt;/content&gt;";
> </xsp:logic>
>
> alas, cincludes appear to be processed *after* the XSP page is compiled
> and so i end up with the above XML in my output stream, rather than it
> being executed along with the rest of the XSP page.
>
> just fyi, what i'm going for is to get "entity-fied" XML (via
> xml-to-string.xsl)
> into a java variable, so i can pass it to a taglib that saves it into an
XML
> repository.
>
> So what i really need, is to get dynamic text (XML in this case) into a
Java
> string at runtime...
> and here i thought i almost had it... isn't there a load_String_from_URL
> method somewhere???
>
> i've been reading the archives for months -- thanks for the kickin'
resource
>
> :j
>
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
>
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


RE: data from url into java String

Posted by Vadim Gritsenko <va...@verizon.net>.
> From: Jon Williams [mailto:jon@ulanguzi.com]
> 
> I've made a great deal of progress on this problem already, but i seem
to
> have hit a snag.
> 
> i have this line in my XSP:
> 
> <cinclude:include
> src="http://localhost:8080/exist/modify_rank/includeXmlTest.xsp" />
> 
> which causes the include of data that looks like:
> 
> <xsp:logic>
> String xml="&lt;/content&gt;";
> </xsp:logic>
> 
> alas, cincludes appear to be processed *after* the XSP page is
compiled

Of course. If you have <map:generate type="serverpages"> and then
<map:transform type="xinclude"/> - it executed *exactly* in this order.


> and so i end up with the above XML in my output stream, rather than it
> being executed along with the rest of the XSP page.
> 
> just fyi, what i'm going for is to get "entity-fied" XML (via
> xml-to-string.xsl)
> into a java variable, so i can pass it to a taglib that saves it into
an XML
> repository.
> 
> So what i really need, is to get dynamic text (XML in this case) into
a Java
> string at runtime...
> and here i thought i almost had it... isn't there a
load_String_from_URL
> method somewhere???

Resolve your source using resolver (resolver.resolve(sURL)), and then
you can use XSPUtil.getContents(source.getInputStream()).

But personally, I would avoid using methods taking String instead of
Source (except may be for really small XML fragments).

Another thing to avoid is http:// pointing to the same Cocoon instance -
it's just ineffective.


> i've been reading the archives for months -- thanks for the kickin'
resource

PS Read some recent email about XSP to get what and when compiled.

Vadim


> :j


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>