You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/05/27 00:38:54 UTC

svn commit: r778913 - in /incubator/pivot/trunk: core/src/pivot/serialization/ core/src/pivot/util/ core/test/pivot/core/test/ tutorials/src/pivot/tutorials/stocktracker/ wtk/src/META-INF/services/ wtk/src/pivot/wtk/

Author: gbrown
Date: Tue May 26 22:38:54 2009
New Revision: 778913

URL: http://svn.apache.org/viewvc?rev=778913&view=rev
Log:
Add support for comments to JSONSerializer; add support for empty lines to pivot.util.Service.

Modified:
    incubator/pivot/trunk/core/src/pivot/serialization/JSONSerializer.java
    incubator/pivot/trunk/core/src/pivot/util/Service.java
    incubator/pivot/trunk/core/test/pivot/core/test/JSONSerializerTest.java
    incubator/pivot/trunk/core/test/pivot/core/test/json_serializer_test.json
    incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker.json
    incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker_fr.json
    incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker_it.json
    incubator/pivot/trunk/wtk/src/META-INF/services/pivot.wtk.Theme
    incubator/pivot/trunk/wtk/src/pivot/wtk/Alert.json
    incubator/pivot/trunk/wtk/src/pivot/wtk/Prompt.json

Modified: incubator/pivot/trunk/core/src/pivot/serialization/JSONSerializer.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/pivot/serialization/JSONSerializer.java?rev=778913&r1=778912&r2=778913&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/pivot/serialization/JSONSerializer.java (original)
+++ incubator/pivot/trunk/core/src/pivot/serialization/JSONSerializer.java Tue May 26 22:38:54 2009
@@ -123,7 +123,7 @@
         throws IOException, SerializationException {
         Object object = null;
 
-        skipWhitespace(reader);
+        skipWhitespaceAndComments(reader);
 
         if (c == -1) {
             throw new SerializationException("Unexpected end of input stream.");
@@ -148,10 +148,49 @@
         return object;
     }
 
-    private void skipWhitespace(Reader reader)
-        throws IOException {
-        while (c != -1 && Character.isWhitespace(c)) {
+    private void skipWhitespaceAndComments(Reader reader)
+        throws IOException, SerializationException {
+        while (c != -1
+            && (Character.isWhitespace(c)
+                || c == '/')) {
+            boolean comment = (c == '/');
+
+            // Read the next character
             c = reader.read();
+
+            if (comment) {
+                if (c == '/') {
+                    // Single-line comment
+                    while (c != -1
+                        && c != '\n'
+                        && c != '\r') {
+                        c = reader.read();
+                    }
+                } else if (c == '*') {
+                    // Multi-line comment
+                    boolean closed = false;
+
+                    while (c != -1
+                        && !closed) {
+                        c = reader.read();
+
+                        if (c == '*') {
+                            c = reader.read();
+                            closed = (c == '/');
+                        }
+                    }
+
+                    if (!closed) {
+                        throw new SerializationException("Unexpected end of input stream.");
+                    }
+
+                    if (c != -1) {
+                        c = reader.read();
+                    }
+                } else {
+                    throw new SerializationException("Unexpected character in input stream.");
+                }
+            }
         }
     }
 
@@ -299,11 +338,11 @@
 
         while (c != -1 && c != ']') {
             list.add(readValue(reader));
-            skipWhitespace(reader);
+            skipWhitespaceAndComments(reader);
 
             if (c == ',') {
                 c = reader.read();
-                skipWhitespace(reader);
+                skipWhitespaceAndComments(reader);
             } else if (c == -1) {
                 throw new SerializationException("Unexpected end of input stream.");
             } else {
@@ -325,7 +364,7 @@
 
         // Move to the next character after '{'
         c = reader.read();
-        skipWhitespace(reader);
+        skipWhitespaceAndComments(reader);
 
         while (c != -1 && c != '}') {
             String key = null;
@@ -364,7 +403,7 @@
                 throw new SerializationException("\"" + key + "\" is not a valid key.");
             }
 
-            skipWhitespace(reader);
+            skipWhitespaceAndComments(reader);
 
             if (c != ':') {
                 throw new SerializationException("Unexpected character in input stream.");
@@ -374,11 +413,11 @@
             c = reader.read();
 
             map.put(key, readValue(reader));
-            skipWhitespace(reader);
+            skipWhitespaceAndComments(reader);
 
             if (c == ',') {
                 c = reader.read();
-                skipWhitespace(reader);
+                skipWhitespaceAndComments(reader);
             } else if (c == -1) {
                 throw new SerializationException("Unexpected end of input stream.");
             } else {

Modified: incubator/pivot/trunk/core/src/pivot/util/Service.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/pivot/util/Service.java?rev=778913&r1=778912&r2=778913&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/pivot/util/Service.java (original)
+++ incubator/pivot/trunk/core/src/pivot/util/Service.java Tue May 26 22:38:54 2009
@@ -64,7 +64,8 @@
                         reader = new BufferedReader(new InputStreamReader(serviceInputStream, "UTF-8"));
                         String line = reader.readLine();
                         while (line != null
-                            && line.startsWith("#")) {
+                            && (line.length() == 0
+                                || line.startsWith("#"))) {
                             line = reader.readLine();
                         }
 

Modified: incubator/pivot/trunk/core/test/pivot/core/test/JSONSerializerTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/test/pivot/core/test/JSONSerializerTest.java?rev=778913&r1=778912&r2=778913&view=diff
==============================================================================
--- incubator/pivot/trunk/core/test/pivot/core/test/JSONSerializerTest.java (original)
+++ incubator/pivot/trunk/core/test/pivot/core/test/JSONSerializerTest.java Tue May 26 22:38:54 2009
@@ -63,7 +63,8 @@
         // test1();
         // test2();
     	// test3();
-        test4();
+        // test4();
+        test5();
     }
 
     public static void test0() {
@@ -203,6 +204,16 @@
         System.out.println("a['h'] exists: " + JSONSerializer.containsKey(root, "a['h']"));
     }
 
+    public static void test5() {
+        JSONSerializer jsonSerializer = new JSONSerializer();
+
+        try {
+            jsonSerializer.writeObject(JSONSerializer.parse("// This is a comment\n\n['a', /*FOO*/ //dfsdf\n 'b' // FSKJHJKDSF\r /*ASDKHASD*/]"), System.out);
+        } catch(Exception exception) {
+            System.err.println(exception);
+        }
+    }
+
     private static void testGet(Object root, String path) {
         Object value = JSONSerializer.get(root, path);
         System.out.println(path + ": " + value);

Modified: incubator/pivot/trunk/core/test/pivot/core/test/json_serializer_test.json
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/test/pivot/core/test/json_serializer_test.json?rev=778913&r1=778912&r2=778913&view=diff
==============================================================================
--- incubator/pivot/trunk/core/test/pivot/core/test/json_serializer_test.json (original)
+++ incubator/pivot/trunk/core/test/pivot/core/test/json_serializer_test.json Tue May 26 22:38:54 2009
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 {   foo:"ABCD",
     bar:"\u0041\u0042\u0043\u0044"
 }

Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker.json
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker.json?rev=778913&r1=778912&r2=778913&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker.json (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker.json Tue May 26 22:38:54 2009
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 {	stockTracker: "Pivot Stock Tracker",
 	symbol: "Symbol",
 	companyName: "Company",

Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker_fr.json
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker_fr.json?rev=778913&r1=778912&r2=778913&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker_fr.json (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker_fr.json Tue May 26 22:38:54 2009
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 {	stockTracker: "La Bourse Pivot",
 	symbol: "Code",
 	companyName: "Société",

Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker_it.json
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker_it.json?rev=778913&r1=778912&r2=778913&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker_it.json (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/stocktracker/StockTracker_it.json Tue May 26 22:38:54 2009
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 {   stockTracker:   "Pivot Stock Tracker",
     symbol:         "Simbolo",
     companyName:    "Azienda",

Modified: incubator/pivot/trunk/wtk/src/META-INF/services/pivot.wtk.Theme
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/META-INF/services/pivot.wtk.Theme?rev=778913&r1=778912&r2=778913&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/META-INF/services/pivot.wtk.Theme (original)
+++ incubator/pivot/trunk/wtk/src/META-INF/services/pivot.wtk.Theme Tue May 26 22:38:54 2009
@@ -12,5 +12,6 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
 # Service provider for Terra theme 
 pivot.wtk.skin.terra.TerraTheme

Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/Alert.json
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/Alert.json?rev=778913&r1=778912&r2=778913&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/Alert.json (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/Alert.json Tue May 26 22:38:54 2009
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 {   defaultOption: "OK",
     defaultTitle: "Alert"
 }

Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/Prompt.json
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/Prompt.json?rev=778913&r1=778912&r2=778913&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/Prompt.json (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/Prompt.json Tue May 26 22:38:54 2009
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 {   defaultOption: "OK",
     defaultTitle: "Prompt"
 }