Ejemplo n.º 1
0
  /**
   * get RemoteView according to request. HTTP Header from JQuery XHR: Accept: application/json,
   * text/javascript, * / * Accept: application/xml, text/xml, * / * However, IE6 will send Accept:
   * * / * and accept: application/json, text/javascript, * / * at same time
   *
   * @param req
   * @return
   */
  private String getViewType(VRaptorServletRequest req) {
    Enumeration<?> accepts = req.getHeaders(ACCEPTREQUESTEADER); // IE6 will send two Accept header

    StringBuilder acceptBuilder = new StringBuilder();
    for (; accepts.hasMoreElements(); ) {
      acceptBuilder.append(accepts.nextElement());
      acceptBuilder.append(", ");
    }

    String accept = acceptBuilder.toString();

    if (StringUtils.isEmpty(accept)) return null;
    if (accept.indexOf("application/json") > -1) {
      return SUPPORTEDJSON;
    } else if (accept.indexOf("application/xml") > -1) {
      return SUPPORTEDXML;
    }
    return null;
  }
Ejemplo n.º 2
0
 /**
  * is it XMLHttpRequest? when JQuery send a ajax request to remote, it will send the header.
  * xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  *
  * @param req
  * @return
  */
 private boolean isXhr(VRaptorServletRequest req) {
   return XHRHEADERVALUE.equals(req.getHeader(XREQUESTEADER));
 }