Example usage for org.json.simple JSONObject writeJSONString

List of usage examples for org.json.simple JSONObject writeJSONString

Introduction

In this page you can find the example usage for org.json.simple JSONObject writeJSONString.

Prototype

public static void writeJSONString(Map<String, Object> map, Writer out) throws IOException 

Source Link

Usage

From source file:org.geoserver.sfs.CapabilitiesJSONFormat.java

@Override
protected void write(Object object, OutputStream out) throws IOException {
    Catalog catalog = (Catalog) object;//ww w . j  a  v  a  2  s .  c  o m
    Writer writer = null;
    try {
        writer = new OutputStreamWriter(out);
        writer.write("[");

        // write out the layers
        List<LayerInfo> layers = getFeatureTypeLayers(catalog);
        for (Iterator it = layers.iterator(); it.hasNext();) {
            LayerInfo layerInfo = (LayerInfo) it.next();
            Map json = toJSON(layerInfo);
            JSONObject.writeJSONString(json, writer);
            if (it.hasNext()) {
                writer.write(",\n");
            }
        }

        writer.write("]");
    } finally {
        IOUtils.closeQuietly(writer);
    }
}

From source file:org.geoserver.sfs.DescribeJSONFormat.java

@Override
protected void write(Object object, OutputStream out) throws IOException {
    FeatureTypeInfo fti = (FeatureTypeInfo) object;
    SimpleFeatureType schema = (SimpleFeatureType) fti.getFeatureType();
    Writer writer = null;/*from w  w  w  .jav  a2s . com*/
    try {
        writer = new OutputStreamWriter(out);
        writer.write("[");

        Map<String, String> attributes = new LinkedHashMap<String, String>();
        for (AttributeDescriptor att : schema.getAttributeDescriptors()) {
            attributes.put(att.getLocalName(), findAttributeType(att));
        }
        JSONObject.writeJSONString(attributes, writer);

        writer.write("]");
    } finally {
        IOUtils.closeQuietly(writer);
    }
}

From source file:org.opencastproject.lti.LtiServlet.java

/**
 * {@inheritDoc}/*from   www  . ja v a  2  s . c  om*/
 * 
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 */
@SuppressWarnings("unchecked")
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    HttpSession session = req.getSession(false);
    if (session == null) {
        resp.sendError(HttpServletResponse.SC_NOT_FOUND); // If there is no session, there is nothing to see here
    } else {
        Map<String, String> ltiAttributes = (Map<String, String>) session.getAttribute(SESSION_ATTRIBUTE_KEY);
        if (ltiAttributes == null) {
            ltiAttributes = new HashMap<String, String>();
        }
        resp.setContentType("application/json");
        JSONObject.writeJSONString(ltiAttributes, resp.getWriter());
    }
}