/**
   * On submit action.
   *
   * @param request the request
   * @param response the response
   * @param command the command
   * @param errors the errors
   */
  @Override
  protected void onSubmitAction(
      ActionRequest request, ActionResponse response, Object command, BindException errors) {
    ProducerVideoDataInputEditModel model = (ProducerVideoDataInputEditModel) command;

    // upload -- enctype="multipart/form-data"

    if (PortletFileUpload.isMultipartContent(request)) doUpload(request, response, model);
    // delete requested files
    String action = request.getParameter("action");
    Integer vidId = new Integer(request.getParameter("videoId"));
    // update video-object for model

    // here get video object
    List<Video> videoList = ((VideoDao) getDaoBeanFactory().getBean("videoDao")).getById(vidId);
    Video video = videoList.iterator().next();
    // -- video object end

    try {
      // delete video request
      if (action.equals("deleteVideo")) {
        deleteMp3(model);
        model.setMp3File(null);
        deleteM4v(model);
        model.setM4vFile(null);
        deletePdf(model);
        model.setPdfFile(null);
        deleteM4a(model);
        model.setM4aFile(null);
        deleteTar(model);
        // has to be at the and
        deleteVideo(model);
      }
      // delete mp3 request
      if (action.equals("deleteMp3")) {
        deleteMp3(model);
        model.setMp3File(null);
      }
      // delete m4v request
      if (action.equals("deleteM4v")) {
        deleteM4v(model);
        model.setM4vFile(null);
      }
      // delete m4a request
      if (action.equals("deleteM4a")) {
        deleteM4a(model);
        model.setM4aFile(null);
      }
      // delete pdf request
      if (action.equals("deletePdf")) {
        deletePdf(model);
        model.setPdfFile(null);
      }
      // upload request
      if (action.equals("upload")) {
        // check for mp3 or mp4 file
        // here update mp3-file in model
        try {
          if (video.getMp3File().isFile()) model.setMp3File(video.getMp3File().toString());
        } catch (NullPointerException npe) {
        }

        // update model
        model.setVideo(video);
        model.setURL(null);
      }

    } catch (Exception e) {
    }
  }
  /**
   * Form backing object.
   *
   * @param request the request
   * @return the object
   */
  @Override
  protected Object formBackingObject(PortletRequest request) {
    ProducerVideoDataInputEditModel model = new ProducerVideoDataInputEditModel();
    String vid = request.getParameter("videoId");

    try {
      int vidId = new Integer(vid);
      Video video =
          ((VideoDao) getDaoBeanFactory().getBean("videoDao")).getById(vidId).iterator().next();
      Host host =
          ((HostDao) getDaoBeanFactory().getBean("hostDao"))
              .getById(video.getHostId())
              .iterator()
              .next();
      model.setHost(host);
      String remoteUserId = request.getRemoteUser();
      Integer ruid = new Integer(remoteUserId);
      // check user
      if (video.getProducerId() != ruid) {
        video.setId(-1);
      }
      Producer producer =
          ((ProducerDao) getDaoBeanFactory().getBean("producerDao"))
              .getByUserId(ruid)
              .iterator()
              .next();
      model.setProducer(producer);

      Metadata metadata =
          ((MetadataDao) getDaoBeanFactory().getBean("metadataDao"))
              .getById(video.getMetadataId())
              .iterator()
              .next();
      model.setMetadata(metadata);

      Lectureseries lectureseries =
          ((LectureseriesDao) getDaoBeanFactory().getBean("lectureseriesDao"))
              .getById(video.getLectureseriesId())
              .iterator()
              .next();
      model.setLectureseries(lectureseries);

      if (video.getFilename() == null) {
        model.setM4vFile(null);
        model.setMp3File(null);
        model.setPdfFile(null);
        model.setM4aFile(null);
      } else {
        String preffix = "";

        if (video.isOpenaccess()) {
          preffix = video.getPreffix();
          model.setOpenaccess(true);
          model.setSecureUrl(null);
        } else {
          preffix = video.getSPreffix();
          model.setOpenaccess(false);
          model.setSecureUrl(video.getSecureUrl());
        }

        // check, if existent on the hard disc
        String mp3File = preffix + ".mp3";
        String pdfFile = preffix + ".pdf";
        String m4vFile = preffix + ".m4v";
        String m4aFile = preffix + ".m4a";

        File fMp3 =
            new File(
                L2goPropsUtil.get("lecture2go.media.repository")
                    + "/"
                    + host.getServerRoot()
                    + "/"
                    + producer.getHomeDir()
                    + "/"
                    + mp3File);
        File fPdf =
            new File(
                L2goPropsUtil.get("lecture2go.media.repository")
                    + "/"
                    + host.getServerRoot()
                    + "/"
                    + producer.getHomeDir()
                    + "/"
                    + pdfFile);
        File fM4v =
            new File(
                L2goPropsUtil.get("lecture2go.media.repository")
                    + "/"
                    + host.getServerRoot()
                    + "/"
                    + producer.getHomeDir()
                    + "/"
                    + m4vFile);
        File fM4a =
            new File(
                L2goPropsUtil.get("lecture2go.media.repository")
                    + "/"
                    + host.getServerRoot()
                    + "/"
                    + producer.getHomeDir()
                    + "/"
                    + m4aFile);

        if (fMp3.isFile()) model.setMp3File(mp3File);
        else model.setMp3File(null);
        if (fPdf.isFile()) model.setPdfFile(pdfFile);
        else model.setPdfFile(null);
        if (fM4v.isFile()) model.setM4vFile(m4vFile);
        else model.setM4vFile(null);
        if (fM4a.isFile()) model.setM4aFile(m4aFile);
        else model.setM4aFile(null);
        if (video.isDownloadAllawed()) model.setDownloadAllawed(true);
        else model.setDownloadAllawed(false);
      }

      model.setDomainURL(L2goPropsUtil.get("lecture2go.web.home"));
      model.setVideo(video);
      model.setLectureseriesId(video.getLectureseriesId());
      model.setCommsyEmbed(true);
      model.setVideoId(video.getId());

    } catch (Exception e) {
      model.setVideoId(-1);
    }
    // set current seite for browsing!
    int currentSeite = 1;
    try {
      currentSeite = new Integer(request.getParameter("videoSeite"));
    } catch (Exception e) {
      // nothing to do
    }
    model.setCurrentSeite(currentSeite);
    model.setURL(null);
    return model;
  }