Problems Using a javax.xml.transform.dom.DOMSource with xtags library
Hi, I have been having a great deal of difficulty transforming a org.w3c.dom.Document object with the xtags:style (and also x:transform) tag. All the examples have been targetted toward reading XML from a file ( url and StreamSource approaches). However, in our application we need to receive data from the business layer as an XML org.w3c.dom.Document object - I don't want to transform the Document object into a String object before trying the transformation. Here's the test code I've been using with what does and what doesn't seem to work: %@page language=java session=true% html body %@ taglib uri=examples-taglib prefix=eg % %@ taglib uri=jakarta-import-taglib prefix=c % %@ taglib uri=xtags-taglib prefix=xtags % %@ taglib uri=x-transform-taglib prefix=x % buResource description: /u/b !-- Trial XSLT -- !-- FORM tags always needed otherwise input will not show in Netscape 4.75 -- form %! javax.xml.transform.Source source; % %! java.lang.String uriXSL; % % String uriXML = file:///D:/development/tools/jakarta-tomcat-4.0.1 + /webapps/proto/jsp/test.xml; uriXSL = file:///D:development/tools/jakarta-tomcat-4.0.1 + /webapps/proto/jsp/test.xsl; source = new javax.xml.transform.stream.StreamSource(uriXML); % !-- this works Fine-- xtags:style xsl=%= uriXSL % xmlSource=%= source %/ !-- now test as DOM object -- %! javax.xml.transform.dom.DOMSource domSource; % !-- this bean simply creates a full textual xml presentation of the DOM tree -- !-- it works fine -- jsp:useBean id=testDomProcessor class=com.tietoenator.domutils.TestDomProcessor/ % // // Create a DOM tree for this test (in practice this would be an object in the session) // // Instantiate DocumentBuilderFactory. javax.xml.parsers.DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory.newInstance(); // Use DocumentBuilderFactory to access a DocumentBuilder. javax.xml.parsers.DocumentBuilder dBuilder = dfactory.newDocumentBuilder(); // Use DocumentBuilder to parse XML input. org.w3c.dom.Document doc = dBuilder.parse(uriXML); //Now create a textual representation of the DOM tree StringBuffer buf = new StringBuffer(); org.w3c.dom.Element root = doc.getDocumentElement(); testDomProcessor.stepThroughAll(buf, root); % !-- this works fine also -- xtags:style xsl=%= uriXSL % %= buf.toString() % /xtags:style !-- this DOESN'T work - DOMSource content is empty -- % domSource = new javax.xml.transform.dom.DOMSource(doc); % xtags:style xsl=%= uriXSL % xmlSource=%= domSource %/ !-- x taglibs used - this works for static resources and doesn't handle DOM tree -- c:import url=test.xml var=xml/ c:import url=test.xsl var=xslt/ x:transform source=$xml xslt=$xslt/ /form /body /html Anyone got any ideas how to get xtags:style and x:transform to work with a org.w3c.dom.Document object? Many thanks in advance, - Peter * Peter Burgess Technical Architect TietoEnator (Belgium) Mobile: +32 476 562972 email: [EMAIL PROTECTED] * -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
[standard] c:if accepts what expression types?
Hi I'm a newbie to JSTL (and Java more or less too) and was extremely confused about the syntax for the ECMAscript EL. Until I read http://www.mail-archive.com/taglibs-user@jakarta.apache.org/msg01249.html Of course, I had first tried something like c:if test=$rows.get('element_type') == 'i' || $rows.get('element_type') == 'I' and it didn't work. From my point of view (and the way we'd like to use the JSTL) us programmers should create the data (=Model), and webmasters should create the HTML templates (=View). And since most webmasters know JavaScript, ECMAscript would be the logical choice as an EL. However, it should be really syntax compatible, otherwise I guess it will confuse everybody. Best regards, Eric swissinfo/Swiss Radio International Eric Lewis IT Engineering Giacomettistrasse 1 CH-3000 Berne 15 Phone: ++41 31 350 95 42 Fax:++41 31 350 99 40 mailto:[EMAIL PROTECTED] Switzerland is everywhere. Stay connected! http://www.swissinfo.org http://mobile.swissinfo.org http:/wap.swissinfo.org SRG SSR idée suisse -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
[standard] Newbie: How to extend the examples?
Hi I'm new to JSTL and not quite new to Java. I think JSTL is the best thing since sliced bread :-) but I'm having a problem. Probably this is a very dumb question, but anyway... (I tried the examples and they all work) All I'm trying to do is set up a new iterator. Thus, I modify org.apache.taglibs.standard.examples.startup.Init by copying /** * Array of Objects (String) */ String[] stringArray = new String[] { A first string, La deuxieme string, Ella troisiemo stringo, }; sce.getServletContext().setAttribute(stringArray, stringArray); and modifying it: /** * Array of Objects (String) */ String[] stringArray = new String[] { A first string, La deuxieme string, Ella troisiemo stringo, }; sce.getServletContext().setAttribute(stringArray, stringArray); /** * Array of Objects (String) */ String[] storyArray = new String[] { A first string, La deuxieme string, Ella troisiemo stringo, }; sce.getServletContext().setAttribute(storyArray, storyArray) Then I modify DataTypes.jsp: h4Array of objects (String)/h4 c:forEach var=string items=$stringArray c:expr value=$string/br /c:forEach c:forEach var=story items=$storyArray c:expr value=$story/br /c:forEach I stop and restart Tomcat and open DataTypes.jsp in the browser, but I just get the following error: ReferenceError: storyArray is not defined. at org.mozilla.javascript.NativeGlobal.constructError(Unknown Source) at org.mozilla.javascript.NativeGlobal.constructError(Unknown Source) at org.mozilla.javascript.ScriptRuntime.name(Unknown Source) at org.mozilla.javascript.gen.c11.call(:0) at org.mozilla.javascript.gen.c11.exec() at org.mozilla.javascript.Context.evaluateReader(Unknown Source) at org.mozilla.javascript.Context.evaluateString(Unknown Source) at org.apache.taglibs.standard.lang.javascript.JavascriptExpressionEvaluator.ev aluate(JavascriptExpressionEvaluator.java:115) at org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager.evaluate (ExpressionEvaluatorManager.java:200) at org.apache.taglibs.standard.tag.el.core.ForEachTag.evaluateExpressions(ForEa chTag.java:196) at org.apache.taglibs.standard.tag.el.core.ForEachTag.doStartTag(ForEachTag.jav a:107) at org.apache.jsp.DataTypes$jsp._jspService(DataTypes$jsp.java:201) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) etc. etc. Probably I'm just being naive, but how exactly do you define a new object to be used in JSTL? I couldn't find any further reference to the existing stringArray in the source... Best regards, Eric swissinfo/Swiss Radio International Eric Lewis IT Engineering Giacomettistrasse 1 CH-3000 Berne 15 Phone: ++41 31 350 95 42 Fax:++41 31 350 99 40 mailto:[EMAIL PROTECTED] Switzerland is everywhere. Stay connected! http://www.swissinfo.org http://mobile.swissinfo.org http:/wap.swissinfo.org SRG SSR idée suisse -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: [standard] Newbie: How to extend the examples?
Hi Eric, It actually looks like what you've done is correct. Make sure that you've recomppiled the org.apache.taglibs.standard.examples.startup.Init class and that the container is noticing your changes. For instance, add some logging to that class and see if your message is printed to the log. (I note that the final line you added, while sufficient to expose a scoped attribute to your JSP page and thus to JSP, doesn't end with a ;, which might indicate you didn't recompile the class.) Hope that helps, -- Shawn Bayern Author of JSP Standard Tag Libary (Manning, upcoming) http://jstlbook.com On Fri, 1 Feb 2002 [EMAIL PROTECTED] wrote: Hi I'm new to JSTL and not quite new to Java. I think JSTL is the best thing since sliced bread :-) but I'm having a problem. Probably this is a very dumb question, but anyway... (I tried the examples and they all work) All I'm trying to do is set up a new iterator. Thus, I modify org.apache.taglibs.standard.examples.startup.Init by copying /** * Array of Objects (String) */ String[] stringArray = new String[] { A first string, La deuxieme string, Ella troisiemo stringo, }; sce.getServletContext().setAttribute(stringArray, stringArray); and modifying it: /** * Array of Objects (String) */ String[] stringArray = new String[] { A first string, La deuxieme string, Ella troisiemo stringo, }; sce.getServletContext().setAttribute(stringArray, stringArray); /** * Array of Objects (String) */ String[] storyArray = new String[] { A first string, La deuxieme string, Ella troisiemo stringo, }; sce.getServletContext().setAttribute(storyArray, storyArray) Then I modify DataTypes.jsp: h4Array of objects (String)/h4 c:forEach var=string items=$stringArray c:expr value=$string/br /c:forEach c:forEach var=story items=$storyArray c:expr value=$story/br /c:forEach I stop and restart Tomcat and open DataTypes.jsp in the browser, but I just get the following error: ReferenceError: storyArray is not defined. at org.mozilla.javascript.NativeGlobal.constructError(Unknown Source) at org.mozilla.javascript.NativeGlobal.constructError(Unknown Source) at org.mozilla.javascript.ScriptRuntime.name(Unknown Source) at org.mozilla.javascript.gen.c11.call(:0) at org.mozilla.javascript.gen.c11.exec() at org.mozilla.javascript.Context.evaluateReader(Unknown Source) at org.mozilla.javascript.Context.evaluateString(Unknown Source) at org.apache.taglibs.standard.lang.javascript.JavascriptExpressionEvaluator.ev aluate(JavascriptExpressionEvaluator.java:115) at org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager.evaluate (ExpressionEvaluatorManager.java:200) at org.apache.taglibs.standard.tag.el.core.ForEachTag.evaluateExpressions(ForEa chTag.java:196) at org.apache.taglibs.standard.tag.el.core.ForEachTag.doStartTag(ForEachTag.jav a:107) at org.apache.jsp.DataTypes$jsp._jspService(DataTypes$jsp.java:201) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) etc. etc. Probably I'm just being naive, but how exactly do you define a new object to be used in JSTL? I couldn't find any further reference to the existing stringArray in the source... Best regards, Eric swissinfo/Swiss Radio International Eric Lewis IT Engineering Giacomettistrasse 1 CH-3000 Berne 15 Phone:++41 31 350 95 42 Fax: ++41 31 350 99 40 mailto:[EMAIL PROTECTED] Switzerland is everywhere. Stay connected! http://www.swissinfo.org http://mobile.swissinfo.org http:/wap.swissinfo.org SRG SSR idée suisse -- 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]
XTags param
Hi all, I'm having a problem passing params to using the Xtags taglib. The example shows: !doctype html public -//w3c//dtd html 4.0 transitional//en html %@ taglib uri=http://jakarta.apache.org/taglibs/xtags-1.0; prefix=xtags % %-- Demos the use of the xtags:style tag using relative URIs and parameters are passed into the stylesheet --% xtags:style xml=test2.xml xsl=sample.xsl outputMethod=html xtags:param name=name value=James/ xtags:param name=time%= new java.util.Date().toString()%/xtags:param /xtags:style /html However, even that does not run correct. The error shows: A Servlet Exception Has Occurred org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: 9 in the jsp file: /style/styledemo5.jsp Generated servlet error: C:\JBoss-2.4.3_Tomcat-4.0\catalina\work\localhost\xtags-examples\style\style demo5$jsp.java:94: Undefined variable: James _jspx_th_xtags_param_0.setValue(new String(James)); ^ 1 error at org.apache.jasper.compiler.Compiler.compile(Unknown Source) at org.apache.jasper.servlet.JspServlet.loadJSP(Unknown Source) at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(Unkno wn Source) at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Unknown Source) at org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source) at org.apache.jasper.servlet.JspServlet.service(Unknown Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source) at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source) at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.valves.CertificatesValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardContext.invoke(Unknown Source) at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.connector.http.HttpProcessor.process(Unknown Source) at org.apache.catalina.connector.http.HttpProcessor.run(Unknown Source) at java.lang.Thread.run(Unknown Source) The second method works correctly but I cannot seem to use that param in a xsl:if the syntax that I use is: xtags:param name=valid%= new Boolean(true) %/xtags:param and inside the xsl xsl:param name=valid/ xsl:if test=$valid='true' I have tried variations on this as well xsl:if test=$valid=true xsl:if test=$valid And those combinations with: xtags:param name=valid%= true %/xtags:param None of which works. One thing to note is that I removed Cocoon because I am using Xerces. -Tim - Gin-Ting Chen [EMAIL PROTECTED] 727-738-3000 x6549 Sun Certified Programmer Sun Certified Web Component Developer BEA Certified Developer -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
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.template)); 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 _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]