You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by Henry Saputra <he...@gmail.com> on 2011/11/15 22:18:00 UTC

Question about resolving namespace for the datapipeline script tag in the parent HTML tag

Hi All,

In latest Shindig trunk when I tried to run this gadget:


<html xmlns:os="http://ns.opensocial.org/2008/markup">
<head>
  <script type="text/os-data">
    <os:PeopleRequest key="Viewer" userId="@viewer" groupId="@self"/>
  </script>
  <script type="text/javascript">
    function init() {
      var dataContext = opensocial.data.getDataContext();
      gadgets.log("Data pipelined viewer is  " +
dataContext.getDataSet("Viewer"));
    }
    gadgets.util.registerOnLoadHandler(init);
  </script>
</head>
<body>
  <p>
    Hellow World!
  </p>
  <script type="text/os-template"
xmlns:os="http://ns.opensocial.org/2008/markup">Welcome, <os:Name
person="${Viewer}"/></script>
</body>
</html>


Shindig does not inject the opensocial.data.DataContext.putDataSet
call for the os:PeopleRequest script.
However if I move the xmlns to the os data pipeline script like this:
  <script  xmlns:os="http://ns.opensocial.org/2008/markup" type="text/os-data">
    <os:PeopleRequest key="Viewer" userId="@viewer" groupId="@self"/>
  </script>
it works.

Debugging the code I that the
GadgetHtmlParser.reprocessScriptForOpenSocial does not set the child
namespace URI for the new "osadata" script element injected.

Is this the intended behavior bc my co-workers claim that it was
working in previous Shindig release.

- Henry

Re: Question about resolving namespace for the datapipeline script tag in the parent HTML tag

Posted by Henry Saputra <he...@gmail.com>.
No taker?

I'll answer myself

The bug happen because a fix in Shindig (see
http://codereview.appspot.com/2200046/) to parse xmlns definition in
the <script> tags for os data pipeline.

Shindig provides an wrapper HTML parser with GadgetHtmlParser class.
This class will delegate work to either NekoHTML parser or Caja HTML
parser.
Previously, Caja HTML parser ignore the namespace definition in the
<script> because content of script tag considered as text by most HTML
parsers. Nekohtml parser gets around this by overriding the serializer
start and end element to convert <script> tags to <osadata> or
<ostemplate> tags so the parser can go through the children.
The fix in Shindig removes this solution by moving back the logic to
GadgetHtmlParser class.

The Shindig HTML parser will run 2 iterations: First is for regular
HTML tags, and Second fixing all the script tags with type
text/os-data or text/os-template and convert them to <osdata> and
<ostemplate> tags before running them again to parser that will return
a Document fragment.

So instead of:

<html xmlns:os="http://ns.opensocial.org/2008/markup">
<head>
<script type="text/os-data">
   <os:PeopleRequest key="Viewer" userId="@viewer" groupId="@self"/>
</script>

the right way based on OS spec it should be:

<html>
<head>
   <script xmlns:os="http://ns.opensocial.org/2008/markup" type="text/os-data">
     <os:PeopleRequest key="Viewer" userId="@viewer" groupId="@self"/>
   </script>

Each script tag enclosing OS data and pipeline tags should be treated
as separate document fragment outside the main HTML flow.

- Henry

On Tue, Nov 15, 2011 at 1:18 PM, Henry Saputra <he...@gmail.com> wrote:
> Hi All,
>
> In latest Shindig trunk when I tried to run this gadget:
>
>
> <html xmlns:os="http://ns.opensocial.org/2008/markup">
> <head>
>  <script type="text/os-data">
>    <os:PeopleRequest key="Viewer" userId="@viewer" groupId="@self"/>
>  </script>
>  <script type="text/javascript">
>    function init() {
>      var dataContext = opensocial.data.getDataContext();
>      gadgets.log("Data pipelined viewer is  " +
> dataContext.getDataSet("Viewer"));
>    }
>    gadgets.util.registerOnLoadHandler(init);
>  </script>
> </head>
> <body>
>  <p>
>    Hellow World!
>  </p>
>  <script type="text/os-template"
> xmlns:os="http://ns.opensocial.org/2008/markup">Welcome, <os:Name
> person="${Viewer}"/></script>
> </body>
> </html>
>
>
> Shindig does not inject the opensocial.data.DataContext.putDataSet
> call for the os:PeopleRequest script.
> However if I move the xmlns to the os data pipeline script like this:
>  <script  xmlns:os="http://ns.opensocial.org/2008/markup" type="text/os-data">
>    <os:PeopleRequest key="Viewer" userId="@viewer" groupId="@self"/>
>  </script>
> it works.
>
> Debugging the code I that the
> GadgetHtmlParser.reprocessScriptForOpenSocial does not set the child
> namespace URI for the new "osadata" script element injected.
>
> Is this the intended behavior bc my co-workers claim that it was
> working in previous Shindig release.
>
> - Henry
>