/**
  * Creates a XHTML element that refers the video identified by the specified URL.
  *
  * @param videoURL the URL of the video to display.
  * @return the XHTML element that displays the video.
  */
 private Element createVideoLink(final String videoURL, final Map<String, String> parameters) {
   a videoElement = new a();
   String width =
       (parameters.containsKey(PARAMETER_WIDTH) ? parameters.get(PARAMETER_WIDTH) : DEFAULT_WIDTH);
   String height =
       (parameters.containsKey(PARAMETER_HEIGHT)
           ? parameters.get(PARAMETER_HEIGHT)
           : DEFAULT_HEIGHT);
   videoElement.setStyle("display:block;width:" + width + "px;height:" + height + "px;");
   String videoId = VIDEO_PLAYER_ID + videoURL.hashCode();
   videoElement.setHref(videoURL).setID(videoId);
   return videoElement;
 }
  /**
   * Displays the form part corresponding to the video input. The form input is a way to change or
   * to remove the video file if this one exists.
   *
   * @param attachmentId the identifier of the attached file containing the video to display.
   * @param template the template of the field to which is mapped the video.
   * @param pagesContext the context of the displaying page.
   */
  private void displayVideoFormInput(
      final String attachmentId,
      final FieldTemplate template,
      final ElementContainer xhtmlContainer,
      final PagesContext pagesContext) {
    String fieldName = template.getFieldName();
    String language = pagesContext.getLanguage();
    String deletionIcon = Util.getIcon("delete");
    String deletionLab = Util.getString("removeFile", language);
    String videoURL = computeVideoURL(attachmentId, pagesContext);
    Operation defaultOperation = Operation.ADD;

    if (!videoURL.isEmpty()) {
      defaultOperation = Operation.UPDATE;
      Map<String, String> parameters = template.getParameters(pagesContext.getLanguage());
      parameters.remove(PARAMETER_WIDTH);
      parameters.remove(PARAMETER_HEIGHT);
      // a link to the video
      Element videoLink = createVideoLink(videoURL, parameters);

      // a link to the deletion operation
      img deletionImage = new img();
      deletionImage
          .setAlt(deletionLab)
          .setSrc(deletionIcon)
          .setWidth(15)
          .setHeight(15)
          .setAlt(deletionLab)
          .setTitle(deletionLab);
      a removeLink = new a();
      removeLink
          .setHref("#")
          .addElement(deletionImage)
          .setOnClick(
              "javascript: document.getElementById('"
                  + fieldName
                  + "Video').style.display='none'; document."
                  + pagesContext.getFormName()
                  + "."
                  + fieldName
                  + OPERATION_KEY
                  + ".value='"
                  + Operation.DELETION.name()
                  + "';");
      div videoDiv = new div();
      videoDiv.setID(fieldName + "Video");
      videoDiv.setClass("video");
      videoDiv.addElement(videoLink);
      videoDiv.addElement("&nbsp;");
      videoDiv.addElement(removeLink);

      xhtmlContainer.addElement(videoDiv);
    }

    // the input from which a video file can be selected
    input fileInput = new input();
    fileInput.setID(fieldName);
    fileInput.setType("file");
    fileInput.setSize(50);
    fileInput.setName(fieldName);
    input attachmentInput = new input();
    attachmentInput
        .setType("hidden")
        .setName(fieldName + Field.FILE_PARAM_NAME_SUFFIX)
        .setValue(attachmentId)
        .setID(fieldName + Field.FILE_PARAM_NAME_SUFFIX);
    input operationInput = new input();
    operationInput
        .setType("hidden")
        .setName(fieldName + OPERATION_KEY)
        .setValue(defaultOperation.name())
        .setID(fieldName + OPERATION_KEY);
    div selectionDiv = new div();
    selectionDiv.setID(fieldName + "Selection");
    selectionDiv.addElement(fileInput);
    selectionDiv.addElement(attachmentInput);
    selectionDiv.addElement(operationInput);
    if (template.isMandatory() && pagesContext.useMandatory()) {
      selectionDiv.addElement(Util.getMandatorySnippet());
    }
    xhtmlContainer.addElement(selectionDiv);

    Element player =
        createVideoPlayer(videoURL, template.getParameters(pagesContext.getLanguage()));
    xhtmlContainer.addElement(player);
  }