@@ -0,0 +1,1441 @@
+package foam.lib.json;%0A%0Aimport foam.core.ContextAwareSupport;%0Aimport foam.core.FObject;%0Aimport foam.core.ProxyX;%0Aimport foam.core.X;%0A%0A/**%0A * Class responsible for parsing journal files.%0A * journal files follows this structure.%0A * put(foam.json.parse(%7B%22class%22:%22foam.nanos.boot.NSpec%22,%22name%22:%22Gibs1%22 %7D))%0A * remove(foam.json.parse(%7B%22class%22:%22foam.nanos.boot.NSpec%22,%22name%22:%22Gibs%22 %7D))%0A */%0Apublic class JournalParser extends ContextAwareSupport %7B%0A%0A    protected JSONParser jsonParser;%0A%0A    public JournalParser() %7B%0A        // do not fail if context is null%0A        X ctx = (getX() == null) ? new ProxyX() : getX();%0A        this.jsonParser = new JSONParser();%0A        jsonParser.setX(ctx);%0A    %7D%0A%0A%0A    // TODO(drish): do not generate a second copy of the journalLine%0A    public FObject parseObject(String journalLine) %7B%0A%0A        // get the actual object%0A        int objectIndex = journalLine.indexOf(%22%7B%22);%0A        String object = journalLine.substring(objectIndex, journalLine.lastIndexOf(%22%7D%22) + 1);%0A%0A        return this.jsonParser.parseString(object);%0A    %7D%0A%0A    /**%0A     * Extract the operation (put/remove) from the journal file line.%0A     *%0A     * @param journalLine%0A     * @return operation%0A     */%0A    public String parseOperation(String journalLine) %7B%0A        // get put/remove index.%0A        int operationIndex = journalLine.indexOf(%22(%22);%0A        String operation = journalLine.substring(0, operationIndex);%0A        return operation;%0A    %7D%0A%7D

create Journal file parser