IMHO you should add a special resource for getting the property types. An easy way to do so is by using selectors, eg.

   /foo/bar.metadata.json

where "metadata" is the selector. And the json would give you the metadata of the node, for example with a sub-object (in json) for each property and then all the property type data as key-value pairs.

That way you don't have to mess with the standard json rendering and you don't have to find a solution for the is-not-an-object problem.

Regards,
Alex


Am 01.05.2008 um 21:33 schrieb Craig L. Ching:

I have a question.  I'm looking into adding some information needed by
the JCR browser to the JSON rendering. What I really need to do is add at least the property type (PropertyType.String, etc.) and I'd assume we
want to pass on other traits found in the PropertyDefinition
(isMandatory(), isProtected(), isAutoCreated(), etc.).

The problem is, though, when I look at the JSON output, properties of a node are just key-value pairs. In order to add the other information, a
property needs to be an object in its own right.

So I had a look at the code to change this and I noticed that we have:

   /** Dump given property in JSON */
   public void dump(Property p, Writer w) throws JSONException,
           ValueFormatException, RepositoryException {
       final JSONWriter jw = new JSONWriter(w);
       jw.object();
       writeProperty(jw, p);
       jw.endObject();
   }

Which would be what I'd want (each property appears to be an object in
this code), but what comes out was more likely generated by:

   /** Dump given node in JSON, optionally recursing into its child
nodes */
   protected void dump(Node node, JSONWriter w, int
currentRecursionLevel,
           int maxRecursionLevels) throws RepositoryException,
JSONException {

       w.object();
       PropertyIterator props = node.getProperties();

       // the node's actual properties
       while (props.hasNext()) {
           Property prop = props.nextProperty();

           if (propertyNamesToIgnore != null
               && propertyNamesToIgnore.contains(prop.getName())) {
               continue;
           }

           writeProperty(w, prop);
       }

       // the child nodes
       if (recursionLevelActive(currentRecursionLevel,
maxRecursionLevels)) {
           final NodeIterator children = node.getNodes();
           while (children.hasNext()) {
               final Node n = children.nextNode();
               dumpSingleNode(n, w, currentRecursionLevel,
maxRecursionLevels);
           }
       }

       w.endObject();
   }

I haven't debugged, but I definitely know that the in the output,
properties are not objects but simple key-value pairs.

Any advice?

PS: Sorry for the formatting, but I only have Outlook available to me
and I have never been able to get it right :-(

Cheers,
Craig

>> Day JCR Cup 08 | Win a MacBook Pro: http://dev.day.com/ <<

----------------------------< [EMAIL PROTECTED] >---
Alexander Klimetschek, Day Management AG, Barfuesserplatz 6,
CH - 4001 Basel, T +41 61 226 55 31, M +49 151 15 77 20 56
---------------------------------------< http://www.day.com >---

Xing: http://www.xing.com/go/invite/3268380.32d2d4
LinkedIn: http://www.linkedin.com/in/klimetschek
Blog: http://weblogs.goshaky.com/weblogs/alexkli/



Reply via email to