protected void encodeAll()

in trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/MediaRenderer.java [165:418]


  protected void encodeAll(
    FacesContext     context,
    RenderingContext rc,
    UIComponent      component,
    FacesBean        bean
    ) throws IOException
  {
    if (canSkipRendering(context, rc, component))
      return;

    // get the mime type
    String mimeType = _getMimeType(component, bean);

    // extract the primary cotnent type from the content mime type
    String primaryContentType = _getPrimaryContentType(mimeType);

    MediaRenderer.PlayerData playerData = _getPlayerData(rc, component, bean, mimeType,
      primaryContentType);

    ResponseWriter writer = context.getResponseWriter();

    String  source         = getSource(component, bean);
    String  contentType    = getContentType(component, bean);
    String  id             = getClientId(context, component);

    if (_LINK_PLAYER_DATA == playerData)
    {
      _renderLink(context,
                  rc,
                  component,
                  bean,
                  id,
                  source,
                  null,
                  contentType);
    }
    else
    {
     // determine which controls to display based on the primary
      // mime type
      MediaRenderer.ControlSet  controlSet = playerData.getControlSet(primaryContentType);



      MediaRenderer.ControlData imageWindowControlData =
               playerData.getImageWindowControlData(primaryContentType);

      MediaRenderer.ControlData controlData = (controlSet != null)
                                  ? controlSet.getControlData(
                                                 getControls(component, bean))
                                  : null;

      //
      // Determine which tags to use
      //
      boolean useEmbedTag = true;
      boolean useObjectTag = true;

      boolean isImage = _IMAGE_PLAYER_DATA == playerData;

      if (isImage)
      {
        useEmbedTag  = false;
        useObjectTag = false;
      }
      else
      {
        useEmbedTag  = useEmbed(rc);
        useObjectTag = !useEmbedTag;
      }

      String width = getWidth(component, bean);

      // since current players don't add to width, treat innerWidth
      // identically to width for now
      if (width == null)
        width = getInnerWidth(component, bean);

      // get whether this set of controls can be autosized.
      // embed elements can not be autosized.
      boolean canAutosize = playerData.canAlwaysAutosize ||
                            (controlData.canAutosize && !useEmbedTag);

      // compute default width for players that don't autosize
      if ((width == null) && !canAutosize)
      {
        Number defaultInnerWidth = getDefaultInnerWidth(primaryContentType);

        // use the greater of the default width of the content
        // and the preferred width of the controls
        width = ((defaultInnerWidth.intValue() >
                 controlData.preferredWidth.intValue())
                  ? defaultInnerWidth
                 : controlData.preferredWidth).toString();
      }



      // default the autostarting value
      String  autostartValue  = null;

      // default the playcount param name and value
      String playCountParamName = null;
      Object playCountParamValue = null;

      if (!isImage)
      {
        //
        // Handle looping attributes
        //
        Number playCountValue = getPlayCount(component, bean);

        if (playCountValue != null)
        {
          int playCount = playCountValue.intValue();

          if ((playCount != 1) && (playCount >= 0))
          {
            if (playCount == 0)
            {
              // some players handle infinite looping specially
              playCountParamName  = playerData.infiniteLoopParamName;
              playCountParamValue = playerData.infiniteLoopParamValue;
            }
            else
            {
              playCountParamName  = playerData.playCountParamName;
              playCountParamValue = playCountValue;
            }
          }
        }

        //
        // determine whether we should autostart
        //
        boolean autostarts = getAutostart(component, bean);
        if (autostarts != playerData.autostartByDefault)
        {
          // only write out an autostart value, if its different than
          // the default
          autostartValue = autostarts
            ? playerData.autostartTrueValue
            : playerData.autostartFalseValue;
        }
      }

      String standbyText = getStandbyText(component, bean);

      String height = null;
      // if image window and controls rendered separately
      if ( imageWindowControlData != null )
      {
        height = _getInnerHeight(component, bean, canAutosize, primaryContentType, controlData,
          playerData);

        // since image and controls are rendered separately, a value
        // is needed to associate them. The id will be used if it is not null,
        // otherwise an id will be generated for the value.
        String wireImageToControlsParamValue = id;

        _render( context,
                 rc,
                 component,
                 bean,
                 contentType,
                 id,
                 wireImageToControlsParamValue,
                 source,
                 standbyText,
                 width,
                 height,
                 autostartValue,
                 playCountParamName,
                 playCountParamValue,
                 playerData,
                 imageWindowControlData,
                 useEmbedTag,
                 useObjectTag,
                 isImage,
                 false);


        if ( controlData != _NULL_CONTROL_DATA )
        {
          writer.startElement("div", component);
          writer.endElement("div");


          height = IntegerUtils.getString(controlData.height);
          _render( context,
                   rc,
                   component,
                   bean,
                   contentType,
                   id,
                   wireImageToControlsParamValue,
                   null,
                   null,
                   width,
                   height,
                   null,
                   null,
                   null,
                   playerData,
                   controlData,
                   useEmbedTag,
                   useObjectTag,
                   isImage,
                   true);
        }
      }
      // if image window and controls rendered together
      else
      {
        height = _getHeight(component, bean, canAutosize, primaryContentType, controlData,
          playerData);

        _render( context,
                 rc,
                 component,
                 bean,
                 contentType,
                 id,
                 null,
                 source,
                 standbyText,
                 width,
                 height,
                 autostartValue,
                 playCountParamName,
                 playCountParamValue,
                 playerData,
                 controlData,
                 useEmbedTag,
                 useObjectTag,
                 isImage,
                 false);
      }


      if (useEmbedTag)
      {
        //
        // render the alternative link content
        //
        // =-=bts I feel that our backup rendering should be an icon that
        //        we retrieve using a pretected method
        //
        writer.startElement("noembed", component);
        _renderLink(context, rc, component, bean, null, source, null, contentType);
        writer.endElement("noembed");
      }
    }
  }