why did you change this without a proper jira issue? i think that all clients that rely on this need to be informed.
regards, toby On 4/4/08, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Author: cziegeler > Date: Fri Apr 4 09:05:04 2008 > New Revision: 644750 > > URL: http://svn.apache.org/viewvc?rev=644750&view=rev > Log: > Write lengths of binaries correctly and prefix it with a colon instead of a > star. > > Modified: > > incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/jcr/JsonItemWriter.java > > Modified: > incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/jcr/JsonItemWriter.java > URL: > http://svn.apache.org/viewvc/incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/jcr/JsonItemWriter.java?rev=644750&r1=644749&r2=644750&view=diff > > ============================================================================== > --- > incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/jcr/JsonItemWriter.java > (original) > +++ > incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/jcr/JsonItemWriter.java > Fri Apr 4 09:05:04 2008 > @@ -39,9 +39,9 @@ > * are threadsafe. > */ > public class JsonItemWriter { > - > + > private static DateFormat calendarFormat; > - > + > private final Set<String> propertyNamesToIgnore; > > /** Create a JsonItemWriter > @@ -74,7 +74,7 @@ > public void dump(Property p, Writer w) throws JSONException, > ValueFormatException, RepositoryException { > final JSONWriter jw = new JSONWriter(w); > jw.object(); > - writeProperty(jw, 0, p); > + writeProperty(jw, p); > jw.endObject(); > } > > @@ -93,16 +93,7 @@ > continue; > } > > - if (!prop.getDefinition().isMultiple()) { > - writeProperty(w, currentRecursionLevel, prop); > - } else { > - w.key(prop.getName()); > - w.array(); > - for(Value v : prop.getValues()) { > - dumpValue(w, v); > - } > - w.endArray(); > - } > + writeProperty(w, prop); > } > > // the child nodes > @@ -134,19 +125,38 @@ > /** > * Write a single property > */ > - protected void writeProperty(JSONWriter w, int indent, Property p) > + protected void writeProperty(JSONWriter w, Property p) > throws ValueFormatException, RepositoryException, JSONException { > - if(p.getType() == PropertyType.BINARY) { > - // TODO for now we mark binary properties with an initial star > in their name > - // (star is not allowed as a JCR property name) > + // special handling for binaries: we dump the length and not the > length > + if (p.getType() == PropertyType.BINARY) { > + // TODO for now we mark binary properties with an initial colon > in their name > + // (colon is not allowed as a JCR property name) > // in the name, and the value should be the size of the binary > data > - w.key("*" + p.getName()); > + w.key(":" + p.getName()); > + if (!p.getDefinition().isMultiple()) { > + w.value(p.getLength()); > + } else { > + final long[] sizes = p.getLengths(); > + w.array(); > + for(int i=0;i<sizes.length;i++) { > + w.value(sizes[i]); > + } > + w.endArray(); > + } > + return; > + } > + w.key(p.getName()); > > + if (!p.getDefinition().isMultiple()) { > + dumpValue(w, p.getValue()); > } else { > w.key(p.getName()); > + w.array(); > + for(Value v : p.getValues()) { > + dumpValue(w, v); > + } > + w.endArray(); > } > - > - dumpValue(w, p.getValue()); > } > > /** > @@ -154,7 +164,7 @@ > * conversions are done: > * <table> > * <tr><th>JSR Property Type</th><th>JSON Value Type</th></tr> > - * <tr><td>BINARY</td><td>size of binary value as > long<sup>1</sup></td></tr> > + * <tr><td>BINARY</td><td>always 0 as long</td></tr> > * <tr><td>DATE</td><td>converted date string as defined by > ECMA</td></tr> > * <tr><td>BOOLEAN</td><td>boolean</td></tr> > * <tr><td>LONG</td><td>long</td></tr> > @@ -162,7 +172,7 @@ > * <tr><td><i>all other</li></td><td>string</td></tr> > * </table> > * <sup>1</sup> Currently not implemented and uses 0 as default. > - * > + * > * @param w json writer > * @param v value to dump > */ > @@ -172,18 +182,17 @@ > > switch (v.getType()) { > case PropertyType.BINARY: > - // TODO return the binary size > w.value(0); > break; > > case PropertyType.DATE: > w.value(format(v.getDate())); > break; > - > + > case PropertyType.BOOLEAN: > w.value(v.getBoolean()); > break; > - > + > case PropertyType.LONG: > w.value(v.getLong()); > break; > @@ -196,7 +205,7 @@ > w.value(v.getString()); > } > } > - > + > public static synchronized String format(Calendar date) { > if (calendarFormat == null) { > calendarFormat = new SimpleDateFormat( > > >
