Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@locus.apache.org Received: (qmail 23449 invoked from network); 4 Apr 2008 16:05:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Apr 2008 16:05:31 -0000 Received: (qmail 62204 invoked by uid 500); 4 Apr 2008 16:05:31 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 62174 invoked by uid 500); 4 Apr 2008 16:05:31 -0000 Mailing-List: contact sling-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sling-dev@incubator.apache.org Delivered-To: mailing list sling-commits@incubator.apache.org Received: (qmail 62165 invoked by uid 99); 4 Apr 2008 16:05:31 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Apr 2008 09:05:31 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Apr 2008 16:04:58 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A67481A9832; Fri, 4 Apr 2008 09:05:09 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r644750 - /incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/jcr/JsonItemWriter.java Date: Fri, 04 Apr 2008 16:05:08 -0000 To: sling-commits@incubator.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080404160509.A67481A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 * JSR Property TypeJSON Value Type - * BINARYsize of binary value as long1 + * BINARYalways 0 as long * DATEconverted date string as defined by ECMA * BOOLEANboolean * LONGlong @@ -162,7 +172,7 @@ * all otherstring * * 1 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(