Class JSONReply

  • All Implemented Interfaces:
    IReplyContent

    public class JSONReply
    extends java.lang.Object
    implements IReplyContent
    Class for a JSON reply.
    Author:
    Christopher Mindus
    • Constructor Summary

      Constructors 
      ConstructorDescription
      JSONReply()
      Constructor.
      JSONReply​(JSONObject object)
      Constructor when recreating the JSON document.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      booleancanFormat()
      Checks if formatting the output is supported.
      java.lang.StringformatHTTPReply()
      Formats the URLConnection HTTP headers reply into a String.
      java.lang.StringgetAcceptedContent()
      Gets the accepted contents.
      java.lang.StringgetDescription()
      Gets the format description.
      java.lang.ObjectgetElementFromPath​(java.lang.String path)
      Gets an Object with specified path.
      JSONObjectgetJSONData()
      Gets the JSON data.
      java.lang.StringgetRawOutput​(boolean doFormat)
      Gets the raw text data from the reply.
      booleanisHandled​(java.lang.String type)
      Checks if a content type is handled by this reply.
      voidreadReply​(RESTfulReply reply, java.lang.String data)
      Called to format the request for this reply content, i.e.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JSONReply

        public JSONReply()
        Constructor.
      • JSONReply

        public JSONReply​(JSONObject object)
        Constructor when recreating the JSON document.
        Parameters:
        object - The JSON document object.
    • Method Detail

      • getAcceptedContent

        public java.lang.String getAcceptedContent()
        Gets the accepted contents.
        Specified by:
        getAcceptedContent in interface IReplyContent
        Returns:
        The String "application/json".
      • isHandled

        public boolean isHandled​(java.lang.String type)
        Checks if a content type is handled by this reply.
        Specified by:
        isHandled in interface IReplyContent
        Parameters:
        type - The content type from the HTTP header "Content-Type", without "charset". The type is in lower case.
        Returns:
        true if handled, false otherwise.
      • readReply

        public void readReply​(RESTfulReply reply,
                              java.lang.String data)
                       throws java.io.IOException
        Called to format the request for this reply content, i.e. the accepted content.
        Specified by:
        readReply in interface IReplyContent
        Parameters:
        reply - The reply instance.
        data - The String data from the reply.
        Throws:
        java.io.IOException - For I/O errors.
      • getJSONData

        public JSONObject getJSONData()
        Gets the JSON data.
        Returns:
        The JSON object.
      • canFormat

        public boolean canFormat()
        Checks if formatting the output is supported.
        Specified by:
        canFormat in interface IReplyContent
        Returns:
        true If formatting is supported.
      • getDescription

        public java.lang.String getDescription()
        Gets the format description.
        Specified by:
        getDescription in interface IReplyContent
        Returns:
        The description string.
      • formatHTTPReply

        public java.lang.String formatHTTPReply()
        Formats the URLConnection HTTP headers reply into a String.
        Specified by:
        formatHTTPReply in interface IReplyContent
        Returns:
        The formatted HTML reply string.
      • getRawOutput

        public java.lang.String getRawOutput​(boolean doFormat)
        Gets the raw text data from the reply.
        Specified by:
        getRawOutput in interface IReplyContent
        Parameters:
        doFormat - Flag to format the output (used for JSON and XML).
        Returns:
        The String of the reply, or null if an exception occurred.
      • getElementFromPath

        public java.lang.Object getElementFromPath​(java.lang.String path)
        Gets an Object with specified path. This Object could be one of:
        • Boolean
        • Double
        • String
        • JSONObject
        • JSONArray
        • JSONObject.NULL
        Parameters:
        path - The path to look-up.
        Returns:
        The element found, or null if not found.