Re: JavaScript problems in XSP
Hi Geoff. Thanks for helping me. If you don't mind, I want to ask you some more questions, cause I still don't really understand what I have to do. 1. I didin't find any example of xsp using Rhino. Can you give me an example, or a URL to the page with example? I am sorry, but I tried hard to find examples, and I just didn't succeed. In Cocoon documentation it is mentioned that Rhino can be used as an XSP scripting language, but they don't give any example. 2. Can I use JSGenerator instead of ServerPagesGenerator on the pipeline? All these things confuse me alot, and I'll be very happy if you gave me some more clues. Thank you very very much and sorry for attacking you with so many questions. Anna - Original Message - From: Geoff Howard [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, November 26, 2002 12:14 AM Subject: Re: JavaScript problems in XSP Ugh. This may spell bad news: see inline comments. If you are comfortable in java as well as javascript (at least reasonably so) you may want to look into using a java based javascript interpreter - looking into the cocoon javascript generator (org.apache.cocoon.components.language.markup.xsp.JSGenerator) and other JS related sources around there in the source tree it looks like cocoon is using Rhino (http://www.mozilla.org/rhino/). Then, you can write your xsp in java (which has far more features and users) but still execute arbitrary javascript code when you find it. That said, I think you're on a potentially very confusing path because of all the places javascript can be in an html page, and all the DOM objects it's likely to reference. Still, this may work and I'd be very interested to hear how it goes and help as I can - but I've never touched Rhino and can't right now. Geoff (more comments below) --- Anna Afonchenko [EMAIL PROTECTED] wrote: 1. First of all I tried to give the eval() function some simple string that I declared inside the xsp:logic tag: someStr = document.write('centerHello/center'); If I write this string inside the xsp:exprdocument.text/xsp:expr, the output is: ?xml version=1.0 encoding=UTF-8 ? page xmlns:xsp=http://apache.org/xsp; xmlns:xsp-request=http://apache.org/xsp/request/2.0; xmlns:util=http://apache.org/xsp/util/2.0; pcenterHello/center/p /page which is great, but when I looked in the source code, I found out that the centerHello/center string is written using entities, e.g. it is not a node-set of the output xml document. Right, sorry about that. I had seen in another email that you were using util:include-expr so I left that part out for simplicity but forgot to comment as such. Trying to enclose the xsp:expr tag inside the util:include-expr tag: util:include-exprutil:exprxsp:exprdocument.text/xsp:expr/util:expr /util:include-expr the surprising output is: ?xml version=1.0 encoding=UTF-8 ? page xmlns:xsp=http://apache.org/xsp; xmlns:xsp-request=http://apache.org/xsp/request/2.0; xmlns:util=http://apache.org/xsp/util/2.0; p util:include-expr util:exprcenterHello/center/util:expr /util:include-expr /p /page This is strange. Do you have any idea how can I avoid outputting the result as a string (with entities) rather that outputting it as a node-set? Not surprising - just checked and javascript xsp's have only request, response and session logicsheets. I don't know if it's possible to recreate the include expression functionality in javascript - you may want to send a very specific question on that to this list, making clear that you know it doesn't yet exist. 2. How can I retrieve the content of some html file from xsp with javascript? I don't know if you can - you can't from a browser, but that may be only because of the security limitations imposed. And parse it? See above. Is it possible that there are problem using util library from xsp with javascript? Right. It doesn't exist in javascript. Geoff __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: JavaScript problems in XSP
--- Anna Afonchenko [EMAIL PROTECTED] wrote: Hi Geoff. Thanks for helping me. If you don't mind, I want to ask you some more questions, cause I still don't really understand what I have to do. 1. I didin't find any example of xsp using Rhino. You just need examples of java using rhino. I was recommending changing to regular java xsp. You'll need to use xsp:structure and xsp:include to make sure the rhino classes you need are available in your xsp and then later on in xsp:logic you can do anything you would in a normal java class (because when cocoon is done with your xsp file, it _will_ be a normal java class. If you haven't gone to look for the .java source files that cocoon generates out of your xsp (probably under tomcat's work/ directory) you really should. It would take some of the mystery out of xsp. Rhino is a javascript interpreter/engine (whatever). So within your xsp now written in java, you'll retrieve your html page, pass on any regular tags, and then pass the contents of the script tags to the rhino instance. To be very clear: I have no idea if this is feasible and if you're not very comfortable in java, the chances are slim you'll get this working without more help than I or probably anyone else on the list can provide. I'm just suggesting an avenue to try. Can you give me an example, or a URL to the page with example? I am sorry, but I tried hard to find examples, and I just didn't succeed. I highly doubt that any examples exist of doing exactly what you are trying. In Cocoon documentation it is mentioned that Rhino can be used as an XSP scripting language, but they don't give any example. They do - what they're talking about is xsp-js though. I'm suggesting you abandon xsp-js because of some of the other things you need to do, and call the same java-based javascript interpreter directly from your java class (which xsp just helps you create.) 2. Can I use JSGenerator instead of ServerPagesGenerator on the pipeline? That's happening automatically when you declare that your xsp's are written in javascript. But you probably don't want to do that anymore. The only reason you ever needed xsp-js was because it gave you access to the Rhino javscript stuff behind the scenes. But it took away your ability to use the java stuff you need. All these things confuse me alot, and I'll be very happy if you gave me some more clues. Thank you very very much and sorry for attacking you with so many questions. Anna I can appreciate how confusing this must all seem to someone new to cocoon, and even worse if you're new to java - I'm sure all this just seems like absolute voodoo. Unfortunately, all I can give is clues because my own time is limited and because you're trying something fairly novel. Best of luck, Geoff PS, it's a holiday later this week in the states, so I may be off list for a while. - Original Message - From: Geoff Howard [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, November 26, 2002 12:14 AM Subject: Re: JavaScript problems in XSP Ugh. This may spell bad news: see inline comments. If you are comfortable in java as well as javascript (at least reasonably so) you may want to look into using a java based javascript interpreter - looking into the cocoon javascript generator (org.apache.cocoon.components.language.markup.xsp.JSGenerator) and other JS related sources around there in the source tree it looks like cocoon is using Rhino (http://www.mozilla.org/rhino/). Then, you can write your xsp in java (which has far more features and users) but still execute arbitrary javascript code when you find it. That said, I think you're on a potentially very confusing path because of all the places javascript can be in an html page, and all the DOM objects it's likely to reference. Still, this may work and I'd be very interested to hear how it goes and help as I can - but I've never touched Rhino and can't right now. Geoff (more comments below) --- Anna Afonchenko [EMAIL PROTECTED] wrote: 1. First of all I tried to give the eval() function some simple string that I declared inside the xsp:logic tag: someStr = document.write('centerHello/center'); If I write this string inside the xsp:exprdocument.text/xsp:expr, the output is: ?xml version=1.0 encoding=UTF-8 ? page xmlns:xsp=http://apache.org/xsp; xmlns:xsp-request=http://apache.org/xsp/request/2.0; xmlns:util=http://apache.org/xsp/util/2.0; pcenterHello/center/p /page which is great, but when I looked in the source code, I found out that the centerHello/center string is written using entities, e.g. it is not a node-set of the output xml document. Right, sorry about that. I had seen in another email that you were using util:include-expr so I left that part out for simplicity but forgot to comment as such. Trying to enclose the xsp:expr tag inside the util:include-expr tag
Re: Javascript problems in XSP
hey that's neat! - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript problems in XSP
What do you mean by neat? Sorry if this is an unrelated question - Original Message - From: Jacob L E Blain Christen [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, November 26, 2002 10:23 PM Subject: Re: Javascript problems in XSP hey that's neat! - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: JavaScript problems in XSP
I am not using document.write. What I am trying to do is load some arbitrary file from the net (not my file, just any file, so I don't have control on what's written inside) and if this file contains script tag (which is written, for example, in Javascript), I want to extract the HTML tree fragment that is generated by this (Java)script. I use xsp to include the given file, that's all, then I use xsl to extract the data inside the script tags. But what I get is again the script code, e.g. document.write(centerHello/center); What I'm asking is whether it's possible to extract the HTML that the script is writing - in this case it's just to get the value of the document.write method, but it can be something more complicated. I don't know if this can be done at all, in Cocoon/XSP/XSL. If somebody will have any idea how to do it, I will be very thankful. Sorry if this is too messy, I am new to this list and to cocoon at all. Thank you for all the help. Anna - Original Message - From: Geoff Howard [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, November 24, 2002 4:54 PM Subject: Re: JavaScript problems in XSP Why are you using document.write? document of course is a reference to the client side document object which doesn't exist server side at all. The problem with your example is that you don't need javascript (or xsp for that matter) to do any of that. Obviously you want to move beyond that though. It's also unclear whether you want that fragment to be included in the sax stream, or whether you want that output escaped and displayed as is on screen (i think the first). I'm not sure you can (using javascript in xsp) easily take an xml fragment in string form and generate sax events from it. It doesn't matter though because you probably really don't need to. What you should probably do is start with (note the ... implies that you probably have other page structure but you don't need to for this example) xsp:page language=javascript xmlns:xsp=http://apache.org/xsp; ... center font size=+3 This HTML-document has been created with the help of JavaScript! /font /center ... /xsp:page And then use xsp:logic xsp:expr xsp:attribute xsp:element etc to make whatever parts dynamic. For example, a next step might be : xsp:page language=javascript xmlns:xsp=http://apache.org/xsp; ... xsp:logic message = This HTML-document has been created with the help of JavaScript!; /xsp:logic center font size=+3 xsp:exprmessage/xsp:expr /font /center ... /xsp:page and then, xsp:page language=javascript xmlns:xsp=http://apache.org/xsp; ... xsp:logic message = This HTML-document has been created with the help of JavaScript!; displayMessage = true; /xsp:logic ... xsp:logic if (displayMessage) { center font size=+3 xsp:exprmessage/xsp:expr /font /center } /xsp:logic ... /xsp:page The best place I know of to read up on the xsp sytax is http://outerthought.net/wiki/Wiki.jsp?page=XSPSyntax as the official docs don't catalog the available tags IIRC. If you don't mind me saying so, I'd also suggest that you read up some more on the basic ideas behind the cocoon sax pipeline concept and what generators do as it seems you may have some of the concepts muddled. XSP is only a tool for automatically creating a generator - a compiled java class no matter what language you script your xsp in. Best of luck, Geoff Howard --- Anna Afonchenko [EMAIL PROTECTED] wrote: Thank you Ryan. Now what I get when I run the pipeline, what I see is the result of running the javascript. But what I really need is the source of this javascript, e.g. if the javascript code was: document.write(centerfont size=+3); document.write(This HTML-document has been created ); document.write(with the help of JavaScript!); document.write(/font/center); I want to get as a result the xhtml tree fragment that is created, e.g. I want to get back: center font size=+3 This HTML-document has been created with the help of JavaScript! /font /center e.g. I want to see the actual HTML code that was used in javascript to create the given page, and not the result of executing it. Is it doable in Cocoon/XSP? Thank you very much for your help. Anna - Original Message - From: Ryan Agler [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, November 21, 2002 4:26 PM Subject: RE: JavaScript problems in XSP Hi Anna, Client-side (in your web browser) JavaScript is a completely different beast than server-side (on your web server) JavaScript. In server-side JavaScript, there are no windows, DHTML, or much any other properties or methods you would use to manipulate a browser for dynamic content. To use Cocoon to achieve your task, the first step would to define given-file.html in your sitemap, and make sure its serialized in well-formed XHTML. Then you could use the Cinclude transformer to import given-file.html, kind of like
RE: JavaScript problems in XSP
Hi Geoff, I know, that maybe will not help you, but normally you won't write JavaScript in your xsp, you should do it in your stylesheet and you will avoid many problems... :-) Best regards - Volker - -Original Message- From: Geoff Howard [mailto:[EMAIL PROTECTED]] Sent: Montag, 25. November 2002 14:30 To: [EMAIL PROTECTED] Subject: Re: JavaScript problems in XSP Aha. For future reference, you probably should have made it clear from the beginning that you were a) using javascript xsp, and b) trying to do this specific thing with retrieving external pages out of your control. That said, you are probably in uncharted waters - but interesting ones. The first thing I'd try is make sure that this ability doesn't already exist by some miracle in JTidy or another html parser. I'd suggest trying the following (but you have to promise to let me know whether it works or not). What about tricking the client side javascript into evaluating the document.write and document.writeln? For instance, set up a javascript object called document which initializes an empty text holder and exposes a write() and writeln() method to append to that variable. Then, use eval() on each line taken out of your script tags. So, function write(string) {this.text += string;} function writeln(string) {this.text += (string + '\n')}; function doc() { this.text=; this.write = write; this.writeln = writeln; } then when you encounter a script section do something like: xsp:logic var document = new doc(); eval('document.writeln...); eval('document.write...); /xsp:logic xsp:exprdocument.text/xsp:expr where you take each string to eval out of the incoming script section, probably in a for loop. any other variables and operations it uses to prepare values should work the same as normal. You'll have trouble with escaping quotes, and extracting the strings but it may be possible. Other than that, I'm out of ideas. You may not be able to do this at all in a way that is worth the effort. Geoff --- Anna Afonchenko [EMAIL PROTECTED] wrote: I am not using document.write. What I am trying to do is load some arbitrary file from the net (not my file, just any file, so I don't have control on what's written inside) and if this file contains script tag (which is written, for example, in Javascript), I want to extract the HTML tree fragment that is generated by this (Java)script. I use xsp to include the given file, that's all, then I use xsl to extract the data inside the script tags. But what I get is again the script code, e.g. document.write(centerHello/center); What I'm asking is whether it's possible to extract the HTML that the script is writing - in this case it's just to get the value of the document.write method, but it can be something more complicated. I don't know if this can be done at all, in Cocoon/XSP/XSL. If somebody will have any idea how to do it, I will be very thankful. Sorry if this is too messy, I am new to this list and to cocoon at all. Thank you for all the help. Anna - Original Message - From: Geoff Howard [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, November 24, 2002 4:54 PM Subject: Re: JavaScript problems in XSP Why are you using document.write? document of course is a reference to the client side document object which doesn't exist server side at all. The problem with your example is that you don't need javascript (or xsp for that matter) to do any of that. Obviously you want to move beyond that though. It's also unclear whether you want that fragment to be included in the sax stream, or whether you want that output escaped and displayed as is on screen (i think the first). I'm not sure you can (using javascript in xsp) easily take an xml fragment in string form and generate sax events from it. It doesn't matter though because you probably really don't need to. What you should probably do is start with (note the ... implies that you probably have other page structure but you don't need to for this example) xsp:page language=javascript xmlns:xsp=http://apache.org/xsp; ... center font size=+3 This HTML-document has been created with the help of JavaScript! /font /center ... /xsp:page And then use xsp:logic xsp:expr xsp:attribute xsp:element etc to make whatever parts dynamic. For example, a next step might be : xsp:page language=javascript xmlns:xsp=http://apache.org/xsp; ... xsp:logic message = This HTML-document has been created with the help of JavaScript!; /xsp:logic center font size=+3 xsp:exprmessage/xsp:expr /font /center ... /xsp:page and then, xsp:page language=javascript xmlns:xsp=http://apache.org/xsp; ... xsp:logic message = This HTML-document has been created with the help of JavaScript!; displayMessage = true; /xsp:logic ... xsp:logic if (displayMessage) { center font size=+3 xsp:exprmessage/xsp:expr
Re: JavaScript problems in XSP
Hi Geoff. Thank you for your help, I appreciate this very much. I tried the code that you suggested, and I have a few questions/issues: 1. First of all I tried to give the eval() function some simple string that I declared inside the xsp:logic tag: someStr = document.write('centerHello/center'); If I write this string inside the xsp:exprdocument.text/xsp:expr, the output is: ?xml version=1.0 encoding=UTF-8 ? page xmlns:xsp=http://apache.org/xsp; xmlns:xsp-request=http://apache.org/xsp/request/2.0; xmlns:util=http://apache.org/xsp/util/2.0; pcenterHello/center/p /page which is great, but when I looked in the source code, I found out that the centerHello/center string is written using entities, e.g. it is not a node-set of the output xml document. Trying to enclose the xsp:expr tag inside the util:include-expr tag: util:include-exprutil:exprxsp:exprdocument.text/xsp:expr/util:expr /util:include-expr the surprising output is: ?xml version=1.0 encoding=UTF-8 ? page xmlns:xsp=http://apache.org/xsp; xmlns:xsp-request=http://apache.org/xsp/request/2.0; xmlns:util=http://apache.org/xsp/util/2.0; p util:include-expr util:exprcenterHello/center/util:expr /util:include-expr /p /page i.e. centerHello/center remains to be a string and not a node-set, but now it is enclosed in a tree fragment util:include-exprutil:expr. This is strange. Do you have any idea how can I avoid outputting the result as a string (with entities) rather that outputting it as a node-set? 2. How can I retrieve the content of some html file from xsp with javascript? And parse it? When I was using Java inside an xsp, i could write the following: XSPUtil u = new XSPUtil(); String get = u.getFileContents(URL of the file); Can I do something like this from Javascript? I tried: content = util:get-file-contents name=URL of the file; but it doesn't work. Is it possible that there are problem using util library from xsp with javascript? Thank you for your help. I will wait for your answer. I hope this is not too long. Grateful Anna - Original Message - From: Geoff Howard [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, November 25, 2002 3:30 PM Subject: Re: JavaScript problems in XSP Aha. For future reference, you probably should have made it clear from the beginning that you were a) using javascript xsp, and b) trying to do this specific thing with retrieving external pages out of your control. That said, you are probably in uncharted waters - but interesting ones. The first thing I'd try is make sure that this ability doesn't already exist by some miracle in JTidy or another html parser. I'd suggest trying the following (but you have to promise to let me know whether it works or not). What about tricking the client side javascript into evaluating the document.write and document.writeln? For instance, set up a javascript object called document which initializes an empty text holder and exposes a write() and writeln() method to append to that variable. Then, use eval() on each line taken out of your script tags. So, function write(string) {this.text += string;} function writeln(string) {this.text += (string + '\n')}; function doc() { this.text=; this.write = write; this.writeln = writeln; } then when you encounter a script section do something like: xsp:logic var document = new doc(); eval('document.writeln...); eval('document.write...); /xsp:logic xsp:exprdocument.text/xsp:expr where you take each string to eval out of the incoming script section, probably in a for loop. any other variables and operations it uses to prepare values should work the same as normal. You'll have trouble with escaping quotes, and extracting the strings but it may be possible. Other than that, I'm out of ideas. You may not be able to do this at all in a way that is worth the effort. Geoff __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: JavaScript problems in XSP
Ugh. This may spell bad news: see inline comments. If you are comfortable in java as well as javascript (at least reasonably so) you may want to look into using a java based javascript interpreter - looking into the cocoon javascript generator (org.apache.cocoon.components.language.markup.xsp.JSGenerator) and other JS related sources around there in the source tree it looks like cocoon is using Rhino (http://www.mozilla.org/rhino/). Then, you can write your xsp in java (which has far more features and users) but still execute arbitrary javascript code when you find it. That said, I think you're on a potentially very confusing path because of all the places javascript can be in an html page, and all the DOM objects it's likely to reference. Still, this may work and I'd be very interested to hear how it goes and help as I can - but I've never touched Rhino and can't right now. Geoff (more comments below) --- Anna Afonchenko [EMAIL PROTECTED] wrote: 1. First of all I tried to give the eval() function some simple string that I declared inside the xsp:logic tag: someStr = document.write('centerHello/center'); If I write this string inside the xsp:exprdocument.text/xsp:expr, the output is: ?xml version=1.0 encoding=UTF-8 ? page xmlns:xsp=http://apache.org/xsp; xmlns:xsp-request=http://apache.org/xsp/request/2.0; xmlns:util=http://apache.org/xsp/util/2.0; pcenterHello/center/p /page which is great, but when I looked in the source code, I found out that the centerHello/center string is written using entities, e.g. it is not a node-set of the output xml document. Right, sorry about that. I had seen in another email that you were using util:include-expr so I left that part out for simplicity but forgot to comment as such. Trying to enclose the xsp:expr tag inside the util:include-expr tag: util:include-exprutil:exprxsp:exprdocument.text/xsp:expr/util:expr /util:include-expr the surprising output is: ?xml version=1.0 encoding=UTF-8 ? page xmlns:xsp=http://apache.org/xsp; xmlns:xsp-request=http://apache.org/xsp/request/2.0; xmlns:util=http://apache.org/xsp/util/2.0; p util:include-expr util:exprcenterHello/center/util:expr /util:include-expr /p /page This is strange. Do you have any idea how can I avoid outputting the result as a string (with entities) rather that outputting it as a node-set? Not surprising - just checked and javascript xsp's have only request, response and session logicsheets. I don't know if it's possible to recreate the include expression functionality in javascript - you may want to send a very specific question on that to this list, making clear that you know it doesn't yet exist. 2. How can I retrieve the content of some html file from xsp with javascript? I don't know if you can - you can't from a browser, but that may be only because of the security limitations imposed. And parse it? See above. Is it possible that there are problem using util library from xsp with javascript? Right. It doesn't exist in javascript. Geoff __ Do you Yahoo!? Yahoo! Mail Plus Powerful. Affordable. Sign up now. http://mailplus.yahoo.com - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: JavaScript problems in XSP
Thank you Ryan. Now what I get when I run the pipeline, what I see is the result of running the javascript. But what I really need is the source of this javascript, e.g. if the javascript code was: document.write(centerfont size=+3); document.write(This HTML-document has been created ); document.write(with the help of JavaScript!); document.write(/font/center); I want to get as a result the xhtml tree fragment that is created, e.g. I want to get back: center font size=+3 This HTML-document has been created with the help of JavaScript! /font /center e.g. I want to see the actual HTML code that was used in javascript to create the given page, and not the result of executing it. Is it doable in Cocoon/XSP? Thank you very much for your help. Anna - Original Message - From: Ryan Agler [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, November 21, 2002 4:26 PM Subject: RE: JavaScript problems in XSP Hi Anna, Client-side (in your web browser) JavaScript is a completely different beast than server-side (on your web server) JavaScript. In server-side JavaScript, there are no windows, DHTML, or much any other properties or methods you would use to manipulate a browser for dynamic content. To use Cocoon to achieve your task, the first step would to define given-file.html in your sitemap, and make sure its serialized in well-formed XHTML. Then you could use the Cinclude transformer to import given-file.html, kind of like this (myfile.xsp): ?xml version=1.0? xsp:page language=java xmlns:xsp=http://apache.org/xsp page xmlns:cinclude=http://apache.org/cocoon/include/1.0; p cinclude:include src=cocoon:/given-file.html / /p /page /xsp:page and in your sitemap.xmap: map:match pattern=given-file.html map:generate type=serverpages src=docs/given-file.xsp / map:transform src=stylesheets/given-file.xsl / map:serialize type=xhtml/ /map:match map:match pattern=myfile.xsl map:generate type=serverpages src=docs/myfile.xsp / map:transform type=cinclude/ map:transform src=stylesheets/myfile.xsl / map:serialize / /map:match HTH +Ryan -Original Message- From: Anna Afonchenko [mailto:[EMAIL PROTECTED]] Sent: Thursday, November 21, 2002 7:43 AM To: [EMAIL PROTECTED] Subject: Javascript problems in XSP Hi All. This is my first post, so don't be angry with me if I do something wrong. I am using XSP on Cocoon 2.0.3, and I want to do the following: given a name of the html file that contains javascript, I want to get the result of this javascript and put it inside some element in XSP. But when I write the following code in XSP using javascript: p xsp:logic var js = window.open(given-file.html); var result = js.document.body.innerHTML; /xsp:logic xsp:exprresult/xsp:expr /p nothing happens (even doesn't give any error). If I am using this code inside an html file's script tag, it works fine. If I am trying some simple Javascript functions in XSP (e.g. Date()), it works. Maybe there is some problem with opening files in XSP? Can somebody please tell me what am I doing wrong and how can I get the result of javascript code executed in some given file? Thank you very much in advance. Anna - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript problems in XSP
No. Look in your cocoon\docs\samples\xsp-js directory, there are some examples of xsp using Javascript. You just need to put map:parameter name=programming-language value=js/ into your xsp generator. - Original Message - From: Jacob L E Blain Christen [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, November 21, 2002 6:45 PM Subject: Re: Javascript problems in XSP I may be mistaken but I thought the only valid code inside of xsp:logic tags was java: not javascript, not perl, just java. - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: JavaScript problems in XSP
Why are you using document.write? document of course is a reference to the client side document object which doesn't exist server side at all. The problem with your example is that you don't need javascript (or xsp for that matter) to do any of that. Obviously you want to move beyond that though. It's also unclear whether you want that fragment to be included in the sax stream, or whether you want that output escaped and displayed as is on screen (i think the first). I'm not sure you can (using javascript in xsp) easily take an xml fragment in string form and generate sax events from it. It doesn't matter though because you probably really don't need to. What you should probably do is start with (note the ... implies that you probably have other page structure but you don't need to for this example) xsp:page language=javascript xmlns:xsp=http://apache.org/xsp; ... center font size=+3 This HTML-document has been created with the help of JavaScript! /font /center ... /xsp:page And then use xsp:logic xsp:expr xsp:attribute xsp:element etc to make whatever parts dynamic. For example, a next step might be : xsp:page language=javascript xmlns:xsp=http://apache.org/xsp; ... xsp:logic message = This HTML-document has been created with the help of JavaScript!; /xsp:logic center font size=+3 xsp:exprmessage/xsp:expr /font /center ... /xsp:page and then, xsp:page language=javascript xmlns:xsp=http://apache.org/xsp; ... xsp:logic message = This HTML-document has been created with the help of JavaScript!; displayMessage = true; /xsp:logic ... xsp:logic if (displayMessage) { center font size=+3 xsp:exprmessage/xsp:expr /font /center } /xsp:logic ... /xsp:page The best place I know of to read up on the xsp sytax is http://outerthought.net/wiki/Wiki.jsp?page=XSPSyntax as the official docs don't catalog the available tags IIRC. If you don't mind me saying so, I'd also suggest that you read up some more on the basic ideas behind the cocoon sax pipeline concept and what generators do as it seems you may have some of the concepts muddled. XSP is only a tool for automatically creating a generator - a compiled java class no matter what language you script your xsp in. Best of luck, Geoff Howard --- Anna Afonchenko [EMAIL PROTECTED] wrote: Thank you Ryan. Now what I get when I run the pipeline, what I see is the result of running the javascript. But what I really need is the source of this javascript, e.g. if the javascript code was: document.write(centerfont size=+3); document.write(This HTML-document has been created ); document.write(with the help of JavaScript!); document.write(/font/center); I want to get as a result the xhtml tree fragment that is created, e.g. I want to get back: center font size=+3 This HTML-document has been created with the help of JavaScript! /font /center e.g. I want to see the actual HTML code that was used in javascript to create the given page, and not the result of executing it. Is it doable in Cocoon/XSP? Thank you very much for your help. Anna - Original Message - From: Ryan Agler [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, November 21, 2002 4:26 PM Subject: RE: JavaScript problems in XSP Hi Anna, Client-side (in your web browser) JavaScript is a completely different beast than server-side (on your web server) JavaScript. In server-side JavaScript, there are no windows, DHTML, or much any other properties or methods you would use to manipulate a browser for dynamic content. To use Cocoon to achieve your task, the first step would to define given-file.html in your sitemap, and make sure its serialized in well-formed XHTML. Then you could use the Cinclude transformer to import given-file.html, kind of like this (myfile.xsp): ?xml version=1.0? xsp:page language=java xmlns:xsp=http://apache.org/xsp page xmlns:cinclude=http://apache.org/cocoon/include/1.0; p cinclude:include src=cocoon:/given-file.html / /p /page /xsp:page and in your sitemap.xmap: map:match pattern=given-file.html map:generate type=serverpages src=docs/given-file.xsp / map:transform src=stylesheets/given-file.xsl / map:serialize type=xhtml/ /map:match map:match pattern=myfile.xsl map:generate type=serverpages src=docs/myfile.xsp / map:transform type=cinclude/ map:transform src=stylesheets/myfile.xsl / map:serialize / /map:match HTH +Ryan -Original Message- From: Anna Afonchenko [mailto:[EMAIL PROTECTED]] Sent: Thursday, November 21, 2002 7:43 AM To: [EMAIL PROTECTED] Subject: Javascript problems in XSP Hi All. This is my first post, so don't be angry with me if I do something wrong. I am using XSP on Cocoon 2.0.3, and I want to do the following: given a name of the html file that contains javascript, I want to get the result of this javascript
Javascript problems in XSP
Hi All. This is my first post, so don't be angry with me if I do something wrong. I am using XSP on Cocoon 2.0.3, and I want to do the following: given a name of the htmlfile that contains javascript, I want to get the result of this javascript and put it inside some element in XSP. But when I write the following code in XSP using javascript: p xsp:logic var js = window.open("given-file.html"); var result = js.document.body.innerHTML; /xsp:logic xsp:exprresult/xsp:expr /p nothing happens (even doesn't give any error). If I am using this code inside an html file's script tag, it works fine. If I am trying some simple Javascript functions in XSP (e.g. Date()), it works. Maybe there is some problem with opening files in XSP? Can somebody please tell me what am I doing wrong and how can I get the result of javascript code executed in some given file? Thank you very much in advance. Anna
RE: JavaScript problems in XSP
Hi Anna, Client-side (in your web browser) JavaScript is a completely different beast than server-side (on your web server) JavaScript. In server-side JavaScript, there are no windows, DHTML, or much any other properties or methods you would use to manipulate a browser for dynamic content. To use Cocoon to achieve your task, the first step would to define given-file.html in your sitemap, and make sure its serialized in well-formed XHTML. Then you could use the Cinclude transformer to import given-file.html, kind of like this (myfile.xsp): ?xml version=1.0? xsp:page language=java xmlns:xsp=http://apache.org/xsp page xmlns:cinclude=http://apache.org/cocoon/include/1.0; p cinclude:include src=cocoon:/given-file.html / /p /page /xsp:page and in your sitemap.xmap: map:match pattern=given-file.html map:generate type=serverpages src=docs/given-file.xsp / map:transform src=stylesheets/given-file.xsl / map:serialize type=xhtml/ /map:match map:match pattern=myfile.xsl map:generate type=serverpages src=docs/myfile.xsp / map:transform type=cinclude/ map:transform src=stylesheets/myfile.xsl / map:serialize / /map:match HTH +Ryan -Original Message- From: Anna Afonchenko [mailto:[EMAIL PROTECTED]] Sent: Thursday, November 21, 2002 7:43 AM To: [EMAIL PROTECTED] Subject: Javascript problems in XSP Hi All. This is my first post, so don't be angry with me if I do something wrong. I am using XSP on Cocoon 2.0.3, and I want to do the following: given a name of the html file that contains javascript, I want to get the result of this javascript and put it inside some element in XSP. But when I write the following code in XSP using javascript: p xsp:logic var js = window.open(given-file.html); var result = js.document.body.innerHTML; /xsp:logic xsp:exprresult/xsp:expr /p nothing happens (even doesn't give any error). If I am using this code inside an html file's script tag, it works fine. If I am trying some simple Javascript functions in XSP (e.g. Date()), it works. Maybe there is some problem with opening files in XSP? Can somebody please tell me what am I doing wrong and how can I get the result of javascript code executed in some given file? Thank you very much in advance. Anna - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Javascript problems in XSP
I may be mistaken but I thought the only valid code inside of xsp:logic tags was java: not javascript, not perl, just java. - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]