Package org.json

Examples of org.json.JSONWriter


    protected void getState(HttpServletResponse response, String pid, String uid, int rev) throws Exception {

        Project project = getProject(pid);
       
        Writer w = response.getWriter();
        JSONWriter writer = new JSONWriter(w);
       
        writer.object();
        writer.key("status"); writer.value("ok");
        writer.key("transformations");
        writer.array();
            int size = project.transformations.size();
            for (int i = rev; i < size; i++) {
                writer.value(new JSONObject(project.transformations.get(i)));
            }
        writer.endArray();

        EntityCursor<Lock> cursor = locksByProject.subIndex(pid).entities();
       
        try {
            writer.key("locks");
            writer.array();
            for (Lock lock : cursor) {
                writer.value(lockToJSON(lock, uid));
            }
            writer.endArray();
            writer.endObject();
           
            w.flush();
            w.close();
        } finally {
            cursor.close();
View Full Code Here


    }

    protected static void saveToFile(ProjectMetadata projectMeta, File metadataFile) throws Exception {
        Writer writer = new OutputStreamWriter(new FileOutputStream(metadataFile));
        try {
            JSONWriter jsonWriter = new JSONWriter(writer);
            projectMeta.write(jsonWriter);
        } finally {
            writer.close();
        }
    }
View Full Code Here

        template.setSuffix(suffixString);
        template.setSeparator(separatorString);
       
        if (!"true".equals(options.getProperty("preview"))) {
            StringWriter stringWriter = new StringWriter();
            JSONWriter jsonWriter = new JSONWriter(stringWriter);
            try {
                jsonWriter.object();
                jsonWriter.key("template"); jsonWriter.value(templateString);
                jsonWriter.key("prefix"); jsonWriter.value(prefixString);
                jsonWriter.key("suffix"); jsonWriter.value(suffixString);
                jsonWriter.key("separator"); jsonWriter.value(separatorString);
                jsonWriter.endObject();
            } catch (JSONException e) {
                // ignore
            }
           
            project.getMetadata().getPreferenceStore().put("exporters.templating.template", stringWriter.toString());
View Full Code Here

    protected AbstractSparqlJsonWriter(final Writer newWriter, final String[] newLinks) {
        checkNotNull(newWriter, newLinks);
        this.writer = newWriter;
        this.links = newLinks;
        this.jsonWriter = new JSONWriter(this.writer);
    }
View Full Code Here

        try {
            response.setCharacterEncoding("UTF-8");
            response.setHeader("Content-Type", "application/json");
           
            Properties options = new Properties();
            JSONWriter writer = new JSONWriter(response.getWriter());
           
            writer.object();
            writer.key("entries"); writer.array();
           
            for (HistoryEntry entry : project.history.getLastPastEntries(-1)) {
                writer.object();
                writer.key("description"); writer.value(entry.description);
                if (entry.operation != null) {
                    writer.key("operation");
                    entry.operation.write(writer, options);
                }
                writer.endObject();
            }
            writer.endArray();
            writer.endObject();
        } catch (JSONException e) {
            respondException(response, e);
        }
    }
View Full Code Here

            if (callback != null) {
                writer.write(callback);
                writer.write("(");
            }
           
            JSONWriter jsonWriter = new JSONWriter(writer);
            jsonWriter.object();
           
            RowWritingVisitor rwv = new RowWritingVisitor(start, limit, jsonWriter, options);
           
            JSONObject sortingJson = null;
            try{
                String json = request.getParameter("sorting");
                sortingJson = (json == null) ? null :
                    ParsingUtilities.evaluateJsonStringToObject(json);
            } catch (JSONException e) {
            }

            if (engine.getMode() == Mode.RowBased) {
                FilteredRows filteredRows = engine.getAllFilteredRows();
                RowVisitor visitor = rwv;
               
                if (sortingJson != null) {
                    SortingRowVisitor srv = new SortingRowVisitor(visitor);
                   
                    srv.initializeFromJSON(project, sortingJson);
                    if (srv.hasCriteria()) {
                        visitor = srv;
                    }
                }
               
                jsonWriter.key("mode"); jsonWriter.value("row-based");
                jsonWriter.key("rows"); jsonWriter.array();
                filteredRows.accept(project, visitor);
                jsonWriter.endArray();
                jsonWriter.key("filtered"); jsonWriter.value(rwv.total);
                jsonWriter.key("total"); jsonWriter.value(project.rows.size());
            } else {
                FilteredRecords filteredRecords = engine.getFilteredRecords();
                RecordVisitor visitor = rwv;
               
                if (sortingJson != null) {
                    SortingRecordVisitor srv = new SortingRecordVisitor(visitor);
                   
                    srv.initializeFromJSON(project, sortingJson);
                    if (srv.hasCriteria()) {
                        visitor = srv;
                    }
                }
               
                jsonWriter.key("mode"); jsonWriter.value("record-based");
                jsonWriter.key("rows"); jsonWriter.array();
                filteredRecords.accept(project, visitor);
                jsonWriter.endArray();
                jsonWriter.key("filtered"); jsonWriter.value(rwv.total);
                jsonWriter.key("total"); jsonWriter.value(project.recordModel.getRecordCount());
            }
           
           
            jsonWriter.key("start"); jsonWriter.value(start);
            jsonWriter.key("limit"); jsonWriter.value(limit);
            jsonWriter.key("pool"); pool.write(jsonWriter, options);
           
            jsonWriter.endObject();
           
            if (callback != null) {
                writer.write(")");
            }
        } catch (Exception e) {
View Full Code Here

       
        try {
            response.setCharacterEncoding("UTF-8");
            response.setHeader("Content-Type", "application/json");
           
            JSONWriter writer = new JSONWriter(response.getWriter());
           
            writer.object();
            writer.key("value");
            if (pref == null || pref instanceof String || pref instanceof Number || pref instanceof Boolean) {
                writer.value(pref);
            } else if (pref instanceof TopList) {
                TopList tl = (TopList) pref;
                tl.write(writer, new Properties());
            } else {
                writer.value(pref.toString());
            }
           
            writer.endObject();
        } catch (JSONException e) {
            respondException(response, e);
        }
    }
View Full Code Here

            List<String> starredExpressions = ((TopList)ProjectManager.singleton.getPreferenceStore().get("scripting.starred-expressions")).getList();
           
            response.setCharacterEncoding("UTF-8");
            response.setHeader("Content-Type", "application/json");
           
            JSONWriter writer = new JSONWriter(response.getWriter());
            writer.object();
            writer.key("expressions");
                writer.array();
                for (String s : starredExpressions) {
                    writer.object();
                    writer.key("code"); writer.value(s);
                    writer.endObject();
                }
                writer.endArray();
            writer.endObject();
        } catch (Exception e) {
            respondException(response, e);
        }
    }
View Full Code Here

       
        try {
            response.setCharacterEncoding("UTF-8");
            response.setHeader("Content-Type", "application/json");
           
            JSONWriter writer = new JSONWriter(response.getWriter());
            Properties options = new Properties();
           
            writer.object();
            writer.key("projects");
                writer.object();
                Map<Long, ProjectMetadata> m = ProjectManager.singleton.getAllProjectMetadata();
                for (Entry<Long,ProjectMetadata> e : m.entrySet()) {
                    ProjectMetadata pm = e.getValue();
                    if (pm != null) {
                        writer.key(e.getKey().toString());
                        e.getValue().write(writer, options);
                    }
                }
                writer.endObject();
            writer.endObject();
        } catch (JSONException e) {
            respondException(response, e);
        }
    }
View Full Code Here

        if(request.getParameter("returnList") != null) {
            try {
                response.setCharacterEncoding("UTF-8");
                response.setHeader("Content-Type", "application/json");

                JSONWriter writer = new JSONWriter(response.getWriter());
                writer.object();
                writer.key("expressions");
                writer.array();
                for (String s : starredExpressions) {
                    writer.object();
                    writer.key("code");
                    writer.value(s);
                    writer.endObject();
                }
                writer.endArray();
                writer.endObject();
            } catch (Exception e) {
                respondException(response, e);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.json.JSONWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.