Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id DA014200C5D for ; Fri, 24 Mar 2017 05:46:20 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id D5D5D160B84; Fri, 24 Mar 2017 04:46:20 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 26F3F160B83 for ; Fri, 24 Mar 2017 05:46:20 +0100 (CET) Received: (qmail 12704 invoked by uid 500); 24 Mar 2017 04:46:19 -0000 Mailing-List: contact commits-help@manifoldcf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@manifoldcf.apache.org Delivered-To: mailing list commits@manifoldcf.apache.org Received: (qmail 12695 invoked by uid 99); 24 Mar 2017 04:46:19 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Mar 2017 04:46:19 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 70F183A00A3 for ; Fri, 24 Mar 2017 04:46:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1788361 - /manifoldcf/branches/CONNECTORS-1399/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/Configuration.java Date: Fri, 24 Mar 2017 04:46:18 -0000 To: commits@manifoldcf.apache.org From: kwright@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170324044618.70F183A00A3@svn01-us-west.apache.org> archived-at: Fri, 24 Mar 2017 04:46:21 -0000 Author: kwright Date: Fri Mar 24 04:46:17 2017 New Revision: 1788361 URL: http://svn.apache.org/viewvc?rev=1788361&view=rev Log: Finish rework of Configuration class Modified: manifoldcf/branches/CONNECTORS-1399/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/Configuration.java Modified: manifoldcf/branches/CONNECTORS-1399/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/Configuration.java URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1399/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/Configuration.java?rev=1788361&r1=1788360&r2=1788361&view=diff ============================================================================== --- manifoldcf/branches/CONNECTORS-1399/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/Configuration.java (original) +++ manifoldcf/branches/CONNECTORS-1399/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/Configuration.java Fri Mar 24 04:46:17 2017 @@ -781,9 +781,7 @@ public class Configuration implements IH } public void startObject() { - objectStack.add(currentObject); - keyStack.add(currentKey); - arrayStack.add(currentArray); + pushState(); currentObject = new JSONObject(); currentKey = null; currentArray = null; @@ -800,9 +798,7 @@ public class Configuration implements IH public void endObject() { final JSONObject object = currentObject; // Pop everything - currentObject = objectStack.remove(objectStack.size()-1); - currentKey = keyStack.remove(keyStack.size()-1); - currentArray = arrayStack.remove(arrayStack.size()-1); + popState(); // Either an array is active, or an object is active, or nothing is active if (currentObject != null) { currentObject.put(currentKey, object); @@ -814,9 +810,7 @@ public class Configuration implements IH } public void startArray() { - objectStack.add(currentObject); - keyStack.add(currentKey); - arrayStack.add(currentArray); + pushState(); currentObject = null; currentKey = null; currentArray = new JSONArray(); @@ -825,9 +819,7 @@ public class Configuration implements IH public void endArray() { final JSONArray array = currentArray; // Pop everything - currentObject = objectStack.remove(objectStack.size()-1); - currentKey = keyStack.remove(keyStack.size()-1); - currentArray = arrayStack.remove(arrayStack.size()-1); + popState(); // Either an array is active, or an object is active, or nothing is active if (currentObject != null) { currentObject.put(currentKey, array); @@ -845,47 +837,103 @@ public class Configuration implements IH return finalObject.toJSONString(); } + protected void pushState() { + objectStack.add(currentObject); + keyStack.add(currentKey); + arrayStack.add(currentArray); + } + + protected void popState() { + currentObject = objectStack.remove(objectStack.size()-1); + currentKey = keyStack.remove(keyStack.size()-1); + currentArray = arrayStack.remove(arrayStack.size()-1); + } + } protected static class JSONReader { + private final List objectStack = new ArrayList<>(); + private final List arrayStack = new ArrayList<>(); + private JSONObject currentObject = null; + private Iterator currentArrayIterator = null; + + private Object next = null; + public JSONReader(final String json) throws ManifoldCFException { + final JSONParser parser = new JSONParser(); + try { + next = parser.parse(new StringReader(json)); + } catch (Exception e) { + throw new ManifoldCFException("Bad json: "+e.getMessage(),e); + } } public boolean isObject() { + return next != null && (next instanceof JSONObject); } public void startObject() { + pushState(); + currentObject = (JSONObject)next; + currentArrayIterator = null; } public Iterator getKeys() { + return currentObject.keySet().iterator(); } public boolean valueForKey(final String key) { + next = currentObject.get(key); + return next != null; } public void endObject() { + popState(); } public boolean isArray() { + return next != null && (next instanceof JSONArray); } public void startArray() { + pushState(); + currentObject = null; + currentArrayIterator = ((JSONArray)next).iterator(); } public boolean nextElement() { + if (currentArrayIterator.hasNext()) { + next = currentArrayIterator.next(); + return true; + } + return false; } public void endArray() { + popState(); } public boolean isNull() { + return next == null; } public boolean isValue() { + return next != null && !(next instanceof JSONObject || next instanceof JSONArray); } public String readValue() { + return next.toString(); + } + + protected void pushState() { + objectStack.add(currentObject); + arrayStack.add(currentArrayIterator); + } + + protected void popState() { + currentObject = objectStack.remove(objectStack.size()-1); + currentArrayIterator = arrayStack.remove(arrayStack.size()-1); } }