Package org.json

Examples of org.json.JSONWriter


       
        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("functions");
            writer.object();
            {
                for (Entry<String, Function> entry : ControlFunctionRegistry.getFunctionMapping()) {
                    writer.key(entry.getKey());
                    entry.getValue().write(writer, options);
                }
            }
            writer.endObject();
           
            writer.key("controls");
            writer.object();
            {
                for (Entry<String, Control> entry : ControlFunctionRegistry.getControlMapping()) {
                    writer.key(entry.getKey());
                    entry.getValue().write(writer, options);
                }
            }
            writer.endObject();
           
            writer.endObject();
        } catch (Exception e) {
            respondException(response, e);
        }
    }
View Full Code Here


            if (historyEntry != null) {
                /*
                 * If the process is done, write back the cell's data so that the
                 * client side can update its UI right away.
                 */
                JSONWriter writer = new JSONWriter(response.getWriter());

                Pool pool = new Pool();
                Properties options = new Properties();
                options.put("pool", pool);

                writer.object();
                writer.key("code"); writer.value("ok");
                writer.key("historyEntry"); historyEntry.write(writer, options);
                writer.key("cell"); process.newCell.write(writer, options);
                writer.key("pool"); pool.write(writer, options);
                writer.endObject();
            } else {
                respond(response, "{ \"code\" : \"pending\" }");
            }
        } catch (Exception e) {
            respondException(response, e);
View Full Code Here

            Map<String, DataExtension> map = job.extend(ids, reconCandidateMap);
           
            response.setCharacterEncoding("UTF-8");
            response.setHeader("Content-Type", "application/json");
           
            JSONWriter writer = new JSONWriter(response.getWriter());
            writer.object();
            writer.key("code"); writer.value("ok");
            writer.key("columns");
                writer.array();
                for (ColumnInfo info : job.columns) {
                    writer.object();
                    writer.key("names");
                        writer.array();
                        for (String name : info.names) {
                            writer.value(name);
                        }
                        writer.endArray();
                    writer.key("path");
                        writer.array();
                        for (String id : info.path) {
                            writer.value(id);
                        }
                        writer.endArray();
                    writer.endObject();
                }
                writer.endArray();
           
            writer.key("rows");
                writer.array();
                for (int r = 0; r < topicNames.size(); r++) {
                    String id = topicIds.get(r);
                    String topicName = topicNames.get(r);
                   
                    if (id != null && map.containsKey(id)) {
                        DataExtension ext = map.get(id);
                        boolean first = true;
                       
                        if (ext.data.length > 0) {
                            for (Object[] row : ext.data) {
                                writer.array();
                                if (first) {
                                    writer.value(topicName);
                                    first = false;
                                } else {
                                    writer.value(null);
                                }
                               
                                for (Object cell : row) {
                                    if (cell != null && cell instanceof ReconCandidate) {
                                        ReconCandidate rc = (ReconCandidate) cell;
                                        writer.object();
                                        writer.key("id"); writer.value(rc.id);
                                        writer.key("name"); writer.value(rc.name);
                                        writer.endObject();
                                    } else {
                                        writer.value(cell);
                                    }
                                }
                               
                                writer.endArray();
                            }
                            continue;
                        }
                    }
                   
                    writer.array();
                    if (id != null) {
                        writer.object();
                        writer.key("id"); writer.value(id);
                        writer.key("name"); writer.value(topicName);
                        writer.endObject();
                    } else {
                        writer.value("<not reconciled>");
                    }
                    writer.endArray();
                }
                writer.endArray();
               
            writer.endObject();
        } catch (Exception e) {
            respondException(response, e);
        }
    }
View Full Code Here

        long jobID = Long.parseLong(request.getParameter("jobID"));
        ImportingJob job = ImportingManager.getJob(jobID);
       
        Writer w = response.getWriter();
        JSONWriter writer = new JSONWriter(w);
        try {
            writer.object();
            if (job == null) {
                writer.key("code"); writer.value("error");
                writer.key("message"); writer.value("No such import job");
            } else {
                writer.key("code"); writer.value("ok");
                writer.key("job"); job.write(writer, new Properties());
            }
            writer.endObject();
        } catch (JSONException e) {
            throw new ServletException(e);
        } finally {
            w.flush();
            w.close();
View Full Code Here

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        Writer w = response.getWriter();
        JSONWriter writer = new JSONWriter(w);
        try {
            writer.object();
            writer.key("config"); ImportingManager.writeConfiguration(writer, new Properties());
            writer.endObject();
        } catch (JSONException e) {
            throw new ServletException(e);
        } finally {
            w.flush();
            w.close();
View Full Code Here

            return change;
        }
       
        static protected void writeProtograph(Protograph p, Writer writer) throws IOException {
            if (p != null) {
                JSONWriter jsonWriter = new JSONWriter(writer);
                try {
                    p.write(jsonWriter, new Properties());
                } catch (JSONException e) {
                    e.printStackTrace();
                }
View Full Code Here

            writer.write(name); writer.write('\n');
        }
        writer.write("columnTypeCount="); writer.write(Integer.toString(_columnTypes.size())); writer.write('\n');
        for (FreebaseType type : _columnTypes) {
            try {
                JSONWriter jsonWriter = new JSONWriter(writer);
               
                type.write(jsonWriter, options);
            } catch (JSONException e) {
                // ???
            }
            writer.write('\n');
        }
        writer.write("rowIndexCount="); writer.write(Integer.toString(_rowIndices.size())); writer.write('\n');
        for (Integer rowIndex : _rowIndices) {
            writer.write(rowIndex.toString()); writer.write('\n');
        }
        writer.write("dataExtensionCount="); writer.write(Integer.toString(_dataExtensions.size())); writer.write('\n');
        for (DataExtension dataExtension : _dataExtensions) {
            if (dataExtension == null) {
                writer.write('\n');
                continue;
            }
           
            writer.write(Integer.toString(dataExtension.data.length)); writer.write('\n');
           
            for (Object[] values : dataExtension.data) {
                for (Object value : values) {
                    if (value == null) {
                        writer.write("null");
                    } else if (value instanceof ReconCandidate) {
                        try {
                            JSONWriter jsonWriter = new JSONWriter(writer);
                            ((ReconCandidate) value).write(jsonWriter, options);
                        } catch (JSONException e) {
                            // ???
                        }
                    } else if (value instanceof String) {
View Full Code Here

       
        try {
            String query = null;
            {
                StringWriter stringWriter = new StringWriter();
                JSONWriter jsonWriter = new JSONWriter(stringWriter);
               
                jsonWriter.object();
                jsonWriter.key("query");
                jsonWriter.array();
                jsonWriter.object();

                jsonWriter.key("id"); jsonWriter.value(null);
                jsonWriter.key("name"); jsonWriter.value(null);
                jsonWriter.key("guid"); jsonWriter.value(null);
                jsonWriter.key("type"); jsonWriter.array(); jsonWriter.endArray();

                jsonWriter.key("guid|=");
                jsonWriter.array();
                for (ReconJob job : jobs) {
                    jsonWriter.value(((GuidBasedReconJob) job).guid);
                }
                jsonWriter.endArray();

                jsonWriter.endObject();
                jsonWriter.endArray();
                jsonWriter.endObject();

                query = stringWriter.toString();
            }
           
            StringBuffer sb = new StringBuffer(1024);
View Full Code Here

    }

    protected void saveToFile(File file) throws IOException, JSONException {
        FileWriter writer = new FileWriter(file);
        try {
            JSONWriter jsonWriter = new JSONWriter(writer);
            jsonWriter.object();
            jsonWriter.key("projectIDs");
            jsonWriter.array();
            for (Long id : _projectsMetadata.keySet()) {
                ProjectMetadata metadata = _projectsMetadata.get(id);
                if (metadata != null) {
                    jsonWriter.value(id);

                    try {
                        ProjectMetadataUtilities.save(metadata, getProjectDir(id));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            jsonWriter.endArray();
            writer.write('\n');

            jsonWriter.key("preferences");
            _preferenceStore.write(jsonWriter, new Properties());

            jsonWriter.endObject();
        } finally {
            writer.close();
        }
    }
View Full Code Here

            writer.write("overlayModel:");
            writer.write(modelName);
            writer.write("=");
           
            try {
                JSONWriter jsonWriter = new JSONWriter(writer);
               
                overlayModels.get(modelName).write(jsonWriter, options);
            } catch (JSONException e) {
                e.printStackTrace();
            }
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.