コード例 #1
0
 public void testAccept3() throws Exception {
   String clientContentType =
       getFacesContext().getExternalContext().getRequestHeaderMap().get("Accept");
   String serverSupportedContentTypes = "text/html, text/html;level=1";
   String contentType =
       RenderKitUtils.determineContentType(clientContentType, serverSupportedContentTypes, null);
   assertEquals(contentType, "text/html;level=1");
 }
コード例 #2
0
ファイル: SecretRenderer.java プロジェクト: baraujo75/mojarra
  @Override
  protected void getEndTextToRender(
      FacesContext context, UIComponent component, String currentValue) throws IOException {

    ResponseWriter writer = context.getResponseWriter();
    assert (writer != null);

    String redisplay = String.valueOf(component.getAttributes().get("redisplay"));
    if (redisplay == null || !redisplay.equals("true")) {
      currentValue = "";
    }

    writer.startElement("input", component);
    writeIdAttributeIfNecessary(context, writer, component);
    writer.writeAttribute("type", "password", "type");
    writer.writeAttribute("name", component.getClientId(context), "clientId");

    String autoComplete = (String) component.getAttributes().get("autocomplete");
    if (autoComplete != null) {
      // only output the autocomplete attribute if the value
      // is 'off' since its lack of presence will be interpreted
      // as 'on' by the browser
      if ("off".equals(autoComplete)) {
        writer.writeAttribute("autocomplete", "off", "autocomplete");
      }
    }

    // render default text specified
    if (currentValue != null) {
      writer.writeAttribute("value", currentValue, "value");
    }

    RenderKitUtils.renderPassThruAttributes(
        context, writer, component, ATTRIBUTES, getNonOnChangeBehaviors(component));
    RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer, component);

    RenderKitUtils.renderOnchange(context, component, false);

    String styleClass;
    if (null != (styleClass = (String) component.getAttributes().get("styleClass"))) {
      writer.writeAttribute("class", styleClass, "styleClass");
    }

    writer.endElement("input");
  }
コード例 #3
0
 public void testAccept6() throws Exception {
   String clientContentType =
       getFacesContext().getExternalContext().getRequestHeaderMap().get("Accept");
   String serverSupportedContentTypes = "text/html, application/xhtml+xml";
   String contentType =
       RenderKitUtils.determineContentType(
           clientContentType, serverSupportedContentTypes, "application/xhtml+xml");
   assertEquals(contentType, "text/html");
 }
コード例 #4
0
 @Override
 public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
   ResponseWriter writer = context.getResponseWriter();
   UIViewRoot viewRoot = context.getViewRoot();
   ListIterator iter = (viewRoot.getComponentResources(context, "body")).listIterator();
   while (iter.hasNext()) {
     UIComponent resource = (UIComponent) iter.next();
     resource.encodeAll(context);
   }
   RenderKitUtils.renderUnhandledMessages(context);
   writer.endElement("body");
 }
コード例 #5
0
  /**
   * Renders the start of a table and applies the value of <code>styleClass</code> if available and
   * renders any pass through attributes that may be specified.
   *
   * @param context the <code>FacesContext</code> for the current request
   * @param table the table that's being rendered
   * @param writer the current writer
   * @param passThroughAttributes pass-through attributes that the component supports
   * @throws IOException if content cannot be written
   */
  protected void renderTableStart(
      FacesContext context,
      UIComponent table,
      ResponseWriter writer,
      String[] passThroughAttributes)
      throws IOException {

    writer.startElement("table", table);
    writeIdAttributeIfNecessary(context, writer, table);
    String styleClass = (String) table.getAttributes().get("styleClass");
    if (styleClass != null) {
      writer.writeAttribute("class", styleClass, "styleClass");
    }
    RenderKitUtils.renderPassThruAttributes(writer, table, passThroughAttributes);
    writer.writeText("\n", table, null);
  }
コード例 #6
0
  private void throwIt(FacesContext ctx, FacesException fe) {

    boolean isDevelopment = ctx.isProjectStage(ProjectStage.Development);
    if (isDevelopment && !errorPagePresent) {
      // RELEASE_PENDING_2_1
      // thThe error page here will be text/html which means not all device
      // types are going to render this properly.  This should be addressed
      // in 2.1
      RenderKitUtils.renderHtmlErrorPage(ctx, fe);
    } else {
      if (isDevelopment) {
        // store the view root where the exception occurred into the
        // request scope so that the error page can display that component
        // tree and not the one rendering the errorpage
        ctx.getExternalContext().getRequestMap().put("com.sun.faces.error.view", ctx.getViewRoot());
      }
      throw fe;
    }
  }
コード例 #7
0
  /** @see javax.faces.context.FacesContext#isPostback() */
  @Override
  public boolean isPostback() {

    assertNotReleased();
    Boolean postback = (Boolean) this.getAttributes().get(POST_BACK_MARKER);
    if (postback == null) {
      RenderKit rk = this.getRenderKit();
      if (rk != null) {
        postback = rk.getResponseStateManager().isPostback(this);
      } else {
        // ViewRoot hasn't been set yet, so calculate the RK
        ViewHandler vh = this.getApplication().getViewHandler();
        String rkId = vh.calculateRenderKitId(this);
        postback = RenderKitUtils.getResponseStateManager(this, rkId).isPostback(this);
      }
      this.getAttributes().put(POST_BACK_MARKER, postback);
    }

    return postback;
  }
コード例 #8
0
 public void testReallyLargeAcceptHeader() throws Exception {
   String clientAcceptHeader =
       "application/octet-stream, application/smil, application/vnd.oma.drm.content,"
           + "application/vnd.oma.drm.message, application/vnd.oma.drm.rights+wbxml,"
           + "application/vnd.oma.drm.rights+xml, application/vnd.wap.connectivity-wbxml,"
           + "application/vnd.wap.multipart.mixed, application/vnd.wap.multipart.related,"
           + "application/vnd.wap.wmlscriptc, application/vnd.wap.xhtml+xml,"
           + "application/xhtml+xml;profile=\"http://www.wapforum.org/xhtml\", image/bmp, image/gif,"
           + "image/jpeg, image/png, image/vnd.wap.wbmp, multipart/mixed, multipart/related, text/html,"
           + "text/plain, text/vnd.wap.connectivity-xml, text/vnd.wap.wml;type=4365, application/java,"
           + "application/java-archive, image/wbmp, text/vcalendar, text/vcard, video/3gpp, video/mpeg,"
           + "audio/amr, audio/xmf, audio/x-midi, audio/x-mid, audio/x-wav, audio/imelody, text/x-imelody,"
           + "audio/mp3, audio/mpeg, audio/mpeg3, audio/mpg3, audio/aac, audio/amr-wb, audio/mp4,"
           + "pv-pvx, application/sdp, image/svg+xml, text/vnd.sun.j2me.app-descriptor, \n"
           + "video/x-application/vnd.oma.dd+xml,text/vnd.wap.wmlscript,text/vnd.wap.wml";
   String serverSupportedContentTypes = "text/html, application/xhtml+xml";
   String contentType =
       RenderKitUtils.determineContentType(
           clientAcceptHeader, serverSupportedContentTypes, "text/html");
   assertEquals(contentType, "text/html");
 }
コード例 #9
0
  @Override
  protected void getEndTextToRender(
      FacesContext context, UIComponent component, String currentValue) throws IOException {

    ResponseWriter writer = context.getResponseWriter();
    assert (writer != null);
    boolean shouldWriteIdAttribute = false;
    boolean isOutput = false;

    String style = (String) component.getAttributes().get("style");
    String styleClass = (String) component.getAttributes().get("styleClass");
    String dir = (String) component.getAttributes().get("dir");
    String lang = (String) component.getAttributes().get("lang");
    String title = (String) component.getAttributes().get("title");
    Map<String, Object> passthroughAttributes = component.getPassThroughAttributes(false);
    boolean hasPassthroughAttributes =
        null != passthroughAttributes && !passthroughAttributes.isEmpty();
    if (component instanceof UIInput) {
      writer.startElement("input", component);
      writeIdAttributeIfNecessary(context, writer, component);

      if (component instanceof HtmlInputFile) {
        writer.writeAttribute("type", "file", null);
      } else {
        writer.writeAttribute("type", "text", null);
      }
      writer.writeAttribute("name", (component.getClientId(context)), "clientId");

      // only output the autocomplete attribute if the value
      // is 'off' since its lack of presence will be interpreted
      // as 'on' by the browser
      if ("off".equals(component.getAttributes().get("autocomplete"))) {
        writer.writeAttribute("autocomplete", "off", "autocomplete");
      }

      // render default text specified
      if (currentValue != null) {
        writer.writeAttribute("value", currentValue, "value");
      }
      if (null != styleClass) {
        writer.writeAttribute("class", styleClass, "styleClass");
      }

      // style is rendered as a passthur attribute
      RenderKitUtils.renderPassThruAttributes(
          context, writer, component, INPUT_ATTRIBUTES, getNonOnChangeBehaviors(component));
      RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer, component);

      RenderKitUtils.renderOnchange(context, component, false);

      writer.endElement("input");

    } else if (isOutput = (component instanceof UIOutput)) {
      if (styleClass != null
          || style != null
          || dir != null
          || lang != null
          || title != null
          || hasPassthroughAttributes
          || (shouldWriteIdAttribute = shouldWriteIdAttribute(component))) {
        writer.startElement("span", component);
        writeIdAttributeIfNecessary(context, writer, component);
        if (null != styleClass) {
          writer.writeAttribute("class", styleClass, "styleClass");
        }
        // style is rendered as a passthru attribute
        RenderKitUtils.renderPassThruAttributes(context, writer, component, OUTPUT_ATTRIBUTES);
      }
      if (currentValue != null) {
        Object val = component.getAttributes().get("escape");
        if ((val != null) && Boolean.valueOf(val.toString())) {
          writer.writeText(currentValue, component, "value");
        } else {
          writer.write(currentValue);
        }
      }
    }
    if (isOutput
        && (styleClass != null
            || style != null
            || dir != null
            || lang != null
            || title != null
            || hasPassthroughAttributes
            || (shouldWriteIdAttribute))) {
      writer.endElement("span");
    }
  }
コード例 #10
0
  @Override
  public void encodeEnd(FacesContext context, UIComponent component) throws IOException {

    rendererParamsNotNull(context, component);

    if (!shouldEncode(component)) {
      return;
    }

    Object currentObj = ((ValueHolder) component).getValue();
    String currentValue;
    if (currentObj != null) {
      currentValue = currentObj.toString();
    } else {
      // if the value is null, do not output anything.
      return;
    }

    int childCount = component.getChildCount();
    List<Object> parameterList;

    if (childCount > 0) {
      parameterList = new ArrayList<Object>(childCount);
      // get UIParameter children...

      for (UIComponent kid : component.getChildren()) {
        // PENDING(rogerk) ignore if child is not UIParameter?
        if (!(kid instanceof UIParameter)) {
          continue;
        }

        parameterList.add(((UIParameter) kid).getValue());
      }
    } else {
      parameterList = Collections.emptyList();
    }

    // If at least one substitution parameter was specified,
    // use the string as a MessageFormat instance.
    String message;
    if (parameterList.size() > 0) {
      MessageFormat fmt = new MessageFormat(currentValue, context.getViewRoot().getLocale());
      StringBuffer buf = new StringBuffer(currentValue.length() * 2);
      fmt.format(parameterList.toArray(new Object[parameterList.size()]), buf, null);
      message = buf.toString();
    } else {
      message = currentValue;
    }

    ResponseWriter writer = context.getResponseWriter();
    assert (writer != null);

    String style = (String) component.getAttributes().get("style");
    String styleClass = (String) component.getAttributes().get("styleClass");
    String lang = (String) component.getAttributes().get("lang");
    String dir = (String) component.getAttributes().get("dir");
    String title = (String) component.getAttributes().get("title");
    boolean wroteSpan = false;
    if (styleClass != null
        || style != null
        || dir != null
        || lang != null
        || title != null
        || shouldWriteIdAttribute(component)) {
      writer.startElement("span", component);
      writeIdAttributeIfNecessary(context, writer, component);
      wroteSpan = true;

      if (style != null) {
        writer.writeAttribute("style", style, "style");
      }
      if (null != styleClass) {
        writer.writeAttribute("class", styleClass, "styleClass");
      }
      if (dir != null) {
        writer.writeAttribute("dir", dir, "dir");
      }
      if (lang != null) {
        writer.writeAttribute(RenderKitUtils.prefixAttribute("lang", writer), lang, "lang");
      }
      if (title != null) {
        writer.writeAttribute("title", title, "title");
      }
    }

    Object val = component.getAttributes().get("escape");
    boolean escape = (val != null) && Boolean.valueOf(val.toString());

    if (escape) {
      writer.writeText(message, component, "value");
    } else {
      writer.write(message);
    }
    if (wroteSpan) {
      writer.endElement("span");
    }
  }
コード例 #11
0
ファイル: BootstrapMessages.java プロジェクト: defensoria/sid
  @Override
  public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
    rendererParamsNotNull(context, component);

    if (!shouldEncode(component)) return;

    boolean mustRender = shouldWriteIdAttribute(component);

    UIMessages messages = (UIMessages) component;
    ResponseWriter writer = context.getResponseWriter();
    assert (writer != null);

    String clientId = ((UIMessages) component).getFor();
    if (clientId == null) if (messages.isGlobalOnly()) clientId = "";

    Iterator messageIter = getMessageIter(context, clientId, component);

    assert (messageIter != null);
    if (!messageIter.hasNext()) {
      if (mustRender) {
        if ("javax_faces_developmentstage_messages".equals(component.getId())) {
          return;
        }
        writer.startElement("div", component);
        writeIdAttributeIfNecessary(context, writer, component);
        writer.endElement("div");
      }
      return;
    }

    writeIdAttributeIfNecessary(context, writer, component);

    // style is rendered as a passthru attribute
    RenderKitUtils.renderPassThruAttributes(context, writer, component, ATTRIBUTES);

    Map<Severity, List<FacesMessage>> msgs = new HashMap<Severity, List<FacesMessage>>();
    msgs.put(FacesMessage.SEVERITY_INFO, new ArrayList<FacesMessage>()); // Bootstrap info
    msgs.put(FacesMessage.SEVERITY_WARN, new ArrayList<FacesMessage>()); // Bootstrap warning
    msgs.put(FacesMessage.SEVERITY_ERROR, new ArrayList<FacesMessage>()); // Bootstrap error
    msgs.put(FacesMessage.SEVERITY_FATAL, new ArrayList<FacesMessage>()); // Bootstrap error

    while (messageIter.hasNext()) {
      FacesMessage curMessage = (FacesMessage) messageIter.next();

      if (curMessage.isRendered() && !messages.isRedisplay()) {
        continue;
      }
      msgs.get(curMessage.getSeverity()).add(curMessage);
    }

    List<FacesMessage> severityMessages = msgs.get(FacesMessage.SEVERITY_FATAL);
    if (severityMessages.size() > 0) {
      encodeLoadingInfo(
          context, component, messages, FacesMessage.SEVERITY_FATAL, severityMessages);
    }

    severityMessages = msgs.get(FacesMessage.SEVERITY_ERROR);
    if (severityMessages.size() > 0) {
      encodeLoadingInfo(
          context, component, messages, FacesMessage.SEVERITY_ERROR, severityMessages);
    }

    severityMessages = msgs.get(FacesMessage.SEVERITY_WARN);
    if (severityMessages.size() > 0) {
      encodeLoadingInfo(context, component, messages, FacesMessage.SEVERITY_WARN, severityMessages);
    }

    severityMessages = msgs.get(FacesMessage.SEVERITY_INFO);
    if (severityMessages.size() > 0) {
      encodeLoadingInfo(context, component, messages, FacesMessage.SEVERITY_INFO, severityMessages);
    }
  }
コード例 #12
0
  private static String buildAjaxCommand(
      ClientBehaviorContext behaviorContext,
      AjaxBehavior ajaxBehavior,
      boolean namespaceParameters) {

    // First things first - if AjaxBehavior is disabled, we are done.
    if (ajaxBehavior.isDisabled()) {
      return null;
    }

    UIComponent component = behaviorContext.getComponent();
    String eventName = behaviorContext.getEventName();

    StringBuilder ajaxCommand = new StringBuilder(256);
    Collection<String> execute = ajaxBehavior.getExecute();
    Collection<String> render = ajaxBehavior.getRender();
    String onevent = ajaxBehavior.getOnevent();
    String onerror = ajaxBehavior.getOnerror();
    String sourceId = behaviorContext.getSourceId();
    String delay = ajaxBehavior.getDelay();
    Boolean resetValues = null;
    if (ajaxBehavior.isResetValuesSet()) {
      resetValues = ajaxBehavior.isResetValues();
    }
    Collection<ClientBehaviorContext.Parameter> params = behaviorContext.getParameters();

    // Needed workaround for SelectManyCheckbox - if execute doesn't have sourceId,
    // we need to add it - otherwise, we use the default, which is sourceId:child, which
    // won't work.
    ClientBehaviorContext.Parameter foundparam = null;
    for (ClientBehaviorContext.Parameter param : params) {
      if (param.getName().equals("incExec") && (Boolean) param.getValue()) {
        foundparam = param;
      }
    }
    if (foundparam != null && !execute.contains(sourceId)) {
      execute = new LinkedList<>(execute);
      execute.add(component.getClientId());
    }
    if (foundparam != null) {
      try {
        // And since this is a hack, we now try to remove the param
        params.remove(foundparam);
      } catch (UnsupportedOperationException uoe) {
        if (logger.isLoggable(Level.FINEST)) {
          logger.log(Level.FINEST, "Unsupported operation", uoe);
        }
      }
    }

    ajaxCommand.append("mojarra.ab(");

    if (sourceId == null) {
      ajaxCommand.append("this");
    } else {
      ajaxCommand.append("'");
      ajaxCommand.append(sourceId);
      ajaxCommand.append("'");
    }

    ajaxCommand.append(",event,'");
    ajaxCommand.append(eventName);
    ajaxCommand.append("',");

    appendIds(component, ajaxCommand, execute);
    ajaxCommand.append(",");
    appendIds(component, ajaxCommand, render);

    String namingContainerId = null;
    if (namespaceParameters) {
      FacesContext context = behaviorContext.getFacesContext();
      UIViewRoot viewRoot = context.getViewRoot();
      if (viewRoot instanceof NamingContainer) {
        namingContainerId = viewRoot.getContainerClientId(context);
      }
    }

    if ((namingContainerId != null)
        || (onevent != null)
        || (onerror != null)
        || (delay != null)
        || (resetValues != null)
        || !params.isEmpty()) {

      ajaxCommand.append(",{");

      if (namingContainerId != null) {
        // the literal string must exactly match the corresponding value
        // in jsf.js.
        RenderKitUtils.appendProperty(
            ajaxCommand, "com.sun.faces.namingContainerId", namingContainerId, true);
      }

      if (onevent != null) {
        RenderKitUtils.appendProperty(ajaxCommand, "onevent", onevent, false);
      }

      if (onerror != null) {
        RenderKitUtils.appendProperty(ajaxCommand, "onerror", onerror, false);
      }

      if (delay != null) {
        RenderKitUtils.appendProperty(ajaxCommand, "delay", delay, true);
      }

      if (resetValues != null) {
        RenderKitUtils.appendProperty(ajaxCommand, "resetValues", resetValues, false);
      }

      if (!params.isEmpty()) {
        for (ClientBehaviorContext.Parameter param : params) {
          RenderKitUtils.appendProperty(ajaxCommand, param.getName(), param.getValue());
        }
      }

      ajaxCommand.append("}");
    }

    ajaxCommand.append(")");

    return ajaxCommand.toString();
  }
コード例 #13
0
  @Override
  public void encodeBegin(FacesContext context, UIComponent component) throws IOException {

    // Hoy por hoy se tiene que hacer de esta manera
    rendererParamsNotNull(context, component);

    if (!shouldEncode(component)) {
      return;
    }

    // Which button type (SUBMIT, RESET, or BUTTON) should we generate?
    String type = getButtonType(component);

    ResponseWriter writer = context.getResponseWriter();
    assert (writer != null);

    String label = "";
    Object value = ((UICommand) component).getValue();
    if (value != null) {
      label = value.toString();
    }

    /*
     * If we have any parameters and the button type is submit or button,
     * then render Javascript to use later.
     * RELEASE_PENDING this logic is slightly wrong - we should buffer the user onclick, and use it later.
     * Leaving it for when we decide how to do script injection.
     */

    Collection<ClientBehaviorContext.Parameter> params = getBehaviorParameters(component);
    if (!params.isEmpty() && (type.equals("submit") || type.equals("button"))) {
      RenderKitUtils.renderJsfJs(context);
    }

    String imageSrc = (String) component.getAttributes().get("image");
    writer.startElement("input", component);
    writeIdAttributeIfNecessary(context, writer, component);
    String clientId = component.getClientId(context);
    if (imageSrc != null) {
      writer.writeAttribute("type", "image", "type");
      writer.writeURIAttribute(
          "src", RenderKitUtils.getImageSource(context, component, "image"), "image");
      writer.writeAttribute("name", clientId, "clientId");
    } else {
      writer.writeAttribute("type", type, "type");
      writer.writeAttribute("name", clientId, "clientId");
      writer.writeAttribute("value", label, "value");
    }

    RenderKitUtils.renderPassThruAttributes(
        context, writer, component, ATTRIBUTES, getNonOnClickBehaviors(component));

    RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer, component);

    String styleClass = (String) component.getAttributes().get("styleClass");
    if (styleClass != null && styleClass.length() > 0) {
      writer.writeAttribute("class", styleClass, "styleClass");
    }

    // EasyTech
    // Data-*
    for (String key : component.getAttributes().keySet()) {
      if (key.startsWith("data-"))
        writer.writeAttribute(key, component.getAttributes().get(key), key);
    }

    RenderKitUtils.renderOnclick(context, component, params, null, false);

    writer.endElement("input");
  }