You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Peter Svensson <ps...@gmail.com> on 2008/01/19 09:38:15 UTC

Sling JSON format

Hi,

I've been battling to convert the JSON format the Sling outputs when
describing all resources hierarchically ("
http://localhost:8080/content.json?maxlevels=999") , into a format that is
accepted by the Dojo Tree widget. It was slow in the beginning, because the
Tree dies silently if the format isn't absolutely perfect :)

However, I realize that I need to use regular expressions to get the correct
format, and I really suck at regular expressions :|

here's the kind of format the Tree likes;

            {
                label: 'name',
                identifier: 'name',
                items:
                [
                    { name:'Fruit', type:'category'},
                    { name:'Cinammon', type: 'category',
                    children:
                    [
                        { name:'Cinammon Roll', type:'poptart' },
                        { name:'Brown Sugar Cinnamon', type:'poptart' },
                        { name:'French Toast', type:'poptart' }
                    ]
                    },
                    { name:'Chocolate', type: 'category'}
                ]
            }

And here's the Sling output;

{
  "jcr:primaryType":"nt:unstructured", "testing":
   {
      "jcr:primaryType":"nt:unstructured","test2":
       {

"title":"test2","sling:resourceType":"usling/example","jcr:primaryType":"nt:unstructured","text":"Default
text of the test node"
       },
       "dojo_editor":
       {
          "title":"dojo
editor","sling:resourceType":"usling/editor","jcr:primaryType":"nt:unstructured","text":"This
is the dojo 1.x editor"
       },
       "d1":
       {
          "title":"d1","sling:resourceType":"<!DOCTYPE HTML PUBLIC
\"-//W3C//DTD HTML 4.01//EN\"\r\n            \"
http://www.w3.org/TR/html4/strict.dtd\">\r\n<html>\r\n<head>\r\n<meta
http-equiv=\"Content-Type\" content=\"text/html;
charset=UTF-8\">\r\n<title>Editor Demo<\/title>\r\n    <style
type=\"text/css\">\r\n        @import \"
http://o.aolcdn.com/dojo/1.0.0/dijit/themes/tundra/tundra.css\";\r\n
@import \"http://o.aolcdn.com/dojo/1.0.0/dojo/resources/dojo.css\"\r\n
<\/style>\r\n    <script type=\"text/javascript\" src=\"
http://o.aolcdn.com/dojo/1.0.0/dojo/dojo.xd.js\"\r\n
djConfig=\"parseOnLoad: true\"><\/script>\r\n        <script
type=\"text/javascript\">\r\n       dojo.require(\"dojo.parser\");\r\n
dojo.require(\"dijit.Editor\");\r\n     <\/script>\r\n<\/head>\r\n<body
class=\"tundra\">\r\n<form method=\"post\">\r\n<textarea name=\"field\"
width=\"200px\" dojoType=\"dijit.Editor\">\r\n        It was a dark and
stormy night.  Your story belongs here!\r\n<\/textarea>\r\n<input
type=\"submit\" value=\"Save\"
/>\r\n<\/form>\r\n<\/body>\r\n<\/html>","jcr:primaryType":"nt:unstructured","text":"dddd"
       }
   }
}



Also, I wonder if there would be possible to get the output ina  more
condensed format. The ideal format would, for instance not include data, but
only unique ids for different levels in the tree, and then I could use a
separate Sling resource to get the content. A large tree could possible
contain quite a lot of data.

But What I'm asking for right now is to try another route: Maybe I can write
the JSON formatter myself? If someone points out where it is, and what kind
of magic guards it, I could write it.

Cheers,
PS

Re: Sling JSON format

Posted by Lars Trieloff <la...@trieloff.net>.
If possible, do not use MoinMoin, but introduce another Wiki Space in  
Confluence. This makes it much easier to move content once it is ready  
to graduate into the "official" documentation.

Lars

On 22.01.2008, at 21:21, Bertrand Delacretaz wrote:

> On Jan 22, 2008 6:22 PM, Lars Trieloff <la...@trieloff.net> wrote:
>
>> ...perhaps we could have something like a scratchpad wiki
>> space that is completely open and keep access to the main wiki  
>> tightly
>> limited to committers....
>
> That sounds like a good way to get new contributions and contributors
> - of course, such an open space will need some babysitting, but that's
> probably worth it.
>
> What do others think? Shall we ask infranfor an open moinmoin wiki in
> addition to the one we already have?
>
> -Bertrand

--
Lars Trieloff
lars@trieloff.net
http://weblogs.goshaky.com/weblogs/lars


Re: Sling JSON format

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Jan 22, 2008 6:22 PM, Lars Trieloff <la...@trieloff.net> wrote:

> ...perhaps we could have something like a scratchpad wiki
> space that is completely open and keep access to the main wiki tightly
> limited to committers....

That sounds like a good way to get new contributions and contributors
- of course, such an open space will need some babysitting, but that's
probably worth it.

What do others think? Shall we ask infranfor an open moinmoin wiki in
addition to the one we already have?

-Bertrand

Re: Sling JSON format

Posted by Alexander Klimetschek <ak...@day.com>.
+1

As a non-committer with no CLA filed at ASF yet, I find this a *huge*  
barrier. The idea of a seperate section is good and saves the main  
website from Spammers. Apart from that an open source software wiki  
should be a wiki for everyone!

Alex

Am 22.01.2008 um 18:22 schrieb Lars Trieloff:

> Hi Betrand,
>
> I think the question who can edit the wiki is a more general one and  
> actually I like it the way Cocoon handles it. The Cocoon MoinMoin  
> Wiki has no access control whatsoever and this means that the  
> barrier for contribution is much lower than here in Sling.
> I know that the Sling website is built from the wiki, so this is a  
> sensible issue, perhaps we could have something like a scratchpad  
> wiki space that is completely open and keep access to the main wiki  
> tightly limited to committers.
>
> As much as a like to write about Sling in my blog, some pieces  
> should go to the Wiki, for others to check and refine if things  
> change.
>
> regards,
>
> Lars
>
> On 22.01.2008, at 12:32, Bertrand Delacretaz wrote:
>
>> Hi,
>>
>> On Jan 22, 2008 12:24 PM, Lars Trieloff <la...@trieloff.net> wrote:
>>> ...would it be possible to give non-committers or even anonymous  
>>> wiki-
>>> editing karma, so we do not just discuss about improving the docs,  
>>> but
>>> can start with it right now?...
>>
>> I'm +1 on giving write access to our wiki to people who are active in
>> the Sling community, after a committer's vote, and once these people
>> have a CLA on file with the ASF [1] (As a Cocoon committer, Lars does
>> have one).
>>
>> That access would be subject to the usual rules for committing code:
>> people have to revert their changes if a committer opposes them (with
>> justification), and for "big changes" we'd like people to ask or hold
>> a vote first.
>>
>> There's no official concept of "wiki committers" at the ASF yet, so  
>> we
>> might want to limit this "experiment" to the Sling incubation period.
>>
>> -Bertrand (who's not supposed to be working on Sling today, but
>> there's so much happening here ;-)
>>
>> [1] http://www.apache.org/licenses/
>
> --
> Lars Trieloff
> lars@trieloff.net
> http://weblogs.goshaky.com/weblogs/lars
>

--
Alexander Klimetschek
alexander.klimetschek@day.com





Re: Sling JSON format

Posted by Lars Trieloff <la...@trieloff.net>.
Hi Betrand,

I think the question who can edit the wiki is a more general one and  
actually I like it the way Cocoon handles it. The Cocoon MoinMoin Wiki  
has no access control whatsoever and this means that the barrier for  
contribution is much lower than here in Sling.
I know that the Sling website is built from the wiki, so this is a  
sensible issue, perhaps we could have something like a scratchpad wiki  
space that is completely open and keep access to the main wiki tightly  
limited to committers.

As much as a like to write about Sling in my blog, some pieces should  
go to the Wiki, for others to check and refine if things change.

regards,

Lars

On 22.01.2008, at 12:32, Bertrand Delacretaz wrote:

> Hi,
>
> On Jan 22, 2008 12:24 PM, Lars Trieloff <la...@trieloff.net> wrote:
>> ...would it be possible to give non-committers or even anonymous  
>> wiki-
>> editing karma, so we do not just discuss about improving the docs,  
>> but
>> can start with it right now?...
>
> I'm +1 on giving write access to our wiki to people who are active in
> the Sling community, after a committer's vote, and once these people
> have a CLA on file with the ASF [1] (As a Cocoon committer, Lars does
> have one).
>
> That access would be subject to the usual rules for committing code:
> people have to revert their changes if a committer opposes them (with
> justification), and for "big changes" we'd like people to ask or hold
> a vote first.
>
> There's no official concept of "wiki committers" at the ASF yet, so we
> might want to limit this "experiment" to the Sling incubation period.
>
> -Bertrand (who's not supposed to be working on Sling today, but
> there's so much happening here ;-)
>
> [1] http://www.apache.org/licenses/

--
Lars Trieloff
lars@trieloff.net
http://weblogs.goshaky.com/weblogs/lars


Re: Sling JSON format

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Jan 22, 2008 12:24 PM, Lars Trieloff <la...@trieloff.net> wrote:
> ...would it be possible to give non-committers or even anonymous wiki-
> editing karma, so we do not just discuss about improving the docs, but
> can start with it right now?...

I'm +1 on giving write access to our wiki to people who are active in
the Sling community, after a committer's vote, and once these people
have a CLA on file with the ASF [1] (As a Cocoon committer, Lars does
have one).

That access would be subject to the usual rules for committing code:
people have to revert their changes if a committer opposes them (with
justification), and for "big changes" we'd like people to ask or hold
a vote first.

There's no official concept of "wiki committers" at the ASF yet, so we
might want to limit this "experiment" to the Sling incubation period.

-Bertrand (who's not supposed to be working on Sling today, but
there's so much happening here ;-)

[1] http://www.apache.org/licenses/

Re: Sling JSON format

Posted by Lars Trieloff <la...@trieloff.net>.
Hi Felix,

would it be possible to give non-committers or even anonymous wiki- 
editing karma, so we do not just discuss about improving the docs, but  
can start with it right now?

regards,

Lars

On 21.01.2008, at 11:44, Felix Meschberger wrote:

> Hi Peter,
>
> Not on the first one, but on a page like "Scripting in Sling How-To"  
> or
> such...
>
> Regards
> Felix
>
> Am Samstag, den 19.01.2008, 15:57 +0100 schrieb Peter Svensson:
>> This is great. This info should be on the first page of the "So,  
>> you want to
>> become a Sling wizard" page in the Wiki :)
>>
>> Cheers,
>> PS
>>
>> On Jan 19, 2008 3:07 PM, Felix Meschberger <fm...@gmail.com>  
>> wrote:
>>
>>> Hi Peter,
>>>
>>> All resources available to JSP are also available to scripts, this  
>>> is
>>> not different for JavaScript (Rhino in our case).
>>>
>>> For example, each script has the following global objects:
>>>
>>>   request - The SlingHttpServletRequest object for the request
>>>   response - The SlingHttpServletResponse object for the request
>>>   log - An SLF4J logger for logging
>>>   resource - The Resource of the request (same as
>>> request.getResource() or
>>>                    request.resource in JavaScript lingo)
>>>   out - The output channel (same as response.getWriter())
>>>   sling - A SlingScriptHelper instance
>>>
>>>> From these objects you should be able to do just about  
>>>> anything ....
>>>
>>> Hope this helps.
>>>
>>> Regards
>>> Felix
>>>
>>> Am Samstag, den 19.01.2008, 10:26 +0100 schrieb Peter Svensson:
>>>> Argh! Sorry about this. The resource is indeed referenced. My  
>>>> fault.
>>> But
>>>> still, is there some server-side system files which describe which
>>> things
>>>> are accessible from scripts??
>>>>
>>>> Cheers,
>>>> PS
>>>>
>>>> On Jan 19, 2008 10:24 AM, Peter Svensson <ps...@gmail.com>  
>>>> wrote:
>>>>
>>>>> Wait - just another question; In most of the tests; esp, erb,  
>>>>> et.c.
>>> there
>>>>> are magic api references. For instance resource or node, et.c.   
>>>>> In the
>>> js
>>>>> example there's only writeln's. Is it possible to access system
>>> resources
>>>>> from Rhino as well?  If so, is there some Java system file which
>>> describes
>>>>> which resources are accesible to the scripts??
>>>>>
>>>>> Thank!
>>>>>
>>>>> Cheers,
>>>>> PS
>>>>>
>>>>>
>>>>> On Jan 19, 2008 10:21 AM, Peter Svensson <ps...@gmail.com>  
>>>>> wrote:
>>>>>
>>>>>> WoW!  Thanks. :) I half-and-half that you would say that it was
>>>>>> theoretically possible, but not on Saturdays :)  This, I like.
>>>>>>
>>>>>> Cheers,
>>>>>> PS
>>>>>>
>>>>>>
>>>>>> On Jan 19, 2008 10:18 AM, Bertrand Delacretaz <
>>> bdelacretaz@apache.org>
>>>>>> wrote:
>>>>>>
>>>>>>> On Jan 19, 2008 10:14 AM, Peter Svensson < psvensson@gmail.com>
>>> wrote:
>>>>>>>
>>>>>>>> ...If Sling support writing server-side scripts in Rhino,
>>> couldn't I
>>>>>>> just as
>>>>>>>> well write a serve-side javascript which access internal Sling
>>> APIs,
>>>>>>> build
>>>>>>>> the structure, and outputs the correct format?...
>>>>>>>
>>>>>>> Sure - just name your script "json.js", put in in the right  
>>>>>>> place
>>>>>>> based on the sling:resourceType of the node that you're dumping,
>>> and
>>>>>>> that should work if the GET request URL uses the .json  
>>>>>>> extension.
>>>>>>>
>>>>>>> There are no docs on this ATM, but the integration tests found
>>> under
>>>>>>>
>>>>>>>
>>> http://svn.apache.org/repos/asf/incubator/sling/trunk/usling/usling-webapp/src/test
>>>>>>> contain lots of examples.
>>>>>>>
>>>>>>> -Bertrand
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
>>>
>

--
Lars Trieloff
lars@trieloff.net
http://weblogs.goshaky.com/weblogs/lars


Re: Sling JSON format

Posted by Felix Meschberger <fm...@gmail.com>.
Hi Peter,

Not on the first one, but on a page like "Scripting in Sling How-To" or
such...

Regards
Felix

Am Samstag, den 19.01.2008, 15:57 +0100 schrieb Peter Svensson:
> This is great. This info should be on the first page of the "So, you want to
> become a Sling wizard" page in the Wiki :)
> 
> Cheers,
> PS
> 
> On Jan 19, 2008 3:07 PM, Felix Meschberger <fm...@gmail.com> wrote:
> 
> > Hi Peter,
> >
> > All resources available to JSP are also available to scripts, this is
> > not different for JavaScript (Rhino in our case).
> >
> > For example, each script has the following global objects:
> >
> >    request - The SlingHttpServletRequest object for the request
> >    response - The SlingHttpServletResponse object for the request
> >    log - An SLF4J logger for logging
> >    resource - The Resource of the request (same as
> > request.getResource() or
> >                     request.resource in JavaScript lingo)
> >    out - The output channel (same as response.getWriter())
> >    sling - A SlingScriptHelper instance
> >
> > >From these objects you should be able to do just about anything ....
> >
> > Hope this helps.
> >
> > Regards
> > Felix
> >
> > Am Samstag, den 19.01.2008, 10:26 +0100 schrieb Peter Svensson:
> > > Argh! Sorry about this. The resource is indeed referenced. My fault.
> >  But
> > > still, is there some server-side system files which describe which
> > things
> > > are accessible from scripts??
> > >
> > > Cheers,
> > > PS
> > >
> > > On Jan 19, 2008 10:24 AM, Peter Svensson <ps...@gmail.com> wrote:
> > >
> > > > Wait - just another question; In most of the tests; esp, erb, et.c.
> > there
> > > > are magic api references. For instance resource or node, et.c.  In the
> > js
> > > > example there's only writeln's. Is it possible to access system
> > resources
> > > > from Rhino as well?  If so, is there some Java system file which
> > describes
> > > > which resources are accesible to the scripts??
> > > >
> > > > Thank!
> > > >
> > > > Cheers,
> > > > PS
> > > >
> > > >
> > > > On Jan 19, 2008 10:21 AM, Peter Svensson <ps...@gmail.com> wrote:
> > > >
> > > > > WoW!  Thanks. :) I half-and-half that you would say that it was
> > > > > theoretically possible, but not on Saturdays :)  This, I like.
> > > > >
> > > > > Cheers,
> > > > > PS
> > > > >
> > > > >
> > > > > On Jan 19, 2008 10:18 AM, Bertrand Delacretaz <
> > bdelacretaz@apache.org>
> > > > > wrote:
> > > > >
> > > > > > On Jan 19, 2008 10:14 AM, Peter Svensson < psvensson@gmail.com>
> > wrote:
> > > > > >
> > > > > > > ...If Sling support writing server-side scripts in Rhino,
> > couldn't I
> > > > > > just as
> > > > > > > well write a serve-side javascript which access internal Sling
> > APIs,
> > > > > > build
> > > > > > > the structure, and outputs the correct format?...
> > > > > >
> > > > > > Sure - just name your script "json.js", put in in the right place
> > > > > > based on the sling:resourceType of the node that you're dumping,
> > and
> > > > > > that should work if the GET request URL uses the .json extension.
> > > > > >
> > > > > > There are no docs on this ATM, but the integration tests found
> > under
> > > > > >
> > > > > >
> > http://svn.apache.org/repos/asf/incubator/sling/trunk/usling/usling-webapp/src/test
> > > > > > contain lots of examples.
> > > > > >
> > > > > > -Bertrand
> > > > > >
> > > > >
> > > > >
> > > >
> >
> >


Re: Sling JSON format

Posted by Peter Svensson <ps...@gmail.com>.
This is great. This info should be on the first page of the "So, you want to
become a Sling wizard" page in the Wiki :)

Cheers,
PS

On Jan 19, 2008 3:07 PM, Felix Meschberger <fm...@gmail.com> wrote:

> Hi Peter,
>
> All resources available to JSP are also available to scripts, this is
> not different for JavaScript (Rhino in our case).
>
> For example, each script has the following global objects:
>
>    request - The SlingHttpServletRequest object for the request
>    response - The SlingHttpServletResponse object for the request
>    log - An SLF4J logger for logging
>    resource - The Resource of the request (same as
> request.getResource() or
>                     request.resource in JavaScript lingo)
>    out - The output channel (same as response.getWriter())
>    sling - A SlingScriptHelper instance
>
> >From these objects you should be able to do just about anything ....
>
> Hope this helps.
>
> Regards
> Felix
>
> Am Samstag, den 19.01.2008, 10:26 +0100 schrieb Peter Svensson:
> > Argh! Sorry about this. The resource is indeed referenced. My fault.
>  But
> > still, is there some server-side system files which describe which
> things
> > are accessible from scripts??
> >
> > Cheers,
> > PS
> >
> > On Jan 19, 2008 10:24 AM, Peter Svensson <ps...@gmail.com> wrote:
> >
> > > Wait - just another question; In most of the tests; esp, erb, et.c.
> there
> > > are magic api references. For instance resource or node, et.c.  In the
> js
> > > example there's only writeln's. Is it possible to access system
> resources
> > > from Rhino as well?  If so, is there some Java system file which
> describes
> > > which resources are accesible to the scripts??
> > >
> > > Thank!
> > >
> > > Cheers,
> > > PS
> > >
> > >
> > > On Jan 19, 2008 10:21 AM, Peter Svensson <ps...@gmail.com> wrote:
> > >
> > > > WoW!  Thanks. :) I half-and-half that you would say that it was
> > > > theoretically possible, but not on Saturdays :)  This, I like.
> > > >
> > > > Cheers,
> > > > PS
> > > >
> > > >
> > > > On Jan 19, 2008 10:18 AM, Bertrand Delacretaz <
> bdelacretaz@apache.org>
> > > > wrote:
> > > >
> > > > > On Jan 19, 2008 10:14 AM, Peter Svensson < psvensson@gmail.com>
> wrote:
> > > > >
> > > > > > ...If Sling support writing server-side scripts in Rhino,
> couldn't I
> > > > > just as
> > > > > > well write a serve-side javascript which access internal Sling
> APIs,
> > > > > build
> > > > > > the structure, and outputs the correct format?...
> > > > >
> > > > > Sure - just name your script "json.js", put in in the right place
> > > > > based on the sling:resourceType of the node that you're dumping,
> and
> > > > > that should work if the GET request URL uses the .json extension.
> > > > >
> > > > > There are no docs on this ATM, but the integration tests found
> under
> > > > >
> > > > >
> http://svn.apache.org/repos/asf/incubator/sling/trunk/usling/usling-webapp/src/test
> > > > > contain lots of examples.
> > > > >
> > > > > -Bertrand
> > > > >
> > > >
> > > >
> > >
>
>

Re: Sling JSON format

Posted by Felix Meschberger <fm...@gmail.com>.
Hi Peter,

All resources available to JSP are also available to scripts, this is
not different for JavaScript (Rhino in our case).

For example, each script has the following global objects:

    request - The SlingHttpServletRequest object for the request
    response - The SlingHttpServletResponse object for the request
    log - An SLF4J logger for logging
    resource - The Resource of the request (same as
request.getResource() or
                     request.resource in JavaScript lingo)
    out - The output channel (same as response.getWriter())
    sling - A SlingScriptHelper instance

>>From these objects you should be able to do just about anything ....

Hope this helps.

Regards
Felix

Am Samstag, den 19.01.2008, 10:26 +0100 schrieb Peter Svensson:
> Argh! Sorry about this. The resource is indeed referenced. My fault.  But
> still, is there some server-side system files which describe which things
> are accessible from scripts??
> 
> Cheers,
> PS
> 
> On Jan 19, 2008 10:24 AM, Peter Svensson <ps...@gmail.com> wrote:
> 
> > Wait - just another question; In most of the tests; esp, erb, et.c. there
> > are magic api references. For instance resource or node, et.c.  In the js
> > example there's only writeln's. Is it possible to access system resources
> > from Rhino as well?  If so, is there some Java system file which describes
> > which resources are accesible to the scripts??
> >
> > Thank!
> >
> > Cheers,
> > PS
> >
> >
> > On Jan 19, 2008 10:21 AM, Peter Svensson <ps...@gmail.com> wrote:
> >
> > > WoW!  Thanks. :) I half-and-half that you would say that it was
> > > theoretically possible, but not on Saturdays :)  This, I like.
> > >
> > > Cheers,
> > > PS
> > >
> > >
> > > On Jan 19, 2008 10:18 AM, Bertrand Delacretaz < bdelacretaz@apache.org>
> > > wrote:
> > >
> > > > On Jan 19, 2008 10:14 AM, Peter Svensson < psvensson@gmail.com> wrote:
> > > >
> > > > > ...If Sling support writing server-side scripts in Rhino, couldn't I
> > > > just as
> > > > > well write a serve-side javascript which access internal Sling APIs,
> > > > build
> > > > > the structure, and outputs the correct format?...
> > > >
> > > > Sure - just name your script "json.js", put in in the right place
> > > > based on the sling:resourceType of the node that you're dumping, and
> > > > that should work if the GET request URL uses the .json extension.
> > > >
> > > > There are no docs on this ATM, but the integration tests found under
> > > >
> > > > http://svn.apache.org/repos/asf/incubator/sling/trunk/usling/usling-webapp/src/test
> > > > contain lots of examples.
> > > >
> > > > -Bertrand
> > > >
> > >
> > >
> >


Re: Sling JSON format

Posted by Peter Svensson <ps...@gmail.com>.
Argh! Sorry about this. The resource is indeed referenced. My fault.  But
still, is there some server-side system files which describe which things
are accessible from scripts??

Cheers,
PS

On Jan 19, 2008 10:24 AM, Peter Svensson <ps...@gmail.com> wrote:

> Wait - just another question; In most of the tests; esp, erb, et.c. there
> are magic api references. For instance resource or node, et.c.  In the js
> example there's only writeln's. Is it possible to access system resources
> from Rhino as well?  If so, is there some Java system file which describes
> which resources are accesible to the scripts??
>
> Thank!
>
> Cheers,
> PS
>
>
> On Jan 19, 2008 10:21 AM, Peter Svensson <ps...@gmail.com> wrote:
>
> > WoW!  Thanks. :) I half-and-half that you would say that it was
> > theoretically possible, but not on Saturdays :)  This, I like.
> >
> > Cheers,
> > PS
> >
> >
> > On Jan 19, 2008 10:18 AM, Bertrand Delacretaz < bdelacretaz@apache.org>
> > wrote:
> >
> > > On Jan 19, 2008 10:14 AM, Peter Svensson < psvensson@gmail.com> wrote:
> > >
> > > > ...If Sling support writing server-side scripts in Rhino, couldn't I
> > > just as
> > > > well write a serve-side javascript which access internal Sling APIs,
> > > build
> > > > the structure, and outputs the correct format?...
> > >
> > > Sure - just name your script "json.js", put in in the right place
> > > based on the sling:resourceType of the node that you're dumping, and
> > > that should work if the GET request URL uses the .json extension.
> > >
> > > There are no docs on this ATM, but the integration tests found under
> > >
> > > http://svn.apache.org/repos/asf/incubator/sling/trunk/usling/usling-webapp/src/test
> > > contain lots of examples.
> > >
> > > -Bertrand
> > >
> >
> >
>

Re: Sling JSON format

Posted by Peter Svensson <ps...@gmail.com>.
Wait - just another question; In most of the tests; esp, erb, et.c. there
are magic api references. For instance resource or node, et.c.  In the js
example there's only writeln's. Is it possible to access system resources
from Rhino as well?  If so, is there some Java system file which describes
which resources are accesible to the scripts??

Thank!

Cheers,
PS

On Jan 19, 2008 10:21 AM, Peter Svensson <ps...@gmail.com> wrote:

> WoW!  Thanks. :) I half-and-half that you would say that it was
> theoretically possible, but not on Saturdays :)  This, I like.
>
> Cheers,
> PS
>
>
> On Jan 19, 2008 10:18 AM, Bertrand Delacretaz < bdelacretaz@apache.org>
> wrote:
>
> > On Jan 19, 2008 10:14 AM, Peter Svensson < psvensson@gmail.com> wrote:
> >
> > > ...If Sling support writing server-side scripts in Rhino, couldn't I
> > just as
> > > well write a serve-side javascript which access internal Sling APIs,
> > build
> > > the structure, and outputs the correct format?...
> >
> > Sure - just name your script "json.js", put in in the right place
> > based on the sling:resourceType of the node that you're dumping, and
> > that should work if the GET request URL uses the .json extension.
> >
> > There are no docs on this ATM, but the integration tests found under
> >
> > http://svn.apache.org/repos/asf/incubator/sling/trunk/usling/usling-webapp/src/test
> > contain lots of examples.
> >
> > -Bertrand
> >
>
>

Re: Sling JSON format

Posted by Peter Svensson <ps...@gmail.com>.
WoW!  Thanks. :) I half-and-half that you would say that it was
theoretically possible, but not on Saturdays :)  This, I like.

Cheers,
PS

On Jan 19, 2008 10:18 AM, Bertrand Delacretaz <bd...@apache.org>
wrote:

> On Jan 19, 2008 10:14 AM, Peter Svensson <ps...@gmail.com> wrote:
>
> > ...If Sling support writing server-side scripts in Rhino, couldn't I
> just as
> > well write a serve-side javascript which access internal Sling APIs,
> build
> > the structure, and outputs the correct format?...
>
> Sure - just name your script "json.js", put in in the right place
> based on the sling:resourceType of the node that you're dumping, and
> that should work if the GET request URL uses the .json extension.
>
> There are no docs on this ATM, but the integration tests found under
>
> http://svn.apache.org/repos/asf/incubator/sling/trunk/usling/usling-webapp/src/test
> contain lots of examples.
>
> -Bertrand
>

Re: Sling JSON format

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Jan 19, 2008 10:14 AM, Peter Svensson <ps...@gmail.com> wrote:

> ...If Sling support writing server-side scripts in Rhino, couldn't I just as
> well write a serve-side javascript which access internal Sling APIs, build
> the structure, and outputs the correct format?...

Sure - just name your script "json.js", put in in the right place
based on the sling:resourceType of the node that you're dumping, and
that should work if the GET request URL uses the .json extension.

There are no docs on this ATM, but the integration tests found under
http://svn.apache.org/repos/asf/incubator/sling/trunk/usling/usling-webapp/src/test
contain lots of examples.

-Bertrand

Re: Sling JSON format

Posted by Peter Svensson <ps...@gmail.com>.
OK, that sounds great.

I have another, related question though (I just checked out [1], and found
the servlet and JsonItemWriter, checking..);

If Sling support writing server-side scripts in Rhino, couldn't I just as
well write a serve-side javascript which access internal Sling APIs, build
the structure, and outputs the correct format?

This is actually in my next-to-check-out list, but I just thought i'd ask it
now anyway.

Cheers,
PS

On Jan 19, 2008 10:08 AM, Bertrand Delacretaz <bd...@apache.org>
wrote:

> On Jan 19, 2008 9:59 AM, Peter Svensson <ps...@gmail.com> wrote:
> > ...I'm still a bit confused ab out what goes where here, so I'll
> > probably call stuff by the wrong name for weeks....
>
> hmmm...I'm not sure if we are less confused than you are about what is
> what between Sling and (the two existing variants of) microsling ;-)
>
> Watch this space though, between SLING-149 and my next message about
> the Sling Launchpad, things should be better soon.
>
> -Bertrand
>

Re: Sling JSON format

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Jan 19, 2008 9:59 AM, Peter Svensson <ps...@gmail.com> wrote:
> ...I'm still a bit confused ab out what goes where here, so I'll
> probably call stuff by the wrong name for weeks....

hmmm...I'm not sure if we are less confused than you are about what is
what between Sling and (the two existing variants of) microsling ;-)

Watch this space though, between SLING-149 and my next message about
the Sling Launchpad, things should be better soon.

-Bertrand

Re: Sling JSON format

Posted by Peter Svensson <ps...@gmail.com>.
Thanks!  I'm still a bit confused ab out what goes where here, so I'll
probably call stuff by the wrong name for weeks.
I'll check it out and see what I can do.

Cheers,
PS

On Jan 19, 2008 9:55 AM, Bertrand Delacretaz <bd...@apache.org> wrote:

> Hi Peter,
>
> On Jan 19, 2008 9:38 AM, Peter Svensson <ps...@gmail.com> wrote:
> > ...http://localhost:8080/content.json?maxlevels=999"...
>
> seems to indicate that you're running microsling-core.
>
> I don't have time to look at this in detail now, but about this:
>
> > ...Maybe I can write
> > the JSON formatter myself? If someone points out where it is, and what
> kind
> > of magic guards it, I could write it....
>
> The microsling-core [1] JSON format is generated by the
> JsonRendererServlet that you'll find under [1].
>
> The "magic" that guards it is in the microsling-core integration
> tests: if "mvn clean install" succeeds in [1] you're fine (see also
> src/test/java/org/apache/sling/microsling/integration/package.html).
>
> Note that the microsling-core is meant to go away as soon as
> https://issues.apache.org/jira/browse/SLING-149 is completed. The
> replacement is under [2], but I'm still working on it. The code is
> fairly similar though, so if you create a patch for microsling-core,
> porting it to that new module later shouldn't be too hard.
>
> Hope this helps,
> -Bertrand
>
> [1]
> http://svn.apache.org/repos/asf/incubator/sling/trunk/microsling/microsling-core
> [2]
> https://svn.apache.org/repos/asf/incubator/sling/trunk/usling/usling-webapp
>

Re: Sling JSON format

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Peter,

On Jan 19, 2008 9:38 AM, Peter Svensson <ps...@gmail.com> wrote:
> ...http://localhost:8080/content.json?maxlevels=999"...

seems to indicate that you're running microsling-core.

I don't have time to look at this in detail now, but about this:

> ...Maybe I can write
> the JSON formatter myself? If someone points out where it is, and what kind
> of magic guards it, I could write it....

The microsling-core [1] JSON format is generated by the
JsonRendererServlet that you'll find under [1].

The "magic" that guards it is in the microsling-core integration
tests: if "mvn clean install" succeeds in [1] you're fine (see also
src/test/java/org/apache/sling/microsling/integration/package.html).

Note that the microsling-core is meant to go away as soon as
https://issues.apache.org/jira/browse/SLING-149 is completed. The
replacement is under [2], but I'm still working on it. The code is
fairly similar though, so if you create a patch for microsling-core,
porting it to that new module later shouldn't be too hard.

Hope this helps,
-Bertrand

[1]  http://svn.apache.org/repos/asf/incubator/sling/trunk/microsling/microsling-core
[2] https://svn.apache.org/repos/asf/incubator/sling/trunk/usling/usling-webapp