Ignore:
Timestamp:
2012-11-23T00:34:55+13:00 (11 years ago)
Author:
davidb
Message:

Support for o=json as output type in Greenstone 3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java

    r26210 r26507  
    4141import org.w3c.dom.NodeList;
    4242
     43import org.json.JSONObject;
     44import org.json.XML;
     45
    4346import com.google.gson.Gson;
    4447import com.google.gson.reflect.TypeToken;
     
    688691        }
    689692
    690         if (!output.equals("html") && !output.equals("server") && !output.equals("xsltclient"))
     693        if (output.equals("json")) {
     694            response.setContentType("application/json");
     695        }
     696        else if (!output.equals("html") && !output.equals("server") && !output.equals("xsltclient"))
    691697        {
    692698            response.setContentType("text/xml"); // for now use text
     
    747753        Node xml_result = this.recept.process(xml_message);
    748754        encodeURLs(xml_result, response);
    749         out.println(this.converter.getPrettyString(xml_result));
     755
     756        String xml_string = this.converter.getPrettyString(xml_result);
     757
     758        if (output.equals("json")) {
     759            try {
     760            JSONObject json_obj = org.json.XML.toJSONObject(xml_string);
     761           
     762            out.println(json_obj.toString());
     763            }
     764            catch (Exception e) {
     765            e.printStackTrace();
     766            out.println("Error: failed to convert output XML to JSON format");
     767            }
     768        }
     769        else {
     770            out.println(xml_string);
     771        }
    750772
    751773        displaySize(session_ids_table);
Note: See TracChangeset for help on using the changeset viewer.