you know your stuff |
Joined: 22-April-2007 Posts: 79 Location: Belgium | Posted:
5-September-2008 13:57 Menzo, I said it before, you definitely know your XML (and related technologies). I got dojo working in exactly the way you described. But the XRL problem remains. Take these two definitions : <link> <name>framework-dojo</name> <ext>/framework-dojo</ext> <int>active:xrl-html+operator@ffcpl:/etc/XRLLinks.xml+template@ffcpl:/resources/framework_dojo.xml</int> </link>
<link> <name>framework-dojo2</name> <ext>/framework-dojo2</ext> <int>ffcpl:/resources/framework_dojo.htm</int> </link> |
Where both the htm-file and the xml-file contain the basic example from the Dojo manual : <html xmlns:xrl="http://1060.org/xrl"> <head> <title>Dojo: Hello World!</title>
<!-- SECTION 1 --> <style type="text/css"> @import "/dojo/dijit/themes/tundra/tundra.css"; @import "/dojo/dojo/resources/dojo.css" </style> <script type="text/javascript" src="/dojo/dojo/dojo.js" djConfig="parseOnLoad: true"></script> <!-- SECTION 2 --> <script type="text/javascript"> // Load Dojo's code relating to the Button widget dojo.require("dijit.form.Button"); </script> </head>
<body class="tundra"> <button dojoType="dijit.form.Button" id="helloButton"> Hello World! <script type="dojo/method" event="onClick"> alert('You pressed the button'); </script> </button> </body> </html> |
Then the framework_dojo2 works, framework_dojo doesn't. On looking at the source you can see that it gets translated (for the failing example) to : <html xmlns:xrl="http://1060.org/xrl" > <head > <title >Dojo: Hello World!</title>
<!-- SECTION 1 --> <style type="text/css" > @import "/dojo/dijit/themes/tundra/tundra.css"; @import "/dojo/dojo/resources/dojo.css" </style> <script djConfig="parseOnLoad: true" src="/dojo/dojo/dojo.js" type="text/javascript" /> <!-- SECTION 2 --> <script type="text/javascript" > // Load Dojo's code relating to the Button widget dojo.require("dijit.form.Button"); </script> </head>
<body class="tundra" > <button dojoType="dijit.form.Button" id="helloButton" > Hello World! <script event="onClick" type="dojo/method" > alert('You pressed the button'); </script> </button> </body> </html> |
Anyway ... I'm making progress. Thanks again Menzo ! Regards, Tom |
oops |
Joined: 22-April-2007 Posts: 79 Location: Belgium | Posted:
5-September-2008 13:58 This should of course have been a reply to http://www.1060.org/forum/topic/439/1 not a separate topic.
This javascript is getting to me. Time for the weekend. Sorry, Tom |
 |
Joined: 14-March-2005 Posts: 60 Location: Amsterdam, The Netherlands | Posted:
5-September-2008 14:41 Is this escaping some feature of the xrl-html accessor, does it also happen when you use just the xrl accessor? |
only when casting |
Joined: 22-April-2007 Posts: 79 Location: Belgium | Posted:
8-September-2008 08:18 Hi Menzo, No, it doesn't happen when I use the following ... <link> <name>framework-dojo</name> <ext>/framework-dojo</ext> <int>active:xrl+operator@ffcpl:/etc/XRLLinks.xml+template@ffcpl:/resources/framework_dojo.xml</int> </link> |
This gives me a correct XML page. However, any way I cast that page it insists on the encoding ... <link> <name>framework-dojo</name> <ext>/framework-dojo</ext> <int>active:cast+operator@xrl:cast.xml+operand@active:xrl%2Boperator@ffcpl:/etc/XRLLinks.xml%2Btemplate@ffcpl:/resources/framework_dojo.xml</int> </link> |
With the following in cast.xml <cast> <mimetype>text/html</mimetype> </cast> |
And I'm once again stuck with the encoding problem ... Strange ... I can't remember wrestling with encoding that much before ... Regards, Tom |
 |
Joined: 14-March-2005 Posts: 60 Location: Amsterdam, The Netherlands | Posted:
8-September-2008 13:26 Hi Tom, If I understand correctly you want to do something like: <script type="text/javascript" xrl:resolve="text"> /* <![CDATA[ */ ... code goes here ... <img src="xrl:test"/> ... code goes here ... /* ]]> */ </script> |
But the serializer won't keep the CDATA sections intact, and it doesn't have to. So I assume you end up with something like this as a result: <script type="text/javascript"> /* */ ... code goes here ... <img src="http://www.example.com/test.gif"/> ... code goes here ... /* */ </script> |
I think you need to post process the XRL result and at that point add the JavaScript comments. So your template could be: <script type="text/javascript" xrl:resolve="text"> ... code goes here ... <img src="xrl:test"/> ... code goes here ... </script> |
Which after XRL processing will be: <script type="text/javascript"> ... code goes here ... <img src="http://www.example.com/test.gif"/> ... code goes here ... </script> |
Now you can run an XSLT stylesheet over this to hide the scripts from older browsers: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:template match="script"> <xsl:copy> <xsl:comment> <xsl:value-of select="."/> <xsl:text>//</xsl:text> </xsl:comment> </xsl:copy> </xsl:template> </xsl:stylesheet> |
Which results in: <script><!-- ... code goes here ... <img src="http://www.example.com/test.gif"/> ... code goes here ... //--></script> |
Maybe this helps ... Menzo |
pipe through xslt |
Joined: 22-April-2007 Posts: 79 Location: Belgium | Posted:
9-September-2008 09:18 Hi Menzo, Basically all special characters in my javascript were translated to their number values. You did put me on the right track though. When I pipe the output of the xrl-html through an xsl transformation, everything reverts back. So ... in my XRLlinks.xml that looks like ... <int>active:xslt+operator@ffcpl:/resources/mime.xsl+operand@active:xrl-html@ffcpl:/etc/XRLLinks.xml%2Btemplate@ffcpl:/resources/mastertemplate_dojo.xml%2Bcontent@xrl:empty_content.xml</int> |
And in mime.xsl I have : <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" omit-xml-declaration="yes" indent="no" /> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()" /> </xsl:copy> </xsl:template> </xsl:stylesheet> |
And presto, a correct page. Even better, I don't have to hide my javascript between any sort of tags anymore (although that's still better for old browsers of course). Now, solution is there ... what I still do not understand however is the why. Why would an xrl-html start translating all my special characters ? Regards, Tom |
 |
Joined: 14-March-2005 Posts: 60 Location: Amsterdam, The Netherlands | Posted:
9-September-2008 09:32 That's indeed a riddle. I ran around in the XRLLinker.java a bit, and I can see it sets the correct MIME type when you use xrl-html or xrl-html-tolerant ... but I can't see it doing anything to escape 'special' characters. Probably it does it in the serialization phase somewhere ... |
found it ... |
Joined: 14-March-2005 Posts: 60 Location: Amsterdam, The Netherlands | Posted:
9-September-2008 09:48 It indeed happens during serialization. XRL returns a DOMXDA, when that gets serialized using DOMXDASerializer the following code is executed: if (isHTML) { sw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); if (dt!=null) { writeDocumentType(sw,dt); } SerializedDOMAspect.serialize(n,sw); } else { if (dt!=null) { writeDocumentType(sw,dt); } XMLUtils.getInstance().toXML(sw, n, false,false); } |
So in case of a HTML mime type SerializedDOMAspect.serialize() is called. And this is the class that takes care of all HTML specifics. And for content it does the following: case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: writeEscaped(aWriter, aNode.getNodeValue()); break; |
And the writeEscaped method does the following: public static void writeEscaped(Writer aWriter, String aInput) throws IOException { char[] input = aInput.toCharArray(); int length=input.length; for (int i=0; i<length; i++) { char c=input[i]; switch(c) { case '<': aWriter.write("<"); break; case '>': aWriter.write(">"); break; case '\'': aWriter.write("'"); break; case '"': aWriter.write("""); break; case '&': aWriter.write("&"); break; default: aWriter.write(c); break; } } } |
I think the escaping is a bit too eager there. Single and double quotes only need to be escaped inside attribute values, not inside regular content. Isn't it? It's still a bit curious why browsers fail to execute the scripts with the encoded quotes, as I assume they would just resolve all entity references before interpreting the script ... Menzo |