You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Valentin Jacquemin <ja...@gmail.com> on 2009/03/07 11:23:46 UTC

Sling Repository Explorer

Dear all,

I don't know if there are some dev about the Sling-based JCR explorer[1] but
I started a small prototype about it.

I hope it could be usefull for the newcomers on Sling as a sample app for
example. At least, to me it helped to learn some basic functionalities about
Sling.
So enough words, my prototype is here (I don't know the usual process to
propose a contribution, are there any repository available for the
non-comitters?):

<html>
<head>
<script src="/system/sling.js"></script>
<style>
ul li{
    list-style-type: disc;
}
</style>
</head>
<body>
<h1>Sling Repository Explorer</h1>
<div id="nodesTree" style="width: 250px; float:left; padding-right: 10px;
border-right: solid 1px black; margin-right: 5px; overflow: auto;">
<ul>
    <%
          function prt(nodePath, nodeName) { out.println("<li
id='"+nodePath+"'><a
href=\"javascript:Sling.Explorer.getProperties('"+nodePath+"')\">" +
nodeName + "</a></li>"); }
        var root = currentNode.session.getRootNode();
        var nodes = root.getNodes("*");
        for(n in nodes)
        {
            prt(nodes[n].getPath(), nodes[n].getName());
        }
    %>
</ul>
</div>
<div style="float:left; padding-left: 5px;" id="properties">
</div>

<script type="text/javascript">
(function(){
    var folderTypes = ['SLING:FOLDER','NT:FOLDER', 'REP:SYSTEM'];
    var isFolder = function(str){
        for(var x in folderTypes)
        {
            if(str.toUpperCase() === folderTypes[x])
                return true;
        }
        return false;
    };
    var loadChildren = function(path){
        var query = new String(path);
          query = query.toString();
           var props = Sling.getContent(query,1,true);
           var str = '';
           var parent = document.getElementById(path);
           var hide = parent.childNodes.length != 1;
           for(p in props)
           {
               if(props[p] instanceof Object)
               {
                   if(hide === true)
                   {
                       while(parent.childNodes.length != 1)
                       {
                           parent.removeChild(parent.lastChild);
                       }
                   }
                   else
                   {
                      var ulEl = document.createElement('ul');
                      var liEl = document.createElement('li');
                      liEl.setAttribute('id', query + "/" + p);
                      var t = document.createElement('a');
                      t.setAttribute('href',
"javascript:Sling.Explorer.getProperties('"+path+"/"+p+"')");
                      t.appendChild(document.createTextNode(p));
                      liEl.appendChild(t);
                      ulEl.appendChild(liEl);
                      parent.appendChild(ulEl);
                   }
               }
               str += p + ' : ' + props[p];
           }
    };

    Sling.Explorer = {
          getProperties: function(path){
                var query = new String(path);
                 var props = Sling.getContent(query.toString(),0,true);
                 var str = '';
                 for(p in props)
                 {
                     str += p + ' : ' + props[p];
                     str += '<br/>';
                     if(p == 'jcr:primaryType' &&  isFolder(props[p]))
                     {
                             loadChildren(path);
                     }
                 }
                 var domProps = document.getElementById('properties');
                 domProps.innerHTML = str;
          }
    }
})();
</script>
</body>
</html>

Any advices? Am I in the right direction
With my best regards,
Valentin Jacquemin

[1] http://cwiki.apache.org/SLING/sling-based-jcr-explorer.html

Re: Sling Repository Explorer

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

Sorry to take so long to reply...

On Sat, Mar 7, 2009 at 12:23 PM, Valentin Jacquemin
<ja...@gmail.com> wrote:
> ...my prototype is here (I don't know the usual process to
> propose a contribution, are there any repository available for the
> non-comitters?):...

Thanks - I got it working by copying your script to
apps/sling/servlet/default/explorer.html.esp and requesting URLs like
http://localhost:8888/apps.explorer.html

The script does a lot with few lines of code, that's a good demo for Sling!

As discussed recently in another thread, however, an explorer that
allows you to create, edit and delete nodes, assign nodetypes, search
the repository and generally perform all available JCR operations
might need some additional server-side components.

Or better, improvements to Sling's existing RESTful interface - if
that can support a full featured explorer, the interface will be
reasonably feature complete ;-)

The current process for contributions by community members who are not
(yet) committers is to upload patches to JIRA issues. You could also
create a project hosted elsewhere, and have that (possibly) adopted by
Sling later on.

If you do that, however, I'd recommend using the Apache License 2.0
from the start, to make it easier for us to adopt the code, should
that happen.

Simpler examples can also be attached to our public wiki at
http://cwiki.apache.org/SLING/

-Bertrand