I don't see how you can achieve the same functionality with XML without making the whole mess illegible and unusable.
Basically here is what needs to happen: 1. There is a tag that needs to read a file that is a fragment of HTML (JSP). Maybe that fragment could be an XML fragment, but so what? 2. The tag needs to have many many components within itself replaced at run time with computed values: Text that complete HTML controls. Text that represents in-line javascript for controlling functions for keeping state functioning properly. Text that fills out hidden fields so these have correct values for JavaScript functions on the client. 3. Could you use XSL syle transforms well to handle javascript / J2EE / hidden field interactions? I don't see how. Actually I confess I have never understood what good XSL provides, other than enhances complexity and reduced legibility. It seems to be a language all it's own, and without a profound need for it I see no reason to introduce it. I don't seel how xml entities would help either. Here is a typical problem: Consider the simple case where a hidden field with no value initially is populated by a javascript function before the form the javascript function is on is submitted to a page. Perhaps there are items on the page that have a selection based on the values of the request (like a check box, or selection list for instance). The page when regenerated needs to fill out the hidden field with the appropriate values, needs to set the values for the check boxes, or selection lists and needs to regenerate any other required HTML appearances what might be controlling state (such as having rows or columns hilighted a special runtime color to indicate selection). I think something better would be to re-interpret the HTML (or rather change it into JSP instead, and have that re-interpreted). I don't know how I would have that worke though. -G Brady Moritz wrote: > Without really looking at this, isn't string replacement better done as > tag replacement using xsl, ie use tags in the body indicating header, > etc and just transform via xsl? Or even just use xml entities? > > This is probably my favorite thing about xml... its like having a string > with variables/placeholders built into it that can programmatically be > replaced, thus preventing durdeehacking involving many string > concatenations. > > Brady Moritz > > -----Original Message----- > From: Greg Bishop [mailto:[EMAIL PROTECTED]] > Sent: Friday, February 01, 2002 5:05 PM > To: Tag Libraries Users List > Subject: Re: JavaScript Functions-like Taglib > > OK, save, here is something better.... > > /** Takes a string, and replaces the replace text with new text. > * @param str String to replace into > * @param pattern Pattern of text to replace. > * @param replace What to replace it with. > * @return str with the replace text replaced with the new text. > */ > protected static String replace(String str,String pattern, String > replace) { > int s = 0; > int e = 0; > StringBuffer result = new StringBuffer(); > > while ((e = str.indexOf(pattern, s)) >= 0) { > result.append(str.substring(s, e)); > result.append(replace); > s = e+pattern.length(); > } > result.append(str.substring(s)); > return result.toString(); > } > > Ok, here's a shorter one that works better. > > Also, a faster implementation. > > private static String templateText; > > public javascriptJSPInteractiveTagThingy() { > super(); > StringBuffer sb = new StringBuffer(); > try { > BufferedReader br = new BufferedReader(new > FileReader("/home/gbishop/www/bmg/dev/run/ckie/jsp/charttabletag.templat > e")); > String line; > while( ((line=br.readLine())!=null)){ > sb.append(line); > sb.append("\n"); > } > } catch(IOException e) { > System.err.println("IO Error: " + e.getMessage()); > } > templateText = sb.toString(); > } > > /** > * Reads a file from the disk. Replaces XXXX_GOES_HERE text in the > file with > * Strings that contain the things we want the tag to show. Looks at > the page > * attributes to control the appearance of the tag's generated HTML. > */ > public int doStartTag() throws JspTagException > { > ... > JspWriter wr = pageContext.getOut(); > PrintWriter writer = new PrintWriter(wr); > String line = templateText; > line = replace(line, "HEADER_GOES_HERE", header ); > line = replace(line, "TABLE_CONTENTS_GOES_HERE", > tableContents ); > line = replace(line, "SELECTIONS_GOES_HERE", > pageContext.getRequest().getParameter("TableSelections") ); > line = replace(line, "BACKGROUND_COLOR_GOES_HERE", > backgroundColor ); > line = replace(line, "HILIGHTED_COLOR_GOES_HERE", > hilightedColor ); > line = replace(line, "DRAG_COLOR_GOES_HERE", dragColor > ); > line = replace(line, "SELECTED_COLOR_GOES_HERE", > selectedColor ); > line = replace(line, "BORDER_COLOR_GOES_HERE", borderColor > ); > line = replace(line, "TABLE_DATA_VIEW_NAME_GOES_HERE", > tableDataViewHiddenFieldName ); > line = replace(line, "HTCS_TO_INVOKE_GOES_HERE", htcs ); > writer.println(line); > > return SKIP_BODY; > ... > > Dave Newton wrote: > > > I know it's protocode :) > > > > On Friday 01 February 2002 15:22, Greg Bishop wrote: > > > protected static String replaceTextInMiddleOfStringIfItExists(String > str, > > > String > replace, > > > String > newtext){ > > > > Well, seems to me the "IfItExists" is implied and it replaces text in > a string > > regardless of location (doesn't have to be in the middle) so why > bother > > with the novella function name? ;) > > > > Dave > > -- > To unsubscribe, e-mail: > <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: > <mailto:[EMAIL PROTECTED]> > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>