+ /*!
+ Determines based on the Request what format the response should be in.
+ */
+ protected function _GetResponseType(Request $request, Response $response)
+ {
+ // Check if an Action specified an overriding response type.
+ if (isset($response->context[self::RESPONSE_TYPE]))
+ return $response->context[self::RESPONSE_TYPE];
+
+ // See if the HTTP request contains the desired output format.
+ if (isset($request->data['format'])) {
+ if ($request->data['format'] == 'xml')
+ return 'xml';
+ else if ($request->data['format'] == 'json')
+ return 'json';
+ }
+
+ // If the request didn't specify a type, try and figure it out using
+ // heuristics.
+
+ // If this was from an XHR, assume JSON.
+ if (isset($request->data['_SERVER']['HTTP_X_REQUESTED_WITH']))
+ return 'json';
+
+ // If no type has been determined, just assume HTML.
+ return 'html';
+ }
+