[Portfolio] Xpath Question for Sakai3

hongbo zhang hbzhang at vt.edu
Mon Oct 11 13:33:18 PDT 2010


I used the following but of Ruby code to convert Bryan's code to XML. The
reason using Ruby is just for a quick hack. 

 

require "rubygems"
require "crack"
require "json"
require "xmlsimple"

my_hash = Crack::JSON.parse(File.read("test.json"))

my_xml = XmlSimple.xml_out(my_hash)

file = File.open("test.xml","w") do |f1|

f1.puts(my_xml)
end




depending on the query scenario, 

 

./opt[@sling:resourceType= $username][1]/

 

Could work

 

Where $username is in the format of sakai/user-home, for example
sakai/bryan-home or sakai/jack-home

 

 

Not sure it fits the need. Hope it can help a little bit.

 

 

Hongbo

 

 

 

 

From: portfolio-bounces at collab.sakaiproject.org
[mailto:portfolio-bounces at collab.sakaiproject.org] On Behalf Of Holladay,
Bryan Andrew
Sent: Monday, October 11, 2010 9:52 AM
To: portfolio at collab.sakaiproject.org
Subject: [Portfolio] Xpath Question for Sakai3

 

Hey Everyone,

We Sakai3 developers are running into some xPath problems that are greatly
reducing our performance in our searches, and since I remember how fun
Reports was in ePort, I thought I may be able to tap Eports expertise in
this field.  Any help will be greatly appreciated and would help contribute
greatly to Sakai3.  Please read below if you are interested.

Thanks,
Bryan



For the interested:

Our current query is:

//*[@sling:resourceType='sakai/user-home']/*[fn:name() = 'public' or
fn:name() = 'pages']//*[jcr:contains(.,'{q}')]   (q is a parameter that the
user passes in, so you can replace that with '*' OR 'BRYAN', ect)


The basic problem we are running into is this query returns too many results
in our searches, when we just want the root parent (which is
//*[@sling:resourceType='sakai/user-home']).  We are hoping to smash this
query into a single query and return just the parent node, but search
through the user nodes in their "Pages" and "Public" subtrees.  

So for example, if a node looks like this:

{user1   {pages {page1} {page2}}}
where
Q=*

Currently, our search would return 4 nodes, when in fact it should only
return 1 node: {user1 ...}.


I tried something along this line, but it doesn't seem to work:

/*[@sling:resourceType='sakai/user-home' and (jcr:contains(path/*,'{q}') or
jcr:contains(pages/*,'{q}'))]


Does anyone have any ideas or suggestions or something to point to for an
example?

Below you can find an example of a json tree for a user which is being
searched on.  You can pretend that json is just XML for this query, since
its basically the same concept.


Thanks,
Bryan



{
   "sling:resourceType":"sakai/user-home",
   "jcr:mixinTypes":[
      "rep:AccessControllable"
   ],
   "jcr:primaryType":"nt:unstructured",
   "rep:policy":{
      "jcr:primaryType":"rep:ACL",
      "allow":{
         "rep:privileges":[
            "jcr:read"
         ],
         "rep:principalName":"anonymous",
         "jcr:primaryType":"rep:GrantACE"
      },
      "allow0":{
         "rep:privileges":[
            "jcr:read"
         ],
         "rep:principalName":"everyone",
         "jcr:primaryType":"rep:GrantACE"
      },
      "allow1":{
         "rep:privileges":[
            "jcr:all"
         ],
         "rep:principalName":"bahollad",
         "jcr:primaryType":"rep:GrantACE"
      }
   },
   "private":{
      "jcr:primaryType":"nt:unstructured"
   },
   "public":{
      "jcr:primaryType":"nt:unstructured",
      "authprofile":{
         "rep:userId":"bahollad",
         "sling:resourceType":"sakai/user-profile",
         "jcr:uuid":"9e3e386a-3a19-4e58-96e3-a30363e91d1a",
         "jcr:mixinTypes":[
            "mix:referenceable"
         ],
         "email":"bahollad at indiana.edu",
         "path":"/b/ba/bahollad",
         "jcr:primaryType":"nt:unstructured",
         "basic":{
            "access":"everybody",
            "jcr:primaryType":"nt:unstructured",
            "elements":{
               "jcr:primaryType":"nt:unstructured",
               "firstName":{
                  "value":"Bryan",
                  "jcr:primaryType":"nt:unstructured"
               },
               "lastName":{
                  "value":"Holladay",
                  "jcr:primaryType":"nt:unstructured"
               },
               "email":{
                  "value":"bahollad at indiana.edu",
                  "jcr:primaryType":"nt:unstructured"
               }
            }
         }
      }
   },
   "calendar":{
      "sling:resourceType":"sakai/calendar",
      "jcr:mixinTypes":[
         "rep:AccessControllable"
      ],
      "jcr:primaryType":"nt:unstructured",
      "rep:policy":{
         "jcr:primaryType":"rep:ACL",
         "allow":{
            "rep:privileges":[
               "jcr:all"
            ],
            "rep:principalName":"bahollad",
            "jcr:primaryType":"rep:GrantACE"
         }
      }
   },
   "contacts":{
      "sling:resourceType":"sakai/contactstore",
      "jcr:mixinTypes":[
         "rep:AccessControllable"
      ],
      "jcr:primaryType":"nt:unstructured",
      "rep:policy":{
         "jcr:primaryType":"rep:ACL",
         "allow":{
            "rep:privileges":[
               "jcr:all"
            ],
            "rep:principalName":"bahollad",
            "jcr:primaryType":"rep:GrantACE"
         },
         "deny":{
            "rep:privileges":[
               "jcr:write",
               "jcr:read"
            ],
            "rep:principalName":"anonymous",
            "jcr:primaryType":"rep:DenyACE"
         },
         "deny0":{
            "rep:privileges":[
               "jcr:write",
               "jcr:read"
            ],
            "rep:principalName":"everyone",
            "jcr:primaryType":"rep:DenyACE"
         }
      }
   },
   "message":{
      "sling:resourceType":"sakai/messagestore",
      "jcr:mixinTypes":[
         "rep:AccessControllable"
      ],
      "jcr:primaryType":"nt:unstructured",
      "rep:policy":{
         "jcr:primaryType":"rep:ACL",
         "allow":{
            "rep:privileges":[
               "jcr:all"
            ],
            "rep:principalName":"bahollad",
            "jcr:primaryType":"rep:GrantACE"
         },
         "deny":{
            "rep:privileges":[
               "jcr:write",
               "jcr:read"
            ],
            "rep:principalName":"anonymous",
            "jcr:primaryType":"rep:DenyACE"
         },
         "deny0":{
            "rep:privileges":[
               "jcr:write",
               "jcr:read"
            ],
            "rep:principalName":"everyone",
            "jcr:primaryType":"rep:DenyACE"
         }
      }
   },
   "pages":{
      "description":"This is the default user template",
      "id":"defaultuser",
      "name":"defaultuser",
      "sling:resourceType":"sakai/template",
      "jcr:mixinTypes":[
         "rep:AccessControllable"
      ],
      "sakai:is-site-template":"true",
      "status":"online",
      "sakai:site-template":"/templates/defaultuser",
      "sakai:skin":"/dev/_skins/original/original.html",
      "jcr:primaryType":"nt:unstructured",
      "_navigation":{
         "jcr:createdBy":"admin",
         "jcr:created":"Fri Oct 08 2010 11:55:57 GMT-0400",
         "jcr:primaryType":"sling:Folder",
         "content":{
            "sling:resourceType":"sakai/pagenavigationcontent",
            "jcr:createdBy":"admin",
            "jcr:created":"Fri Oct 08 2010 11:55:57 GMT-0400",
            "sakai:pagenavigationcontent":"<p><img
id=\"widget_navigation_id759008084\" class=\"widget_inline\"
style=\"display:block; padding: 10px; margin: 4px\"
src=\"/devwidgets/navigation/images/icon.png\" border=\"1\" alt=\"\"
/><\/p>",
            "jcr:primaryType":"sling:Folder"
         }
      },
      "_pages":{
         "jcr:createdBy":"admin",
         "jcr:created":"Fri Oct 08 2010 11:55:57 GMT-0400",
         "jcr:primaryType":"sling:Folder",
         "profile":{
            "pageTitle":"Profile",
            "pageType":"profile",
            "sling:resourceType":"sakai/page",
            "deletable":false,
            "jcr:createdBy":"admin",
            "jcr:created":"Fri Oct 08 2010 11:55:57 GMT-0400",
            "jcr:primaryType":"sling:Folder",
            "pagePosition":100000,
            "_pages":{
               "jcr:createdBy":"admin",
               "jcr:created":"Fri Oct 08 2010 11:55:57 GMT-0400",
               "jcr:primaryType":"sling:Folder"
            },
            "pageContent":{
               "jcr:predecessors":[
                  "1d2c7221-7fcb-45ab-8de0-cbf42d315cfa"
               ],
               "sling:resourceType":"sakai/pagecontent",
               "jcr:uuid":"13506682-e119-4cda-9592-8c07cfa382ab",
               "jcr:mixinTypes":[
                  "sakai:propertiesmix"
               ],
               "jcr:createdBy":"admin",
               "jcr:versionHistory":"326e7f52-2520-4271-89dd-4a5bf9868e28",
               "jcr:created":"Fri Oct 08 2010 11:55:57 GMT-0400",
               "jcr:baseVersion":"1d2c7221-7fcb-45ab-8de0-cbf42d315cfa",
               "sakai:pagecontent":"<div id='widget_userprofile'
class='widget_inline'><\/div>",
               "jcr:primaryType":"nt:folder",
               "jcr:isCheckedOut":true
            }
         },
         "user-dashboard":{
            "pageTitle":"User Dashboard",
            "pageType":"dashboard",
            "sling:resourceType":"sakai/page",
            "deletable":false,
            "jcr:createdBy":"admin",
            "jcr:created":"Fri Oct 08 2010 11:55:57 GMT-0400",
            "jcr:primaryType":"sling:Folder",
            "pagePosition":200000,
            "_pages":{
               "jcr:createdBy":"admin",
               "jcr:created":"Fri Oct 08 2010 11:55:57 GMT-0400",
               "jcr:primaryType":"sling:Folder"
            },
            "pageContent":{
               "jcr:predecessors":[
                  "4282671e-7b05-41da-9a62-07aa99cb46a7"
               ],
               "sling:resourceType":"sakai/pagecontent",
               "jcr:uuid":"4743be06-333c-498c-8fd4-4623cca2d1fe",
               "jcr:mixinTypes":[
                  "sakai:propertiesmix"
               ],
               "jcr:createdBy":"admin",
               "jcr:versionHistory":"266d0268-15ab-4e24-9231-8bda3c6023ad",
               "jcr:created":"Fri Oct 08 2010 11:55:57 GMT-0400",
               "jcr:baseVersion":"4282671e-7b05-41da-9a62-07aa99cb46a7",
               "sakai:pagecontent":"<div
id='widget_dashboard_sitedashboard4568062738100'
class='widget_inline'><\/div>",
               "jcr:primaryType":"nt:folder",
               "jcr:isCheckedOut":true
            }
         },
         "test-page-for-bryan":{
            "pageTitle":"Test Page for Bryan",
            "pageType":"webpage",
            "sling:resourceType":"sakai/page",
            "fullwidth":false,
            "jcr:createdBy":"bahollad",
            "jcr:created":"Mon Oct 11 2010 09:48:03 GMT-0400",
            "jcr:primaryType":"sling:Folder",
            "pagePosition":300000,
            "_pages":{
               "jcr:createdBy":"bahollad",
               "jcr:created":"Mon Oct 11 2010 09:48:09 GMT-0400",
               "jcr:primaryType":"sling:Folder"
            },
            "pageContent":{
               "jcr:predecessors":[
                  "4e4c25ee-f5eb-423a-a77e-f73504fc767b"
               ],
               "sling:resourceType":"sakai/pagecontent",
               "jcr:uuid":"1211b0b3-2135-483f-b1cc-22208139e772",
               "jcr:mixinTypes":[
                  "mix:versionable"
               ],
               "jcr:createdBy":"bahollad",
               "jcr:versionHistory":"55797dea-5b25-4641-be37-a3412f397ef4",
               "sakai:savedBy":"bahollad",
               "jcr:created":"Mon Oct 11 2010 09:48:09 GMT-0400",
               "jcr:baseVersion":"4e4c25ee-f5eb-423a-a77e-f73504fc767b",
               "sakai:pagecontent":"<p>This is just a test<br
mce_bogus=\"1\"><\/p>",
               "jcr:isCheckedOut":true,
               "jcr:primaryType":"sling:Folder"
            }
         }
      },
      "_widgets":{
         "jcr:createdBy":"admin",
         "jcr:created":"Fri Oct 08 2010 11:55:57 GMT-0400",
         "jcr:primaryType":"sling:Folder",
         "sitedashboard4568062738100":{
            "jcr:createdBy":"admin",
            "jcr:created":"Fri Oct 08 2010 11:55:57 GMT-0400",
            "jcr:primaryType":"sling:Folder",
            "dashboard":{
               "jcr:createdBy":"admin",
               "layout":"dev",
               "jcr:created":"Fri Oct 08 2010 11:55:57 GMT-0400",
               "jcr:primaryType":"sling:Folder",
               "columns":{
                  "jcr:createdBy":"admin",
                  "jcr:created":"Fri Oct 08 2010 11:55:57 GMT-0400",
                  "jcr:primaryType":"sling:Folder",
                  "column1":{
                     "jcr:createdBy":"admin",
                     "jcr:created":"Fri Oct 08 2010 11:55:57 GMT-0400",
                     "jcr:primaryType":"sling:Folder",
                     "__array__0__":{
                        "visible":"block",
                        "name":"discussion",
                        "jcr:createdBy":"admin",
                        "uid":"id402868778",
                        "jcr:created":"Fri Oct 08 2010 11:55:57 GMT-0400",
                        "jcr:primaryType":"sling:Folder"
                     }
                  }
               }
            }
         }
      }
   },
   "dashboard":{
      "jcr:primaryType":"nt:unstructured",
      "mysakaidashboard":{
         "jcr:primaryType":"nt:unstructured",
         "dashboard":{
            "layout":"dev",
            "jcr:primaryType":"nt:unstructured",
            "columns":{
               "jcr:primaryType":"nt:unstructured",
               "column1":{
                  "jcr:primaryType":"nt:unstructured",
                  "__array__0__":{
                     "visible":"block",
                     "name":"mygroups",
                     "uid":"id9192894494298",
                     "jcr:primaryType":"nt:unstructured"
                  },
                  "__array__1__":{
                     "visible":"block",
                     "name":"mycontacts",
                     "uid":"id4110578868787",
                     "jcr:primaryType":"nt:unstructured"
                  }
               },
               "column2":{
                  "jcr:primaryType":"nt:unstructured",
                  "__array__0__":{
                     "visible":"block",
                     "name":"myprofile",
                     "uid":"id5406983344586",
                     "jcr:primaryType":"nt:unstructured"
                  },
                  "__array__1__":{
                     "visible":"block",
                     "name":"mycontent",
                     "uid":"id8727044907582",
                     "jcr:primaryType":"nt:unstructured"
                  }
               }
            }
         }
      }
   }
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/portfolio/attachments/20101011/99b2936e/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rawdata.xml
Type: text/xml
Size: 11640 bytes
Desc: not available
Url : http://collab.sakaiproject.org/pipermail/portfolio/attachments/20101011/99b2936e/attachment-0001.xml 


More information about the portfolio mailing list