Skip to Content
author's profile photo Former Member
Former Member

rendering xml iviews in java

hi there..

I've wrote an iview which renders and iview just like the .net using sap's xml and I'm trying to get it working. I think the iView server is having some problems with characters but I'm not sure how to replace them without extensive code..

in .net I can simply do this:

temp = Replace(temp, "href=""", "target=""_new"" href=""")

but I'm thinking I cannot use string.replaceAll or string.replace because we must use sdk 1.3.1 instead of 1.4.. and I dont want to tokenize etc.. unless I have to. Is there an easy way to replace characters in a string so my xml will not have problems because when it renders through the iview server it says:

"Incorrect syntax was used in a comment."

I need to replace all odd characters and html encode the &, "," etc.. any advice?

see code:

//Â Â This program written by John Mittendorf

//Â Â as a template for the SAP XML iView parcer

//

//Â Â This program in particulat goes to http://www.chron.com (Houston Chronicle Newspaper)

//Â Â and dnloads the top stories form the web page

//

//Â Â This program opens a stream from a url and

//Â Â is used to then parse the url for content in

//Â Â a format that the SAP Portal can understand

import com.sapportals.portal.prt.component.*;

import java.io.*;

import java.net.*;

public class aportalparser extends AbstractPortalComponent

{

    public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)

    {

   URL uRL;

   InputStream incommingStream = null;

   DataInputStream dis;

   String buff="";

   String incommingString;

   String out;

   String tweaked;

   String subStr;

   int Start=0;

   int End=0;

   int StartPos=0;

   int EndPos = 0;

//Write xml for iView server.. note the escape char ..language="HyperRelational".. the "" for the ""

//See the portal iView dev docs for detail on the xml

response.write(

"");

//Code to nab the url data and put it into a stream

  try {

   uRL = new URL("http://www.chron.com");

   incommingStream = uRL.openStream();

   dis = new DataInputStream(new BufferedInputStream(incommingStream));

   while ((incommingString = dis.readLine()) != null)

   {

    buff += incommingString; //reads one line at a time and concatenates

   }

   //tweak the buffer and thin it down between content search points

   Start=(buff.indexOf("<! TOP STORY2 VIGNETTE LIST ->", StartPos + 32));

   End=(buff.indexOf("<! OTHER NEWS >", StartPos)+ 0);

   tweaked=buff.substring(Start, End);

   //start parsing.. page is nasty so the code is also...

   //reset the string parse points for the tweaked buffer

   StartPos = 0;

   EndPos=0;

   //start to search here.. we need to grap one before the loop

   StartPos=(tweaked.indexOf("Cassius called", StartPos + 14));

   //nab top article

   StartPos = (tweaked.indexOf("");

   }

}

Add comment
10|10000 characters needed characters exceeded

2 Answers

  • Posted on Feb 22, 2004 at 02:30 PM
    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 23, 2004 at 11:11 AM

    When bound to jdk1.3, a good and powerfull way to work with strings is a library for regular expressions, e.g.: http://jakarta.apache.org/regexp/index.html

    JDK1.4 already contains a regex library.

    Add comment
    10|10000 characters needed characters exceeded