예제 #1
0
 @Override
 public Map<String, String> getResponseHeaders() {
   Map<String, String> responseHeaders = new HashMap<String, String>(3);
   long lastModified = info.getLastModified();
   responseHeaders.put("Last-Modified", Utils.formatRFC1123(new Date(lastModified)));
   responseHeaders.put(
       "Expires", Utils.formatRFC1123(new Date(System.currentTimeMillis() + info.getMaxAge())));
   responseHeaders.put(
       "Etag", String.format("W/\"%d-%d\"", info.getContentLength(), lastModified));
   responseHeaders.put(
       "Pragma", ""); // Explicitly set empty pragma to prevent some containers from setting it.
   return responseHeaders;
 }
예제 #2
0
  /**
   * Converts a <code>Iterable&lt;E&gt;</code> to a <code>List&lt;E&gt;</code>. Useful when you want
   * to iterate over an <code>Iterable</code>, which includes any type of <code>Collection</code>
   * (which includes e.g. a <code>Set</code>) in for example <code>&lt;ui:repeat&gt;</code> and
   * <code>&lt;h:dataTable&gt;</code>.
   *
   * <p>When iterating specifically over a Set using the above mentioned components {@link
   * Converters#setToList(Set)} is an alternative to this.
   *
   * @param <E> The generic iterable element type.
   * @param iterable The Iterable to be converted to a List.
   * @return The converted List.
   * @since 1.5
   */
  public static <E> List<E> iterableToList(Iterable<E> iterable) {
    if (iterable == null) {
      return null;
    }

    return Utils.iterableToList(iterable);
  }
예제 #3
0
  @Override
  public boolean userAgentNeedsUpdate(FacesContext context) {
    String ifModifiedSince =
        context.getExternalContext().getRequestHeaderMap().get("If-Modified-Since");

    if (ifModifiedSince != null) {
      try {
        return info.getLastModified() > Utils.parseRFC1123(ifModifiedSince).getTime();
      } catch (ParseException ignore) {
        return true;
      }
    }

    return true;
  }
  /**
   * Encode the conditional comment.
   *
   * @throws IllegalArgumentException When <code>if</code> attribute is not specified.
   */
  @Override
  public void encodeChildren(final FacesContext context) throws IOException {
    final String _if = getIf();

    if (Utils.isEmpty(_if)) {
      throw new IllegalArgumentException(ConditionalComment.ERROR_MISSING_IF);
    }

    final ResponseWriter writer = context.getResponseWriter();
    writer.write("<!--[if ");
    writer.writeText(_if, this, "if");
    writer.write("]>");
    super.encodeChildren(context);
    writer.write("<![endif]-->");
  }