Examples of JsonWriter


Examples of org.apache.sling.commons.json.io.JSONWriter

    private StringWriter output;
   
    @Before
    public void setup() {
        output = new StringWriter();
        w = new JSONWriter(output);
    }
View Full Code Here

Examples of org.apache.sling.commons.json.io.JSONWriter

            } else {
                // We are not allowed to do the dump.
                // Send a 300
                String tidyUrl = (tidy) ? "tidy." : "";
                resp.setStatus(HttpServletResponse.SC_MULTIPLE_CHOICES);
                JSONWriter writer = new JSONWriter(resp.getWriter());
                writer.array();
                while (allowedLevel >= 0) {
                    writer.value(r.getResourceMetadata().getResolutionPath() + "." + tidyUrl + allowedLevel + ".json");
                    allowedLevel--;
                }
                writer.endArray();
            }
        } catch (JSONException je) {
            reportException(je);
        }
    }
View Full Code Here

Examples of org.apache.sling.commons.json.io.JSONWriter

            }

            resp.setContentType(req.getResponseContentType());
            resp.setCharacterEncoding("UTF-8");

            final JSONWriter w = new JSONWriter(resp.getWriter());
            w.setTidy(isTidy(req));

            w.array();

            long count = -1;
            if (req.getParameter(ROWS) != null) {
                count = Long.parseLong(req.getParameter(ROWS));
            }

            List<String> properties = new ArrayList<String>();
            if (req.getParameterValues(PROPERTY) != null) {
                for (String property : req.getParameterValues(PROPERTY)) {
                    properties.add(property);
                }
            }

            String exerptPath = "";
            if (req.getParameter(EXCERPT_PATH) != null) {
                exerptPath = req.getParameter(EXCERPT_PATH);
            }

            // iterate through the result set and build the "json result"
            while (result.hasNext() && count != 0) {
                Map<String, Object> row = result.next();


                w.object();
                String path = row.get("jcr:path").toString();

                w.key("name");
                w.value(ResourceUtil.getName(path));

                // dump columns
                for (String colName : row.keySet()) {
                    w.key(colName);
                    String strValue = "";
                    if (colName.equals(REP_EXCERPT)) {
                        Object ev = row.get("rep:excerpt(" + exerptPath + ")");
                        strValue = (ev == null) ? "" : ev.toString();
                        w.value(strValue);

                    } else {
                        //strValue = formatValue(row.get(colName));
                      itemWriter.dumpValue(w, row.get(colName));
                    }
                    //w.value(strValue);
                }

                // load properties and add it to the result set
                if (!properties.isEmpty()) {
                    Resource nodeRes = resolver.getResource(path);
                    dumpProperties(w, nodeRes, properties);
                }

                w.endObject();


                count--;
            }
            w.endArray();
        } catch (JSONException je) {
            throw wrapException(je);
        }
    }
View Full Code Here

Examples of org.apache.sling.commons.json.io.JSONWriter

        // render data in JSON format
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");

        final Writer out = response.getWriter();
        final JSONWriter w = new JSONWriter(out);

        try {
            w.object();
            for (Map.Entry<String, String> e : data.entrySet()) {
                w.key(e.getKey());
                w.value(e.getValue());
            }
            w.endObject();

        } catch (JSONException jse) {
            out.write(jse.toString());

        } finally {
View Full Code Here

Examples of org.apache.sling.commons.json.io.JSONWriter

    }

    public void render(Writer out) {

        try {
            JSONWriter writer = new JSONWriter(out);
            writer.object();
            writer.key("status").value(status ? "OK" : "FAILURE");
            if (!StringUtils.isEmpty(message)) {
                writer.key("message").value(message);
            }
            writer.endObject();
        } catch (JSONException e) {
            // never happens
            throw new RuntimeException(e);
        }
    }
View Full Code Here

Examples of org.apache.sling.commons.json.io.JSONWriter

        }
    }

    private static class JsonRenderer implements Renderer {
        public void render(PrintWriter pw, String streamPath, String streamResource) throws IOException {
            JSONWriter w = new JSONWriter(pw);
            try {
                w.object();
                w.key("info");
                w.value("Background job information");
                w.key("jobStreamPath");
                w.value(streamPath);
                w.endObject();
            } catch (JSONException e) {
                throw (IOException)new IOException("JSONException in " + getClass().getSimpleName()).initCause(e);
            }
        }
View Full Code Here

Examples of org.apache.sling.commons.json.io.JSONWriter

        }
    }

    private String getScriptConfig0() throws JSONException {
        StringWriter sw = new StringWriter();
        JSONWriter jw = new JSONWriter(sw);
        jw.setTidy(true);
        jw.array();

        for(ScriptEngineFactory sef : scriptEngineManager.getEngineFactories()){
            jw.object();
            if(sef.getExtensions().isEmpty()){
                continue;
            }
            jw.key("langName").value(sef.getLanguageName());
            jw.key("langCode").value(sef.getExtensions().get(0));

            //Language mode as per CodeMirror names
            String mode = determineMode(sef.getExtensions());
            if(mode != null){
                jw.key("mode").value(mode);
            }

            jw.endObject();
        }

        jw.endArray();
        return sw.toString();
    }
View Full Code Here

Examples of org.apache.sling.commons.json.io.JSONWriter

            final SortedSet<String> layers = new TreeSet<String>();
           
            // Visit our child resources and build the statsData object
            // from those that have the stats data resource type
            {
                final JSONWriter w = new JSONWriter(response.getWriter());
                w.setTidy(true);
                out.write("var statsData = ");
                w.array();
                dumpStatsData(request.getResource(), w, layers);
                w.endArray();
                out.flush();
                out.write(";\n");
            }
           
            // Output the layers array in JSON
            {
                final JSONWriter w = new JSONWriter(response.getWriter());
                w.setTidy(true);
                out.write("var layers = ");
                w.array();
                for(String layer : layers) {
                    w.value(layer);
                };
                w.endArray();
                out.write(";");
            }
           
        } catch(JSONException je) {
            throw new ServletException("JSONException in doGet", je);
View Full Code Here

Examples of org.apache.sling.commons.json.io.JSONWriter

        j.requestStateChange(desiredState);
        final JobStatus.State newState = j.getState();
       
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        final JSONWriter w = new JSONWriter(response.getWriter());
        try {
            w.object();
            w.key("info").value("Requested state change");
            w.key(PARAM_STATE).value(desiredState.toString());
            w.key("path").value(j.getPath());
            w.key("currentState").value(newState);
            w.key("stateChanged").value(newState != oldState);
            w.endObject();
        } catch(JSONException je) {
            throw new ServletException("JSONException in doPost", je);
        }
    }
View Full Code Here

Examples of org.apache.sling.commons.json.io.JSONWriter

        // Dump config in JSON
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        final Enumeration<?> keys = props.keys();
        try {
            final JSONWriter w = new JSONWriter(response.getWriter());
            w.setTidy(Arrays.asList(request.getRequestPathInfo().getSelectors()).contains("tidy"));
            w.object();
            w.key("source").value(getClass().getName());
            w.key("pid").value(pid);
            w.key("properties");
            w.object();
            while(keys.hasMoreElements()) {
                final Object key = keys.nextElement();
                final Object value = props.get(key);
                if(value != null) {
                    w.key(key.toString()).value(value.toString());
                }
            }
            w.endObject();
            w.endObject();
        } catch(JSONException je) {
            throw (IOException)new IOException("JSONException in doGet").initCause(je);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.