You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Craig L. Ching" <cc...@mqsoftware.com> on 2008/05/01 21:33:28 UTC
JSON renderer
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
RE: JSON renderer
Posted by "Craig L. Ching" <cc...@mqsoftware.com>.
> -----Original Message-----
> From: Alexander Klimetschek [mailto:aklimets@day.com]
> Sent: Thursday, May 01, 2008 6:13 PM
> To: sling-dev@incubator.apache.org
> Subject: Re: JSON renderer
>
> 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.
>
Sorry for being a pain, but I'm still getting myself oriented here ;-)
So, should I be creating a new servlet with a new extension? Or should
I add this to the JsonRendererServlet and just look for my selector
there (since this is technically still a json rendering and I'm not sure
how the extension resolution would work if I use a similar extension)?
The latter seems like the right approach to me.
Also, the code I pointed out in my original e-mail where there are two
implementations for properties, do you think that needs to be addressed
in some way?
> Regards,
> Alex
>
Thanks for the help!
Cheers,
Craig
RE: JSON renderer
Posted by "Craig L. Ching" <cc...@mqsoftware.com>.
> -----Original Message-----
> From: Craig L. Ching [mailto:cching@mqsoftware.com]
> Sent: Friday, May 02, 2008 9:27 AM
> To: sling-dev@incubator.apache.org
> Subject: RE: JSON renderer
>
> > 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
> >
> Ok, I can do that, but then who would use which in what
> situaions? (That was a mouth-ful :-P) I may not fully
> understand how you guys envisioned using the JSON renderer so
> I'd like to understand that.
>
> > 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.
> >
> Ok, I'll have a look at doing that.
>
This also means I can't use Lars' dojo stores, so I'll have to provide
some new ones to cover this JSON output. Seems like a lot of redundancy
to me, but please comment.
> > Regards,
> > Alex
> >
>
> Cheers,
> Craig
>
RE: JSON renderer
Posted by "Craig L. Ching" <cc...@mqsoftware.com>.
> -----Original Message-----
> From: Alexander Klimetschek [mailto:aklimets@day.com]
> Sent: Friday, May 02, 2008 10:12 AM
> To: sling-dev@incubator.apache.org
> Subject: Re: JSON renderer
>
> Am 02.05.2008 um 16:27 schrieb Craig L. Ching:
> > I may not fully understand how you guys envisioned using the JSON
> > renderer so I'd like to understand that.
>
> For access to the (property) *data*. In typical JCR
> applications, you know which properties to read and set, so
> you'll only define property types at the beginning through
> node types or when setting the property value for the first
> time. Thus the json renderer for reading property data is
> just perfect.
>
Ok, gotcha. I just responded to myself as well, but I'll repeat it
here. I'll have to provide some new dojo stores to provide this
information as well.
> Regards,
> Alex
>
Cheers,
Craig
Re: JSON renderer
Posted by Alexander Klimetschek <ak...@day.com>.
Am 02.05.2008 um 16:27 schrieb Craig L. Ching:
> I may not fully understand how you guys envisioned
> using the JSON renderer so I'd like to understand that.
For access to the (property) *data*. In typical JCR applications, you
know which properties to read and set, so you'll only define property
types at the beginning through node types or when setting the property
value for the first time. Thus the json renderer for reading property
data is just perfect.
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com
>> Day JCR Cup 08 | Win a MacBook Pro: http://dev.day.com/ <<
RE: JSON renderer
Posted by "Craig L. Ching" <cc...@mqsoftware.com>.
> 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
>
Ok, I can do that, but then who would use which in what situaions? (That
was a mouth-ful :-P) I may not fully understand how you guys envisioned
using the JSON renderer so I'd like to understand that.
> 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.
>
Ok, I'll have a look at doing that.
> Regards,
> Alex
>
Cheers,
Craig
Re: JSON renderer
Posted by Alexander Klimetschek <ak...@day.com>.
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/ <<
----------------------------< alexander.klimetschek@day.com >---
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/